Clamping

Clamps a value to a certain range. Use this function to make sure the value doesn't get bigger than the given maximum value and smaller than the minimum value.

---
-- Clamps a value to a certain range.
-- @param min - The minimum value.
-- @param val - The value to clamp.
-- @param max - The maximum value.
--
function clamp(min, val, max)
    return math.max(min, math.min(val, max));
end