diff --git a/mesa/space.py b/mesa/space.py index a99026c2d1c..afa9a250e4e 100644 --- a/mesa/space.py +++ b/mesa/space.py @@ -56,9 +56,8 @@ def clamp(x: float, lowest: float, highest: float) -> float: - # This should be faster than np.clip for a scalar x. - # TODO: measure how much faster this function is. - return max(lowest, min(x, highest)) + # much faster than np.clip for a scalar x. + return lowest if x <= lowest else (highest if x >= highest else x) def accept_tuple_argument(wrapped_function: F) -> F: