Skip to main content

Numeric

Struct Numeric 

Source
pub struct Numeric;
Expand description

A zero-sized namespace struct providing static math utility methods.

This struct follows the same pattern as App, serving as a namespace for free-standing mathematical functions such as clamp, lerp, angle conversions, and interpolation helpers.

Implementations§

Source§

impl Numeric

Implements static math utility methods on the Numeric namespace struct.

Source

pub fn clamp(value: f64, min: f64, max: f64) -> f64

Clamps a value between a minimum and maximum bound.

§Arguments
  • f64 - The value to clamp.
  • f64 - The minimum allowed value.
  • f64 - The maximum allowed value.
§Returns
  • f64 - The clamped value.
Source

pub fn lerp(start: f64, end: f64, t: f64) -> f64

Performs linear interpolation between two values.

§Arguments
  • f64 - The start value.
  • f64 - The end value.
  • f64 - The interpolation factor, typically in the range 0.0 to 1.0.
§Returns
  • f64 - The interpolated value.
Source

pub fn deg_to_rad(degrees: f64) -> f64

Converts an angle from degrees to radians.

§Arguments
  • f64 - The angle in degrees.
§Returns
  • f64 - The angle in radians.
Source

pub fn rad_to_deg(radians: f64) -> f64

Converts an angle from radians to degrees.

§Arguments
  • f64 - The angle in radians.
§Returns
  • f64 - The angle in degrees.
Source

pub fn normalize_angle(radians: f64) -> f64

Normalizes an angle to the range -PI to PI.

§Arguments
  • f64 - The angle in radians.
§Returns
  • f64 - The normalized angle in the range -PI to PI.
Source

pub fn angle_delta(from: f64, to: f64) -> f64

Computes the shortest angular difference between two angles.

§Arguments
  • f64 - The source angle in radians.
  • f64 - The target angle in radians.
§Returns
  • f64 - The signed angular delta in the range -PI to PI.
Source

pub fn lerp_angle(from: f64, to: f64, t: f64) -> f64

Performs angular interpolation taking the shortest path around the circle.

§Arguments
  • f64 - The source angle in radians.
  • f64 - The target angle in radians.
  • f64 - The interpolation factor, typically in the range 0.0 to 1.0.
§Returns
  • f64 - The interpolated angle in radians.
Source

pub fn distance(a: Vector2D, b: Vector2D) -> f64

Computes the Euclidean distance between two 2D points.

§Arguments
  • Vector2D - The first point.
  • Vector2D - The second point.
§Returns
  • f64 - The distance between the two points.
Source

pub fn distance_squared(a: Vector2D, b: Vector2D) -> f64

Computes the squared Euclidean distance between two 2D points.

Avoids a square root, making it faster for comparison-only use cases.

§Arguments
  • Vector2D - The first point.
  • Vector2D - The second point.
§Returns
  • f64 - The squared distance between the two points.
Source

pub fn smoothstep(edge_min: f64, edge_max: f64, value: f64) -> f64

Computes a smoothstep interpolation factor using a cubic Hermite polynomial.

§Arguments
  • f64 - The edge minimum.
  • f64 - The edge maximum.
  • f64 - The input value.
§Returns
  • f64 - The smoothstep result in the range 0.0 to 1.0.
Source

pub fn approach(current: f64, target: f64, max_delta: f64) -> f64

Moves current towards target by at most max_delta.

§Arguments
  • f64 - The current value.
  • f64 - The target value.
  • f64 - The maximum allowed change.
§Returns
  • f64 - The new value moved towards target.
Source

pub fn sign(value: f64) -> f64

Returns the sign of a value as -1.0, 0.0, or 1.0.

§Arguments
  • f64 - The input value.
§Returns
  • f64 - -1.0 if negative, 0.0 if zero, 1.0 if positive.
Source

pub fn wrap(value: f64, max: f64) -> f64

Wraps a value into the range 0.0 to max.

§Arguments
  • f64 - The value to wrap.
  • f64 - The upper bound of the range.
§Returns
  • f64 - The wrapped value in the range 0.0 to max.
Source

pub fn sign_or_positive(value: f64) -> f64

Returns 1.0 if the value is positive, -1.0 otherwise.

§Arguments
  • f64 - The input value.
§Returns
  • f64 - 1.0 if the value is non-negative, -1.0 otherwise.
Source

pub fn distance_3d(a: Vector3D, b: Vector3D) -> f64

Computes the Euclidean distance between two 3D points.

§Arguments
  • Vector3D - The first point.
  • Vector3D - The second point.
§Returns
  • f64 - The distance between the two points.
Source

pub fn distance_squared_3d(a: Vector3D, b: Vector3D) -> f64

Computes the squared Euclidean distance between two 3D points.

Avoids a square root, making it faster for comparison-only use cases.

§Arguments
  • Vector3D - The first point.
  • Vector3D - The second point.
§Returns
  • f64 - The squared distance between the two points.
Source§

impl Numeric

Source

pub fn new() -> Self

Trait Implementations§

Source§

impl Clone for Numeric

Source§

fn clone(&self) -> Numeric

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Numeric

Source§

impl Debug for Numeric

Source§

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

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

impl Default for Numeric

Source§

fn default() -> Numeric

Returns the “default value” for a type. Read more
Source§

impl Eq for Numeric

Source§

impl Hash for Numeric

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Numeric

Source§

fn cmp(&self, other: &Numeric) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

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

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

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

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

impl PartialEq for Numeric

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 PartialOrd for Numeric

Source§

fn partial_cmp(&self, other: &Numeric) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 StructuralPartialEq for Numeric

Auto Trait Implementations§

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> 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<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more