From 47b86c18627d43ad8d46f75f507f0f9b25c7a09e Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 2 Jan 2022 17:11:52 +0100 Subject: [PATCH] feat: add wrap function --- sonic-radiance.love/birb/utils/math.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/sonic-radiance.love/birb/utils/math.lua b/sonic-radiance.love/birb/utils/math.lua index 3d0ba85..84aeeaa 100644 --- a/sonic-radiance.love/birb/utils/math.lua +++ b/sonic-radiance.love/birb/utils/math.lua @@ -64,6 +64,18 @@ function Math.either(bool, val1, val2) end end +function Math.wrap(val, min, max) + while (val < min) do + local diff = ((min-1) - val) + val = max - diff + end + while (val > max) do + local diff = ((max+1) - val) + val = min + diff + end + return val +end + -- VECTOR/DIRECTION functions -- Easy-to-use function to handle point and motion