Skip to main content

Scalar

Trait Scalar 

Source
pub trait Scalar:
    Copy
    + Clone
    + Send
    + Sync
    + 'static
    + Default
    + PartialOrd
    + Add<Output = Self>
    + Sub<Output = Self>
    + Mul<Output = Self>
    + Div<Output = Self>
    + Rem<Output = Self>
    + Neg<Output = Self>
    + AddAssign
    + SubAssign
    + MulAssign
    + DivAssign
    + Debug {
    const ZERO: Self;
    const ONE: Self;
    const MIN: Self;
    const MAX: Self;

    // Required methods
    fn abs(self) -> Self;
    fn min(self, other: Self) -> Self;
    fn max(self, other: Self) -> Self;
    fn clamp(self, min: Self, max: Self) -> Self;
    fn from_usize(n: usize) -> Self;
}
Expand description

Base numeric trait for all scalar types.

Includes arithmetic, min/max/clamp, and abs operations. Implemented for f32, f64 and all integer types (i8/i16/i32/i64, u8/u16/u32/u64).

Required Associated Constants§

Source

const ZERO: Self

Additive identity (zero).

Source

const ONE: Self

Multiplicative identity (one).

Source

const MIN: Self

Minimum value typically used in normalized ranges (e.g. -1.0 for floats).

Source

const MAX: Self

Maximum value typically used in normalized ranges (e.g. 1.0 for floats).

Required Methods§

Source

fn abs(self) -> Self

Compute the absolute value.

Source

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

Return the smaller of two values.

Source

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

Return the larger of two values.

Source

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

Constrain a value to the inclusive range [min, max].

Source

fn from_usize(n: usize) -> Self

Create a value from a usize. For floats, this is n as f32/n as f64. For integers, this is n as $ty.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Scalar for f32

Source§

const ZERO: f32 = 0.0

Source§

const ONE: f32 = 1.0

Source§

const MIN: f32 = -1.0

Source§

const MAX: f32 = 1.0

Source§

fn abs(self) -> f32

Source§

fn min(self, other: f32) -> f32

Source§

fn max(self, other: f32) -> f32

Source§

fn clamp(self, min: f32, max: f32) -> f32

Source§

fn from_usize(n: usize) -> f32

Source§

impl Scalar for f64

Source§

const ZERO: f64 = 0.0

Source§

const ONE: f64 = 1.0

Source§

const MIN: f64 = -1.0

Source§

const MAX: f64 = 1.0

Source§

fn abs(self) -> f64

Source§

fn min(self, other: f64) -> f64

Source§

fn max(self, other: f64) -> f64

Source§

fn clamp(self, min: f64, max: f64) -> f64

Source§

fn from_usize(n: usize) -> f64

Source§

impl Scalar for i8

Source§

const ZERO: i8 = 0

Source§

const ONE: i8 = 1

Source§

const MIN: i8 = i8::MIN

Source§

const MAX: i8 = i8::MAX

Source§

fn abs(self) -> i8

Source§

fn min(self, other: i8) -> i8

Source§

fn max(self, other: i8) -> i8

Source§

fn clamp(self, lo: i8, hi: i8) -> i8

Source§

fn from_usize(n: usize) -> i8

Source§

impl Scalar for i16

Source§

const ZERO: i16 = 0

Source§

const ONE: i16 = 1

Source§

const MIN: i16 = i16::MIN

Source§

const MAX: i16 = i16::MAX

Source§

fn abs(self) -> i16

Source§

fn min(self, other: i16) -> i16

Source§

fn max(self, other: i16) -> i16

Source§

fn clamp(self, lo: i16, hi: i16) -> i16

Source§

fn from_usize(n: usize) -> i16

Source§

impl Scalar for i32

Source§

const ZERO: i32 = 0

Source§

const ONE: i32 = 1

Source§

const MIN: i32 = i32::MIN

Source§

const MAX: i32 = i32::MAX

Source§

fn abs(self) -> i32

Source§

fn min(self, other: i32) -> i32

Source§

fn max(self, other: i32) -> i32

Source§

fn clamp(self, lo: i32, hi: i32) -> i32

Source§

fn from_usize(n: usize) -> i32

Source§

impl Scalar for i64

Source§

const ZERO: i64 = 0

Source§

const ONE: i64 = 1

Source§

const MIN: i64 = i64::MIN

Source§

const MAX: i64 = i64::MAX

Source§

fn abs(self) -> i64

Source§

fn min(self, other: i64) -> i64

Source§

fn max(self, other: i64) -> i64

Source§

fn clamp(self, lo: i64, hi: i64) -> i64

Source§

fn from_usize(n: usize) -> i64

Implementors§