aboutsummaryrefslogtreecommitdiff
path: root/.config/awesome/quarrel/math/init.lua
blob: d437654e50690020454459917e1e17436f25c069 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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