Skip to main content

constrain

Function constrain 

Source
pub fn constrain(x: f32, min_val: f32, max_val: f32) -> f32
Expand description

Clips x to the range min_val..max_val.

Deliberately not f32::clamp: clamp panics when min_val > max_val (or when a bound is NaN), while the C original returns a value for any input. This port keeps the C semantics and stays panic-free, which matters on the real-time render path where a panic aborts the whole process.