summaryrefslogtreecommitdiff
path: root/core/math
diff options
context:
space:
mode:
authorAaron Franke <arnfranke@yahoo.com>2021-02-01 00:42:00 -0500
committerAaron Franke <arnfranke@yahoo.com>2021-06-03 12:04:57 -0400
commit94bc0bd9193d5e361bbe657d59a492467f129721 (patch)
tree2adf53e9a8efb9d027961eeb0c5726e47be9bbe1 /core/math
parentf288a79482ad5272d872fdc84fdb64a228334d8e (diff)
Rename Vector2 clamped to limit_length and add limit_length to Vector3
Diffstat (limited to 'core/math')
-rw-r--r--core/math/vector2.cpp4
-rw-r--r--core/math/vector2.h3
-rw-r--r--core/math/vector3.cpp11
-rw-r--r--core/math/vector3.h1
4 files changed, 15 insertions, 4 deletions
diff --git a/core/math/vector2.cpp b/core/math/vector2.cpp
index 46a08b53ab..ab114673d8 100644
--- a/core/math/vector2.cpp
+++ b/core/math/vector2.cpp
@@ -128,8 +128,8 @@ Vector2 Vector2::snapped(const Vector2 &p_step) const {
Math::snapped(y, p_step.y));
}
-Vector2 Vector2::clamped(real_t p_len) const {
- real_t l = length();
+Vector2 Vector2::limit_length(const real_t p_len) const {
+ const real_t l = length();
Vector2 v = *this;
if (l > 0 && p_len < l) {
v /= l;
diff --git a/core/math/vector2.h b/core/math/vector2.h
index 6abe0f5ea9..2a540bd8aa 100644
--- a/core/math/vector2.h
+++ b/core/math/vector2.h
@@ -84,6 +84,7 @@ struct Vector2 {
real_t length() const;
real_t length_squared() const;
+ Vector2 limit_length(const real_t p_len = 1.0) const;
Vector2 min(const Vector2 &p_vector2) const {
return Vector2(MIN(x, p_vector2.x), MIN(y, p_vector2.y));
@@ -107,8 +108,6 @@ struct Vector2 {
Vector2 plane_project(real_t p_d, const Vector2 &p_vec) const;
- Vector2 clamped(real_t p_len) const;
-
_FORCE_INLINE_ Vector2 lerp(const Vector2 &p_to, real_t p_weight) const;
_FORCE_INLINE_ Vector2 slerp(const Vector2 &p_to, real_t p_weight) const;
Vector2 cubic_interpolate(const Vector2 &p_b, const Vector2 &p_pre_a, const Vector2 &p_post_b, real_t p_weight) const;
diff --git a/core/math/vector3.cpp b/core/math/vector3.cpp
index d4317d506c..cc71b1dacf 100644
--- a/core/math/vector3.cpp
+++ b/core/math/vector3.cpp
@@ -64,6 +64,17 @@ Vector3 Vector3::snapped(Vector3 p_step) const {
return v;
}
+Vector3 Vector3::limit_length(const real_t p_len) const {
+ const real_t l = length();
+ Vector3 v = *this;
+ if (l > 0 && p_len < l) {
+ v /= l;
+ v *= p_len;
+ }
+
+ return v;
+}
+
Vector3 Vector3::cubic_interpolate(const Vector3 &p_b, const Vector3 &p_pre_a, const Vector3 &p_post_b, real_t p_weight) const {
Vector3 p0 = p_pre_a;
Vector3 p1 = *this;
diff --git a/core/math/vector3.h b/core/math/vector3.h
index adfc52566f..8bab8fd847 100644
--- a/core/math/vector3.h
+++ b/core/math/vector3.h
@@ -86,6 +86,7 @@ struct Vector3 {
_FORCE_INLINE_ Vector3 normalized() const;
_FORCE_INLINE_ bool is_normalized() const;
_FORCE_INLINE_ Vector3 inverse() const;
+ Vector3 limit_length(const real_t p_len = 1.0) const;
_FORCE_INLINE_ void zero();