diff options
author | Aaron Franke <arnfranke@yahoo.com> | 2019-04-25 13:19:14 -0400 |
---|---|---|
committer | Aaron Franke <arnfranke@yahoo.com> | 2019-04-25 13:20:29 -0400 |
commit | b2e1c9c276cd833b642dfbaea3dde36d490b014e (patch) | |
tree | 1e5a46ea7be22d211525d1994f16d0240706961c /core/math/vector3.h | |
parent | cce2e4b07c1c4b6f2f9d72cac340d9f9ecbb790e (diff) | |
download | redot-engine-b2e1c9c276cd833b642dfbaea3dde36d490b014e.tar.gz |
[Core] Approximate equality
Diffstat (limited to 'core/math/vector3.h')
-rw-r--r-- | core/math/vector3.h | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/core/math/vector3.h b/core/math/vector3.h index e9074c5bd4..21fc09653f 100644 --- a/core/math/vector3.h +++ b/core/math/vector3.h @@ -341,17 +341,17 @@ Vector3 Vector3::operator-() const { bool Vector3::operator==(const Vector3 &p_v) const { - return (x == p_v.x && y == p_v.y && z == p_v.z); + 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::operator!=(const Vector3 &p_v) const { - return (x != p_v.x || y != p_v.y || z != p_v.z); + 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::operator<(const Vector3 &p_v) const { - if (x == p_v.x) { - if (y == p_v.y) + if (Math::is_equal_approx(x, p_v.x)) { + if (Math::is_equal_approx(y, p_v.y)) return z < p_v.z; else return y < p_v.y; @@ -362,8 +362,8 @@ bool Vector3::operator<(const Vector3 &p_v) const { bool Vector3::operator<=(const Vector3 &p_v) const { - if (x == p_v.x) { - if (y == p_v.y) + if (Math::is_equal_approx(x, p_v.x)) { + if (Math::is_equal_approx(y, p_v.y)) return z <= p_v.z; else return y < p_v.y; @@ -402,13 +402,14 @@ real_t Vector3::length_squared() const { void Vector3::normalize() { - real_t l = length(); - if (l == 0) { + real_t lengthsq = length_squared(); + if (lengthsq == 0) { x = y = z = 0; } else { - x /= l; - y /= l; - z /= l; + real_t length = Math::sqrt(lengthsq); + x /= length; + y /= length; + z /= length; } } |