Struct Angle

Source
pub struct Angle<F> { /* private fields */ }
Expand description

Represents a point on the circle as a unit-agnostic angle.

The parameter F is the floating-point type used to store the value.

§Behaviour

Two different values of the same point on the circle are the same Angle.

let a = Angle::from_degrees(90.0);
let b = Angle::from_degrees(450.0);

assert_eq!(a, b);

§Why doesn’t it implement PartialOrd ?

Because Angles represent points on the circle (i.e., not a numerical value), they cannot be ordered.

§The NaN angle

An angle can be NaN in the following cases:

  • Create an angle from a non-finite value;
let a = Angle::from_radians(f32::INFINITY);
assert!(a.is_nan());

let b = Angle::from_radians(f32::NAN);
assert!(b.is_nan());
  • Doing an operation that result into a non-finite value;
let a = Angle::DEG_90;
let b = a / 0.0;

assert!(b.is_nan());

Implementations§

Source§

impl<F: Float> Angle<F>

Source

pub const ZERO: Self

The angle of value zero.

Source

pub const EPSILON: Self

Source§

impl<F: Float> Angle<F>

Source

pub const RAD_PI: Self

The angle of π radians.

Source

pub const RAD_FRAC_PI_2: Self

The angle of π/2 radians.

Source

pub const RAD_FRAC_PI_3: Self

The angle of π/3 radians.

Source

pub const RAD_FRAC_PI_4: Self

The angle of π/4 radians.

Source

pub const RAD_FRAC_PI_6: Self

The angle of π/6 radians.

Source

pub const RAD_FRAC_PI_8: Self

The angle of π/8 radians.

Source§

impl<F: Float> Angle<F>

Source

pub const DEG_180: Self = Self::RAD_PI

The angle of 180°.

Source

pub const DEG_90: Self = Self::RAD_FRAC_PI_2

The angle of 90°.

Source

pub const DEG_60: Self = Self::RAD_FRAC_PI_3

The angle of 60°.

Source

pub const DEG_45: Self = Self::RAD_FRAC_PI_4

The angle of 45°.

Source

pub const DEG_30: Self = Self::RAD_FRAC_PI_6

The angle of 30°.

Source

pub const DEG_22_5: Self = Self::RAD_FRAC_PI_8

The angle of 22.5°.

Source§

impl<F: Float> Angle<F>

Source

pub const HALF: Self = Self::RAD_PI

The angle of a half of a circle (1/2 turns).

Source

pub const QUARTER: Self = Self::RAD_FRAC_PI_2

The angle of a quarter of a circle (1/4 turns).

Source

pub const SIXTH: Self = Self::RAD_FRAC_PI_3

The angle of a sixth of a circle (1/6 turns).

Source

pub const EIGHTH: Self = Self::RAD_FRAC_PI_4

The angle of a eighth of a circle (1/8 turns).

Source

pub const TWELFTH: Self = Self::RAD_FRAC_PI_6

The angle of a twelfth of a circle (1/12 turns).

Source

pub const SIXTEENTH: Self = Self::RAD_FRAC_PI_8

The angle of a sixteenth of a circle (1/16 turns).

Source§

impl<F: Float> Angle<F>

Source

pub const GRAD_200: Self = Self::RAD_PI

The angle of 200g.

Source

pub const GRAD_100: Self = Self::RAD_FRAC_PI_2

The angle of 100g.

Source

pub const GRAD_66_6: Self = Self::RAD_FRAC_PI_3

The angle of 66.6g.

Source

pub const GRAD_50: Self = Self::RAD_FRAC_PI_4

The angle of 50g.

Source

pub const GRAD_33_3: Self = Self::RAD_FRAC_PI_6

The angle of 33.3g.

Source

pub const GRAD_25: Self = Self::RAD_FRAC_PI_8

The angle of 25g.

Source§

impl<F> Angle<F>

Source

pub const fn from_radians_unchecked(radians: F) -> Self

Creates a new angle from a value in radians assuming it is already in the the range (-π, π].

Source§

impl<F: Float> Angle<F>

Source

pub fn from_radians(radians: F) -> Self

Creates a new angle from a value in radians.

Source

pub fn from_degrees(degrees: F) -> Self

Creates a new angle from a value in degrees.

Source

pub fn from_turns(turns: F) -> Self

Creates a new angle from a value in turns.

Source

pub fn from_gradians(gradians: F) -> Self

Creates a new angle from a value in gradians.

Source§

impl<F: Copy> Angle<F>

Source

pub const fn to_radians(self) -> F

The value of the angle in radians.

This value is in the range (-π, π].

Source§

impl<F: Float> Angle<F>

Source

pub fn to_degrees(self) -> F

The value of the angle in degrees.

This value is in the range (-180, 180].

Source

pub fn to_turns(self) -> F

The value of the angle in turns.

This value is in the range (-0.5, 0.5].

Source

pub fn to_gradians(self) -> F

The value of the angle in gradians.

This value is in the range (-200, 200].

Source§

impl<F: Float> Angle<F>

Source

pub fn is_nan(self) -> bool

Returns true if this angle is NaN.

See Angle documentation for more details.

Source§

impl<F: Copy> Angle<F>

Source

pub const fn to_unbounded(self) -> AngleUnbounded<F>

Converts this angle into an unbounded angle in the main range.

Source§

impl Angle<f32>

Source

pub fn to_f64(self) -> Angle<f64>

Converts the floating point type to f64.

Source§

impl Angle<f64>

Source

pub fn to_f32(self) -> Angle<f32>

Converts the floating point type to f32.

Source§

impl<F: FloatMath> Angle<F>

Source

pub fn sin(self) -> F

Available on crate features std or libm only.

Computes the sine.

Source

pub fn cos(self) -> F

Available on crate features std or libm only.

Computes the cosine.

Source

pub fn tan(self) -> F

Available on crate features std or libm only.

Computes the tangent.

Source

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

Available on crate features std or libm only.

Simultaneously computes the sine and cosine. Returns (sin(x), cos(x)).

Trait Implementations§

Source§

impl<F: Float> Add<&Angle<F>> for &Angle<F>

Source§

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

The resulting type after applying the + operator.
Source§

fn add(self, other: &Angle<F>) -> <Angle<F> as Add<Angle<F>>>::Output

Performs the + operation. Read more
Source§

impl<F: Float> Add<&Angle<F>> for Angle<F>

Source§

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

The resulting type after applying the + operator.
Source§

fn add(self, other: &Angle<F>) -> <Angle<F> as Add<Angle<F>>>::Output

Performs the + operation. Read more
Source§

impl<'a, F: Float> Add<Angle<F>> for &'a Angle<F>

Source§

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

The resulting type after applying the + operator.
Source§

fn add(self, other: Angle<F>) -> <Angle<F> as Add<Angle<F>>>::Output

Performs the + operation. Read more
Source§

impl<F: Float> Add for Angle<F>

Source§

type Output = Angle<F>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl<F: Float> AddAssign<&Angle<F>> for Angle<F>

Source§

fn add_assign(&mut self, other: &Angle<F>)

Performs the += operation. Read more
Source§

impl<F: Float> AddAssign for Angle<F>

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl<F: Clone> Clone for Angle<F>

Source§

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

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<F: Debug> Debug for Angle<F>

Source§

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

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

impl<F: Float> Default for Angle<F>

Source§

fn default() -> Self

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

impl<'de, F: Float + Deserialize<'de>> Deserialize<'de> for Angle<F>

Available on crate feature serde only.
Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<F: Float> Distribution<Angle<F>> for Standard
where Self: Distribution<F>,

Available on crate feature rand only.
Source§

fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Angle<F>

Generate a random value of T, using rng as the source of randomness.
Source§

fn sample_iter<R>(self, rng: R) -> DistIter<Self, R, T>
where R: Rng, Self: Sized,

Create an iterator that generates random values of T, using rng as the source of randomness. Read more
Source§

fn map<F, S>(self, func: F) -> DistMap<Self, F, T, S>
where F: Fn(T) -> S, Self: Sized,

Create a distribution of values of ‘S’ by mapping the output of Self through the closure F Read more
Source§

impl<F: Float> Div<&F> for &Angle<F>

Source§

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

The resulting type after applying the / operator.
Source§

fn div(self, other: &F) -> <Angle<F> as Div<F>>::Output

Performs the / operation. Read more
Source§

impl<F: Float> Div<&F> for Angle<F>

Source§

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

The resulting type after applying the / operator.
Source§

fn div(self, other: &F) -> <Angle<F> as Div<F>>::Output

Performs the / operation. Read more
Source§

impl<'a, F: Float> Div<F> for &'a Angle<F>

Source§

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

The resulting type after applying the / operator.
Source§

fn div(self, other: F) -> <Angle<F> as Div<F>>::Output

Performs the / operation. Read more
Source§

impl<F: Float> Div<F> for Angle<F>

Source§

type Output = Angle<F>

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl<F: Float> DivAssign<&F> for Angle<F>

Source§

fn div_assign(&mut self, other: &F)

Performs the /= operation. Read more
Source§

impl<F: Float> DivAssign<F> for Angle<F>

Source§

fn div_assign(&mut self, rhs: F)

Performs the /= operation. Read more
Source§

impl<F: Copy> From<Angle<F>> for AngleUnbounded<F>

Source§

fn from(angle: Angle<F>) -> Self

Converts to this type from the input type.
Source§

impl From<Angle<f32>> for Angle<f64>

Source§

fn from(value: Angle<f32>) -> Self

Converts to this type from the input type.
Source§

impl From<Angle<f64>> for Angle<f32>

Source§

fn from(value: Angle<f64>) -> Self

Converts to this type from the input type.
Source§

impl<F: Float> From<AngleUnbounded<F>> for Angle<F>

Source§

fn from(angle: AngleUnbounded<F>) -> Self

Converts to this type from the input type.
Source§

impl<F: Hash> Hash for Angle<F>

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 = <f32 as Mul<Angle<f32>>>::Output

The resulting type after applying the * operator.
Source§

fn mul(self, other: &Angle<f32>) -> <f32 as Mul<Angle<f32>>>::Output

Performs the * operation. Read more
Source§

impl Mul<&Angle<f32>> for f32

Source§

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

The resulting type after applying the * operator.
Source§

fn mul(self, other: &Angle<f32>) -> <f32 as Mul<Angle<f32>>>::Output

Performs the * operation. Read more
Source§

impl Mul<&Angle<f64>> for &f64

Source§

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

The resulting type after applying the * operator.
Source§

fn mul(self, other: &Angle<f64>) -> <f64 as Mul<Angle<f64>>>::Output

Performs the * operation. Read more
Source§

impl Mul<&Angle<f64>> for f64

Source§

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

The resulting type after applying the * operator.
Source§

fn mul(self, other: &Angle<f64>) -> <f64 as Mul<Angle<f64>>>::Output

Performs the * operation. Read more
Source§

impl<F: Float> Mul<&F> for &Angle<F>

Source§

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

The resulting type after applying the * operator.
Source§

fn mul(self, other: &F) -> <Angle<F> as Mul<F>>::Output

Performs the * operation. Read more
Source§

impl<F: Float> Mul<&F> for Angle<F>

Source§

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

The resulting type after applying the * operator.
Source§

fn mul(self, other: &F) -> <Angle<F> as Mul<F>>::Output

Performs the * operation. Read more
Source§

impl<'a> Mul<Angle<f32>> for &'a f32

Source§

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

The resulting type after applying the * operator.
Source§

fn mul(self, other: Angle<f32>) -> <f32 as Mul<Angle<f32>>>::Output

Performs the * operation. 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<'a> Mul<Angle<f64>> for &'a f64

Source§

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

The resulting type after applying the * operator.
Source§

fn mul(self, other: Angle<f64>) -> <f64 as Mul<Angle<f64>>>::Output

Performs the * operation. Read more
Source§

impl Mul<Angle<f64>> for f64

Source§

type Output = Angle<f64>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<'a, F: Float> Mul<F> for &'a Angle<F>

Source§

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

The resulting type after applying the * operator.
Source§

fn mul(self, other: F) -> <Angle<F> as Mul<F>>::Output

Performs the * operation. Read more
Source§

impl<F: Float> Mul<F> for Angle<F>

Source§

type Output = Angle<F>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<F: Float> MulAssign<&F> for Angle<F>

Source§

fn mul_assign(&mut self, other: &F)

Performs the *= operation. Read more
Source§

impl<F: Float> MulAssign<F> for Angle<F>

Source§

fn mul_assign(&mut self, rhs: F)

Performs the *= operation. Read more
Source§

impl<F: Float> Neg for &Angle<F>

Source§

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

The resulting type after applying the - operator.
Source§

fn neg(self) -> <Angle<F> as Neg>::Output

Performs the unary - operation. Read more
Source§

impl<F: Float> Neg for Angle<F>

Source§

type Output = Angle<F>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl<F: PartialEq> PartialEq for Angle<F>

Source§

fn eq(&self, other: &Angle<F>) -> 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<F> SampleRange<Angle<F>> for Range<Angle<F>>
where UniformFloat<F>: UniformSampler<X = F>, F: SampleBorrow<F> + Float,

Available on crate feature rand only.
Source§

fn sample_single<R: RngCore + ?Sized>(self, rng: &mut R) -> Angle<F>

Generate a sample from the given range.
Source§

fn is_empty(&self) -> bool

Check whether the range is empty.
Source§

impl<F> SampleRange<Angle<F>> for RangeInclusive<Angle<F>>
where UniformFloat<F>: UniformSampler<X = F>, F: SampleBorrow<F> + Float,

Available on crate feature rand only.
Source§

fn sample_single<R: RngCore + ?Sized>(self, rng: &mut R) -> Angle<F>

Generate a sample from the given range.
Source§

fn is_empty(&self) -> bool

Check whether the range is empty.
Source§

impl<F> SampleUniform for Angle<F>
where UniformFloat<F>: UniformSampler<X = F>, F: SampleBorrow<F> + Float,

Available on crate feature rand only.
Source§

type Sampler = UniformAngle<F>

The UniformSampler implementation supporting type X.
Source§

impl<F: Copy + Serialize> Serialize for Angle<F>

Available on crate feature serde only.
Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<F: Float> Sub<&Angle<F>> for &Angle<F>

Source§

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

The resulting type after applying the - operator.
Source§

fn sub(self, other: &Angle<F>) -> <Angle<F> as Sub<Angle<F>>>::Output

Performs the - operation. Read more
Source§

impl<F: Float> Sub<&Angle<F>> for Angle<F>

Source§

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

The resulting type after applying the - operator.
Source§

fn sub(self, other: &Angle<F>) -> <Angle<F> as Sub<Angle<F>>>::Output

Performs the - operation. Read more
Source§

impl<'a, F: Float> Sub<Angle<F>> for &'a Angle<F>

Source§

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

The resulting type after applying the - operator.
Source§

fn sub(self, other: Angle<F>) -> <Angle<F> as Sub<Angle<F>>>::Output

Performs the - operation. Read more
Source§

impl<F: Float> Sub for Angle<F>

Source§

type Output = Angle<F>

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl<F: Float> SubAssign<&Angle<F>> for Angle<F>

Source§

fn sub_assign(&mut self, other: &Angle<F>)

Performs the -= operation. Read more
Source§

impl<F: Float> SubAssign for Angle<F>

Source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
Source§

impl<F: Float + Sum> Sum for Angle<F>

Source§

fn sum<I: Iterator<Item = Self>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl<F: Copy> Copy for Angle<F>

Source§

impl<F: Eq> Eq for Angle<F>

Source§

impl<F> StructuralPartialEq for Angle<F>

Auto Trait Implementations§

§

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

§

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

§

impl<F> Send for Angle<F>
where F: Send,

§

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

§

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

§

impl<F> UnwindSafe for Angle<F>
where F: 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<Borrowed> SampleBorrow<Borrowed> for Borrowed
where Borrowed: SampleUniform,

Source§

fn borrow(&self) -> &Borrowed

Immutably borrows from an owned value. See Borrow::borrow
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, 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.
Source§

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