From b744faa2e42ed37459fe3edb69c1149146233e5b Mon Sep 17 00:00:00 2001 From: ne_mene Date: Sun, 8 Mar 2026 22:21:42 +0100 Subject: let there be light --- src/utils.lua | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/utils.lua (limited to 'src/utils.lua') diff --git a/src/utils.lua b/src/utils.lua new file mode 100644 index 0000000..c3e4bea --- /dev/null +++ b/src/utils.lua @@ -0,0 +1,39 @@ + +function lerp(a, b, c) + return a + (b - a) * c +end + +function dlerp(a, b, c) + return lerp(b, a, 0.5^c) +end + +function bton(bool) + return bool and 1 or 0 +end + +function min(a, b) + if a < b then + return a + end + return b +end + +function normalize(x, y) + if x == 0 and y == 0 then + return 0, 0 + end + + local leng = math.sqrt(x*x + y*y) + return x / leng, y / leng +end + +-- Top left corner +function point_in_rect(px, py, rx, ry, rw, rh) + return px > rx and px < rx + rw and py > ry and py < ry + rh +end + +function dist(x1, y1, x2, y2) + local dx = x1 - x2 + local dy = y1 - y2 + return (dx*dx + dy*dy)^0.5 +end -- cgit v1.3-2-g0d8e