Skip to content

Commit

Permalink
Improve clamp implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
KmolYuan authored and Nil Goyette committed Dec 6, 2023
1 parent a982f0b commit fa57078
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions src/numeric/impl_float_maths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,9 @@ where
///
/// # Panics
///
/// Panics if `min > max`, `min` is `NaN`, or `max` is `NaN`.
/// Panics if `!(min <= max)`.
pub fn clamp(&self, min: A, max: A) -> Array<A, D> {
assert!(min <= max, "min must be less than or equal to max");
self.mapv(|v| {
if v < min {
min.clone()
} else if v > max {
max.clone()
} else {
v
}
})
self.mapv(|a| num_traits::clamp(a, min.clone(), max.clone()))
}
}

0 comments on commit fa57078

Please sign in to comment.