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
impl Angle
Sourcepub const fn to_rads(self) -> f32
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);Sourcepub fn to_degs(self) -> f32
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);Sourcepub fn to_turns(self) -> f32
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);Sourcepub fn clamp(self, min: Self, max: Self) -> Self
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
impl Angle
Sourcepub fn sin(self) -> f32
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)Sourcepub fn cos(self) -> f32
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)Sourcepub fn sin_cos(self) -> (f32, f32)
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);Trait Implementations§
Source§impl Affine for Angle
impl Affine for Angle
Source§impl ApproxEq for Angle
impl ApproxEq for Angle
Source§fn approx_eq_eps(&self, other: &Self, eps: &Self) -> bool
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
fn relative_epsilon() -> Self
Returns the default relative epsilon of type
E.impl Copy for Angle
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Lerp for T
impl<T> Lerp for T
Source§fn lerp(&self, other: &T, t: f32) -> T
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 * otheror 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));