diff options
author | Aaron Franke <arnfranke@yahoo.com> | 2018-10-27 16:12:27 -0400 |
---|---|---|
committer | Aaron Franke <arnfranke@yahoo.com> | 2019-07-18 16:33:43 -0400 |
commit | a60f242982d70e85a5b2c182eb3289b2fa7812e1 (patch) | |
tree | 212cd72bf8e9b157de9b35ec8ccda3337f30bbbc /core | |
parent | 20a3bb9c484431439ffa60a158d7563c466cd530 (diff) |
Add integer posmod and rename default arg names
"posmod" is the integer version of "fposmod". We do not need a "mod" because of the % operator.
I changed the default arg names from "x" and "y" to "a" and "b" because they are not coordinates. I also changed pow's arg names to "base" and "exp". Also, I reorganized the code in the VS built-in funcs switch statement.
Diffstat (limited to 'core')
-rw-r--r-- | core/math/expression.cpp | 8 | ||||
-rw-r--r-- | core/math/expression.h | 1 | ||||
-rw-r--r-- | core/math/math_funcs.h | 7 |
3 files changed, 16 insertions, 0 deletions
diff --git a/core/math/expression.cpp b/core/math/expression.cpp index b52658e2cf..2786229cf3 100644 --- a/core/math/expression.cpp +++ b/core/math/expression.cpp @@ -52,6 +52,7 @@ const char *Expression::func_name[Expression::FUNC_MAX] = { "sqrt", "fmod", "fposmod", + "posmod", "floor", "ceil", "round", @@ -175,6 +176,7 @@ int Expression::get_func_argument_count(BuiltinFunc p_func) { case MATH_ATAN2: case MATH_FMOD: case MATH_FPOSMOD: + case MATH_POSMOD: case MATH_POW: case MATH_EASE: case MATH_STEPIFY: @@ -283,6 +285,12 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant VALIDATE_ARG_NUM(1); *r_return = Math::fposmod((double)*p_inputs[0], (double)*p_inputs[1]); } break; + case MATH_POSMOD: { + + VALIDATE_ARG_NUM(0); + VALIDATE_ARG_NUM(1); + *r_return = Math::posmod((int)*p_inputs[0], (int)*p_inputs[1]); + } break; case MATH_FLOOR: { VALIDATE_ARG_NUM(0); diff --git a/core/math/expression.h b/core/math/expression.h index 1113bb6587..03a2bb70e6 100644 --- a/core/math/expression.h +++ b/core/math/expression.h @@ -51,6 +51,7 @@ public: MATH_SQRT, MATH_FMOD, MATH_FPOSMOD, + MATH_POSMOD, MATH_FLOOR, MATH_CEIL, MATH_ROUND, diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h index 0e3bd8a318..b6398712e4 100644 --- a/core/math/math_funcs.h +++ b/core/math/math_funcs.h @@ -198,6 +198,13 @@ public: value += 0.0; return value; } + static _ALWAYS_INLINE_ int posmod(int p_x, int p_y) { + int value = p_x % p_y; + if ((value < 0 && p_y > 0) || (value > 0 && p_y < 0)) { + value += p_y; + } + return value; + } static _ALWAYS_INLINE_ double deg2rad(double p_y) { return p_y * Math_PI / 180.0; } static _ALWAYS_INLINE_ float deg2rad(float p_y) { return p_y * Math_PI / 180.0; } |