diff --git a/panda/src/linmath/lmatrix3_src.I b/panda/src/linmath/lmatrix3_src.I index 8d5d4ad4ac..b97d1e6cfe 100644 --- a/panda/src/linmath/lmatrix3_src.I +++ b/panda/src/linmath/lmatrix3_src.I @@ -315,6 +315,30 @@ end() const { return begin() + get_num_components(); } +//////////////////////////////////////////////////////////////////// +// Function: LMatrix3::Ordering Operator +// Access: Public +// Description: This performs a lexicographical comparison. It's of +// questionable mathematical meaning, but sometimes has +// a practical purpose for sorting unique vectors, +// especially in an STL container. Also see +// compare_to(). +//////////////////////////////////////////////////////////////////// +INLINE bool FLOATNAME(LMatrix3):: +operator < (const FLOATNAME(LMatrix3) &other) const { + return compare_to(other) < 0; +} + +//////////////////////////////////////////////////////////////////// +// Function: LMatrix3::Equality Operator +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE bool FLOATNAME(LMatrix3):: +operator == (const FLOATNAME(LMatrix3) &other) const { + return compare_to(other) == 0; +} + //////////////////////////////////////////////////////////////////// // Function: LMatrix3::Inequality Operator // Access: Public diff --git a/panda/src/linmath/lmatrix3_src.cxx b/panda/src/linmath/lmatrix3_src.cxx index 2ded892eb0..284964cf18 100644 --- a/panda/src/linmath/lmatrix3_src.cxx +++ b/panda/src/linmath/lmatrix3_src.cxx @@ -17,7 +17,6 @@ FLOATNAME(LMatrix3) FLOATNAME(LMatrix3)::_ident_mat = // fill_value. This is of questionable value, but is // sometimes useful when initializing to zero. //////////////////////////////////////////////////////////////////// - void FLOATNAME(LMatrix3):: fill(FLOATTYPE fill_value) { set(fill_value, fill_value, fill_value, @@ -26,24 +25,14 @@ fill(FLOATTYPE fill_value) { } //////////////////////////////////////////////////////////////////// -// Function: LMatrix3::Equality Operator +// Function: LMatrix3::compare_to // Access: Public -// Description: +// Description: Sorts matrices lexicographically, componentwise. +// Returns a number less than 0 if this matrix sorts +// before the other one, greater than zero if it sorts +// after, 0 if they are equivalent (within the indicated +// tolerance). //////////////////////////////////////////////////////////////////// - -bool FLOATNAME(LMatrix3):: -operator == (const FLOATNAME(LMatrix3) &other) const { - return ((*this)(0, 0) == other(0, 0) && - (*this)(0, 1) == other(0, 1) && - (*this)(0, 2) == other(0, 2) && - (*this)(1, 0) == other(1, 0) && - (*this)(1, 1) == other(1, 1) && - (*this)(1, 2) == other(1, 2) && - (*this)(2, 0) == other(2, 0) && - (*this)(2, 1) == other(2, 1) && - (*this)(2, 2) == other(2, 2)); -} - int FLOATNAME(LMatrix3):: compare_to(const FLOATNAME(LMatrix3) &other, FLOATTYPE threshold) const { for (int i = 0; i < 9; i++) { @@ -60,7 +49,6 @@ compare_to(const FLOATNAME(LMatrix3) &other, FLOATTYPE threshold) const { // Description: Returns true if two matrices are memberwise equal // within a specified tolerance. //////////////////////////////////////////////////////////////////// - bool FLOATNAME(LMatrix3):: almost_equal(const FLOATNAME(LMatrix3) &other, FLOATTYPE threshold) const { return (IS_THRESHOLD_EQUAL((*this)(0, 0), other(0, 0), threshold) && @@ -79,7 +67,6 @@ almost_equal(const FLOATNAME(LMatrix3) &other, FLOATTYPE threshold) const { // Access: Public, Static // Description: //////////////////////////////////////////////////////////////////// - void FLOATNAME(LMatrix3):: init_type() { if (_type_handle == TypeHandle::none()) { @@ -95,7 +82,6 @@ init_type() { // Function: LMatrix3::write_datagram // Description: Writes the matrix to the datagram //////////////////////////////////////////////////////////////////// - void FLOATNAME(LMatrix3):: write_datagram(Datagram &destination) const { @@ -112,7 +98,6 @@ write_datagram(Datagram &destination) const // Function: LMatrix3::read_datagram // Description: Reads itself out of the datagram //////////////////////////////////////////////////////////////////// - void FLOATNAME(LMatrix3):: read_datagram(DatagramIterator &scan) { diff --git a/panda/src/linmath/lmatrix3_src.h b/panda/src/linmath/lmatrix3_src.h index f50103780d..988ca10169 100644 --- a/panda/src/linmath/lmatrix3_src.h +++ b/panda/src/linmath/lmatrix3_src.h @@ -60,7 +60,8 @@ public: INLINE const_iterator end() const; PUBLISHED: - bool operator == (const FLOATNAME(LMatrix3) &other) const; + INLINE bool operator < (const FLOATNAME(LMatrix3) &other) const; + INLINE bool operator == (const FLOATNAME(LMatrix3) &other) const; INLINE bool operator != (const FLOATNAME(LMatrix3) &other) const; INLINE int compare_to(const FLOATNAME(LMatrix3) &other) const; diff --git a/panda/src/linmath/lmatrix4_src.I b/panda/src/linmath/lmatrix4_src.I index 583885fa8f..bf1591984e 100644 --- a/panda/src/linmath/lmatrix4_src.I +++ b/panda/src/linmath/lmatrix4_src.I @@ -419,6 +419,30 @@ end() const { return begin() + 16; } +//////////////////////////////////////////////////////////////////// +// Function: LMatrix4::Ordering Operator +// Access: Public +// Description: This performs a lexicographical comparison. It's of +// questionable mathematical meaning, but sometimes has +// a practical purpose for sorting unique vectors, +// especially in an STL container. Also see +// compare_to(). +//////////////////////////////////////////////////////////////////// +INLINE bool FLOATNAME(LMatrix4):: +operator < (const FLOATNAME(LMatrix4) &other) const { + return compare_to(other) < 0; +} + +//////////////////////////////////////////////////////////////////// +// Function: LMatrix4::Equality Operator +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE bool FLOATNAME(LMatrix4):: +operator == (const FLOATNAME(LMatrix4) &other) const { + return compare_to(other) == 0; +} + //////////////////////////////////////////////////////////////////// // Function: LMatrix4::Inequality Operator // Access: Public diff --git a/panda/src/linmath/lmatrix4_src.cxx b/panda/src/linmath/lmatrix4_src.cxx index 1e3e974bef..243cfe49a7 100644 --- a/panda/src/linmath/lmatrix4_src.cxx +++ b/panda/src/linmath/lmatrix4_src.cxx @@ -23,40 +23,12 @@ const FLOATNAME(LMatrix4) FLOATNAME(LMatrix4)::_z_to_y_up_mat = 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0); -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::Equality Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// - -bool FLOATNAME(LMatrix4):: -operator == (const FLOATNAME(LMatrix4) &other) const { - return ((*this)(0, 0) == other(0, 0) && - (*this)(0, 1) == other(0, 1) && - (*this)(0, 2) == other(0, 2) && - (*this)(0, 3) == other(0, 3) && - (*this)(1, 0) == other(1, 0) && - (*this)(1, 1) == other(1, 1) && - (*this)(1, 2) == other(1, 2) && - (*this)(1, 3) == other(1, 3) && - (*this)(2, 0) == other(2, 0) && - (*this)(2, 1) == other(2, 1) && - (*this)(2, 2) == other(2, 2) && - (*this)(2, 3) == other(2, 3) && - (*this)(3, 0) == other(3, 0) && - (*this)(3, 1) == other(3, 1) && - (*this)(3, 2) == other(3, 2) && - (*this)(3, 3) == other(3, 3)); -} - - //////////////////////////////////////////////////////////////////// // Function: LMatrix::convert_mat // Access: Public, Static // Description: Returns a matrix that transforms from the indicated // coordinate system to the indicated coordinate system. //////////////////////////////////////////////////////////////////// - FLOATNAME(LMatrix4) FLOATNAME(LMatrix4):: convert_mat(CoordinateSystem from, CoordinateSystem to) { if (from == CS_default) { @@ -121,7 +93,6 @@ convert_mat(CoordinateSystem from, CoordinateSystem to) { // Description: Returns true if two matrices are memberwise equal // within a specified tolerance. //////////////////////////////////////////////////////////////////// - bool FLOATNAME(LMatrix4):: almost_equal(const FLOATNAME(LMatrix4) &other, FLOATTYPE threshold) const { return (IS_THRESHOLD_EQUAL((*this)(0, 0), other(0, 0), threshold) && @@ -148,7 +119,6 @@ almost_equal(const FLOATNAME(LMatrix4) &other, FLOATTYPE threshold) const { // Access: Private // Description: //////////////////////////////////////////////////////////////////// - bool FLOATNAME(LMatrix4):: decompose_mat(int index[4]) { int i, j, k; @@ -222,7 +192,6 @@ decompose_mat(int index[4]) { // Access: Private // Description: //////////////////////////////////////////////////////////////////// - bool FLOATNAME(LMatrix4):: back_sub_mat(int index[4], FLOATNAME(LMatrix4) &inv, int row) const { int ii = -1; @@ -258,7 +227,6 @@ back_sub_mat(int index[4], FLOATNAME(LMatrix4) &inv, int row) const { // Access: Public, Static // Description: //////////////////////////////////////////////////////////////////// - void FLOATNAME(LMatrix4):: init_type() { if (_type_handle == TypeHandle::none()) { @@ -274,7 +242,6 @@ init_type() { // Function: LMatrix4::write_datagram // Description: Writes the matrix to the datagram //////////////////////////////////////////////////////////////////// - void FLOATNAME(LMatrix4):: write_datagram(Datagram &destination) const { @@ -292,7 +259,6 @@ write_datagram(Datagram &destination) const // Function: LMatrix4::read_datagram // Description: Reads itself out of the datagram //////////////////////////////////////////////////////////////////// - void FLOATNAME(LMatrix4):: read_datagram(DatagramIterator &scan) { @@ -314,7 +280,6 @@ read_datagram(DatagramIterator &scan) // after, 0 if they are equivalent (within the indicated // tolerance). //////////////////////////////////////////////////////////////////// - int FLOATNAME(LMatrix4):: compare_to(const FLOATNAME(LMatrix4) &other, FLOATTYPE threshold) const { for (int i = 0; i < 16; i++) { diff --git a/panda/src/linmath/lmatrix4_src.h b/panda/src/linmath/lmatrix4_src.h index deec2430ca..15bcd3aa5d 100644 --- a/panda/src/linmath/lmatrix4_src.h +++ b/panda/src/linmath/lmatrix4_src.h @@ -67,7 +67,8 @@ PUBLISHED: INLINE const_iterator begin() const; INLINE const_iterator end() const; - bool operator == (const FLOATNAME(LMatrix4) &other) const; + INLINE bool operator < (const FLOATNAME(LMatrix4) &other) const; + INLINE bool operator == (const FLOATNAME(LMatrix4) &other) const; INLINE bool operator != (const FLOATNAME(LMatrix4) &other) const; INLINE int compare_to(const FLOATNAME(LMatrix4) &other) const; diff --git a/panda/src/linmath/lvecBase3_src.cxx b/panda/src/linmath/lvecBase3_src.cxx index 601425f837..f74d349ac9 100644 --- a/panda/src/linmath/lvecBase3_src.cxx +++ b/panda/src/linmath/lvecBase3_src.cxx @@ -19,7 +19,6 @@ const FLOATNAME(LVecBase3) FLOATNAME(LVecBase3)::_unit_z = // Access: Public, Static // Description: //////////////////////////////////////////////////////////////////// - void FLOATNAME(LVecBase3):: init_type() { if (_type_handle == TypeHandle::none()) {