Changeset 17612 in josm


Ignore:
Timestamp:
2021-03-21T08:56:56+01:00 (3 years ago)
Author:
simon04
Message:

fix #18074 - Duplicate Node: detect errors caused by different rounding in JOSM and on OSM server

Reduce the precision used by the duplicate node test by one decimal digit

The advanced preference value validator.duplicatenodes.precision now defaults to 1e-6 (previously 1e-7).

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/validation/tests/DuplicateNode.java

    r17377 r17612  
    4141public class DuplicateNode extends Test {
    4242
    43     private static class NodeHash implements Hash<Object, Object> {
    44 
    45         private final double precision = Config.getPref().getDouble("validator.duplicatenodes.precision", 0.);
    46 
    47         private LatLon roundCoord(LatLon coor) {
     43    protected static class NodeHash implements Hash<Object, Object> {
     44
     45        /**
     46         * Rounding on OSM server and via {@link LatLon#roundToOsmPrecision} sometimes differs in the last digit by 1.
     47         * Thus, for the duplicate node test, we reduce the precision by one to find errors before uploading.
     48         * @see LatLon#MAX_SERVER_INV_PRECISION
     49         */
     50        private final double precision =
     51                1 / Config.getPref().getDouble("validator.duplicatenodes.precision", LatLon.MAX_SERVER_PRECISION * 10);
     52
     53        /**
     54         * @see LatLon#roundToOsmPrecision
     55         */
     56        protected LatLon roundCoord(LatLon coor) {
    4857            return new LatLon(
    49                     Math.round(coor.lat() / precision) * precision,
    50                     Math.round(coor.lon() / precision) * precision
     58                    Math.round(coor.lat() * precision) / precision,
     59                    Math.round(coor.lon() * precision) / precision
    5160                    );
    5261        }
  • trunk/test/unit/org/openstreetmap/josm/data/validation/tests/DuplicateNodeTest.java

    r17376 r17612  
    178178
    179179    /**
     180     * Test of "Duplicate node" validation test - server precision.
     181     *
     182     * Non-regression test for ticket #18074.
     183     */
     184    @Test
     185    void testServerPrecision() {
     186        DuplicateNode.NodeHash nodeHash = new DuplicateNode.NodeHash();
     187        DataSet ds = new DataSet();
     188
     189        Node a = new Node(new LatLon(-23.51108285, -46.489264256));
     190        Node b = new Node(new LatLon(-23.511082861, -46.489264251));
     191        ds.addPrimitive(a);
     192        ds.addPrimitive(b);
     193
     194        a.put("foo", "bar");
     195        b.put("bar", "foo");
     196
     197        // on OSM server, both are: lat = -23.5110829 lon = -46.4892643
     198        assertEquals(new LatLon(-23.5110828, -46.4892643), a.getCoor().getRoundedToOsmPrecision());
     199        assertEquals(new LatLon(-23.5110829, -46.4892643), b.getCoor().getRoundedToOsmPrecision());
     200        assertEquals(new LatLon(-23.511083, -46.489264), nodeHash.roundCoord(a.getCoor()));
     201        assertEquals(new LatLon(-23.511083, -46.489264), nodeHash.roundCoord(b.getCoor()));
     202        performTest(DuplicateNode.DUPLICATE_NODE, ds, false);
     203    }
     204
     205    /**
    180206     * Test of "Duplicate node" validation test - mixed case.
    181207     */
Note: See TracChangeset for help on using the changeset viewer.