summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2017-10-22 12:06:00 +0200
committerGitHub <noreply@github.com>2017-10-22 12:06:00 +0200
commit99c8a8c7b1da2831a2d6f7fb3b78bd9f68272e9f (patch)
treef7810fc7be2c4eee2b0ec3bf4795f1930fd6f7ce /core
parentbc667aeada757463fbb562eb262d404968f0ca37 (diff)
parent2e22c07f4261625834bd0d16aa5e09005666ab14 (diff)
Merge pull request #11401 from SaracenOne/snapped_drag
Added snapping to spatial drag and drop.
Diffstat (limited to 'core')
-rw-r--r--core/math/math_funcs.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h
index d63da322a5..65b2ffb0df 100644
--- a/core/math/math_funcs.h
+++ b/core/math/math_funcs.h
@@ -387,6 +387,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