integer_angles/lib.rs
1//! # Angles Done With Integers
2//!
3//! ```
4//! use integer_angles::Angle;
5//!
6//! assert_eq!(Angle::pi_2().cos::<f64>(), 0.0f64);
7//! ```
8//!
9//! Here we go, down the rabbit hole of floating-point instability and all sorts of crazy problems
10//! that come with representing angles within computers. The goal of this library is to solve the
11//! following problems:
12//!
13//! * If you have multiple angles, and you add them together, the result you get should be exactly
14//! correct.
15//! * If you add multiple angles together and end up with a full circle, that should be exactly a
16//! full circle.
17//! * If you do trigonometry of some multiple of `pi` radians, you should end up with the exact
18//! answer.
19//! * Keep track of the difference between a `0` radian angle, and a `2 pi` radians angle.
20//! * Keep track of if the angle is going clockwise or counter-clockwise starting at the positive x
21//! axis.
22//! * Do not allow the user to represent an angle outside the range [`-2 pi` to `2 pi`]
23//!
24//! The way this library does it's magic is the following:
25//!
26//! * Stores the angle in units of `[0..2**64)` where each unit is `1/(2**64)`th of a circle.
27//! * This means that adding and subtracting angles (with wrapping) will always be correct, and
28//! always within the specified range. (No more range reduction!)
29//! * This also means that you can (inside the library) *cast* an angle from `u64` to `i64` and
30//! end up with the same angle.
31//! * Set a flag for a full circle, and allow units to be `0` for a `0` degree angle.
32//! * This also means, for example, `pi` radians is exactly equal to `1<<63` units in this library.
33//! * Keep track of the clockwise/counterclockwise-ness of the angle using a separate flag.
34//! * Solves the Chebyshev to compute the sin/cos/tan using the new units (with more precision
35//! than the standard library).
36//! * Uses a binary search (at the moment) to compute asin/acos/atan/atan2.
37//!
38//! Caveats:
39//! * This library is slower than using an f64 (about 10 times slower to compute `cos`. You've
40//! gotta wait a whole 80 ns to get the result!).
41//! * ... Probably other things.
42
43mod angle;
44
45#[cfg(test)]
46mod tests;
47
48#[cfg(test)]
49#[macro_use(quickcheck)]
50extern crate quickcheck_macros;
51
52pub use angle::Angle;