Function tmx_utils::math_utils::clamp01

source ·
pub fn clamp01<T: PartialOrd + Num>(val: T) -> T
Expand description

Clamps val between 0 and 1. Had intended to use clamp(val, 0, 1), but float doesn’t implement the Ord trait.

Examples

assert_eq!(clamp01(0.5), 0.5);
assert_eq!(clamp01(-1), 0);
assert_eq!(clamp01(3), 1);
assert_eq!(clamp01(3.0), 1.0);