[][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.

Methods

impl Angle[src]

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

Is this angle zero?

use integer_angles::Angle;

assert!(Angle::zero().is_zero());
assert!(!Angle::pi().is_zero());

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 zero() -> Angle[src]

Create a 0-degree angle

use integer_angles::Angle;

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

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 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.

use integer_angles::Angle;

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

pub fn into<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().into::<f64>(), f64::pi());

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 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<T: RealField> From<T> for Angle[src]

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

Convert from radians into an angle.

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 PartialEq<Angle> for Angle[src]

impl PartialOrd<Angle> for Angle[src]

impl Serialize 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
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

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: Deserialize<'de>, 
[src]

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

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

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
[src]

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

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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>,