From 2db6c323106f966862af3246698d46aebdbbd80d Mon Sep 17 00:00:00 2001 From: lisyarus Date: Thu, 3 Sep 2026 12:14:43 +0300 Subject: [PATCH] Add math::clamp(x, low, high) --- libs/math/include/psemek/math/math.hpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libs/math/include/psemek/math/math.hpp b/libs/math/include/psemek/math/math.hpp index 6f3f194a..a84b7871 100644 --- a/libs/math/include/psemek/math/math.hpp +++ b/libs/math/include/psemek/math/math.hpp @@ -183,6 +183,14 @@ namespace psemek::math return (x >= 0) ? std::fmod(x, m) : (m - std::fmod(-x, m)); } + template + auto clamp(T const & x, T const & low, T const & high) + { + using std::min; + using std::max; + return min(high, max(low, x)); + } + template bool make_min(T & target, T const & source) {