You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by th...@apache.org on 2016/04/14 01:21:24 UTC

[08/50] lucene-solr:jira/SOLR-8908: LUCENE-7194: Roll our own toRadians() method, and also make it less likely we'll need to restaple the toString() tests.

LUCENE-7194: Roll our own toRadians() method, and also make it less likely we'll need to restaple the toString() tests.


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/a4bf526a
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/a4bf526a
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/a4bf526a

Branch: refs/heads/jira/SOLR-8908
Commit: a4bf526a62dbf5e2c3fed6d98112c71ed33e15d6
Parents: d377e7f
Author: Karl Wright <Da...@gmail.com>
Authored: Sun Apr 10 05:11:12 2016 -0400
Committer: Karl Wright <Da...@gmail.com>
Committed: Sun Apr 10 05:11:12 2016 -0400

----------------------------------------------------------------------
 .../org/apache/lucene/spatial3d/Geo3DPoint.java | 10 ++++++----
 .../apache/lucene/spatial3d/TestGeo3DPoint.java | 20 ++++++++++++--------
 2 files changed, 18 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/a4bf526a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/Geo3DPoint.java
----------------------------------------------------------------------
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/Geo3DPoint.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/Geo3DPoint.java
index 1e07aa7..1a36c3e 100644
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/Geo3DPoint.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/Geo3DPoint.java
@@ -51,7 +51,9 @@ import org.apache.lucene.util.NumericUtils;
 public final class Geo3DPoint extends Field {
 
   /** How many radians are in one earth surface meter */
-  protected final static double RADIANS_PER_METER = 1.0 / PlanetModel.WGS84_MEAN;
+  public final static double RADIANS_PER_METER = 1.0 / PlanetModel.WGS84_MEAN;
+  /** How many radians are in one degree */
+  public final static double RADIANS_PER_DEGREE = Math.PI / 180.0;
   
   /** Indexing {@link FieldType}. */
   public static final FieldType TYPE = new FieldType();
@@ -75,12 +77,12 @@ public final class Geo3DPoint extends Field {
   }
 
   /** Converts degress to radians */
-  protected static double fromDegrees(final double degrees) {
-    return Math.toRadians(degrees);
+  private static double fromDegrees(final double degrees) {
+    return degrees * RADIANS_PER_DEGREE;
   }
   
   /** Converts earth-surface meters to radians */
-  protected static double fromMeters(final double meters) {
+  private static double fromMeters(final double meters) {
     return meters * RADIANS_PER_METER;
   }
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/a4bf526a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/TestGeo3DPoint.java
----------------------------------------------------------------------
diff --git a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/TestGeo3DPoint.java b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/TestGeo3DPoint.java
index 5c876ce..c80f3bb 100644
--- a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/TestGeo3DPoint.java
+++ b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/TestGeo3DPoint.java
@@ -132,7 +132,7 @@ public class TestGeo3DPoint extends LuceneTestCase {
   }
 
   private static double toRadians(double degrees) {
-    return Math.toRadians(degrees);
+    return degrees * Geo3DPoint.RADIANS_PER_DEGREE;
   }
 
   private static class Cell {
@@ -810,13 +810,17 @@ public class TestGeo3DPoint extends LuceneTestCase {
   }
 
   public void testToString() {
+    // Don't compare entire strings because Java 9 and Java 8 have slightly different values
     Geo3DPoint point = new Geo3DPoint("point", 44.244272, 7.769736);
-    assertEquals("Geo3DPoint <point: x=", point.toString().substring(0,"Geo3DPoint <point: x=".length()));
+    final String stringToCompare = "Geo3DPoint <point: x=";
+    assertEquals(stringToCompare, point.toString().substring(0,stringToCompare.length()));
   }
 
   public void testShapeQueryToString() {
-    assertEquals("PointInGeo3DShapeQuery: field=point: Shape: GeoStandardCircle: {planetmodel=PlanetModel.WGS84, center=[lat=0.7722082215479366, lon=0.13560747521073413([X=0.7094263130137863, Y=0.09679758930862137, Z=0.6973564619248455])], radius=0.1(5.729577951308232)}",
-                 Geo3DPoint.newShapeQuery("point", GeoCircleFactory.makeGeoCircle(PlanetModel.WGS84, toRadians(44.244272), toRadians(7.769736), 0.1)).toString());
+    // Don't compare entire strings because Java 9 and Java 8 have slightly different values
+    final String stringToCompare = "PointInGeo3DShapeQuery: field=point: Shape: GeoStandardCircle: {planetmodel=PlanetModel.WGS84, center=[lat=0.7";
+    assertEquals(stringToCompare,
+      Geo3DPoint.newShapeQuery("point", GeoCircleFactory.makeGeoCircle(PlanetModel.WGS84, toRadians(44.244272), toRadians(7.769736), 0.1)).toString().substring(0,stringToCompare.length()));
   }
 
   private static Directory getDirectory() {     
@@ -841,7 +845,7 @@ public class TestGeo3DPoint extends LuceneTestCase {
   public void testComplexPolygons() {
     final PlanetModel pm = PlanetModel.WGS84;
     // Pick a random pole
-    final GeoPoint randomPole = new GeoPoint(pm, Math.toRadians(GeoTestUtil.nextLatitude()), Math.toRadians(GeoTestUtil.nextLongitude()));
+    final GeoPoint randomPole = new GeoPoint(pm, toRadians(GeoTestUtil.nextLatitude()), toRadians(GeoTestUtil.nextLongitude()));
     int iters = atLeast(100);
     for (int i = 0; i < iters; i++) {
       // Create a polygon that's less than 180 degrees
@@ -854,8 +858,8 @@ public class TestGeo3DPoint extends LuceneTestCase {
     }
   }
 
-  protected static double MINIMUM_EDGE_ANGLE = Math.toRadians(5.0);
-  protected static double MINIMUM_ARC_ANGLE = Math.toRadians(1.0);
+  protected static double MINIMUM_EDGE_ANGLE = toRadians(5.0);
+  protected static double MINIMUM_ARC_ANGLE = toRadians(1.0);
   
   /** Cook up a random Polygon that makes sense, with possible nested polygon within.
     * This is part of testing more complex polygons with nested holes.  Picking random points
@@ -1036,7 +1040,7 @@ public class TestGeo3DPoint extends LuceneTestCase {
     final double[] lons = polygon.getPolyLons();
     final List<GeoPoint> polyPoints = new ArrayList<>(lats.length-1);
     for (int i = 0; i < lats.length - 1; i++) {
-      final GeoPoint newPoint = new GeoPoint(pm, Math.toRadians(lats[i]), Math.toRadians(lons[i]));
+      final GeoPoint newPoint = new GeoPoint(pm, toRadians(lats[i]), toRadians(lons[i]));
       if (!outsidePolygon.isWithin(newPoint)) {
         return false;
       }