Skip to main content

UnitValue

Trait UnitValue 

Source
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§

Source

fn zero() -> Self

The value representing 0 (start of the interval).

Source

fn one() -> Self

The value representing 1 (end of the interval).

Source

fn to_index(self) -> usize

Convert this value to a LUT index (0-based).

Source

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.

Source

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.

Source

fn lerp_u16(self, a: u16, b: u16) -> u16

Linearly interpolate between two u16 endpoints using self as the blend weight.

Source

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.

Implementations on Foreign Types§

Source§

impl UnitValue for u8

Source§

fn zero() -> Self

Source§

fn one() -> Self

Source§

fn to_index(self) -> usize

Source§

fn from_time_frac(elapsed_ms: u32, duration_ms: u32) -> Self

Source§

fn to_time_offset(self, duration_ms: u32) -> u32

Source§

fn lerp_u16(self, a: u16, b: u16) -> u16

Source§

fn inv_lerp_u16(a: u16, b: u16, target: u16) -> Self

Source§

impl UnitValue for u16

Source§

fn zero() -> Self

Source§

fn one() -> Self

Source§

fn to_index(self) -> usize

Source§

fn from_time_frac(elapsed_ms: u32, duration_ms: u32) -> Self

Source§

fn to_time_offset(self, duration_ms: u32) -> u32

Source§

fn lerp_u16(self, a: u16, b: u16) -> u16

Source§

fn inv_lerp_u16(a: u16, b: u16, target: u16) -> Self

Implementors§