diff options
| author | delta <darkussdelta@gmail.com> | 2025-07-04 00:38:29 +0200 |
|---|---|---|
| committer | delta <darkussdelta@gmail.com> | 2025-07-04 00:38:29 +0200 |
| commit | b3530d7c4a102935fa26498a160ee1dc6c1e9c03 (patch) | |
| tree | d7751206a694bc5de2d6b34b0c077cfcd1855798 /.config/awesome/quarrel/math | |
| parent | df75ec5ed5e3848c497f0439acb43ec9246ad3e7 (diff) | |
:3
Diffstat (limited to '.config/awesome/quarrel/math')
| -rw-r--r-- | .config/awesome/quarrel/math/consts.lua | 5 | ||||
| -rw-r--r-- | .config/awesome/quarrel/math/init.lua | 29 |
2 files changed, 34 insertions, 0 deletions
diff --git a/.config/awesome/quarrel/math/consts.lua b/.config/awesome/quarrel/math/consts.lua new file mode 100644 index 0000000..f18a093 --- /dev/null +++ b/.config/awesome/quarrel/math/consts.lua @@ -0,0 +1,5 @@ +local C = {} + +C.EPSILON = 2 ^ -52 + +return C diff --git a/.config/awesome/quarrel/math/init.lua b/.config/awesome/quarrel/math/init.lua new file mode 100644 index 0000000..d437654 --- /dev/null +++ b/.config/awesome/quarrel/math/init.lua @@ -0,0 +1,29 @@ +local M = require "quarrel.math.consts" +local gmath = require "gears.math" + +-- TODO: Finish documenting these functions + +function M.step_value(value, steps) + if value > steps[#steps - 1][1] then + return steps[#steps - 1][2] + end + for i, step in ipairs(steps) do + if step[1] <= value and value <= steps[i + 1][1] then + return step[2] + end + end +end + +function M.translate_range(value, in_min, in_max, out_min, out_max) + return out_min + ((out_max - out_min) / (in_max - in_min)) * (value - in_min) +end + +function M.percentage(value, max) + return gmath.round(value / max * 100) +end + +function M.clamp(value, min, max) + return math.max(math.min(value, max), min) +end + +return M |
