summaryrefslogtreecommitdiff
path: root/math.lua
diff options
context:
space:
mode:
Diffstat (limited to 'math.lua')
-rw-r--r--math.lua8
1 files changed, 8 insertions, 0 deletions
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