Function physics2d::math::clamp [] [src]

pub fn clamp(x: f32, min: f32, max: f32) -> f32

Clamps (limits) the value of x in the inclusive range from min to max.

If x < min, min is returned. If x > max, max is returned.

Examples


assert_eq!(clamp(-10.0, -3.0, 5.0), -3.0);
assert_eq!(clamp(1.0, -3.0, 5.0), 1.0);
assert_eq!(clamp(999999.0, -3.0, 5.0), 5.0);