Angle

Enum Angle 

Source
pub enum Angle<T = f64> {
    Radians(T),
    Degrees(T),
}
Expand description

An angle.

Might be a value in degrees or in radians.

Variants§

§

Radians(T)

The angle value in radians.

§

Degrees(T)

The angle value in degrees.

Implementations§

Source§

impl<T: Copy + NumCast> Angle<T>

Source

pub fn in_radians(self) -> T

Yield the value encoded in radians.

Source

pub fn in_degrees(self) -> T

Yield the value encoded in degrees.

Source

pub fn eighth() -> Angle<T>

An angle of 45°.

Source

pub fn quarter() -> Angle<T>

An angle of 90° (right angle).

Source

pub fn half() -> Angle<T>

An angle of 180° (straight).

Source

pub fn full() -> Angle<T>

An angle of 360° (perigon).

Source§

impl<T: Copy + Num + NumCast + PartialOrd> Angle<T>

Source

pub fn normalized(self) -> Self

Create a new angle by normalizing the value into the range of [0, 2π) rad.

§Examples
let alpha = Degrees(-90.0f64).normalized();
assert!((alpha.in_degrees() - 270.0).abs() < 1.0e-10);

let beta = Radians(2.0 * PI).normalized();
assert!((beta.in_radians() - 0.0).abs() < 1.0e-10);
Source§

impl<T: Float> Angle<T>

Source

pub fn min_dist(self, other: Angle<T>) -> Angle<T>

Computes the minimal unsigned distance between two normalized angles. Returns an angle in the range of [0, π] rad.

let distance = Degrees(345.0).min_dist(Degrees(15.0));
assert!((distance.in_degrees() - 30.0) < 1.0e-10);
Source§

impl<T: Signed> Angle<T>

Source

pub fn abs(&self) -> Self

Compute the absolute angle.

Source

pub fn signum(&self) -> Self

Returns a number that represents the sign of self.

  • 1.0 if the number is positive, +0.0 or Float::infinity()
  • -1.0 if the number is negative, -0.0 or Float::neg_infinity()
  • Float::nan() if the number is Float::nan()
Source

pub fn is_positive(&self) -> bool

Returns true if the number is positive and false if the number is zero or negative

Source

pub fn is_negative(&self) -> bool

Returns true if the number is negative and false if the number is zero or positive.

Source§

impl<T: Float + NumCast> Angle<T>

Source

pub fn sin(self) -> T

Compute the sine of the angle.

Source

pub fn cos(self) -> T

Compute the cosine of the angle.

Source

pub fn tan(self) -> T

Compute the tangent of the angle.

Source

pub fn sin_cos(self) -> (T, T)

Simultaneously compute the sine and cosine of the number, x.

Return (sin(x), cos(x)).

Trait Implementations§

Source§

impl<T: AbsDiffEq + Copy + NumCast> AbsDiffEq for Angle<T>

Source§

type Epsilon = <T as AbsDiffEq>::Epsilon

Used for specifying relative comparisons.
Source§

fn default_epsilon() -> Self::Epsilon

The default tolerance to use when testing values that are close together. Read more
Source§

fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool

A test for equality that uses the absolute difference to compute the approximate equality of two numbers.
Source§

fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool

The inverse of AbsDiffEq::abs_diff_eq.
Source§

impl<T: Add + Copy + NumCast> Add for Angle<T>

Source§

type Output = Angle<<T as Add>::Output>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Angle<T>) -> Self::Output

Performs the + operation. Read more
Source§

impl<T: AddAssign + Copy + NumCast> AddAssign for Angle<T>

Source§

fn add_assign(&mut self, rhs: Angle<T>)

Performs the += operation. Read more
Source§

impl<T: Clone> Clone for Angle<T>

Source§

fn clone(&self) -> Angle<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for Angle<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Default> Default for Angle<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T: Display> Display for Angle<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Div<Angle<f32>> for f32

Source§

type Output = Angle<f32>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Angle<f32>) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<Angle<i16>> for i16

Source§

type Output = Angle<i16>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Angle<i16>) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<Angle<i32>> for i32

Source§

type Output = Angle<i32>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Angle<i32>) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<Angle<i64>> for i64

Source§

type Output = Angle<i64>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Angle<i64>) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<Angle<i8>> for i8

Source§

type Output = Angle<i8>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Angle<i8>) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<Angle<isize>> for isize

Source§

type Output = Angle<isize>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Angle<isize>) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<Angle<u16>> for u16

Source§

type Output = Angle<u16>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Angle<u16>) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<Angle<u32>> for u32

Source§

type Output = Angle<u32>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Angle<u32>) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<Angle<u64>> for u64

Source§

type Output = Angle<u64>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Angle<u64>) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<Angle<u8>> for u8

Source§

type Output = Angle<u8>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Angle<u8>) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<Angle<usize>> for usize

Source§

type Output = Angle<usize>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Angle<usize>) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<Angle> for f64

Source§

type Output = Angle

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Angle<f64>) -> Self::Output

Performs the / operation. Read more
Source§

impl<T: Div + Copy> Div<T> for Angle<T>

Source§

type Output = Angle<<T as Div>::Output>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: T) -> Self::Output

Performs the / operation. Read more
Source§

impl<T: DivAssign> DivAssign<T> for Angle<T>

Source§

fn div_assign(&mut self, rhs: T)

Performs the /= operation. Read more
Source§

impl<T: Hash> Hash for Angle<T>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Mul<Angle<f32>> for f32

Source§

type Output = Angle<f32>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Angle<f32>) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Angle<i16>> for i16

Source§

type Output = Angle<i16>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Angle<i16>) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Angle<i32>> for i32

Source§

type Output = Angle<i32>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Angle<i32>) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Angle<i64>> for i64

Source§

type Output = Angle<i64>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Angle<i64>) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Angle<i8>> for i8

Source§

type Output = Angle<i8>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Angle<i8>) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Angle<isize>> for isize

Source§

type Output = Angle<isize>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Angle<isize>) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Angle<u16>> for u16

Source§

type Output = Angle<u16>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Angle<u16>) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Angle<u32>> for u32

Source§

type Output = Angle<u32>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Angle<u32>) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Angle<u64>> for u64

Source§

type Output = Angle<u64>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Angle<u64>) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Angle<u8>> for u8

Source§

type Output = Angle<u8>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Angle<u8>) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Angle<usize>> for usize

Source§

type Output = Angle<usize>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Angle<usize>) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Angle> for f64

Source§

type Output = Angle

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Angle<f64>) -> Self::Output

Performs the * operation. Read more
Source§

impl<T: Mul + Copy> Mul<T> for Angle<T>

Source§

type Output = Angle<<T as Mul>::Output>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: T) -> Self::Output

Performs the * operation. Read more
Source§

impl<T: MulAssign> MulAssign<T> for Angle<T>

Source§

fn mul_assign(&mut self, rhs: T)

Performs the *= operation. Read more
Source§

impl<T: Neg> Neg for Angle<T>

Source§

type Output = Angle<<T as Neg>::Output>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl<T: Ord + Eq + Copy + NumCast> Ord for Angle<T>

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T: Copy + NumCast + PartialEq> PartialEq for Angle<T>

Source§

fn eq(&self, other: &Angle<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: PartialOrd + Copy + NumCast> PartialOrd for Angle<T>

Source§

fn partial_cmp(&self, other: &Angle<T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T: RelativeEq + Copy + NumCast> RelativeEq for Angle<T>

Source§

fn default_max_relative() -> Self::Epsilon

The default relative tolerance for testing values that are far-apart. Read more
Source§

fn relative_eq( &self, other: &Self, epsilon: Self::Epsilon, max_relative: Self::Epsilon, ) -> bool

A test for equality that uses a relative comparison if the values are far apart.
Source§

fn relative_ne( &self, other: &Rhs, epsilon: Self::Epsilon, max_relative: Self::Epsilon, ) -> bool

The inverse of RelativeEq::relative_eq.
Source§

impl<T: Sub + Copy + NumCast> Sub for Angle<T>

Source§

type Output = Angle<<T as Sub>::Output>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Angle<T>) -> Self::Output

Performs the - operation. Read more
Source§

impl<T: SubAssign + Copy + NumCast> SubAssign for Angle<T>

Source§

fn sub_assign(&mut self, rhs: Angle<T>)

Performs the -= operation. Read more
Source§

impl<T: UlpsEq + Copy + NumCast> UlpsEq for Angle<T>

Source§

fn default_max_ulps() -> u32

The default ULPs to tolerate when testing values that are far-apart. Read more
Source§

fn ulps_eq(&self, other: &Self, epsilon: Self::Epsilon, max_ulps: u32) -> bool

A test for equality that uses units in the last place (ULP) if the values are far apart.
Source§

fn ulps_ne(&self, other: &Rhs, epsilon: Self::Epsilon, max_ulps: u32) -> bool

The inverse of UlpsEq::ulps_eq.
Source§

impl<T: Zero + Copy + NumCast> Zero for Angle<T>

Source§

fn zero() -> Self

Returns the additive identity element of Self, 0. Read more
Source§

fn is_zero(&self) -> bool

Returns true if self is equal to the additive identity.
Source§

fn set_zero(&mut self)

Sets self to the additive identity element of Self, 0.
Source§

impl<T: Copy> Copy for Angle<T>

Source§

impl<T: Copy + Eq + NumCast> Eq for Angle<T>

Source§

impl<T: Send> Send for Angle<T>

Auto Trait Implementations§

§

impl<T> Freeze for Angle<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Angle<T>
where T: RefUnwindSafe,

§

impl<T> Sync for Angle<T>
where T: Sync,

§

impl<T> Unpin for Angle<T>
where T: Unpin,

§

impl<T> UnwindSafe for Angle<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.