utils: add a simple function to substract a variable to another to zero

This commit is contained in:
Kazhnuz 2019-04-27 22:04:18 +02:00
parent ea5011642c
commit dcfa657f64

View file

@ -40,6 +40,16 @@ function Math.round(num)
return math.floor(num + 0.5) return math.floor(num + 0.5)
end end
function Math.toZero(num, sub)
local sub = math.floor(sub)
if math.abs(num) < sub then
return 0
else
return num - (sub * Math.sign(num))
end
end
-- VECTOR/DIRECTION functions -- VECTOR/DIRECTION functions
-- Easy-to-use function to handle point and motion -- Easy-to-use function to handle point and motion