Merge pull request #65 from idbrii/fix-round
Fix index nil error in private.round
This commit is contained in:
commit
a3aacc354c
@ -5,7 +5,7 @@ local floor = math.floor
|
||||
local ceil = math.ceil
|
||||
|
||||
function private.round(value, precision)
|
||||
if precision then return utils.round(value / precision) * precision end
|
||||
if precision then return private.round(value / precision) * precision end
|
||||
return value >= 0 and floor(value+0.5) or ceil(value-0.5)
|
||||
end
|
||||
|
||||
|
@ -27,6 +27,18 @@ describe("utils:", function()
|
||||
local v = utils.decay(0, 1, 0.5, 1)
|
||||
assert.is_true(tolerance(v, 0.39346934028737))
|
||||
end)
|
||||
|
||||
it("rounds a number", function()
|
||||
-- round up
|
||||
local v = utils.round(1.3252525, 0.01)
|
||||
assert.is_true(tolerance(v, 1.33))
|
||||
-- round down
|
||||
v = utils.round(1.3242525, 0.1)
|
||||
assert.is_true(tolerance(v, 1.3))
|
||||
-- no precision
|
||||
v = utils.round(1.3242525)
|
||||
assert.is_true(tolerance(v, 1))
|
||||
end)
|
||||
end)
|
||||
|
||||
--[[
|
||||
@ -37,7 +49,6 @@ tolerance(value, threshold)
|
||||
map(value, min_in, max_in, min_out, max_out)
|
||||
lerp(progress, low, high)
|
||||
smoothstep(progress, low, high)
|
||||
round(value, precision)
|
||||
wrap(value, limit)
|
||||
is_pot(value)
|
||||
project_on(out, a, b)
|
||||
|
Loading…
x
Reference in New Issue
Block a user