From 091210df417b8035453bb76c94960cb4c751f91a Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Mon, 4 Feb 2019 09:02:50 +0100 Subject: [PATCH] loveutils: add back the wrap function --- sonic-boost.love/libs/loveutils/math.lua | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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