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.
- Relative
Bearing - 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§
- Cardinal
Point - 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§
Functions§
- wrap180
- Normalises a finite angle into
[-180.0, 180.0). - wrap360
- Normalises a finite angle into
[0.0, 360.0).
Type Aliases§
- Compass
Bearing - Bearing, compass. Alias of
CompassCourse. - Compass
Course - Course or bearing, compass.
- Gyro
Bearing - Bearing, gyro. Alias of
GyroCourse. - Gyro
Course - Course, gyro.
- Magnetic
Bearing - Bearing, magnetic. Alias of
MagneticCourse. - Magnetic
Course - Course or bearing, magnetic.
- True
Bearing - Bearing, true. Alias of
TrueCourse. - True
Course - Course or bearing, true.