From c1c04fd1395cfad3d89237600b6ca4f7edc2075c Mon Sep 17 00:00:00 2001 From: lisyarus Date: Thu, 3 Sep 2026 12:14:54 +0300 Subject: [PATCH] Add 3-argument step, smoothstep and smootherstep --- libs/math/include/psemek/math/math.hpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/libs/math/include/psemek/math/math.hpp b/libs/math/include/psemek/math/math.hpp index a84b7871..8bcc8825 100644 --- a/libs/math/include/psemek/math/math.hpp +++ b/libs/math/include/psemek/math/math.hpp @@ -224,12 +224,24 @@ namespace psemek::math return false; } + template + H step(T edge0, T edge1, H x) + { + return clamp((x - edge0) / (edge1 - edge0), H{0}, H{1}); + } + template T smoothstep(T x) { return x * x * (T{3} - T{2} * x); } + template + H smoothstep(T edge0, T edge1, H x) + { + return smoothstep(clamp((x - edge0) / (edge1 - edge0), H{0}, H{1})); + } + template T smootherstep(T x) { @@ -237,6 +249,12 @@ namespace psemek::math return x * x2 * (T{10} - x * T{15} + x2 * T{6}); } + template + H smootherstep(T edge0, T edge1, H x) + { + return smootherstep(clamp((x - edge0) / (edge1 - edge0), H{0}, H{1})); + } + template T inverse_smoothstep(T x) {