You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ds...@apache.org on 2015/05/31 04:50:21 UTC

svn commit: r1682667 - /lucene/dev/branches/lucene6487/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/geo3d/GeoPointTest.java

Author: dsmiley
Date: Sun May 31 02:50:21 2015
New Revision: 1682667

URL: http://svn.apache.org/r1682667
Log:
LUCENE-6487: Geo3D with WGS84: fix GeoPointTest to test via distance

Modified:
    lucene/dev/branches/lucene6487/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/geo3d/GeoPointTest.java

Modified: lucene/dev/branches/lucene6487/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/geo3d/GeoPointTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6487/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/geo3d/GeoPointTest.java?rev=1682667&r1=1682666&r2=1682667&view=diff
==============================================================================
--- lucene/dev/branches/lucene6487/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/geo3d/GeoPointTest.java (original)
+++ lucene/dev/branches/lucene6487/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/geo3d/GeoPointTest.java Sun May 31 02:50:21 2015
@@ -30,15 +30,25 @@ public class GeoPointTest extends Lucene
 
   @Test
   public void testConversion() {
-    final double pLat = (randomFloat() * 180.0 - 90.0) * DistanceUtils.DEGREES_TO_RADIANS;
-    final double pLon = (randomFloat() * 360.0 - 180.0) * DistanceUtils.DEGREES_TO_RADIANS;
-    final GeoPoint p1 = new GeoPoint(PlanetModel.SPHERE, pLat, pLon);
-    assertEquals(pLat, p1.getLatitude(), 1e-12);
-    assertEquals(pLon, p1.getLongitude(), 1e-12);
-    final GeoPoint p2 = new GeoPoint(PlanetModel.WGS84, pLat, pLon);
-    assertEquals(pLat, p2.getLatitude(), 1e-12);
-    assertEquals(pLon, p2.getLongitude(), 1e-12);
-    
+    testPointRoundTrip(PlanetModel.SPHERE, 90, 0, 1e-12);
+    testPointRoundTrip(PlanetModel.SPHERE, -90, 0, 1e-12);
+    testPointRoundTrip(PlanetModel.WGS84, 90, 0, 1e-12);
+    testPointRoundTrip(PlanetModel.WGS84, -90, 0, 1e-12);
+
+    final int times = atLeast(100);
+    for (int i = 0; i < times; i++) {
+      final double pLat = (randomFloat() * 180.0 - 90.0) * DistanceUtils.DEGREES_TO_RADIANS;
+      final double pLon = (randomFloat() * 360.0 - 180.0) * DistanceUtils.DEGREES_TO_RADIANS;
+      testPointRoundTrip(PlanetModel.SPHERE, pLat, pLon, 1e-6);//1e-6 since there's a square root in there (Karl says)
+      testPointRoundTrip(PlanetModel.WGS84, pLat, pLon, 1e-6);
+    }
+  }
+
+  protected void testPointRoundTrip(PlanetModel planetModel, double pLat, double pLon, double epsilon) {
+    final GeoPoint p1 = new GeoPoint(planetModel, pLat, pLon);
+    final GeoPoint p2 = new GeoPoint(planetModel, p1.getLatitude(), p1.getLongitude());
+    double dist = p1.arcDistance(p2);
+    assertEquals(0, dist, epsilon);
   }
 
 }