operator + method

Direction operator +(
  1. Direction other
)

Adds two Direction objects.

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

Returns: Direction: A new Direction object representing the sum of the two directions.

Implementation

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

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

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