Added new wrap functions
This commit is contained in:
parent
409e58e67a
commit
216a8aa643
6 changed files with 85 additions and 1 deletions
|
|
@ -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));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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__ (
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue