Expand description
Unit agnostic angle.
Overview
Using simple floating point numbers to store an angle value is error-prone : you may add two angle with one in radians and the second in degrees or you may try to compute the cosine of a value in degrees and get an unexpected result.
Angle and AngleUnbounded represent an angle value with no specific unit.
Angle vs AngleUnbounded
Both represent a point on the circle as a unit agnostic angle.
But Angle considere two different values of the same point as the same angle :
let a = Angle::from_degrees(90.0);
let b = Angle::from_degrees(450.0);
assert_eq!(a, b);While AngleUnbounded considere those value as two different angle :
let a = AngleUnbounded::from_degrees(90.0);
let b = AngleUnbounded::from_degrees(450.0);
assert_ne!(a, b);From value to angle
To create an angle from a value, you can use the from_* methods with the unit of the value…
let deg = Angle::from_degrees(90.0);
let rad = Angle::from_radians(3.14);
let turns = Angle::from_turns(0.75);
let grad = Angle::from_gradians(50.0);or you use the ToAngle trait directly on the value.
let deg = 90.0.deg();
let rad = 3.14.rad();
let turns = 0.75.turns();
let grad = 50.0.grad();From angle to value
To convert back an angle to a value you can use the to_* methods with the desired unit.
let a = Angle32::QUARTER;
assert_eq!(a.to_radians(), std::f32::consts::FRAC_PI_2);
assert_eq!(a.to_degrees(), 90.0);
assert_eq!(a.to_turns(), 0.25);
assert_eq!(a.to_gradians(), 100.0);Display
Since Angle and AngleUnbounded are unit agnotic they didn’t implement the Display trait.
But you can use one of the unit wrapper from the units module to specify a unit.
Crate features
serde: (De)Serialization with the serde crate.rand: Generate random angles with the rand crate.
Modules
Macros
Structs
Traits
Type Definitions
Angle::<f32>.Angle::<f64>.AngleUnbounded::<f32>.AngleUnbounded::<f64>.