diff options
| author | ne_mene <[email protected]> | 2026-03-08 22:21:42 +0100 |
|---|---|---|
| committer | ne_mene <[email protected]> | 2026-03-08 22:21:42 +0100 |
| commit | b744faa2e42ed37459fe3edb69c1149146233e5b (patch) | |
| tree | 25f238d3e467c7cf43e619b579e0df89762b1cca /src/utils.lua | |
| parent | 95d50b15634bf4799a2005e381d82c110fbff39b (diff) | |
let there be light
Diffstat (limited to 'src/utils.lua')
| -rw-r--r-- | src/utils.lua | 39 |
1 files changed, 39 insertions, 0 deletions
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 |
