diff options
author | Malcolm Nixon <Malcolm.nixon@gmail.com> | 2024-06-14 03:08:16 -0400 |
---|---|---|
committer | Malcolm Nixon <Malcolm.nixon@gmail.com> | 2024-08-15 19:08:05 -0400 |
commit | 23fc704cbc79c77fb3e8bda8c58a8bbb4815951e (patch) | |
tree | 2550acf6c8e56bdccb4ce0ac5876c3655a2ba71f /core/math/math_funcs.h | |
parent | ee363af0ed65f6ca9a906f6065d0bd9c19dcf9e4 (diff) | |
download | redot-engine-23fc704cbc79c77fb3e8bda8c58a8bbb4815951e.tar.gz |
This PR handles the smoothstep degenerate case where the range is empty.
It also updates the documentation to describe positive and negative ranges.
Co-Authored-By: Hugo Locurcio <hugo.locurcio@hugo.pro>
Co-Authored-By: kleonc <9283098+kleonc@users.noreply.github.com>
Diffstat (limited to 'core/math/math_funcs.h')
-rw-r--r-- | core/math/math_funcs.h | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h index 3060f31970..fd53ed28fd 100644 --- a/core/math/math_funcs.h +++ b/core/math/math_funcs.h @@ -447,14 +447,22 @@ public: static _ALWAYS_INLINE_ double smoothstep(double p_from, double p_to, double p_s) { if (is_equal_approx(p_from, p_to)) { - return p_from; + if (likely(p_from <= p_to)) { + return p_s <= p_from ? 0.0 : 1.0; + } else { + return p_s <= p_to ? 1.0 : 0.0; + } } double s = CLAMP((p_s - p_from) / (p_to - p_from), 0.0, 1.0); return s * s * (3.0 - 2.0 * s); } static _ALWAYS_INLINE_ float smoothstep(float p_from, float p_to, float p_s) { if (is_equal_approx(p_from, p_to)) { - return p_from; + if (likely(p_from <= p_to)) { + return p_s <= p_from ? 0.0f : 1.0f; + } else { + return p_s <= p_to ? 1.0f : 0.0f; + } } float s = CLAMP((p_s - p_from) / (p_to - p_from), 0.0f, 1.0f); return s * s * (3.0f - 2.0f * s); |