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 2016/03/22 23:20:03 UTC
lucene-solr:master: LUCENE-7128: fix a few more lon/lat places;
remove more dead code
Repository: lucene-solr
Updated Branches:
refs/heads/master 5385c8d92 -> 99c3bb237
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/99c3bb23
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/99c3bb23
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/99c3bb23
Branch: refs/heads/master
Commit: 99c3bb23710b22bdfb6908ea587b24308bf50ba9
Parents: 5385c8d
Author: Mike McCandless <mi...@apache.org>
Authored: Tue Mar 22 18:21:24 2016 -0400
Committer: Mike McCandless <mi...@apache.org>
Committed: Tue Mar 22 18:21:24 2016 -0400
----------------------------------------------------------------------
.../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 | 72 --------------------
.../apache/lucene/spatial/util/GeoUtils.java | 38 ++---------
.../spatial/util/BaseGeoPointTestCase.java | 32 +++++++--
.../lucene/spatial/util/TestGeoUtils.java | 27 +++-----
8 files changed, 46 insertions(+), 182 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/99c3bb23/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/99c3bb23/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/99c3bb23/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/99c3bb23/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/99c3bb23/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 32a16cd..1a412ac 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
@@ -30,20 +30,6 @@ public class GeoDistanceUtils {
}
/**
- * Computes distance between two points in a cartesian (x, y, {z - optional}) coordinate system
- */
- public static double linearDistance(double[] pt1, double[] pt2) {
- assert pt1 != null && pt2 != null && pt1.length == pt2.length && pt1.length > 1;
- final double d0 = pt1[0] - pt2[0];
- final double d1 = pt1[1] - pt2[1];
- if (pt1.length == 3) {
- final double d2 = pt1[2] - pt2[2];
- return Math.sqrt(d0*d0 + d1*d1 + d2*d2);
- }
- return Math.sqrt(d0*d0 + d1*d1);
- }
-
- /**
* 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
@@ -65,46 +51,6 @@ public class GeoDistanceUtils {
return StrictMath.toDegrees(StrictMath.acos(1-((2d*h)/(cLat*cLat))));
}
- /**
- * Finds the closest point within a rectangle (defined by rMinX, rMinY, rMaxX, rMaxY) to the given (lon, lat) point
- * the result is provided in closestPt (lat, lon). When the point is outside the rectangle, the closest point is on an edge
- * or corner of the rectangle; else, the closest point is the point itself.
- */
- public static void closestPointOnBBox(final double rMinY, final double rMaxY, final double rMinX, final double rMaxX,
- final double lat, final double lon, double[] closestPt) {
- assert closestPt != null && closestPt.length == 2;
-
- closestPt[0] = 0;
- closestPt[1] = 0;
-
- boolean xSet = true;
- boolean ySet = true;
-
- if (lon > rMaxX) {
- closestPt[1] = rMaxX;
- } else if (lon < rMinX) {
- closestPt[1] = rMinX;
- } else {
- xSet = false;
- }
-
- if (lat > rMaxY) {
- closestPt[0] = rMaxY;
- } else if (lat < rMinY) {
- closestPt[0] = rMinY;
- } else {
- ySet = false;
- }
-
- if (closestPt[0] == 0 && ySet == false) {
- closestPt[0] = lat;
- }
-
- if (closestPt[1] == 0 && xSet == false) {
- closestPt[1] = lon;
- }
- }
-
/** Returns the maximum distance/radius (in meters) from the point 'center' before overlapping */
public static double maxRadialDistanceMeters(final double centerLat, final double centerLon) {
if (Math.abs(centerLat) == GeoUtils.MAX_LAT_INCL) {
@@ -112,22 +58,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 * GeoUtils.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/99c3bb23/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 a07ea72..08c3615 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
@@ -72,30 +72,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;
@@ -129,8 +105,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;
@@ -139,16 +115,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/99c3bb23/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 6f3a73c..f0334b2 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
@@ -82,8 +82,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;
}
// A particularly tricky adversary for BKD tree:
@@ -403,7 +427,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();
}
@@ -413,7 +437,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/99c3bb23/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 fe8444f..49a6411 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
@@ -45,26 +45,15 @@ 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);
}
}
- public void testClosestPointOnBBox() {
- double[] result = new double[2];
- GeoDistanceUtils.closestPointOnBBox(30, 50, 20, 40, 70, 70, result);
- assertEquals(50.0, result[0], 0.0);
- assertEquals(40.0, result[1], 0.0);
-
- GeoDistanceUtils.closestPointOnBBox(-20, 0, -20, 0, 70, 70, result);
- assertEquals(0.0, result[0], 0.0);
- assertEquals(0.0, result[1], 0.0);
- }
-
public long scaleLon(final double val) {
return (long) ((val-GeoUtils.MIN_LON_INCL) * LON_SCALE);
}
@@ -84,7 +73,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();
}
@@ -94,7 +83,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();
}
@@ -199,15 +188,15 @@ public class TestGeoUtils extends LuceneTestCase {
lon = randomLon(useSmallRanges);
} else {
// pick a lat/lon within the bbox or "slightly" outside it to try to improve test efficiency
- lat = GeoUtils.normalizeLat(randomRangeMaybeSlightlyOutside(bbox.minLat, bbox.maxLat));
+ lat = BaseGeoPointTestCase.normalizeLat(randomRangeMaybeSlightlyOutside(bbox.minLat, bbox.maxLat));
if (bbox.crossesDateline()) {
if (random().nextBoolean()) {
- lon = GeoUtils.normalizeLon(randomRangeMaybeSlightlyOutside(bbox.maxLon, -180));
+ lon = BaseGeoPointTestCase.normalizeLon(randomRangeMaybeSlightlyOutside(bbox.maxLon, -180));
} else {
- lon = GeoUtils.normalizeLon(randomRangeMaybeSlightlyOutside(0, bbox.minLon));
+ lon = BaseGeoPointTestCase.normalizeLon(randomRangeMaybeSlightlyOutside(0, bbox.minLon));
}
} else {
- lon = GeoUtils.normalizeLon(randomRangeMaybeSlightlyOutside(bbox.minLon, bbox.maxLon));
+ lon = BaseGeoPointTestCase.normalizeLon(randomRangeMaybeSlightlyOutside(bbox.minLon, bbox.maxLon));
}
}