From 4881ebb6162bde6658431f5723c16576aa2b55bb Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 4 Mar 2012 16:06:09 +0000 Subject: Added comparison operators to math:Vector3f. --- src/math/vector3f.cc | 17 +++++++++-------- src/math/vector3f.h | 24 ++++++++++++++++++++---- 2 files changed, 29 insertions(+), 12 deletions(-) (limited to 'src/math') diff --git a/src/math/vector3f.cc b/src/math/vector3f.cc index 421d84e..03b4307 100644 --- a/src/math/vector3f.cc +++ b/src/math/vector3f.cc @@ -36,6 +36,15 @@ void Vector3f::clear() memset(coord, 0, sizeof(coord)); } +bool Vector3f::equals(const Vector3f &other) const +{ + return( + (coord[0] == other.coord[0]) && + (coord[1] == other.coord[1]) && + (coord[2] == other.coord[2]) + ); +} + void Vector3f::assign(const float x, const float y, const float z) { coord[0] = x; @@ -89,14 +98,6 @@ Vector3f &Vector3f::operator+=(const Vector3f &other) return (*this); } -bool Vector3f::operator==(const Vector3f& other) const -{ - for (int i = 0; i < 3; i++) - if (coord[i] != other.coord[i]) - return (false); - return (true); -} - float Vector3f::lengthsquared() const { float r = 0; diff --git a/src/math/vector3f.h b/src/math/vector3f.h index 2ff4ba0..24a7610 100644 --- a/src/math/vector3f.h +++ b/src/math/vector3f.h @@ -39,7 +39,26 @@ public: /// destructor ~Vector3f(); - + + /** + * @brief comparison + * */ + bool equals(const Vector3f &other) const; + + /** + * @brief equality operator + * */ + inline bool operator==(const Vector3f &other) const { + return (equals(other)); + } + + /** + * @brief inequality operator + * */ + inline bool operator!=(const Vector3f &other) const { + return (!equals(other)); + } + /* -- Assignment operators -- */ /// assign (0, 0, 0) void clear(); @@ -98,9 +117,6 @@ public: return v; } - /// comparison operator - bool operator==(const Vector3f &other) const; - /// assign a value to an element of this vector /*! range is not checked * @param index the index of the element to assign to ( 0 <= index < 3 ) -- cgit v1.2.3