diff options
author | SaracenOne <SaracenOne@gmail.com> | 2017-09-18 22:44:04 +0100 |
---|---|---|
committer | SaracenOne <SaracenOne@gmail.com> | 2017-09-20 01:54:01 +0100 |
commit | 2e22c07f4261625834bd0d16aa5e09005666ab14 (patch) | |
tree | 108928c82ae2d08410fb57f541d38c64baeeda56 /core/math | |
parent | cd2ffdc6725aa6f7a9a4af6fd5abcc4cafae61b4 (diff) |
Added snapping to spatial drag and drop.
Diffstat (limited to 'core/math')
-rw-r--r-- | core/math/math_funcs.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h index 9651e37f3e..0bba662dac 100644 --- a/core/math/math_funcs.h +++ b/core/math/math_funcs.h @@ -351,6 +351,23 @@ public: return hf; } + + static _ALWAYS_INLINE_ float snap_scalar(float p_offset, float p_step, float p_target) { + return p_step != 0 ? Math::stepify(p_target - p_offset, p_step) + p_offset : p_target; + } + + static _ALWAYS_INLINE_ float snap_scalar_seperation(float p_offset, float p_step, float p_target, float p_separation) { + if (p_step != 0) { + float a = Math::stepify(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; + } }; #endif // MATH_FUNCS_H |