diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2021-10-11 22:55:01 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-11 22:55:01 +0200 |
commit | 9ed4f8367b29204b89f9feaf86727b24396fb180 (patch) | |
tree | 8c41815399d8eff5746ac17464ebb34d82b0a747 /core/math | |
parent | 5edfdc53ebb97616a6a72031b2e28ec7865d6ab8 (diff) | |
parent | 372ba7666304805abe8641487c97899f9bdd97af (diff) |
Merge pull request #48332 from TokageItLab/implement-ping-pong
Diffstat (limited to 'core/math')
-rw-r--r-- | core/math/math_funcs.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h index 4e4f566517..5824d194a6 100644 --- a/core/math/math_funcs.h +++ b/core/math/math_funcs.h @@ -291,6 +291,19 @@ public: return is_zero_approx(range) ? min : value - (range * Math::floor((value - min) / range)); } + static _ALWAYS_INLINE_ float fract(float value) { + return value - floor(value); + } + static _ALWAYS_INLINE_ double fract(double value) { + return value - floor(value); + } + static _ALWAYS_INLINE_ float pingpong(float value, float length) { + return (length != 0.0f) ? abs(fract((value - length) / (length * 2.0f)) * length * 2.0f - length) : 0.0f; + } + static _ALWAYS_INLINE_ double pingpong(double value, double length) { + return (length != 0.0) ? abs(fract((value - length) / (length * 2.0)) * length * 2.0 - length) : 0.0; + } + // 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); |