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) -> Representationwhere 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) -> Representationwhere 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<'de> Deserialize<'de> for Angle

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 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) -> Selfwhere Self: Sized,

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

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

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

fn clamp(self, min: Self, max: Self) -> Selfwhere 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 Serialize for Angle

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 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 StructuralEq for Angle

source§

impl StructuralPartialEq for Angle

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§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
§

impl<A> Cast for A

§

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

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

impl<A> CastFrom<A> for A

§

fn from_cast(from: A) -> A

Returns from as Self.
§

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

§

fn cast_into(self) -> A

Returns self as To.
§

impl<Q, K> Comparable<K> for Qwhere Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere 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 Unitwhere Unit: Copy,

source§

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

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

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

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

impl<T> ToOwned for Twhere 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 Twhere 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 Twhere 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 Twhere 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.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
source§

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

§

impl<T> WasmNotSend for Twhere T: Send,

§

impl<T> WasmNotSendSync for Twhere T: WasmNotSend + WasmNotSync,

§

impl<T> WasmNotSync for Twhere T: Sync,