From a71eeea17a7b54f46710f8d0ccb5e1e22fd54752 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Sun, 2 Nov 2025 20:11:34 +0000 Subject: rmath: add clerp round squish unsquish sqlerp --- math.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/math.lua b/math.lua index cd6745e..a60ca0c 100644 --- a/math.lua +++ b/math.lua @@ -20,5 +20,13 @@ function M.clamp(x,minv,maxv) return math.min(math.max(x,minv),maxv) end +function M.clerp(a,b,t) return M.lerp(a,b,M.clamp(t,0,1)) end +function M.round(x) return math.floor(x+0.5) end + +-- [-1,1] -> [0,1] +function M.squish(x) return (x/2)+0.5 end +-- [0,1] -> [-1,1] +function M.unsquish(x) return (x*2)-1 end +function M.sqlerp(a,b,t) return M.lerp(a,b,M.squish(t)) end return M -- cgit v1.2.3