diff options
Diffstat (limited to 'core/math/math_funcs.cpp')
-rw-r--r-- | core/math/math_funcs.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/core/math/math_funcs.cpp b/core/math/math_funcs.cpp index 6fb688f16b..64e01e5841 100644 --- a/core/math/math_funcs.cpp +++ b/core/math/math_funcs.cpp @@ -176,3 +176,18 @@ float Math::random(float from, float to) { float ret = (float)r / (float)RANDOM_MAX; return (ret) * (to - from) + from; } + +int Math::wrapi(int value, int min, int max) { + --max; + int rng = max - min + 1; + value = ((value - min) % rng); + if (value < 0) + return max + 1 + value; + else + return min + value; +} + +float Math::wrapf(float value, float min, float max) { + float rng = max - min; + return min + (value - min) - (rng * floor((value - min) / rng)); +} |