Changeset 18464 in josm
- Timestamp:
- 2022-06-06T16:04:20+02:00 (2 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/coor/ILatLon.java
r13173 r18464 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 /** … … 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 18464 (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 / precision. 77 * @since 18464 (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 } -
trunk/src/org/openstreetmap/josm/data/coor/LatLon.java
r17333 r18464 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 … … 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 */ 188 * @deprecated since 18464 (use {@link ILatLon#equalsEpsilon(ILatLon)} instead) 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 -
trunk/src/org/openstreetmap/josm/data/osm/Node.java
r16553 r18464 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 -
trunk/src/org/openstreetmap/josm/data/osm/NodePositionComparator.java
r12161 r18464 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 -
trunk/test/unit/org/openstreetmap/josm/gui/datatransfer/OsmTransferHandlerTest.java
r17275 r18464 49 49 50 50 transferHandler.pasteOn(target, null); 51 assertTrue(n1. getCoor().equalsEpsilon(ds2.getNodes().iterator().next().getCoor()));51 assertTrue(n1.equalsEpsilon(ds2.getNodes().iterator().next())); 52 52 53 53 ds2.clear(); … … 56 56 LatLon pos = new LatLon(55, -5); 57 57 transferHandler.pasteOn(target, ProjectionRegistry.getProjection().latlon2eastNorth(pos)); 58 assertTrue(pos.equalsEpsilon(ds2.getNodes().iterator().next() .getCoor()));58 assertTrue(pos.equalsEpsilon(ds2.getNodes().iterator().next())); 59 59 } 60 60 -
trunk/test/unit/org/openstreetmap/josm/io/GeoJSONReaderTest.java
r18037 r18464 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
Note:
See TracChangeset
for help on using the changeset viewer.