Skip to main content

Module angle

Module angle 

Source
Expand description

Angles tagged with their reference frame.

With bare f64, calculate_true_bearing(bearing, variation) and calculate_true_bearing(variation, bearing) both compile and both yield a plausible course. Here a CompassCourse cannot be passed where a MagneticCourse is expected, nor a Variation where a course is expected.

The types also enforce range: a Direction is always finite and in [0°, 360°), so functions consuming one cannot fail on range and return no Result.

§Example

use kinavis_kernel::{CompassCourse, Deviation, MagneticCourse, Variation};

let cc = CompassCourse::new(3.0)?;
let variation = Variation::new(-2.7)?;

// Out-of-range and non-finite inputs are rejected at construction.
assert!(CompassCourse::new(400.0).is_err());
assert!(Variation::new(f64::NAN).is_err());

// 360° is accepted and normalised to 0°.
assert_eq!(CompassCourse::new(360.0)?.degrees(), 0.0);

// Arbitrary values are wrapped explicitly.
assert_eq!(MagneticCourse::wrap(-10.0)?.degrees(), 350.0);

Structs§

Compass
Compass north of the ship’s magnetic compass.
Deviation
Compass deviation: angle from magnetic north to compass north.
Direction
Direction in [0°, 360°), tagged with its reference frame.
Gyro
Gyrocompass north.
Magnetic
Magnetic north.
RelativeBearing
Bearing clockwise from the ship’s head, in [0°, 360°).
True
True (geographic) north.
Variation
Magnetic variation: angle from true north to magnetic north.

Enums§

CardinalPoint
Cardinal or intercardinal compass point.
Side
Side relative to the bow.

Constants§

MAX_DEVIATION_DEG
Maximum magnitude of a compass deviation, degrees.
MAX_VARIATION_DEG
Maximum magnitude of a magnetic variation, degrees.

Traits§

Frame
Reference frame of a Direction.

Functions§

wrap180
Normalises a finite angle into [-180.0, 180.0).
wrap360
Normalises a finite angle into [0.0, 360.0).

Type Aliases§

CompassBearing
Bearing, compass. Alias of CompassCourse.
CompassCourse
Course or bearing, compass.
GyroBearing
Bearing, gyro. Alias of GyroCourse.
GyroCourse
Course, gyro.
MagneticBearing
Bearing, magnetic. Alias of MagneticCourse.
MagneticCourse
Course or bearing, magnetic.
TrueBearing
Bearing, true. Alias of TrueCourse.
TrueCourse
Course or bearing, true.