Skip to content

Commit

Permalink
Make Position totally ordered
Browse files Browse the repository at this point in the history
  • Loading branch information
joto committed May 1, 2012
1 parent 1e746d3 commit a304d9d
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions include/osmium/osm/position.hpp
Expand Up @@ -26,6 +26,7 @@ You should have received a copy of the Licenses along with Osmium. If not, see
#include <ostream>
#include <limits>
#include <math.h>
#include <boost/operators.hpp>

#ifdef OSMIUM_WITH_GEOS
# include <geos/geom/Coordinate.h>
Expand All @@ -41,7 +42,7 @@ namespace Osmium {
* centimeters, good enough for OSM use. (The main OSM database uses
* the same scheme.)
*/
class Position {
class Position : boost::totally_ordered<Position> {

public:

Expand Down Expand Up @@ -98,8 +99,12 @@ namespace Osmium {
return p1.m_x == p2.m_x && p1.m_y == p2.m_y;
}

friend bool operator!=(const Position& p1, const Position& p2) {
return !(p1 == p2);
friend bool operator<(const Position& p1, const Position& p2) {
if (p1.m_x == p2.m_x) {
return p1.m_y < p2.m_y;
} else {
return p1.m_x < p2.m_x;
}
}

friend std::ostream& operator<<(std::ostream& out, const Position& position) {
Expand Down

0 comments on commit a304d9d

Please sign in to comment.