From 4085a1700c478dac386a78b88c9e7c9cd56825cb Mon Sep 17 00:00:00 2001 From: josh Date: Thu, 21 Mar 2024 20:43:07 -0400 Subject: [PATCH] Implement Vector3::Equals --- include/J3ML/LinearAlgebra/Vector3.h | 4 ++++ src/J3ML/LinearAlgebra/Vector3.cpp | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/include/J3ML/LinearAlgebra/Vector3.h b/include/J3ML/LinearAlgebra/Vector3.h index ee161e9..02ecfe3 100644 --- a/include/J3ML/LinearAlgebra/Vector3.h +++ b/include/J3ML/LinearAlgebra/Vector3.h @@ -162,6 +162,10 @@ public: /// Unary - operator (Negation) Vector3 operator-() const; + bool Equals(const Vector3& rhs, float epsilon = 1e-3f) const; + bool Equals(float _x, float _y, float _z, float epsilon = 1e-3f) const; + + Vector3 &operator =(const Vector3& rhs); Vector3& operator+=(const Vector3& rhs); Vector3& operator-=(const Vector3& rhs); diff --git a/src/J3ML/LinearAlgebra/Vector3.cpp b/src/J3ML/LinearAlgebra/Vector3.cpp index a7517a1..5f2ab14 100644 --- a/src/J3ML/LinearAlgebra/Vector3.cpp +++ b/src/J3ML/LinearAlgebra/Vector3.cpp @@ -409,5 +409,17 @@ namespace J3ML::LinearAlgebra { return rhs.Abs(); } + bool Vector3::Equals(const Vector3 &rhs, float epsilon) const { + return std::abs(x - rhs.x) < epsilon && + std::abs(y - rhs.y) < epsilon && + std::abs(z - rhs.z) < epsilon; + } + + bool Vector3::Equals(float _x, float _y, float _z, float epsilon) const { + return std::abs(x - _x) < epsilon && + std::abs(y - _y) < epsilon && + std::abs(z - _z) < epsilon; + } + } \ No newline at end of file