Crate angulus

Source
Expand description

This crate provides two types (Angle and AngleUnbounded) that both represent an angle value with no specific unit (radian, degree, etc.).

They can be used in place of f32 and f64 for angle manipulations.

§Angle vs AngleUnbounded

Angle is a specific point of the circle.

let a = Angle::from_degrees(90.0);
let b = Angle::from_degrees(450.0);

assert_eq!(a, b);

While AngleUnbounded preserves the “number of turns”.

let a = AngleUnbounded::from_degrees(90.0);
let b = AngleUnbounded::from_degrees(450.0);

assert_ne!(a, b);

§The main range

The main range for an angle is :

  • (-π, π] radians
  • (-180, 180] degrees
  • (-0.5, 0.5] turns
  • (-200, 200] gradians

§Display

Since Angle and AngleUnbounded are unit-agnostic, they cannot implement the Display trait.

To display an angle with a specific unit, wrap it in one of the unit struct of the units module.

§Crate features

  • std: by default angulus links to the standard library. Disable this feature to remove this dependency and be able to use angulus in #![no_std] crates.
  • libm: use the libm crate for the math methods (sin, cos, tan) when std is disabled.
  • serde: enable serialization and deserialization with the serde crate.
  • rand: enable generation of random angle with the rand crate.

Modules§

float
Defines which types can be used as a floating-point value for the angle.
randrand
Generate random angles with the rand crate.
serdeserde
(De)Serialization with the serde crate.
units
Wrappers to represent an angle with a specific unit.

Structs§

Angle
Represents a point on the circle as a unit-agnostic angle.
AngleUnbounded
Represents a point on the circle as a unit-agnostic angle.

Traits§

ToAngle
Helper trait to convert a numerical value into an angle.

Type Aliases§

Angle32
Type alias for Angle::<f32>.
Angle64
Type alias for Angle::<f64>.
AngleUnbounded32
Type alias for AngleUnbounded::<f32>.
AngleUnbounded64
Type alias for AngleUnbounded::<f64>.