[][src]Struct integer_angles::Angle

pub struct Angle { /* fields omitted */ }

Implements an angle structure where angles are stored as integers.

Also keeps track of if the angle is going clockwise or counter-clockwise. It also stores a full circle different from a 0 degree arc. This gets rid of precision issues when storing angles as pi can be represented exactly if you change the units.


impl Angle[src]

pub fn is_zero(&self) -> bool[src]

Is this angle zero?

use integer_angles::Angle;


pub fn pi_over(n: i64) -> Angle[src]

Divide pi by some number, and return the result

use integer_angles::Angle;

assert_eq!(Angle::pi_over(2) * 2, Angle::pi());

pub fn set_clockwise(&self, clockwise: bool) -> Angle[src]

Don't change the direction of the angle, but possibly change the direction to get to that angle.

use integer_angles::Angle;

assert_eq!(Angle::pi_over(2).set_clockwise(true), -3 * Angle::pi_over(2));

pub fn add_or_subtract(&self, add: bool, other: Angle) -> Angle[src]

Add or subtract an angle depending on the value of the add boolean.

use integer_angles::Angle;

assert_eq!(Angle::pi() + Angle::pi(), Angle::pi().add_or_subtract(true, Angle::pi()));
assert_eq!(Angle::pi() - Angle::pi(), Angle::pi().add_or_subtract(false, Angle::pi()));

pub fn zero() -> Angle[src]

Create a 0-degree angle

use integer_angles::Angle;

assert_eq!(Angle::zero() * 2, Angle::zero());

pub fn wrapping_eq(&self, other: Angle) -> bool[src]

Determine if the angles are equal while allowing wrapping (meaning, 0 == 2pi).

use integer_angles::Angle;


pub fn wrapping_approx_eq(&self, other: Angle, error: Angle) -> bool[src]

pub fn length<T: RealField>(&self, radius: T) -> T[src]

Get the length of this as an arc given a specific radius

use integer_angles::Angle;
use nalgebra::RealField;

assert_eq!(Angle::zero().length(1.0f64), 0.0f64);
assert_eq!(Angle::two_pi().length(1.0f64), f64::two_pi());
assert_eq!(Angle::pi_2().length(1.0f64), f64::frac_pi_2());

pub fn pi_2() -> Angle[src]

Create an angle of pi over two counter-clockwise (for convenience).

use integer_angles::Angle;

assert_eq!(Angle::pi_2(), Angle::pi_over(2));
assert_eq!(Angle::pi_2() * 2, Angle::pi());

pub fn pi() -> Angle[src]

Create an angle of pi counter-clockwise.

use integer_angles::Angle;

assert_eq!(Angle::pi() / 2, Angle::pi_2());

pub fn two_pi() -> Angle[src]

Create an angle that is two_pi radians counter-clockwise.

use integer_angles::Angle;

assert_eq!(Angle::two_pi() * 2, Angle::pi() * 2);

pub fn units(&self) -> Option<u64>[src]

Get the number of units in this angle. This will be some number between 0 and 2^64 - 1 where a full circle is 2^64 units. If this represents a full cirle, None will be returned.

use integer_angles::Angle;

assert_eq!(Angle::zero().units(), Some(0));
assert_eq!(Angle::two_pi().units(), None);

pub fn clockwise(&self) -> bool[src]

Is this angle clockwise or counter-clockwise?

use integer_angles::Angle;

assert_eq!(Angle::pi().clockwise(), false);
assert_eq!((-Angle::pi()).clockwise(), true);

pub fn to_i64(&self) -> i64[src]

Returns the angle as an i64 (for doing math), and wrap 2pi to 0. If clockwise, return the negative of the result.

use integer_angles::Angle;

assert_eq!(Angle::pi().to_i64(), i64::min_value());
assert_eq!(Angle::two_pi().to_i64(), 0);
assert_eq!(-Angle::pi_2().to_i64(), i64::min_value() / 2);
assert_eq!(Angle::pi_2().to_i64(), -(i64::min_value() / 2));

pub fn cos<T: RealField>(&self) -> T[src]

Returns the cosine of the angle.

use integer_angles::Angle;

assert_eq!(Angle::zero().cos::<f64>(), 1.0f64);
assert_eq!(Angle::pi_2().cos::<f64>(), 0.0f64);
assert_eq!(Angle::pi().cos::<f64>(), -1.0f64);
assert_eq!((Angle::pi_2() * 3).cos::<f64>(), 0.0f64);
assert_eq!(Angle::two_pi().cos::<f64>(), 1.0f64);

pub fn sin<T: RealField>(&self) -> T[src]

Returns the cosine of the angle.

use integer_angles::Angle;

assert_eq!(Angle::zero().sin::<f64>(), 0.0f64);
assert_eq!(Angle::pi_2().sin::<f64>(), 1.0f64);
assert_eq!(Angle::pi().sin::<f64>(), 0.0f64);
assert_eq!((3 * Angle::pi_2()).sin::<f64>(), -1.0f64);
assert_eq!(Angle::two_pi().sin::<f64>(), 0.0f64);

pub fn tan<T: RealField>(&self) -> T[src]

Returns the tangent of the angle.

use integer_angles::Angle;

assert_eq!(Angle::pi_over(4).tan::<f64>(), 1.0f64);

pub fn acos<T: RealField>(x: T) -> Angle[src]

Compute the arccos of the number.

use integer_angles::Angle;

assert_eq!(Angle::acos(0.0f64), Angle::pi_over(2));

pub fn asin<T: RealField>(x: T) -> Angle[src]

Compute the arcsin of the number.

use integer_angles::Angle;

assert_eq!(Angle::asin(0.5f64).sin::<f64>(), 0.5f64);

pub fn atan<T: RealField>(x: T) -> Angle[src]

Compute the arctan of the number.

use integer_angles::Angle;

assert_eq!(Angle::atan(1.0f64), Angle::pi_over(4));

pub fn atan2<T: RealField>(y: T, x: T) -> Option<Angle>[src]

Compute the atan(y / x) but keeping the sign of y and x.

Returns None if both y and x are 0.

use integer_angles::Angle;

assert_eq!(Angle::atan2(1.0f64, 0.0).unwrap(), Angle::pi_2());
assert_eq!(Angle::atan2(0.0, 0.0f64), None);

pub fn radians<T: RealField>(self) -> T[src]

Convert the angle into radians. This can lose precision pretty easily

use integer_angles::Angle;
use nalgebra::RealField;

assert_eq!(Angle::pi().radians::<f64>(), f64::pi());

pub fn degrees<T: RealField>(self) -> T[src]

Trait Implementations

impl Add<Angle> for Angle[src]

type Output = Self

The resulting type after applying the + operator.

impl AddAssign<Angle> for Angle[src]

impl Arbitrary for Angle[src]

impl Clone for Angle[src]

impl Copy for Angle[src]

impl Debug for Angle[src]

impl Default for Angle[src]

impl<'de> Deserialize<'de> for Angle[src]

impl Div<i64> for Angle[src]

type Output = Angle

The resulting type after applying the / operator.

impl DivAssign<i64> for Angle[src]

impl Eq for Angle[src]

impl<T: RealField> From<T> for Angle[src]

fn from(real: T) -> Angle[src]

Convert from radians into an angle. Panics if NaN or infinity is received

use integer_angles::Angle;
use nalgebra::RealField;

assert_eq!(Angle::from(f64::pi()), Angle::pi());

impl Mul<Angle> for i64[src]

type Output = Angle

The resulting type after applying the * operator.

impl Mul<i64> for Angle[src]

type Output = Angle

The resulting type after applying the * operator.

impl MulAssign<i64> for Angle[src]

impl Neg for Angle[src]

type Output = Angle

The resulting type after applying the - operator.

impl Ord for Angle[src]

impl PartialEq<Angle> for Angle[src]

impl PartialOrd<Angle> for Angle[src]

impl Serialize for Angle[src]

impl StructuralEq for Angle[src]

impl StructuralPartialEq for Angle[src]

impl Sub<Angle> for Angle[src]

type Output = Self

The resulting type after applying the - operator.

impl SubAssign<Angle> for Angle[src]

Auto Trait Implementations

impl RefUnwindSafe for Angle

impl Send for Angle

impl Sync for Angle

impl Unpin for Angle

impl UnwindSafe for Angle

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized

impl<T> Borrow<T> for T where
    T: ?Sized

impl<T> BorrowMut<T> for T where
    T: ?Sized

impl<T, Right> ClosedAdd<Right> for T where
    T: Add<Right, Output = T> + AddAssign<Right>, 

impl<T, Right> ClosedDiv<Right> for T where
    T: Div<Right, Output = T> + DivAssign<Right>, 

impl<T, Right> ClosedMul<Right> for T where
    T: Mul<Right, Output = T> + MulAssign<Right>, 

impl<T> ClosedNeg for T where
    T: Neg<Output = T>, 

impl<T, Right> ClosedSub<Right> for T where
    T: Sub<Right, Output = T> + SubAssign<Right>, 

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> Scalar for T where
    T: PartialEq<T> + Copy + Any + Debug

impl<SS, SP> SupersetOf<SS> for SP where
    SS: SubsetOf<SP>, 

impl<T> ToOwned for T where
    T: Clone

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,