diff --git a/sonic-boost.love/libs/loveutils/math.lua b/sonic-boost.love/libs/loveutils/math.lua index 678720f..62a339e 100644 --- a/sonic-boost.love/libs/loveutils/math.lua +++ b/sonic-boost.love/libs/loveutils/math.lua @@ -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