lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject lucene-solr:branch_6_0: LUCENE-7128: fix a few more lon/lat places; remove more dead code
Date Tue, 22 Mar 2016 22:50:32 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/branch_6_0 09013e097 -> 137dd158f


LUCENE-7128: fix a few more lon/lat places; remove more dead code


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

Branch: refs/heads/branch_6_0
Commit: 137dd158fa5d4a1b1d6ad7cb369c69738f02401d
Parents: 09013e0
Author: Mike McCandless <mikemccand@apache.org>
Authored: Tue Mar 22 18:21:24 2016 -0400
Committer: Mike McCandless <mikemccand@apache.org>
Committed: Tue Mar 22 18:51:51 2016 -0400

----------------------------------------------------------------------
 .../lucene/search/TestLatLonPointQueries.java   |  8 +--
 .../geopoint/document/GeoPointTokenStream.java  |  2 +-
 .../spatial/geopoint/search/GeoBoundingBox.java | 53 --------------------
 .../search/GeoPointDistanceRangeQuery.java      |  2 +-
 .../geopoint/search/GeoPointMultiTermQuery.java |  2 +-
 .../lucene/spatial/util/GeoDistanceUtils.java   | 20 +-------
 .../lucene/spatial/util/GeoProjectionUtils.java |  2 -
 .../apache/lucene/spatial/util/GeoUtils.java    | 38 +++-----------
 .../spatial/util/BaseGeoPointTestCase.java      | 32 ++++++++++--
 .../lucene/spatial/util/TestGeoUtils.java       |  8 +--
 10 files changed, 47 insertions(+), 120 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/137dd158/lucene/sandbox/src/test/org/apache/lucene/search/TestLatLonPointQueries.java
----------------------------------------------------------------------
diff --git a/lucene/sandbox/src/test/org/apache/lucene/search/TestLatLonPointQueries.java
b/lucene/sandbox/src/test/org/apache/lucene/search/TestLatLonPointQueries.java
index df026e2..b90956c 100644
--- a/lucene/sandbox/src/test/org/apache/lucene/search/TestLatLonPointQueries.java
+++ b/lucene/sandbox/src/test/org/apache/lucene/search/TestLatLonPointQueries.java
@@ -187,15 +187,15 @@ public class TestLatLonPointQueries extends BaseGeoPointTestCase {
           lon = randomLon(useSmallRanges);
         } else {
           // pick a lat/lon within the bbox or "slightly" outside it to try to improve test
efficiency
-          lat = quantizeLat(GeoUtils.normalizeLat(randomRangeMaybeSlightlyOutside(bbox.minLat,
bbox.maxLat)));
+          lat = quantizeLat(BaseGeoPointTestCase.normalizeLat(randomRangeMaybeSlightlyOutside(bbox.minLat,
bbox.maxLat)));
           if (bbox.crossesDateline()) {
             if (random().nextBoolean()) {
-              lon = quantizeLon(GeoUtils.normalizeLon(randomRangeMaybeSlightlyOutside(bbox.maxLon,
-180)));
+              lon = quantizeLon(BaseGeoPointTestCase.normalizeLon(randomRangeMaybeSlightlyOutside(bbox.maxLon,
-180)));
             } else {
-              lon = quantizeLon(GeoUtils.normalizeLon(randomRangeMaybeSlightlyOutside(0,
bbox.minLon)));
+              lon = quantizeLon(BaseGeoPointTestCase.normalizeLon(randomRangeMaybeSlightlyOutside(0,
bbox.minLon)));
             }
           } else {
-            lon = quantizeLon(GeoUtils.normalizeLon(randomRangeMaybeSlightlyOutside(bbox.minLon,
bbox.maxLon)));
+            lon = quantizeLon(BaseGeoPointTestCase.normalizeLon(randomRangeMaybeSlightlyOutside(bbox.minLon,
bbox.maxLon)));
           }
         }
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/137dd158/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/document/GeoPointTokenStream.java
----------------------------------------------------------------------
diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/document/GeoPointTokenStream.java
b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/document/GeoPointTokenStream.java
index 66216ab..c374c4e 100644
--- a/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/document/GeoPointTokenStream.java
+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/document/GeoPointTokenStream.java
@@ -60,7 +60,7 @@ import static org.apache.lucene.spatial.geopoint.document.GeoPointField.PRECISIO
  *   document.add(geoPointField);
  *
  *   // query by bounding box (default uses TermEncoding.PREFIX)
- *   Query q = new GeoPointInBBoxQuery(fieldName1, minLon, minLat, maxLon, maxLat);
+ *   Query q = new GeoPointInBBoxQuery(fieldName1, minLat, maxLat, minLon, maxLon);
  *
  *   // using numeric terms
  *   geoPointField = new GeoPointField(fieldName2, lat, lon, GeoPointField.NUMERIC_TYPE_NOT_STORED);

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/137dd158/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoBoundingBox.java
----------------------------------------------------------------------
diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoBoundingBox.java
b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoBoundingBox.java
deleted file mode 100644
index 8f30f60..0000000
--- a/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoBoundingBox.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.lucene.spatial.geopoint.search;
-
-import org.apache.lucene.spatial.util.GeoUtils;
-
-/** NOTE: package private; just used so {@link GeoPointInPolygonQuery} can communicate its
bounding box to {@link GeoPointInBBoxQuery}. */
-class GeoBoundingBox {
-  /** minimum longitude value (in degrees) */
-  public final double minLon;
-  /** minimum latitude value (in degrees) */
-  public final double maxLon;
-  /** maximum longitude value (in degrees) */
-  public final double minLat;
-  /** maximum latitude value (in degrees) */
-  public final double maxLat;
-
-  /**
-   * Constructs a bounding box by first validating the provided latitude and longitude coordinates
-   */
-  public GeoBoundingBox(double minLon, double maxLon, double minLat, double maxLat) {
-    if (GeoUtils.isValidLon(minLon) == false) {
-      throw new IllegalArgumentException("invalid minLon " + minLon);
-    }
-    if (GeoUtils.isValidLon(maxLon) == false) {
-      throw new IllegalArgumentException("invalid maxLon " + minLon);
-    }
-    if (GeoUtils.isValidLat(minLat) == false) {
-      throw new IllegalArgumentException("invalid minLat " + minLat);
-    }
-    if (GeoUtils.isValidLat(maxLat) == false) {
-      throw new IllegalArgumentException("invalid maxLat " + minLat);
-    }
-    this.minLon = minLon;
-    this.maxLon = maxLon;
-    this.minLat = minLat;
-    this.maxLat = maxLat;
-  }
-}

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/137dd158/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointDistanceRangeQuery.java
----------------------------------------------------------------------
diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointDistanceRangeQuery.java
b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointDistanceRangeQuery.java
index bdfbb88..5cc778a 100644
--- a/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointDistanceRangeQuery.java
+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointDistanceRangeQuery.java
@@ -30,7 +30,7 @@ import org.apache.lucene.spatial.geopoint.document.GeoPointField.TermEncoding;
  *    @lucene.experimental
  */
 public final class GeoPointDistanceRangeQuery extends GeoPointDistanceQuery {
-  /** minimum distance range (in meters) from lon, lat center location, maximum is inherited
*/
+  /** minimum distance range (in meters) from lat, lon center location, maximum is inherited
*/
   protected final double minRadiusMeters;
 
   /**

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/137dd158/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointMultiTermQuery.java
----------------------------------------------------------------------
diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointMultiTermQuery.java
b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointMultiTermQuery.java
index a63c4d6..c23ceb8 100644
--- a/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointMultiTermQuery.java
+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointMultiTermQuery.java
@@ -98,7 +98,7 @@ abstract class GeoPointMultiTermQuery extends MultiTermQuery {
    * Computes the maximum shift based on the diagonal distance of the bounding box
    */
   protected short computeMaxShift() {
-    // in this case a factor of 4 brings the detail level to ~0.002/0.001 degrees lon/lat
respectively (or ~222m/111m)
+    // in this case a factor of 4 brings the detail level to ~0.001/0.002 degrees lat/lon
respectively (or ~111m/222m)
     final short shiftFactor;
 
     // compute diagonal distance

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/137dd158/lucene/spatial/src/java/org/apache/lucene/spatial/util/GeoDistanceUtils.java
----------------------------------------------------------------------
diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/util/GeoDistanceUtils.java
b/lucene/spatial/src/java/org/apache/lucene/spatial/util/GeoDistanceUtils.java
index 8956c4b..53debe4 100644
--- a/lucene/spatial/src/java/org/apache/lucene/spatial/util/GeoDistanceUtils.java
+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/util/GeoDistanceUtils.java
@@ -33,7 +33,7 @@ public class GeoDistanceUtils {
   private GeoDistanceUtils() {
   }
 
-  /**
+   /**
    * Computes distance between two points in a cartesian (x, y, {z - optional}) coordinate
system
    */
   public static double linearDistance(double[] pt1, double[] pt2) {
@@ -116,22 +116,4 @@ public class GeoDistanceUtils {
     }
     return SloppyMath.haversinMeters(centerLat, centerLon, centerLat, (GeoUtils.MAX_LON_INCL
+ centerLon) % 360);
   }
-
-  /**
-   * Compute the inverse haversine to determine distance in degrees longitude for provided
distance in meters
-   * @param lat latitude to compute delta degrees lon
-   * @param distance distance in meters to convert to degrees lon
-   * @return Sloppy distance in degrees longitude for provided distance in meters
-   */
-  public static double distanceToDegreesLat(double lat, double distance) {
-    // get the diameter at the latitude
-    final double diameter = 2 * GeoProjectionUtils.SEMIMAJOR_AXIS;
-
-    // compute inverse haversine
-    double a = StrictMath.sin(distance/diameter);
-    double h = StrictMath.min(1, a);
-    h *= h;
-
-    return StrictMath.toDegrees(StrictMath.acos(1-(2d*h)));
-  }
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/137dd158/lucene/spatial/src/java/org/apache/lucene/spatial/util/GeoProjectionUtils.java
----------------------------------------------------------------------
diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/util/GeoProjectionUtils.java
b/lucene/spatial/src/java/org/apache/lucene/spatial/util/GeoProjectionUtils.java
index 61aa09f..3287a45 100644
--- a/lucene/spatial/src/java/org/apache/lucene/spatial/util/GeoProjectionUtils.java
+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/util/GeoProjectionUtils.java
@@ -28,8 +28,6 @@ import static org.apache.lucene.spatial.util.GeoUtils.MAX_LON_INCL;
 import static org.apache.lucene.spatial.util.GeoUtils.MIN_LAT_INCL;
 import static org.apache.lucene.spatial.util.GeoUtils.MIN_LON_INCL;
 import static org.apache.lucene.spatial.util.GeoUtils.PIO2;
-import static org.apache.lucene.spatial.util.GeoUtils.normalizeLat;
-import static org.apache.lucene.spatial.util.GeoUtils.normalizeLon;
 import static org.apache.lucene.spatial.util.GeoUtils.sloppySin;
 import static org.apache.lucene.spatial.util.GeoUtils.sloppyTan;
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/137dd158/lucene/spatial/src/java/org/apache/lucene/spatial/util/GeoUtils.java
----------------------------------------------------------------------
diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/util/GeoUtils.java b/lucene/spatial/src/java/org/apache/lucene/spatial/util/GeoUtils.java
index 935da60..833881f 100644
--- a/lucene/spatial/src/java/org/apache/lucene/spatial/util/GeoUtils.java
+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/util/GeoUtils.java
@@ -68,30 +68,6 @@ public final class GeoUtils {
     return Double.isNaN(lon) == false && lon >= MIN_LON_INCL && lon <=
MAX_LON_INCL;
   }
 
-  /** Puts longitude in range of -180 to +180. */
-  public static double normalizeLon(double lon_deg) {
-    if (lon_deg >= -180 && lon_deg <= 180) {
-      return lon_deg; //common case, and avoids slight double precision shifting
-    }
-    double off = (lon_deg + 180) % 360;
-    if (off < 0) {
-      return 180 + off;
-    } else if (off == 0 && lon_deg > 0) {
-      return 180;
-    } else {
-      return -180 + off;
-    }
-  }
-
-  /** Puts latitude in range of -90 to 90. */
-  public static double normalizeLat(double lat_deg) {
-    if (lat_deg >= -90 && lat_deg <= 90) {
-      return lat_deg; //common case, and avoids slight double precision shifting
-    }
-    double off = abs((lat_deg + 90) % 360);
-    return (off <= 180 ? off : 360-off) - 90;
-  }
-
   /** Compute Bounding Box for a circle using WGS-84 parameters */
   public static GeoRect circleToBBox(final double centerLat, final double centerLon, final
double radiusMeters) {
     final double radLat = TO_RADIANS * centerLat;
@@ -125,8 +101,8 @@ public final class GeoUtils {
 
   /** Compute Bounding Box for a polygon using WGS-84 parameters */
   public static GeoRect polyToBBox(double[] polyLats, double[] polyLons) {
-    if (polyLons.length != polyLats.length) {
-      throw new IllegalArgumentException("polyLons and polyLats must be equal length");
+    if (polyLats.length != polyLons.length) {
+      throw new IllegalArgumentException("polyLats and polyLons must be equal length");
     }
 
     double minLon = Double.POSITIVE_INFINITY;
@@ -135,16 +111,16 @@ public final class GeoUtils {
     double maxLat = Double.NEGATIVE_INFINITY;
 
     for (int i=0;i<polyLats.length;i++) {
-      if (GeoUtils.isValidLon(polyLons[i]) == false) {
-        throw new IllegalArgumentException("invalid polyLons[" + i + "]=" + polyLons[i]);
-      }
       if (GeoUtils.isValidLat(polyLats[i]) == false) {
         throw new IllegalArgumentException("invalid polyLats[" + i + "]=" + polyLats[i]);
       }
-      minLon = min(polyLons[i], minLon);
-      maxLon = max(polyLons[i], maxLon);
+      if (GeoUtils.isValidLon(polyLons[i]) == false) {
+        throw new IllegalArgumentException("invalid polyLons[" + i + "]=" + polyLons[i]);
+      }
       minLat = min(polyLats[i], minLat);
       maxLat = max(polyLats[i], maxLat);
+      minLon = min(polyLons[i], minLon);
+      maxLon = max(polyLons[i], maxLon);
     }
     // expand bounding box by TOLERANCE factor to handle round-off error
     return new GeoRect(max(minLat - TOLERANCE, MIN_LAT_INCL), min(maxLat + TOLERANCE, MAX_LAT_INCL),

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/137dd158/lucene/spatial/src/test/org/apache/lucene/spatial/util/BaseGeoPointTestCase.java
----------------------------------------------------------------------
diff --git a/lucene/spatial/src/test/org/apache/lucene/spatial/util/BaseGeoPointTestCase.java
b/lucene/spatial/src/test/org/apache/lucene/spatial/util/BaseGeoPointTestCase.java
index a4f70d9..593dbe9 100644
--- a/lucene/spatial/src/test/org/apache/lucene/spatial/util/BaseGeoPointTestCase.java
+++ b/lucene/spatial/src/test/org/apache/lucene/spatial/util/BaseGeoPointTestCase.java
@@ -68,8 +68,32 @@ public abstract class BaseGeoPointTestCase extends LuceneTestCase {
     lonRange = 2 * (random().nextDouble() + 0.5);
     latRange = 2 * (random().nextDouble() + 0.5);
 
-    originLon = GeoUtils.normalizeLon(GeoUtils.MIN_LON_INCL + lonRange + (GeoUtils.MAX_LON_INCL
- GeoUtils.MIN_LON_INCL - 2 * lonRange) * random().nextDouble());
-    originLat = GeoUtils.normalizeLat(GeoUtils.MIN_LAT_INCL + latRange + (GeoUtils.MAX_LAT_INCL
- GeoUtils.MIN_LAT_INCL - 2 * latRange) * random().nextDouble());
+    originLon = normalizeLon(GeoUtils.MIN_LON_INCL + lonRange + (GeoUtils.MAX_LON_INCL -
GeoUtils.MIN_LON_INCL - 2 * lonRange) * random().nextDouble());
+    originLat = normalizeLat(GeoUtils.MIN_LAT_INCL + latRange + (GeoUtils.MAX_LAT_INCL -
GeoUtils.MIN_LAT_INCL - 2 * latRange) * random().nextDouble());
+  }
+
+  /** Puts longitude in range of -180 to +180. */
+  public static double normalizeLon(double lon_deg) {
+    if (lon_deg >= -180 && lon_deg <= 180) {
+      return lon_deg; //common case, and avoids slight double precision shifting
+    }
+    double off = (lon_deg + 180) % 360;
+    if (off < 0) {
+      return 180 + off;
+    } else if (off == 0 && lon_deg > 0) {
+      return 180;
+    } else {
+      return -180 + off;
+    }
+  }
+
+  /** Puts latitude in range of -90 to 90. */
+  public static double normalizeLat(double lat_deg) {
+    if (lat_deg >= -90 && lat_deg <= 90) {
+      return lat_deg; //common case, and avoids slight double precision shifting
+    }
+    double off = Math.abs((lat_deg + 90) % 360);
+    return (off <= 180 ? off : 360-off) - 90;
   }
 
   /** Return true when testing on a non-small region may be too slow (GeoPoint*Query) */
@@ -419,7 +443,7 @@ public abstract class BaseGeoPointTestCase extends LuceneTestCase {
   public double randomLat(boolean small) {
     double result;
     if (small) {
-      result = GeoUtils.normalizeLat(originLat + latRange * (random().nextDouble() - 0.5));
+      result = normalizeLat(originLat + latRange * (random().nextDouble() - 0.5));
     } else {
       result = -90 + 180.0 * random().nextDouble();
     }
@@ -429,7 +453,7 @@ public abstract class BaseGeoPointTestCase extends LuceneTestCase {
   public double randomLon(boolean small) {
     double result;
     if (small) {
-      result = GeoUtils.normalizeLon(originLon + lonRange * (random().nextDouble() - 0.5));
+      result = normalizeLon(originLon + lonRange * (random().nextDouble() - 0.5));
     } else {
       result = -180 + 360.0 * random().nextDouble();
     }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/137dd158/lucene/spatial/src/test/org/apache/lucene/spatial/util/TestGeoUtils.java
----------------------------------------------------------------------
diff --git a/lucene/spatial/src/test/org/apache/lucene/spatial/util/TestGeoUtils.java b/lucene/spatial/src/test/org/apache/lucene/spatial/util/TestGeoUtils.java
index b5573a6..d0b2129 100644
--- a/lucene/spatial/src/test/org/apache/lucene/spatial/util/TestGeoUtils.java
+++ b/lucene/spatial/src/test/org/apache/lucene/spatial/util/TestGeoUtils.java
@@ -57,9 +57,9 @@ public class TestGeoUtils extends LuceneTestCase {
     latRange = 2 * (random().nextDouble() + 0.5);
 
     originLon = GeoUtils.MIN_LON_INCL + lonRange + (GeoUtils.MAX_LON_INCL - GeoUtils.MIN_LON_INCL
- 2 * lonRange) * random().nextDouble();
-    originLon = GeoUtils.normalizeLon(originLon);
+    originLon = BaseGeoPointTestCase.normalizeLon(originLon);
     originLat = GeoUtils.MIN_LAT_INCL + latRange + (GeoUtils.MAX_LAT_INCL - GeoUtils.MIN_LAT_INCL
- 2 * latRange) * random().nextDouble();
-    originLat = GeoUtils.normalizeLat(originLat);
+    originLat = BaseGeoPointTestCase.normalizeLat(originLat);
 
     if (VERBOSE) {
       System.out.println("TEST: originLon=" + originLon + " lonRange= " + lonRange + " originLat="
+ originLat + " latRange=" + latRange);
@@ -131,7 +131,7 @@ public class TestGeoUtils extends LuceneTestCase {
   public double randomLat(boolean small) {
     double result;
     if (small) {
-      result = GeoUtils.normalizeLat(originLat + latRange * (random().nextDouble() - 0.5));
+      result = BaseGeoPointTestCase.normalizeLat(originLat + latRange * (random().nextDouble()
- 0.5));
     } else {
       result = -90 + 180.0 * random().nextDouble();
     }
@@ -141,7 +141,7 @@ public class TestGeoUtils extends LuceneTestCase {
   public double randomLon(boolean small) {
     double result;
     if (small) {
-      result = GeoUtils.normalizeLon(originLon + lonRange * (random().nextDouble() - 0.5));
+      result = BaseGeoPointTestCase.normalizeLon(originLon + lonRange * (random().nextDouble()
- 0.5));
     } else {
       result = -180 + 360.0 * random().nextDouble();
     }


Mime
View raw message