From e5e0cb86d5f9699328bf3485650f38618944209b Mon Sep 17 00:00:00 2001 From: David Rose Date: Thu, 7 Jan 2010 22:10:12 +0000 Subject: [PATCH] fix eggvertex comparision --- panda/src/egg/eggVertex.I | 11 +++++++++++ panda/src/egg/eggVertex.cxx | 30 +++++++++++++++--------------- panda/src/egg/eggVertex.h | 3 ++- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/panda/src/egg/eggVertex.I b/panda/src/egg/eggVertex.I index 659e685a2f..367b25d250 100644 --- a/panda/src/egg/eggVertex.I +++ b/panda/src/egg/eggVertex.I @@ -318,6 +318,17 @@ get_external_index() const { return _external_index; } +//////////////////////////////////////////////////////////////////// +// Function: EggVertex::sorts_less_than +// Access: Published +// Description: An ordering operator to compare two vertices for +// sorting order. This imposes an arbitrary ordering +// useful to identify unique vertices. +//////////////////////////////////////////////////////////////////// +INLINE bool EggVertex:: +sorts_less_than(const EggVertex &other) const { + return compare_to(other) < 0; +} diff --git a/panda/src/egg/eggVertex.cxx b/panda/src/egg/eggVertex.cxx index d7604282ba..0a83d9d738 100644 --- a/panda/src/egg/eggVertex.cxx +++ b/panda/src/egg/eggVertex.cxx @@ -281,7 +281,6 @@ clear_uv(const string &name) { } - /////////////////////////////////////////////////////////////////// // Class : GroupRefEntry // Description : A temporary class used in EggVertex::write(), below, @@ -362,7 +361,7 @@ write(ostream &out, int indent_level) const { //////////////////////////////////////////////////////////////////// -// Function: EggVertex::sorts_less_than +// Function: EggVertex::compare_to // Access: Published // Description: An ordering operator to compare two vertices for // sorting order. This imposes an arbitrary ordering @@ -382,22 +381,23 @@ write(ostream &out, int indent_level) const { // memberships, else the vertices will tend to fly apart // when the joints animate. //////////////////////////////////////////////////////////////////// -bool EggVertex:: -sorts_less_than(const EggVertex &other) const { +int EggVertex:: +compare_to(const EggVertex &other) const { if (_external_index != other._external_index) { - return _external_index < other._external_index; + return (int)_external_index - (int)other._external_index; } if (_num_dimensions != other._num_dimensions) { - return _num_dimensions < other._num_dimensions; + return (int)_num_dimensions - (int)other._num_dimensions; } int compare = _pos.compare_to(other._pos, egg_parameters->_pos_threshold); if (compare != 0) { - return compare < 0; + return compare; } - if (_dxyzs != other._dxyzs) { - return _dxyzs < other._dxyzs; + compare = _dxyzs.compare_to(other._dxyzs); + if (compare != 0) { + return compare; } // Merge-compare the uv maps. @@ -406,28 +406,28 @@ sorts_less_than(const EggVertex &other) const { bi = other._uv_map.begin(); while (ai != _uv_map.end() && bi != other._uv_map.end()) { if ((*ai).first < (*bi).first) { - return true; + return -1; } else if ((*bi).first < (*ai).first) { - return false; + return 1; } else { int compare = (*ai).second->compare_to(*(*bi).second); if (compare != 0) { - return compare < 0; + return compare; } } ++ai; ++bi; } if (bi != other._uv_map.end()) { - return true; + return -1; } if (ai != _uv_map.end()) { - return false; + return 1; } - return EggAttributes::sorts_less_than(other); + return EggAttributes::compare_to(other); } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/egg/eggVertex.h b/panda/src/egg/eggVertex.h index 9faf7f1588..95d9856051 100644 --- a/panda/src/egg/eggVertex.h +++ b/panda/src/egg/eggVertex.h @@ -104,7 +104,8 @@ PUBLISHED: INLINE int get_external_index() const; void write(ostream &out, int indent_level) const; - bool sorts_less_than(const EggVertex &other) const; + INLINE bool sorts_less_than(const EggVertex &other) const; + int compare_to(const EggVertex &other) const; int get_num_local_coord() const; int get_num_global_coord() const;