Angle

Struct Angle 

Source
pub struct Angle<T: Float = f32> { /* private fields */ }
Expand description

This struct represents an angle in 2d space,

Implementations§

Source§

impl<T: Float> Angle<T>

Source

pub const ZERO: Self

0 angle is pointing to positive x axis

Source

pub fn map<U: Float>(&self, f: impl Fn(T) -> U) -> Angle<U>

Map inner value to a different type

Source

pub fn acos(cos: T) -> Self

Computes the arccosine of a number as an angle.

Return value is in radians in the range [0, pi] or NaN if the number is outside the range [-1, 1].

Source

pub fn asin(sin: T) -> Self

Computes the arcsine of a number as an angle.

Return value is in radians in the range [-pi/2, pi/2] or NaN if the number is outside the range [-1, 1].

Source

pub fn atan(tan: T) -> Self

Computes the arctangent of a number as an angle.

Return value is in radians in the range [-pi/2, pi/2];

Source

pub fn atan2(y: T, x: T) -> Self

Computes the four quadrant arctangent of self (y) and other (x) as an angle.

  • x = 0, y = 0: 0
  • x >= 0: arctan(y/x) -> [-pi/2, pi/2]
  • y >= 0: arctan(y/x) + pi -> (pi/2, pi]
  • y < 0: arctan(y/x) - pi -> (-pi, -pi/2)
Source

pub fn sin(&self) -> T

Compute the sine

Source

pub fn cos(&self) -> T

Compute the cosine

Source

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

Simultaneously computes the sine and cosine of the angle. Returns (sin(self), cos(self)).

Source

pub fn tan(self) -> T

Computes the tangent of the angle.

Source

pub fn from_radians(radians: T) -> Self

Create angle from value in radians

Source

pub fn from_degrees(degrees: T) -> Self

Create angle from value in degrees

Source

pub fn as_radians(&self) -> T

See angle value as radians

Source

pub fn as_degrees(&self) -> T

See angle value as degrees

Source

pub fn normalized_2pi(&self) -> Self

Normalize the angle to be in range 0..2*pi.

Source

pub fn abs(&self) -> Self

Calculate absolute value

Source

pub fn normalized_pi(&self) -> Self

Normalize the angle to be in range -pi..pi.

Source

pub fn angle_from(&self, from: Self) -> Self

Calculates the angle between from and self in range -pi..pi.

Source

pub fn angle_to(&self, target: Self) -> Self

Calculates the angle between self and target in range -pi..pi.

Source

pub fn unit_vec(&self) -> vec2<T>

Returns a direction vector of unit length.

Trait Implementations§

Source§

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

Source§

type Output = Angle<T>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

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

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl<T: Clone + Float> 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 + Float> Debug for Angle<T>

Source§

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

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

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

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<T: Float> Distribution<Angle<T>> for Standard

Source§

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

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<T: Float> Div<T> for Angle<T>

Source§

type Output = Angle<T>

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

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

Source§

type Output = Angle<T>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

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

Source§

type Output = Angle<T>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl<T: Ord + Float> Ord for Angle<T>

Source§

fn cmp(&self, other: &Angle<T>) -> 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: PartialEq + Float> 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 + Float> 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> Serialize for Angle<T>
where T: Serialize + Float,

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<T: Float> Sub for Angle<T>

Source§

type Output = Angle<T>

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

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

Source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
Source§

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

Source§

impl<T: Eq + Float> Eq for Angle<T>

Source§

impl<T: Float> StructuralPartialEq 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> Send for Angle<T>
where T: Send,

§

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> Clamp for T
where T: PartialOrd,

Source§

fn clamp_range(self, range: impl FixedRangeBounds<Self>) -> Self
where Self: Clone,

Clamps a value in range. Read more
Source§

fn clamp_abs(self, max: Self) -> Self
where Self: Neg<Output = Self> + Copy,

Clamp the absolute value. Same as self.clamp_range(-max..=max)
Source§

fn clamp_max(self, max: Self) -> Self

Clamp by maximum value Read more
Source§

fn clamp_min(self, min: Self) -> Self

Clamp by minimum 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, 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

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