Add is_zero_approx methods to Vector2, 3, and 4
This commit is contained in:
parent
c6fd311da0
commit
15d057c521
26 changed files with 70 additions and 31 deletions
|
|
@ -1033,13 +1033,13 @@ void Basis::rotate_sh(real_t *p_values) {
|
|||
|
||||
Basis Basis::looking_at(const Vector3 &p_target, const Vector3 &p_up) {
|
||||
#ifdef MATH_CHECKS
|
||||
ERR_FAIL_COND_V_MSG(p_target.is_equal_approx(Vector3()), Basis(), "The target vector can't be zero.");
|
||||
ERR_FAIL_COND_V_MSG(p_up.is_equal_approx(Vector3()), Basis(), "The up vector can't be zero.");
|
||||
ERR_FAIL_COND_V_MSG(p_target.is_zero_approx(), Basis(), "The target vector can't be zero.");
|
||||
ERR_FAIL_COND_V_MSG(p_up.is_zero_approx(), Basis(), "The up vector can't be zero.");
|
||||
#endif
|
||||
Vector3 v_z = -p_target.normalized();
|
||||
Vector3 v_x = p_up.cross(v_z);
|
||||
#ifdef MATH_CHECKS
|
||||
ERR_FAIL_COND_V_MSG(v_x.is_equal_approx(Vector3()), Basis(), "The target vector and up vector can't be parallel to each other.");
|
||||
ERR_FAIL_COND_V_MSG(v_x.is_zero_approx(), Basis(), "The target vector and up vector can't be parallel to each other.");
|
||||
#endif
|
||||
v_x.normalize();
|
||||
Vector3 v_y = v_z.cross(v_x);
|
||||
|
|
|
|||
|
|
@ -182,6 +182,10 @@ bool Vector2::is_equal_approx(const Vector2 &p_v) const {
|
|||
return Math::is_equal_approx(x, p_v.x) && Math::is_equal_approx(y, p_v.y);
|
||||
}
|
||||
|
||||
bool Vector2::is_zero_approx() const {
|
||||
return Math::is_zero_approx(x) && Math::is_zero_approx(y);
|
||||
}
|
||||
|
||||
Vector2::operator String() const {
|
||||
return "(" + String::num_real(x, false) + ", " + String::num_real(y, false) + ")";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -124,6 +124,7 @@ struct _NO_DISCARD_ Vector2 {
|
|||
Vector2 reflect(const Vector2 &p_normal) const;
|
||||
|
||||
bool is_equal_approx(const Vector2 &p_v) const;
|
||||
bool is_zero_approx() const;
|
||||
|
||||
Vector2 operator+(const Vector2 &p_v) const;
|
||||
void operator+=(const Vector2 &p_v);
|
||||
|
|
|
|||
|
|
@ -145,6 +145,10 @@ bool Vector3::is_equal_approx(const Vector3 &p_v) const {
|
|||
return Math::is_equal_approx(x, p_v.x) && Math::is_equal_approx(y, p_v.y) && Math::is_equal_approx(z, p_v.z);
|
||||
}
|
||||
|
||||
bool Vector3::is_zero_approx() const {
|
||||
return Math::is_zero_approx(x) && Math::is_zero_approx(y) && Math::is_zero_approx(z);
|
||||
}
|
||||
|
||||
Vector3::operator String() const {
|
||||
return "(" + String::num_real(x, false) + ", " + String::num_real(y, false) + ", " + String::num_real(z, false) + ")";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -142,6 +142,7 @@ struct _NO_DISCARD_ Vector3 {
|
|||
_FORCE_INLINE_ Vector3 reflect(const Vector3 &p_normal) const;
|
||||
|
||||
bool is_equal_approx(const Vector3 &p_v) const;
|
||||
bool is_zero_approx() const;
|
||||
|
||||
/* Operators */
|
||||
|
||||
|
|
|
|||
|
|
@ -71,6 +71,10 @@ bool Vector4::is_equal_approx(const Vector4 &p_vec4) const {
|
|||
return Math::is_equal_approx(x, p_vec4.x) && Math::is_equal_approx(y, p_vec4.y) && Math::is_equal_approx(z, p_vec4.z) && Math::is_equal_approx(w, p_vec4.w);
|
||||
}
|
||||
|
||||
bool Vector4::is_zero_approx() const {
|
||||
return Math::is_zero_approx(x) && Math::is_zero_approx(y) && Math::is_zero_approx(z) && Math::is_zero_approx(w);
|
||||
}
|
||||
|
||||
real_t Vector4::length() const {
|
||||
return Math::sqrt(length_squared());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,6 +73,7 @@ struct _NO_DISCARD_ Vector4 {
|
|||
|
||||
_FORCE_INLINE_ real_t length_squared() const;
|
||||
bool is_equal_approx(const Vector4 &p_vec4) const;
|
||||
bool is_zero_approx() const;
|
||||
real_t length() const;
|
||||
void normalize();
|
||||
Vector4 normalized() const;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue