source: josm/trunk/test/unit/org/openstreetmap/josm/data/projection/EllipsoidTest.java@ 4541

Last change on this file since 4541 was 3531, checked in by stoecker, 14 years ago

fix array preferences a bit

  • Property svn:eol-style set to native
File size: 1.6 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.projection;
3
4import java.util.Random;
5
6import org.junit.Assert;
7import org.junit.Test;
8
9import org.openstreetmap.josm.data.coor.LatLon;
10
11public class EllipsoidTest {
12
13 final double EPSILON = 1e-8;
14
15 /**
16 * convert latlon to cartesian coordinates back and forth
17 */
18 @Test
19 public void latLon2Cart2LatLon() {
20 Random r = new Random(System.currentTimeMillis());
21 double maxErrLat = 0, maxErrLon = 0;
22 Ellipsoid ellips = Ellipsoid.WGS84;
23 for (int num=0; num<1000; ++num) {
24
25 double lat = r.nextDouble() * 180.0 - 90.0;
26 double lon = r.nextDouble() * 360.0 - 180.0;
27 LatLon ll = new LatLon(lat,lon);
28
29 for (int i=0; i<1000; ++i) {
30 double[] cart = ellips.latLon2Cart(ll);
31 ll = ellips.cart2LatLon(cart);
32
33 if (!(Math.abs(lat - ll.lat())<EPSILON && Math.abs(lon - ll.lon())<EPSILON)) {
34 String error = String.format("point: %s iterations: %s current: %s errorLat: %s errorLon %s",
35 new LatLon(lat, lon), i, ll, Math.abs(lat - ll.lat()), Math.abs(lon - ll.lon()));
36 System.err.println(error);
37 Assert.fail();
38 }
39 }
40
41 maxErrLat = Math.max(maxErrLat, Math.abs(lat - ll.lat()));
42 maxErrLon = Math.max(maxErrLon, Math.abs(lon - ll.lon()));
43 }
44 //System.err.println(String.format("maxerror lat: %s maxerror lon: %s", maxErrLat, maxErrLon));
45 }
46}
Note: See TracBrowser for help on using the repository browser.