summaryrefslogtreecommitdiff
path: root/core/math
diff options
context:
space:
mode:
authorChaosus <chaosus89@gmail.com>2017-10-11 20:38:55 +0300
committerChaosus <chaosus89@gmail.com>2017-10-13 11:10:45 +0300
commit216a8aa643503b898e1562634240b93406ae1ce3 (patch)
treec9a7d0ac38b2d7d3d02e65004c0492416ab7b912 /core/math
parent409e58e67abde4e7af6e43b32c23338e119377fb (diff)
Added new wrap functions
Diffstat (limited to 'core/math')
-rw-r--r--core/math/math_funcs.cpp15
-rw-r--r--core/math/math_funcs.h5
2 files changed, 19 insertions, 1 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));
+}
diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h
index d63da322a5..4644a00d7c 100644
--- a/core/math/math_funcs.h
+++ b/core/math/math_funcs.h
@@ -207,6 +207,9 @@ public:
static _ALWAYS_INLINE_ double round(double p_val) { return (p_val >= 0) ? Math::floor(p_val + 0.5) : -Math::floor(-p_val + 0.5); }
static _ALWAYS_INLINE_ float round(float p_val) { return (p_val >= 0) ? Math::floor(p_val + 0.5) : -Math::floor(-p_val + 0.5); }
+ static int wrapi(int value, int min, int max);
+ static float wrapf(float value, float min, float max);
+
// double only, as these functions are mainly used by the editor and not performance-critical,
static double ease(double p_x, double p_c);
static int step_decimals(double p_step);
@@ -268,7 +271,7 @@ public:
#elif defined(_MSC_VER) && _MSC_VER < 1800
__asm fld a __asm fistp b
-/*#elif defined( __GNUC__ ) && ( defined( __i386__ ) || defined( __x86_64__ ) )
+ /*#elif defined( __GNUC__ ) && ( defined( __i386__ ) || defined( __x86_64__ ) )
// use AT&T inline assembly style, document that
// we use memory as output (=m) and input (m)
__asm__ __volatile__ (