Add clamp function
This commit is contained in:
parent
817ab00f64
commit
28633b7e6d
|
@ -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}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue