- Timestamp:
- 2024-08-12T20:27:49+02:00 (5 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/data/projection/ProjectionRegressionTest.java
r19182 r19185 15 15 import java.util.ArrayList; 16 16 import java.util.List; 17 import java.util.Locale; 17 18 import java.util.Map; 18 19 import java.util.Random; … … 28 29 import org.openstreetmap.josm.testutils.annotations.ProjectionNadGrids; 29 30 import org.openstreetmap.josm.tools.Pair; 31 import org.openstreetmap.josm.tools.Utils; 30 32 31 33 /** … … 152 154 } 153 155 156 double fact = 12; 157 if(Utils.getSystemProperty("os.name").toLowerCase(Locale.ENGLISH).startsWith("mac os x")) 158 fact = 1700; 154 159 for (TestData data : allData) { 155 160 Projection proj = Projections.getProjectionByCode(data.code); … … 160 165 EastNorth en = proj.latlon2eastNorth(data.ll); 161 166 LatLon ll2 = proj.eastNorth2latlon(data.en); 162 if (!equalsJava9(en, data.en )) {167 if (!equalsJava9(en, data.en, fact)) { 163 168 String error = String.format("%s (%s): Projecting latlon(%s,%s):%n" + 164 169 " expected: eastnorth(%s,%s),%n" + 165 " but got: eastnorth(%s,%s)!%n", 166 proj, data.code, data.ll.lat(), data.ll.lon(), data.en.east(), data.en.north(), en.east(), en.north()); 170 " but got: eastnorth(%s,%s)!%n" + 171 " test: [%s,%s] factor [%s,%s] threshold [%s,%s]%n", 172 proj, data.code, data.ll.lat(), data.ll.lon(), data.en.east(), data.en.north(), en.east(), en.north(), 173 Math.abs(en.east()-data.en.east()), Math.abs(en.north()-data.en.north()), 174 Math.abs(en.east()-data.en.east())/Math.ulp(en.east()), Math.abs(en.north()-data.en.north())/Math.ulp(en.north()), 175 Math.ulp(en.east()), Math.ulp(en.north())); 167 176 fail.append(error); 168 177 } 169 if (!equalsJava9(ll2, data.ll2 )) {178 if (!equalsJava9(ll2, data.ll2, fact)) { 170 179 String error = String.format("%s (%s): Inverse projecting eastnorth(%s,%s):%n" + 171 180 " expected: latlon(%s,%s),%n" + 172 " but got: latlon(%s,%s)!%n", 173 proj, data.code, data.en.east(), data.en.north(), data.ll2.lat(), data.ll2.lon(), ll2.lat(), ll2.lon()); 181 " but got: latlon(%s,%s)!%n" + 182 " test: [%s,%s] factor [%s,%s], threshold [%s,%s]%n", 183 proj, data.code, data.en.east(), data.en.north(), data.ll2.lat(), data.ll2.lon(), ll2.lat(), ll2.lon(), 184 Math.abs(ll2.lat()-data.ll2.lat()), Math.abs(ll2.lon()-data.ll2.lon()), 185 Math.abs(ll2.lat()-data.ll2.lat())/Math.ulp(ll2.lat()), Math.abs(ll2.lon()-data.ll2.lon())/Math.ulp(ll2.lon()), 186 Math.ulp(ll2.lat()), Math.ulp(ll2.lon())); 174 187 fail.append(error); 175 188 } … … 182 195 } 183 196 184 private static boolean equalsDoubleMaxUlp(double d1, double d2 ) {197 private static boolean equalsDoubleMaxUlp(double d1, double d2, double fact) { 185 198 // Due to error accumulation in projection computation, the difference can reach hundreds of ULPs 186 199 // The worst error is 1168 ULP (followed by 816 ULP then 512 ULP) with: … … 188 201 // expected: eastnorth(-1004398.8994415681,24167.8944844745), 189 202 // but got: eastnorth(-1004398.8994415683,24167.894484478747)! 190 // MacOS has higher errors, otherwise 1200 would be enough 191 return Math.abs(d1 - d2) <= 1700 * Math.ulp(d1); 192 } 193 194 private static boolean equalsJava9(EastNorth en1, EastNorth en2) { 195 return equalsDoubleMaxUlp(en1.east(), en2.east()) && 196 equalsDoubleMaxUlp(en1.north(), en2.north()); 197 } 198 199 private static boolean equalsJava9(LatLon ll1, LatLon ll2) { 200 return equalsDoubleMaxUlp(ll1.lat(), ll2.lat()) && 201 equalsDoubleMaxUlp(ll1.lon(), ll2.lon()); 203 return Math.abs(d1 - d2) <= fact * Math.ulp(d1); 204 } 205 206 private static boolean equalsJava9(EastNorth en1, EastNorth en2, double fact) { 207 return equalsDoubleMaxUlp(en1.east(), en2.east(), fact) && 208 equalsDoubleMaxUlp(en1.north(), en2.north(), fact); 209 } 210 211 private static boolean equalsJava9(LatLon ll1, LatLon ll2, double fact) { 212 return equalsDoubleMaxUlp(ll1.lat(), ll2.lat(), fact) && 213 equalsDoubleMaxUlp(ll1.lon(), ll2.lon(), fact); 202 214 } 203 215 }
Note:
See TracChangeset
for help on using the changeset viewer.