@@ -109,3 +109,10 @@ pub mod traits {
pub mod rational {
pub use num_rational::*;
}
+
+pub fn clamp<T: PartialOrd + Copy>(input: T, min: T, max: T) -> T {
+ debug_assert!(min < max, "min must be less than max");
+ if input < min {min}
+ else if input > max {max}
+ else {input}
+}