From 2e22c07f4261625834bd0d16aa5e09005666ab14 Mon Sep 17 00:00:00 2001 From: SaracenOne Date: Mon, 18 Sep 2017 22:44:04 +0100 Subject: Added snapping to spatial drag and drop. --- core/math/math_funcs.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'core/math/math_funcs.h') 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 -- cgit v1.2.3