pub trait UnitValue: Copy + 'static {
// Required methods
fn zero() -> Self;
fn one() -> Self;
fn to_index(self) -> usize;
fn from_time_frac(elapsed_ms: u32, duration_ms: u32) -> Self;
fn to_time_offset(self, duration_ms: u32) -> u32;
fn lerp_u16(self, a: u16, b: u16) -> u16;
fn inv_lerp_u16(a: u16, b: u16, target: u16) -> Self;
}Expand description
A normalized value type usable as a curve domain / range.
Implementors map a unit interval onto a discrete integer type so that the tickless scheduler can convert between wall-clock time fractions and curve positions.
Required Methods§
Sourcefn from_time_frac(elapsed_ms: u32, duration_ms: u32) -> Self
fn from_time_frac(elapsed_ms: u32, duration_ms: u32) -> Self
Create a value from a time fraction elapsed / duration.
Returns Self::zero() when elapsed == 0 and Self::one() when
elapsed >= duration.
Sourcefn to_time_offset(self, duration_ms: u32) -> u32
fn to_time_offset(self, duration_ms: u32) -> u32
Convert this value back to a wall-clock offset in milliseconds within
duration_ms, rounding up.
Sourcefn lerp_u16(self, a: u16, b: u16) -> u16
fn lerp_u16(self, a: u16, b: u16) -> u16
Linearly interpolate between two u16 endpoints using self as the
blend weight.
Sourcefn inv_lerp_u16(a: u16, b: u16, target: u16) -> Self
fn inv_lerp_u16(a: u16, b: u16, target: u16) -> Self
Inverse linear interpolation: find the blend weight T such that
T::lerp_u16(a, b) ≈ target, rounding toward b.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.