diff --git a/src/org/openstreetmap/josm/data/coor/ILatLon.java b/src/org/openstreetmap/josm/data/coor/ILatLon.java
index 0b1bcb40d6..7b930deca0 100644
a
|
b
|
import org.openstreetmap.josm.data.projection.Projecting;
|
15 | 15 | * @since 12161 |
16 | 16 | */ |
17 | 17 | public interface ILatLon { |
| 18 | /** |
| 19 | * Minimum difference in location to not be represented as the same position. |
| 20 | * The API returns 7 decimals. |
| 21 | */ |
| 22 | double MAX_SERVER_PRECISION = 1e-7; |
18 | 23 | |
19 | 24 | /** |
20 | 25 | * Returns the longitude, i.e., the east-west position in degrees. |
… |
… |
public interface ILatLon {
|
51 | 56 | return projecting.latlon2eastNorth(this); |
52 | 57 | } |
53 | 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Determines if the other point has almost the same lat/lon values. |
| 62 | * @param other other lat/lon |
| 63 | * @return <code>true</code> if the other point has almost the same lat/lon |
| 64 | * values, only differing by no more than 1 / {@link #MAX_SERVER_PRECISION MAX_SERVER_PRECISION}. |
| 65 | * @since xxx (extracted from {@link LatLon}) |
| 66 | */ |
| 67 | default boolean equalsEpsilon(ILatLon other) { |
| 68 | return equalsEpsilon(other, MAX_SERVER_PRECISION); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Determines if the other point has almost the same lat/lon values. |
| 73 | * @param other other lat/lon |
| 74 | * @param precision The precision to use |
| 75 | * @return <code>true</code> if the other point has almost the same lat/lon |
| 76 | * values, only differing by no more than 1 / {@link #MAX_SERVER_PRECISION MAX_SERVER_PRECISION}. |
| 77 | * @since xxx (extracted from {@link LatLon}) |
| 78 | */ |
| 79 | default boolean equalsEpsilon(ILatLon other, double precision) { |
| 80 | double p = precision / 2; |
| 81 | return Math.abs(lat()-other.lat()) <= p && Math.abs(lon()-other.lon()) <= p; |
| 82 | } |
54 | 83 | } |
diff --git a/src/org/openstreetmap/josm/data/coor/LatLon.java b/src/org/openstreetmap/josm/data/coor/LatLon.java
index dcbd54e444..6b2b5231f6 100644
a
|
b
|
public class LatLon extends Coordinate implements ILatLon {
|
45 | 45 | * Minimum difference in location to not be represented as the same position. |
46 | 46 | * The API returns 7 decimals. |
47 | 47 | */ |
48 | | public static final double MAX_SERVER_PRECISION = 1e-7; |
| 48 | public static final double MAX_SERVER_PRECISION = ILatLon.MAX_SERVER_PRECISION; |
49 | 49 | /** |
50 | 50 | * The inverse of the server precision |
51 | 51 | * @see #MAX_SERVER_PRECISION |
… |
… |
public class LatLon extends Coordinate implements ILatLon {
|
185 | 185 | * @param other other lat/lon |
186 | 186 | * @return <code>true</code> if the other point has almost the same lat/lon |
187 | 187 | * values, only differing by no more than 1 / {@link #MAX_SERVER_PRECISION MAX_SERVER_PRECISION}. |
| 188 | * @deprecated since xxx (use {@link ILatLon#equalsEpsilon(ILatLon)} instead) |
188 | 189 | */ |
| 190 | @Deprecated |
189 | 191 | public boolean equalsEpsilon(LatLon other) { |
190 | | double p = MAX_SERVER_PRECISION / 2; |
191 | | return Math.abs(lat()-other.lat()) <= p && Math.abs(lon()-other.lon()) <= p; |
| 192 | return ILatLon.super.equalsEpsilon(other); |
192 | 193 | } |
193 | 194 | |
194 | 195 | /** |
diff --git a/src/org/openstreetmap/josm/data/osm/Node.java b/src/org/openstreetmap/josm/data/osm/Node.java
index 3936917229..e0b780ed22 100644
a
|
b
|
public final class Node extends OsmPrimitive implements INode {
|
292 | 292 | } |
293 | 293 | |
294 | 294 | private boolean hasEqualCoordinates(Node other) { |
295 | | final LatLon c1 = getCoor(); |
296 | | final LatLon c2 = other.getCoor(); |
297 | | return (c1 == null && c2 == null) || (c1 != null && c2 != null && c1.equalsEpsilon(c2)); |
| 295 | if (this.isLatLonKnown() && other.isLatLonKnown()) { |
| 296 | return this.equalsEpsilon(other); |
| 297 | } |
| 298 | return false; |
298 | 299 | } |
299 | 300 | |
300 | 301 | @Override |
diff --git a/src/org/openstreetmap/josm/data/osm/NodePositionComparator.java b/src/org/openstreetmap/josm/data/osm/NodePositionComparator.java
index 96aa69af31..ce8cdb3e96 100644
a
|
b
|
public class NodePositionComparator implements Comparator<Node>, Serializable {
|
16 | 16 | @Override |
17 | 17 | public int compare(Node n1, Node n2) { |
18 | 18 | |
19 | | if (n1.getCoor().equalsEpsilon(n2.getCoor())) |
| 19 | if (n1.equalsEpsilon(n2)) |
20 | 20 | return 0; |
21 | 21 | |
22 | 22 | int dLat = Double.compare(n1.lat(), n2.lat()); |
diff --git a/test/unit/org/openstreetmap/josm/gui/datatransfer/OsmTransferHandlerTest.java b/test/unit/org/openstreetmap/josm/gui/datatransfer/OsmTransferHandlerTest.java
index 985cea6449..6954d8fe7c 100644
a
|
b
|
class OsmTransferHandlerTest {
|
41 | 41 | OsmDataLayer target = new OsmDataLayer(ds2, "target", null); |
42 | 42 | |
43 | 43 | transferHandler.pasteOn(target, null); |
44 | | assertTrue(n1.getCoor().equalsEpsilon(ds2.getNodes().iterator().next().getCoor())); |
| 44 | assertTrue(n1.equalsEpsilon(ds2.getNodes().iterator().next())); |
45 | 45 | |
46 | 46 | ds2.clear(); |
47 | 47 | assertTrue(ds2.getNodes().isEmpty()); |
48 | 48 | |
49 | 49 | LatLon pos = new LatLon(55, -5); |
50 | 50 | transferHandler.pasteOn(target, ProjectionRegistry.getProjection().latlon2eastNorth(pos)); |
51 | | assertTrue(pos.equalsEpsilon(ds2.getNodes().iterator().next().getCoor())); |
| 51 | assertTrue(pos.equalsEpsilon(ds2.getNodes().iterator().next())); |
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
diff --git a/test/unit/org/openstreetmap/josm/io/GeoJSONReaderTest.java b/test/unit/org/openstreetmap/josm/io/GeoJSONReaderTest.java
index 9317c2be05..94eeb2bf13 100644
a
|
b
|
class GeoJSONReaderTest {
|
166 | 166 | private static boolean areEqualNodes(final OsmPrimitive p1, final OsmPrimitive p2) { |
167 | 167 | return (p1 instanceof Node) |
168 | 168 | && (p2 instanceof Node) |
169 | | && ((Node) p1).getCoor().equalsEpsilon(((Node) p2).getCoor()); |
| 169 | && ((Node) p1).equalsEpsilon(((Node) p2)); |
170 | 170 | } |
171 | 171 | |
172 | 172 | private static boolean areEqualWays(final OsmPrimitive p1, final OsmPrimitive p2) { |