operator - method

Direction operator -(
  1. Direction other
)

Subtracts one Direction object from another.

Args: other (Direction): The other Direction object to subtract.

Returns: Direction: A new Direction object representing the difference between the two directions.

Implementation

Direction operator -(Direction other) {
  double newRoll = roll - other.roll;
  double newPitch = pitch - other.pitch;
  double newHeading = (heading - other.heading + 360) % 360;

  newRoll = (newRoll + 180) % 360 - 180;
  newPitch = (newPitch + 180) % 360 - 180;

  return Direction(
    roll: newRoll,
    pitch: newPitch,
    heading: newHeading,
  );
}