[3.x] Backport some APIs in math structs

This commit is contained in:
Aaron Franke
2021-11-04 18:17:41 -05:00
parent eb19618fd1
commit 1d8cef8236
17 changed files with 184 additions and 3 deletions

View File

@@ -128,6 +128,7 @@ Vector2 Vector2::snapped(const Vector2 &p_by) const {
}
Vector2 Vector2::clamped(real_t p_len) const {
WARN_DEPRECATED_MSG("'Vector2.clamped()' is deprecated because it has been renamed to 'limit_length'.");
real_t l = length();
Vector2 v = *this;
if (l > 0 && p_len < l) {
@@ -138,6 +139,17 @@ Vector2 Vector2::clamped(real_t p_len) const {
return v;
}
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;
v *= p_len;
}
return v;
}
Vector2 Vector2::cubic_interpolate(const Vector2 &p_b, const Vector2 &p_pre_a, const Vector2 &p_post_b, real_t p_weight) const {
Vector2 p0 = p_pre_a;
Vector2 p1 = *this;