Ticket #22104: 22104.patch

File 22104.patch, 6.3 KB (added by taylor.smock, 3 years ago)
  • src/org/openstreetmap/josm/data/coor/ILatLon.java

    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;  
    1515 * @since 12161
    1616 */
    1717public 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;
    1823
    1924    /**
    2025     * Returns the longitude, i.e., the east-west position in degrees.
    public interface ILatLon {  
    5156            return projecting.latlon2eastNorth(this);
    5257        }
    5358    }
     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    }
    5483}
  • src/org/openstreetmap/josm/data/coor/LatLon.java

    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 {  
    4545     * Minimum difference in location to not be represented as the same position.
    4646     * The API returns 7 decimals.
    4747     */
    48     public static final double MAX_SERVER_PRECISION = 1e-7;
     48    public static final double MAX_SERVER_PRECISION = ILatLon.MAX_SERVER_PRECISION;
    4949    /**
    5050     * The inverse of the server precision
    5151     * @see #MAX_SERVER_PRECISION
    public class LatLon extends Coordinate implements ILatLon {  
    185185     * @param other other lat/lon
    186186     * @return <code>true</code> if the other point has almost the same lat/lon
    187187     * 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)
    188189     */
     190    @Deprecated
    189191    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);
    192193    }
    193194
    194195    /**
  • src/org/openstreetmap/josm/data/osm/Node.java

    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 {  
    292292    }
    293293
    294294    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;
    298299    }
    299300
    300301    @Override
  • src/org/openstreetmap/josm/data/osm/NodePositionComparator.java

    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 {  
    1616    @Override
    1717    public int compare(Node n1, Node n2) {
    1818
    19         if (n1.getCoor().equalsEpsilon(n2.getCoor()))
     19        if (n1.equalsEpsilon(n2))
    2020            return 0;
    2121
    2222        int dLat = Double.compare(n1.lat(), n2.lat());
  • test/unit/org/openstreetmap/josm/gui/datatransfer/OsmTransferHandlerTest.java

    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 {  
    4141        OsmDataLayer target = new OsmDataLayer(ds2, "target", null);
    4242
    4343        transferHandler.pasteOn(target, null);
    44         assertTrue(n1.getCoor().equalsEpsilon(ds2.getNodes().iterator().next().getCoor()));
     44        assertTrue(n1.equalsEpsilon(ds2.getNodes().iterator().next()));
    4545
    4646        ds2.clear();
    4747        assertTrue(ds2.getNodes().isEmpty());
    4848
    4949        LatLon pos = new LatLon(55, -5);
    5050        transferHandler.pasteOn(target, ProjectionRegistry.getProjection().latlon2eastNorth(pos));
    51         assertTrue(pos.equalsEpsilon(ds2.getNodes().iterator().next().getCoor()));
     51        assertTrue(pos.equalsEpsilon(ds2.getNodes().iterator().next()));
    5252    }
    5353
    5454    /**
  • test/unit/org/openstreetmap/josm/io/GeoJSONReaderTest.java

    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 {  
    166166    private static boolean areEqualNodes(final OsmPrimitive p1, final OsmPrimitive p2) {
    167167        return (p1 instanceof Node)
    168168            && (p2 instanceof Node)
    169             && ((Node) p1).getCoor().equalsEpsilon(((Node) p2).getCoor());
     169            && ((Node) p1).equalsEpsilon(((Node) p2));
    170170    }
    171171
    172172    private static boolean areEqualWays(final OsmPrimitive p1, final OsmPrimitive p2) {