Angle

Struct Angle 

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

A scalar angular quantity.

Prevents confusion between degrees and radians by requiring the use of one of the named constructors to create an Angle, as well as one of the named getter methods to obtain the angle as a raw f32 value.

Implementations§

Source§

impl Angle

Source

pub const ZERO: Self

A zero degree angle.

Source

pub const RIGHT: Self

A 90 degree angle.

Source

pub const STRAIGHT: Self

A 180 degree angle.

Source

pub const FULL: Self

A 360 degree angle.

Source

pub const fn to_rads(self) -> f32

Returns the value of self in radians.

§Examples
use std::f32;
use retrofire_core::math::degs;

assert_eq!(degs(90.0).to_rads(), f32::consts::FRAC_PI_2);
Source

pub fn to_degs(self) -> f32

Returns the value of self in degrees.

§Examples
use retrofire_core::math::turns;

assert_eq!(turns(2.0).to_degs(), 720.0);
Source

pub fn to_turns(self) -> f32

Returns the value of self in turns.

§Examples
use retrofire_core::math::degs;

assert_eq!(degs(180.0).to_turns(), 0.5);
Source

pub fn min(self, other: Self) -> Self

Returns the minimum of self and other.

Source

pub fn max(self, other: Self) -> Self

Returns the maximum of self and other.

Source

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

Returns self clamped to the range min..=max.

§Examples
use retrofire_core::math::degs;

let (min, max) = (degs(0.0), degs(45.0));

assert_eq!(degs(100.0).clamp(min, max), max);
assert_eq!(degs(30.0).clamp(min, max), degs(30.0));
assert_eq!(degs(-10.0).clamp(min, max), min);
Source§

impl Angle

Source

pub fn sin(self) -> f32

Returns the sine of self.

§Examples
use retrofire_core::assert_approx_eq;
use retrofire_core::math::degs;

assert_approx_eq!(degs(30.0).sin(), 0.5)
Source

pub fn cos(self) -> f32

Returns the cosine of self.

§Examples
use retrofire_core::assert_approx_eq;
use retrofire_core::math::degs;

assert_approx_eq!(degs(60.0).cos(), 0.5)
Source

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

Simultaneously computes the sine and cosine of self.

§Examples
use retrofire_core::assert_approx_eq;
use retrofire_core::math::degs;

let (sin, cos) = degs(90.0).sin_cos();
assert_approx_eq!(sin, 1.0);
assert_approx_eq!(cos, 0.0);
Source

pub fn tan(self) -> f32

Returns the tangent of self.

§Examples
use retrofire_core::math::degs;
assert_eq!(degs(45.0).tan(), 1.0)
Source

pub fn wrap(self, min: Self, max: Self) -> Self

Returns self “wrapped around” to the range min..max.

§Examples
use retrofire_core::assert_approx_eq;
use retrofire_core::math::{degs, turns};

// 400 (mod 360) = 40
assert_approx_eq!(degs(400.0).wrap(turns(0.0), turns(1.0)), degs(40.0))

Trait Implementations§

Source§

impl Add for Angle

Source§

type Output = Angle

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl Affine for Angle

Source§

const DIM: usize = 1usize

The dimension of Self.
Source§

type Space = ()

The space that Self is the element type of.
Source§

type Diff = Angle

The (signed) difference of two values of Self. Diff must have the same dimension as Self.
Source§

fn add(&self, other: &Self) -> Self

Adds diff to self component-wise. Read more
Source§

fn sub(&self, other: &Self) -> Self

Subtracts other from self, returning the (signed) difference. Read more
Source§

fn combine<S: Copy, const N: usize>( weights: &[S; N], points: &[Self; N], ) -> Self
where Self: Clone, Self::Diff: Linear<Scalar = S>,

Returns an affine combination of points. Read more
Source§

impl ApproxEq for Angle

Source§

fn approx_eq_eps(&self, other: &Self, eps: &Self) -> bool

Returns whether self and other are approximately equal, using the relative epsilon rel_eps.
Source§

fn relative_epsilon() -> Self

Returns the default relative epsilon of type E.
Source§

fn approx_eq(&self, other: &Other) -> bool

Returns whether self and other are approximately equal. Uses the epsilon returned by Self::relative_epsilon.
Source§

impl Clone for Angle

Source§

fn clone(&self) -> Angle

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

Source§

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

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

impl Default for Angle

Source§

fn default() -> Angle

Returns the “default value” for a type. 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

Source§

type Output = Angle

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl Linear for Angle

Source§

type Scalar = f32

The scalar type associated with Self.
Source§

fn zero() -> Self

Returns the additive identity of Self.
Source§

fn mul(&self, scalar: f32) -> Self

Multiplies all components of self by scalar. Read more
Source§

fn neg(&self) -> Self

Returns the additive inverse of self.
Source§

impl Mul<f32> for Angle

Source§

type Output = Angle

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Neg for Angle

Source§

type Output = Angle

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self

Performs the unary - operation. Read more
Source§

impl PartialEq for Angle

Source§

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

Source§

type Output = Angle

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: Self) -> Self

Performs the % operation. Read more
Source§

impl Sub for Angle

Source§

type Output = Angle

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl ZDiv for Angle

Source§

fn z_div(self, _z: f32) -> Self

Source§

impl Copy 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<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> Lerp for T
where T: Affine, <T as Affine>::Diff: Linear<Scalar = f32>,

Source§

fn lerp(&self, other: &T, t: f32) -> T

Linearly interpolates between self and other.

if t = 0, returns self; if t = 1, returns other. For 0 < t < 1, returns the affine combination

(1 - t) * self + t * other

or rearranged:

self + t * (other - self)

If t < 0.0 or t > 1.0, returns the appropriate extrapolated value. If t is NaN, the result is unspecified.

§Examples
use retrofire_core::math::*;

assert_eq!(2.0.lerp(&5.0, 0.0), 2.0);
assert_eq!(2.0.lerp(&5.0, 0.25), 2.75);
assert_eq!(2.0.lerp(&5.0, 0.75), 4.25);
assert_eq!(2.0.lerp(&5.0, 1.0), 5.0);

let v0: Vec2 = vec2(-2.0, 1.0);
let v1 = vec2(3.0, -1.0);
assert_eq!(v0.lerp(&v1, 0.8), vec2(2.0, -0.6));

let p0: Point2 = pt2(-10.0, 5.0);
let p1 = pt2(-5.0, 0.0);
assert_eq!(p0.lerp(&p1, 0.4),pt2(-8.0, 3.0));
Source§

fn midpoint(&self, other: &Self) -> Self

Returns the (unweighted) average of self and other. Read more
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.
Source§

impl<V> Vary for V
where V: Clone + Affine + ZDiv, <V as Affine>::Diff: Linear<Scalar = f32> + Clone,

Source§

fn step(&self, delta: &<V as Vary>::Diff) -> V

Adds delta to self.

Source§

type Iter = Iter<V>

The iterator returned by the vary method.
Source§

type Diff = <V as Affine>::Diff

The difference type of Self.
Source§

fn vary(self, step: <V as Vary>::Diff, n: Option<u32>) -> <V as Vary>::Iter

Returns an iterator that yields values such that the first value equals self, and each subsequent value is offset by step from its predecessor using the step method. If max is Some(n), stops after n steps, otherwise infinite. Read more
Source§

fn dv_dt(&self, other: &V, recip_dt: f32) -> <V as Vary>::Diff

Returns, conceptually, (other - self) / dt.
Source§

fn vary_to(self, other: Self, n: u32) -> Self::Iter

Linearly distributes n values between self and other inclusive. Read more