You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2015/09/18 16:53:40 UTC

svn commit: r1703876 - in /lucene/dev/branches/lucene6780/lucene/sandbox/src: java/org/apache/lucene/search/GeoPointDistanceQuery.java java/org/apache/lucene/util/GeoUtils.java test/org/apache/lucene/util/TestGeoUtils.java

Author: mikemccand
Date: Fri Sep 18 14:53:39 2015
New Revision: 1703876

URL: http://svn.apache.org/viewvc?rev=1703876&view=rev
Log:
LUCENE-6780: remove dup code, cleanup nocommits

Modified:
    lucene/dev/branches/lucene6780/lucene/sandbox/src/java/org/apache/lucene/search/GeoPointDistanceQuery.java
    lucene/dev/branches/lucene6780/lucene/sandbox/src/java/org/apache/lucene/util/GeoUtils.java
    lucene/dev/branches/lucene6780/lucene/sandbox/src/test/org/apache/lucene/util/TestGeoUtils.java

Modified: lucene/dev/branches/lucene6780/lucene/sandbox/src/java/org/apache/lucene/search/GeoPointDistanceQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6780/lucene/sandbox/src/java/org/apache/lucene/search/GeoPointDistanceQuery.java?rev=1703876&r1=1703875&r2=1703876&view=diff
==============================================================================
--- lucene/dev/branches/lucene6780/lucene/sandbox/src/java/org/apache/lucene/search/GeoPointDistanceQuery.java (original)
+++ lucene/dev/branches/lucene6780/lucene/sandbox/src/java/org/apache/lucene/search/GeoPointDistanceQuery.java Fri Sep 18 14:53:39 2015
@@ -47,7 +47,7 @@ public final class GeoPointDistanceQuery
 
   /** NOTE: radius is in meters. */
   public GeoPointDistanceQuery(final String field, final double centerLon, final double centerLat, final double radiusMeters) {
-    this(field, computeBBox(centerLon, centerLat, radiusMeters), centerLon, centerLat, radiusMeters);
+    this(field, GeoUtils.circleToBBox(centerLon, centerLat, radiusMeters), centerLon, centerLat, radiusMeters);
   }
 
   private GeoPointDistanceQuery(final String field, GeoBoundingBox bbox, final double centerLon,
@@ -87,38 +87,6 @@ public final class GeoPointDistanceQuery
     return new GeoPointDistanceQueryImpl(field, this, new GeoBoundingBox(this.minLon, this.maxLon, this.minLat, this.maxLat));
   }
 
-  // nocommit move this to util
-  public static GeoBoundingBox computeBBox(final double centerLon, final double centerLat, final double radiusMeters) {
-    final double radLat = StrictMath.toRadians(centerLat);
-    final double radLon = StrictMath.toRadians(centerLon);
-    double radDistance = (radiusMeters + 12000) / GeoProjectionUtils.SEMIMAJOR_AXIS;
-    double minLat = radLat - radDistance;
-    double maxLat = radLat + radDistance;
-    double minLon;
-    double maxLon;
-
-    if (minLat > GeoProjectionUtils.MIN_LAT_RADIANS && maxLat < GeoProjectionUtils.MAX_LAT_RADIANS) {
-      double deltaLon = StrictMath.asin(StrictMath.sin(radDistance) / StrictMath.cos(radLat));
-      minLon = radLon - deltaLon;
-      if (minLon < GeoProjectionUtils.MIN_LON_RADIANS) {
-        minLon += 2d * StrictMath.PI;
-      }
-      maxLon = radLon + deltaLon;
-      if (maxLon > GeoProjectionUtils.MAX_LON_RADIANS) {
-        maxLon -= 2d * StrictMath.PI;
-      }
-    } else {
-      // a pole is within the distance
-      minLat = StrictMath.max(minLat, GeoProjectionUtils.MIN_LAT_RADIANS);
-      maxLat = StrictMath.min(maxLat, GeoProjectionUtils.MAX_LAT_RADIANS);
-      minLon = GeoProjectionUtils.MIN_LON_RADIANS;
-      maxLon = GeoProjectionUtils.MAX_LON_RADIANS;
-    }
-
-    return new GeoBoundingBox(StrictMath.toDegrees(minLon), StrictMath.toDegrees(maxLon),
-        StrictMath.toDegrees(minLat), StrictMath.toDegrees(maxLat));
-  }
-
   @Override
   public boolean equals(Object o) {
     if (this == o) return true;

Modified: lucene/dev/branches/lucene6780/lucene/sandbox/src/java/org/apache/lucene/util/GeoUtils.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6780/lucene/sandbox/src/java/org/apache/lucene/util/GeoUtils.java?rev=1703876&r1=1703875&r2=1703876&view=diff
==============================================================================
--- lucene/dev/branches/lucene6780/lucene/sandbox/src/java/org/apache/lucene/util/GeoUtils.java (original)
+++ lucene/dev/branches/lucene6780/lucene/sandbox/src/java/org/apache/lucene/util/GeoUtils.java Fri Sep 18 14:53:39 2015
@@ -19,6 +19,8 @@ package org.apache.lucene.util;
 
 import java.util.ArrayList;
 
+import org.apache.lucene.search.GeoBoundingBox;
+
 /**
  * Basic reusable geo-spatial utility methods
  *
@@ -327,6 +329,40 @@ public final class GeoUtils {
   }
 
   /**
+   * Compute Bounding Box for a circle using WGS-84 parameters
+   */
+  public static GeoBoundingBox circleToBBox(final double centerLon, final double centerLat, final double radiusMeters) {
+    final double radLat = StrictMath.toRadians(centerLat);
+    final double radLon = StrictMath.toRadians(centerLon);
+    double radDistance = (radiusMeters + 12000) / GeoProjectionUtils.SEMIMAJOR_AXIS;
+    double minLat = radLat - radDistance;
+    double maxLat = radLat + radDistance;
+    double minLon;
+    double maxLon;
+
+    if (minLat > GeoProjectionUtils.MIN_LAT_RADIANS && maxLat < GeoProjectionUtils.MAX_LAT_RADIANS) {
+      double deltaLon = StrictMath.asin(StrictMath.sin(radDistance) / StrictMath.cos(radLat));
+      minLon = radLon - deltaLon;
+      if (minLon < GeoProjectionUtils.MIN_LON_RADIANS) {
+        minLon += 2d * StrictMath.PI;
+      }
+      maxLon = radLon + deltaLon;
+      if (maxLon > GeoProjectionUtils.MAX_LON_RADIANS) {
+        maxLon -= 2d * StrictMath.PI;
+      }
+    } else {
+      // a pole is within the distance
+      minLat = StrictMath.max(minLat, GeoProjectionUtils.MIN_LAT_RADIANS);
+      maxLat = StrictMath.min(maxLat, GeoProjectionUtils.MAX_LAT_RADIANS);
+      minLon = GeoProjectionUtils.MIN_LON_RADIANS;
+      maxLon = GeoProjectionUtils.MAX_LON_RADIANS;
+    }
+
+    return new GeoBoundingBox(StrictMath.toDegrees(minLon), StrictMath.toDegrees(maxLon),
+        StrictMath.toDegrees(minLat), StrictMath.toDegrees(maxLat));
+  }
+
+  /**
    * Computes whether or a 3dimensional line segment intersects or crosses a sphere
    *
    * @param lon1 longitudinal location of the line segment start point (in degrees)

Modified: lucene/dev/branches/lucene6780/lucene/sandbox/src/test/org/apache/lucene/util/TestGeoUtils.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6780/lucene/sandbox/src/test/org/apache/lucene/util/TestGeoUtils.java?rev=1703876&r1=1703875&r2=1703876&view=diff
==============================================================================
--- lucene/dev/branches/lucene6780/lucene/sandbox/src/test/org/apache/lucene/util/TestGeoUtils.java (original)
+++ lucene/dev/branches/lucene6780/lucene/sandbox/src/test/org/apache/lucene/util/TestGeoUtils.java Fri Sep 18 14:53:39 2015
@@ -209,7 +209,6 @@ public class TestGeoUtils extends Lucene
     assertEquals(50.0, result[1], 0.0);
 
     GeoDistanceUtils.closestPointOnBBox(-20, -20, 0, 0, 70, 70, result);
-    // nocommit this fails but should pass?
     assertEquals(0.0, result[0], 0.0);
     assertEquals(0.0, result[1], 0.0);
   }
@@ -400,8 +399,6 @@ public class TestGeoUtils extends Lucene
 
     int numDocs = atLeast(1000);
     
-    // nocommit commit up front to small or full range
-
     boolean useSmallRanges = random().nextBoolean();
     if (VERBOSE) {
       System.out.println("TEST: " + numDocs + " docs useSmallRanges=" + useSmallRanges);
@@ -410,7 +407,6 @@ public class TestGeoUtils extends Lucene
     double[] docLons = new double[numDocs];
     double[] docLats = new double[numDocs];
     for(int docID=0;docID<numDocs;docID++) {
-      // nocommit use full range:
       docLons[docID] = randomLon(useSmallRanges);
       docLats[docID] = randomLat(useSmallRanges);
       if (VERBOSE) {
@@ -426,13 +422,11 @@ public class TestGeoUtils extends Lucene
 
       Cell.nextCellID = 0;
 
-      // nocommit use small too
       double centerLon = randomLon(useSmallRanges);
       double centerLat = randomLat(useSmallRanges);
 
       // So the circle covers at most 50% of the earth's surface:
 
-      // nocommit if smallbbox then use small radius here:
       double radiusMeters;
       if (useSmallRanges) {
         // Approx 3 degrees lon at the equator:
@@ -448,7 +442,7 @@ public class TestGeoUtils extends Lucene
         log.println("\nTEST: iter=" + iter + " radiusMeters=" + radiusMeters + " centerLon=" + centerLon + " centerLat=" + centerLat);
       }
 
-      GeoBoundingBox bbox = GeoPointDistanceQuery.computeBBox(centerLon, centerLat, radiusMeters);
+      GeoBoundingBox bbox = GeoUtils.circleToBBox(centerLon, centerLat, radiusMeters);
       
       Set<Integer> hits = new HashSet<>();
 
@@ -510,55 +504,4 @@ public class TestGeoUtils extends Lucene
       }
     }
   }
-
-
-  /**
-   * Compute Bounding Box for a circle using WGS-84 parameters
-   */
-  // nocommit should this be in GeoUtils?
-  static BBox computeBBox(final double centerLon, final double centerLat, final double radius) {
-    final double radLat = StrictMath.toRadians(centerLat);
-    final double radLon = StrictMath.toRadians(centerLon);
-    double radDistance = (radius + 12000) / GeoProjectionUtils.SEMIMAJOR_AXIS;
-    double minLat = radLat - radDistance;
-    double maxLat = radLat + radDistance;
-    double minLon;
-    double maxLon;
-
-    if (minLat > GeoProjectionUtils.MIN_LAT_RADIANS && maxLat < GeoProjectionUtils.MAX_LAT_RADIANS) {
-      double deltaLon = StrictMath.asin(StrictMath.sin(radDistance) / StrictMath.cos(radLat));
-      minLon = radLon - deltaLon;
-      if (minLon < GeoProjectionUtils.MIN_LON_RADIANS) {
-        minLon += 2d * StrictMath.PI;
-      }
-      maxLon = radLon + deltaLon;
-      if (maxLon > GeoProjectionUtils.MAX_LON_RADIANS) {
-        maxLon -= 2d * StrictMath.PI;
-      }
-    } else {
-      // a pole is within the distance
-      minLat = StrictMath.max(minLat, GeoProjectionUtils.MIN_LAT_RADIANS);
-      maxLat = StrictMath.min(maxLat, GeoProjectionUtils.MAX_LAT_RADIANS);
-      minLon = GeoProjectionUtils.MIN_LON_RADIANS;
-      maxLon = GeoProjectionUtils.MAX_LON_RADIANS;
-    }
-
-    return new BBox(StrictMath.toDegrees(minLon), StrictMath.toDegrees(maxLon),
-        StrictMath.toDegrees(minLat), StrictMath.toDegrees(maxLat));
-  }
-
-  // nocommit cutover to GeoBBOx:
-  static class BBox {
-    final double minLon;
-    final double minLat;
-    final double maxLon;
-    final double maxLat;
-
-    BBox(final double minLon, final double maxLon, final double minLat, final double maxLat) {
-      this.minLon = minLon;
-      this.minLat = minLat;
-      this.maxLon = maxLon;
-      this.maxLat = maxLat;
-    }
-  }
 }