Changeset 11999 in josm


Ignore:
Timestamp:
2017-04-25T03:18:09+02:00 (2 years ago)
Author:
Don-vip
Message:

see #13387, see #11924 - allow a difference of 3500 ULPs for Java 9 ProjectionRegressionTest (due to Math.cos change of behaviour in JDK-8143353)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/data/projection/ProjectionRegressionTest.java

    r11324 r11999  
    180180        }
    181181
     182        final boolean java9 = TestUtils.getJavaVersion() >= 9;
    182183        for (TestData data : allData) {
    183184            Projection proj = Projections.getProjectionByCode(data.code);
     
    188189            EastNorth en = proj.latlon2eastNorth(data.ll);
    189190            LatLon ll2 = proj.eastNorth2latlon(data.en);
    190             if (TestUtils.getJavaVersion() >= 9) {
    191                 en = getRoundedToOsmPrecision(en.east(), en.north());
    192                 ll2 = ll2.getRoundedToOsmPrecision();
    193                 data.en = getRoundedToOsmPrecision(data.en.east(), data.en.north());
    194                 data.ll2 = data.ll2.getRoundedToOsmPrecision();
    195             }
    196             if (!en.equals(data.en)) {
     191            boolean eqJava8 = !java9 && en.equals(data.en);
     192            boolean eqJava9 = java9 && equalsJava9(en, data.en);
     193            if (!eqJava8 && !eqJava9) {
    197194                String error = String.format("%s (%s): Projecting latlon(%s,%s):%n" +
    198195                        "        expected: eastnorth(%s,%s),%n" +
     
    201198                fail.append(error);
    202199            }
    203             if (!ll2.equals(data.ll2)) {
     200            eqJava8 = !java9 && ll2.equals(data.ll2);
     201            eqJava9 = java9 && equalsJava9(ll2, data.ll2);
     202            if (!eqJava8 && !eqJava9) {
    204203                String error = String.format("%s (%s): Inverse projecting eastnorth(%s,%s):%n" +
    205204                        "        expected: latlon(%s,%s),%n" +
     
    215214        }
    216215    }
     216
     217    private static boolean equalsDoubleMaxUlp(double d1, double d2) {
     218        // Due to error accumulation in projection computation, the difference can reach thousands of ULPs
     219        return Math.abs(d1 - d2) <= 3500 * Math.ulp(d1);
     220    }
     221
     222    private static boolean equalsJava9(EastNorth en1, EastNorth en2) {
     223        return equalsDoubleMaxUlp(en1.east(), en2.east()) &&
     224               equalsDoubleMaxUlp(en1.north(), en2.north());
     225    }
     226
     227    private static boolean equalsJava9(LatLon ll1, LatLon ll2) {
     228        return equalsDoubleMaxUlp(ll1.lat(), ll2.lat()) &&
     229               equalsDoubleMaxUlp(ll1.lon(), ll2.lon());
     230    }
    217231}
Note: See TracChangeset for help on using the changeset viewer.