pub fn clamp<T: PartialOrd>(value: T, min: T, max: T) -> TExpand description
Clamp a value between a minimum and maximum.
ยงExamples
use chie_shared::clamp;
assert_eq!(clamp(5, 0, 10), 5);
assert_eq!(clamp(-5, 0, 10), 0); // Below min
assert_eq!(clamp(15, 0, 10), 10); // Above max
// Works with floats too
assert_eq!(clamp(3.5, 0.0, 5.0), 3.5);
assert_eq!(clamp(-1.0, 0.0, 5.0), 0.0);