Skip to content

Modulo arithmetic as class invariants for heading, pitch, bank #13

Open
@oktal3700

Description

@oktal3700

Resulting from a discussion about headings in the range [-180,180) being displayed by simulator component, I think that does not make any sense. Headings are always in [0,360) and this should be a class invariant. It would be done internally in CHeading so that client code is not littered with lots of calls to normalize methods.

In the same step, pitch should be in [-90,90) and bank should be in [-180,180). This will involve some refactoring into a base class CRotation, derived from CAngle. Then CHeading, CPitch, and CBank would derived from CRotation.

Design considerations:

  • The Liskov Substitution Principle advises that inheritance might be the wrong tool to use here, as CRotation can not be a true generalisation of CAngle.
  • The design should prevent accidental conversions between the three derived classes, which could happen via the base class if we are not careful.
  • We already have CEarthAngle, CLatitude, and CLongitude which should be doing a similar thing.
  • CTrack should have similar semantics. (Is it still needed?)
  • Will CAngle still be needed as a standalone class?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestgood first issueGood for newcomersrefactorChange code structure without affecting behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions