angulus/
lib.rs

1//! This crate provides two types ([`Angle`] and [`AngleUnbounded`]) that both represent an angle value
2//! with no specific unit (radian, degree, etc.).
3//!
4//! They can be used in place of `f32` and `f64` for angle manipulations.
5//!
6//! # [`Angle`] vs [`AngleUnbounded`]
7//!
8//! [`Angle`] is a specific point of the circle.
9//!
10//! ```
11//! # use angulus::Angle;
12//! let a = Angle::from_degrees(90.0);
13//! let b = Angle::from_degrees(450.0);
14//!
15//! assert_eq!(a, b);
16//! ```
17//!
18//! While [`AngleUnbounded`] preserves the "number of turns".
19//!
20//! ```
21//! # use angulus::AngleUnbounded;
22//! let a = AngleUnbounded::from_degrees(90.0);
23//! let b = AngleUnbounded::from_degrees(450.0);
24//!
25//! assert_ne!(a, b);
26//! ```
27//!
28//! # The main range
29//!
30//! The main range for an angle is :
31//!
32//! - `(-π, π]` radians
33//! - `(-180, 180]` degrees
34//! - `(-0.5, 0.5]` turns
35//! - `(-200, 200]` gradians
36//!
37//! # Display
38//!
39//! Since [`Angle`] and [`AngleUnbounded`] are unit-agnostic, they cannot implement the [`Display`][std::fmt::Display] trait.
40//!
41//! To display an angle with a specific unit, wrap it in one of the unit struct of [the `units` module][units].
42//!
43//! # Crate features
44//!
45//! - `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.
46//! - `libm`: use the [libm crate](https://docs.rs/libm/latest/libm/) for the math methods (sin, cos, tan) when `std` is disabled.
47//! - `serde`: enable serialization and deserialization with the [serde crate](https://docs.rs/serde/latest/serde/).
48//! - `rand`: enable generation of random angle with the [rand crate](https://docs.rs/rand/latest/rand/).
49
50#![cfg_attr(not(feature = "std"), no_std)]
51#![cfg_attr(docsrs, feature(doc_auto_cfg))]
52
53#[cfg(feature = "serde")]
54pub mod serde;
55
56#[cfg(feature = "rand")]
57pub mod rand;
58
59mod angle;
60pub mod float;
61mod macros;
62mod to_angle;
63mod unbounded;
64pub mod units;
65
66pub use angle::Angle;
67pub use to_angle::ToAngle;
68pub use unbounded::AngleUnbounded;
69
70#[doc = include_str!("../README.md")]
71#[cfg(all(
72    doctest,
73    any(feature = "std", feature = "libm") // Readme uses math methods.
74))]
75pub struct ReadmeDoctests;
76
77/// Type alias for [`Angle::<f32>`].
78pub type Angle32 = Angle<f32>;
79
80/// Type alias for [`Angle::<f64>`].
81pub type Angle64 = Angle<f64>;
82
83/// Type alias for [`AngleUnbounded::<f32>`].
84pub type AngleUnbounded32 = AngleUnbounded<f32>;
85
86/// Type alias for [`AngleUnbounded::<f64>`].
87pub type AngleUnbounded64 = AngleUnbounded<f64>;