bevy/crates/bevy_math/src/clamp.rs
Lachlan Sneff 17e7642611
Task System for Bevy (#384)
Add bevy_tasks crate to replace rayon
2020-08-29 12:35:41 -07:00

20 lines
555 B
Rust

/// A value bounded by a minimum and a maximum
///
/// If input is less than min then this returns min.
/// If input is greater than max then this returns max.
/// Otherwise this returns input.
///
/// **Panics** in debug mode if `!(min <= max)`.
///
/// Original implementation from num-traits licensed as MIT
pub fn clamp<T: PartialOrd>(input: T, min: T, max: T) -> T {
debug_assert!(min <= max, "min must be less than or equal to max");
if input < min {
min
} else if input > max {
max
} else {
input
}
}