diff options
| author | Aaron Franke <arnfranke@yahoo.com> | 2022-09-18 17:49:02 -0500 |
|---|---|---|
| committer | Aaron Franke <arnfranke@yahoo.com> | 2022-09-19 03:09:59 -0500 |
| commit | b11ff9d87662b4cd5582cc721d2e1d1d5f4f369f (patch) | |
| tree | 05190ab7c17b3c0f335a879673f39b5a288e6ceb /include | |
| parent | d20c4200dbf42116b7601eb8a6290ba302a51ae6 (diff) | |
| download | redot-cpp-b11ff9d87662b4cd5582cc721d2e1d1d5f4f369f.tar.gz | |
Replace stepify with snapped
https://github.com/godotengine/godot/pull/44586
Diffstat (limited to 'include')
| -rw-r--r-- | include/godot_cpp/core/math.hpp | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/include/godot_cpp/core/math.hpp b/include/godot_cpp/core/math.hpp index 78eee8a..ca1e6e9 100644 --- a/include/godot_cpp/core/math.hpp +++ b/include/godot_cpp/core/math.hpp @@ -583,19 +583,6 @@ inline float wrapf(real_t value, real_t min, real_t max) { return is_zero_approx(range) ? min : value - (range * floor((value - min) / range)); } -inline float stepify(float p_value, float p_step) { - if (p_step != 0) { - p_value = floor(p_value / p_step + 0.5f) * p_step; - } - return p_value; -} -inline double stepify(double p_value, double p_step) { - if (p_step != 0) { - p_value = floor(p_value / p_step + 0.5) * p_step; - } - return p_value; -} - inline unsigned int next_power_of_2(unsigned int x) { if (x == 0) return 0; @@ -641,6 +628,24 @@ inline double snapped(double p_value, double p_step) { return p_value; } +inline float snap_scalar(float p_offset, float p_step, float p_target) { + return p_step != 0 ? Math::snapped(p_target - p_offset, p_step) + p_offset : p_target; +} + +inline float snap_scalar_separation(float p_offset, float p_step, float p_target, float p_separation) { + if (p_step != 0) { + float a = Math::snapped(p_target - p_offset, p_step + p_separation) + p_offset; + float b = a; + if (p_target >= 0) { + b -= p_separation; + } else { + b += p_step; + } + return (Math::abs(p_target - a) < Math::abs(p_target - b)) ? a : b; + } + return p_target; +} + } // namespace Math } // namespace godot |
