001 // License: GPL. For details, see LICENSE file. 002 package org.openstreetmap.josm.data.osm; 003 004 import java.util.Comparator; 005 006 /** 007 * Provides some node order , based on coordinates, nodes with equal coordinates are equal. 008 * 009 * @author viesturs 010 */ 011 public class NodePositionComparator implements Comparator<Node> { 012 @Override 013 public int compare(Node n1, Node n2) { 014 015 if (n1.getCoor().equalsEpsilon(n2.getCoor())) 016 return 0; 017 018 double dLat = n1.getCoor().lat() - n2.getCoor().lat(); 019 if (dLat > 0) 020 return 1; 021 if (dLat < 0) 022 return -1; 023 double dLon = n1.getCoor().lon() - n2.getCoor().lon(); 024 if (dLon == 0) 025 return 0; 026 return dLon > 0 ? 1 : -1; 027 } 028 }