Line | |
---|
1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.osm;
|
---|
3 |
|
---|
4 | import java.io.Serializable;
|
---|
5 | import java.util.Comparator;
|
---|
6 |
|
---|
7 | /**
|
---|
8 | * Provides some node order , based on coordinates, nodes with equal coordinates are equal.
|
---|
9 | *
|
---|
10 | * @author viesturs
|
---|
11 | */
|
---|
12 | public class NodePositionComparator implements Comparator<Node>, Serializable {
|
---|
13 |
|
---|
14 | private static final long serialVersionUID = 1L;
|
---|
15 |
|
---|
16 | @Override
|
---|
17 | public int compare(Node n1, Node n2) {
|
---|
18 |
|
---|
19 | if (n1.getCoor().equalsEpsilon(n2.getCoor()))
|
---|
20 | return 0;
|
---|
21 |
|
---|
22 | double dLat = n1.getCoor().lat() - n2.getCoor().lat();
|
---|
23 | if (dLat > 0)
|
---|
24 | return 1;
|
---|
25 | if (dLat < 0)
|
---|
26 | return -1;
|
---|
27 | double dLon = n1.getCoor().lon() - n2.getCoor().lon();
|
---|
28 | if (dLon == 0)
|
---|
29 | return 0;
|
---|
30 | return dLon > 0 ? 1 : -1;
|
---|
31 | }
|
---|
32 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.