summaryrefslogtreecommitdiff
path: root/math.lua
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2025-02-17 14:48:34 +0000
committerubq323 <ubq323@ubq323.website>2025-02-17 14:48:34 +0000
commitf1492b52414b6f2ad6cfff45375c08677feab18c (patch)
tree2eac341c813f513b4acef7ff591f6f68936eb334 /math.lua
initial
Diffstat (limited to 'math.lua')
-rw-r--r--math.lua24
1 files changed, 24 insertions, 0 deletions
diff --git a/math.lua b/math.lua
new file mode 100644
index 0000000..cd6745e
--- /dev/null
+++ b/math.lua
@@ -0,0 +1,24 @@
+local M = {}
+
+function M.lerp(a,b,t) return (1-t)*a + t*b end
+function M.smoothstep(x)
+ if x<0 then return 0 end
+ if x>1 then return 1 end
+ return x*x*(3 - 2*x)
+end
+function M.slerp(a,b,t) return M.lerp(a,b,M.smoothstep(t)) end
+
+
+function M.sign(x)
+ if x == 0 then return 0
+ elseif x < 0 then return -1
+ elseif x > 0 then return 1
+ end
+end
+
+function M.clamp(x,minv,maxv)
+ return math.min(math.max(x,minv),maxv)
+end
+
+
+return M