loveutils: add back the wrap function

This commit is contained in:
Kazhnuz 2019-02-04 09:02:50 +01:00
parent 421e92f80a
commit 091210df41

View file

@ -1,5 +1,21 @@
local Math = {}
function Math.wrap(x, startnumber, endnumber)
local delta = endnumber - startnumber
if delta < 0 then
err("endnumber must be larger than startnumber")
end
while x >= endnumber do
x = x - delta
end
while x < startnumber do
x = x + delta
end
return x
end
function Math.sign(x)
if (x < 0) then
return -1