Struct figures::Angle

source ·
pub struct Angle(/* private fields */);
Expand description

An measurement of distance between two rays sharing a common endpoint, in degrees.

Angle::degrees(1) is equivalent to 1/360th of a full rotation. This type is commonly used to represent the amount of rotation to perform.

Internally, this type ensures that the angle represented using a Fraction is always within the range of 0..=360° (degrees). This ensures that comparing two angles is efficient and deterministic.

use figures::Angle;

assert_eq!(Angle::degrees(-90).into_degrees::<f32>(), 270.);
assert_eq!(Angle::degrees(-90), Angle::degrees(270));

Because this type uses a Fraction internally, it will perform integer math on integer types. The order of operations may impact the amount of precision the final result contains.

§Working with Radians

Because π is an irrational number, this type internally uses degrees for representation. Angles represented in radians can be converted using Angle::radians/Angle::radians_f.

Implementations§

source§

impl Angle

source

pub const fn degrees(degrees: i16) -> Self

Returns an angle for degrees, where 360 degrees is equal to one full rotation.

The value will be normalized to the range of 0..360.

source

pub fn degrees_fraction(degrees: Fraction) -> Self

Returns an angle for radians, where is equal to one full rotation.

The value will be normalized to the range of 0..2π.

source

pub fn degrees_f(degrees: f32) -> Self

Returns an angle for degrees, where 360 degrees is equal to one full rotation.

The value will be normalized to the range of 0..360.

source

pub fn radians(radians: Fraction) -> Self

Returns an angle for radians, where is equal to one full rotation.

The value will be normalized to the range of 0..2π.

source

pub fn radians_f(radians: f32) -> Self

Returns an angle for radians, where is equal to one full rotation.

The value will be normalized to the range of 0..2π.

source

pub fn into_raidans<Representation>(self) -> Representation
where Representation: From<Fraction>,

Returns this angle as represented in radians, where is equal to one full rotation.

source

pub fn into_raidans_f(self) -> f32

Returns this angle as represented in radians, where is equal to one full rotation.

source

pub fn into_degrees<Representation>(self) -> Representation
where Representation: From<Fraction>,

Returns this angle as represented in degrees, where 360 degrees is equal to one full rotation.

source

pub fn sin(&self) -> Fraction

Calculates the sine of this angle.

source

pub fn cos(&self) -> Fraction

Calculates the cosine of this angle.

source

pub fn tan(&self) -> Fraction

Calculates the tangent of this angle.

Trait Implementations§

source§

impl Add<f32> for Angle

§

type Output = Angle

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl Add<i16> for Angle

§

type Output = Angle

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl Add for Angle

§

type Output = Angle

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl AddAssign<f32> for Angle

source§

fn add_assign(&mut self, rhs: f32)

Performs the += operation. Read more
source§

impl AddAssign<i16> for Angle

source§

fn add_assign(&mut self, rhs: i16)

Performs the += operation. Read more
source§

impl AddAssign for Angle

source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
source§

impl Clone for Angle

source§

fn clone(&self) -> Angle

Returns a copy 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 Debug for Angle

source§

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

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

impl Display for Angle

source§

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

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

impl Div<f32> for Angle

§

type Output = Angle

The resulting type after applying the / operator.
source§

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

Performs the / operation. Read more
source§

impl Div<i16> for Angle

§

type Output = Angle

The resulting type after applying the / operator.
source§

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

Performs the / operation. Read more
source§

impl Div for Angle

§

type Output = Angle

The resulting type after applying the / operator.
source§

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

Performs the / operation. Read more
source§

impl DivAssign<f32> for Angle

source§

fn div_assign(&mut self, rhs: f32)

Performs the /= operation. Read more
source§

impl DivAssign<i16> for Angle

source§

fn div_assign(&mut self, rhs: i16)

Performs the /= operation. Read more
source§

impl DivAssign for Angle

source§

fn div_assign(&mut self, rhs: Self)

Performs the /= operation. Read more
source§

impl From<Fraction> for Angle

source§

fn from(value: Fraction) -> Self

Converts to this type from the input type.
source§

impl From<f32> for Angle

source§

fn from(value: f32) -> Self

Converts to this type from the input type.
source§

impl From<i16> for Angle

source§

fn from(value: i16) -> Self

Converts to this type from the input type.
source§

impl Mul<Duration> for Angle

§

type Output = Angle

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl Mul<f32> for Angle

§

type Output = Angle

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl Mul<i16> for Angle

§

type Output = Angle

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl Mul for Angle

§

type Output = Angle

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl MulAssign<f32> for Angle

source§

fn mul_assign(&mut self, rhs: f32)

Performs the *= operation. Read more
source§

impl MulAssign<i16> for Angle

source§

fn mul_assign(&mut self, rhs: i16)

Performs the *= operation. Read more
source§

impl MulAssign for Angle

source§

fn mul_assign(&mut self, rhs: Self)

Performs the *= operation. Read more
source§

impl Neg for Angle

§

type Output = Angle

The resulting type after applying the - operator.
source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
source§

impl Ord for Angle

source§

fn cmp(&self, other: &Angle) -> 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 + PartialOrd,

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

impl PartialEq for Angle

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Angle

source§

fn partial_cmp(&self, other: &Angle) -> 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

This method 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

This method 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

This method 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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Ranged for Angle

source§

const MAX: Self = _

The maximum value for this type.
source§

const MIN: Self = Self::ZERO

The minimum value for this type.
source§

impl Sub<f32> for Angle

§

type Output = Angle

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl Sub<i16> for Angle

§

type Output = Angle

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl Sub for Angle

§

type Output = Angle

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl SubAssign<f32> for Angle

source§

fn sub_assign(&mut self, rhs: f32)

Performs the -= operation. Read more
source§

impl SubAssign<i16> for Angle

source§

fn sub_assign(&mut self, rhs: i16)

Performs the -= operation. Read more
source§

impl SubAssign for Angle

source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
source§

impl Zero for Angle

source§

const ZERO: Self = _

The zero value for this type.
source§

fn is_zero(&self) -> bool

Returns true if self represents 0.
source§

impl Copy for Angle

source§

impl Eq for Angle

source§

impl StructuralPartialEq for Angle

Auto Trait Implementations§

§

impl Freeze for Angle

§

impl RefUnwindSafe for Angle

§

impl Send for Angle

§

impl Sync for Angle

§

impl Unpin for Angle

§

impl UnwindSafe for Angle

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<A> Cast for A

source§

fn cast<To>(self) -> To
where To: CastFrom<A>,

Casts self to the To type. This may be a lossy operation.
source§

impl<A> CastFrom<A> for A

source§

fn from_cast(from: A) -> A

Returns from as Self.
source§

impl<A, B> CastInto<A> for B
where A: CastFrom<B>,

source§

fn cast_into(self) -> A

Returns self as To.
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<Unit> IntoComponents<Unit> for Unit
where Unit: Copy,

source§

fn into_components(self) -> (Unit, Unit)

Extracts this type’s 2d vector components.
source§

fn to_vec<Type>(self) -> Type
where Type: FromComponents<Unit>,

Converts this type to another type using FromComponents and IntoComponents.
source§

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

§

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§

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

§

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

§

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.