# [−][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 Div<i64> for Angle`[src]

#### `type Output = Angle`

The resulting type after applying the `/` operator.

### `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 Neg for Angle`[src]

#### `type Output = Angle`

The resulting type after applying the `-` operator.

### `impl Sub<Angle> for Angle`[src]

#### `type Output = Self`

The resulting type after applying the `-` operator.

## Blanket Implementations

### `impl<T> Same<T> for T`

#### `type Output = T`

Should always be `Self`

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