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/14 23:21:16 UTC
svn commit: r1703062 - in /lucene/dev/branches/lucene6780/lucene/sandbox/src:
java/org/apache/lucene/search/ java/org/apache/lucene/util/
test/org/apache/lucene/util/
Author: mikemccand
Date: Mon Sep 14 21:21:16 2015
New Revision: 1703062
URL: http://svn.apache.org/r1703062
Log:
LUCENE-6780: fix test bug; fix bug in closestPoinOnBBox; add some nocommits
Modified:
lucene/dev/branches/lucene6780/lucene/sandbox/src/java/org/apache/lucene/search/GeoPointDistanceQueryImpl.java
lucene/dev/branches/lucene6780/lucene/sandbox/src/java/org/apache/lucene/util/GeoDistanceUtils.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/GeoPointDistanceQueryImpl.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6780/lucene/sandbox/src/java/org/apache/lucene/search/GeoPointDistanceQueryImpl.java?rev=1703062&r1=1703061&r2=1703062&view=diff
==============================================================================
--- lucene/dev/branches/lucene6780/lucene/sandbox/src/java/org/apache/lucene/search/GeoPointDistanceQueryImpl.java (original)
+++ lucene/dev/branches/lucene6780/lucene/sandbox/src/java/org/apache/lucene/search/GeoPointDistanceQueryImpl.java Mon Sep 14 21:21:16 2015
@@ -62,7 +62,7 @@ final class GeoPointDistanceQueryImpl ex
protected short computeMaxShift() {
final short shiftFactor;
- if (query.radius > 2000000) {
+ if (query.radius > 1000000) {
shiftFactor = 5;
} else {
shiftFactor = 4;
Modified: lucene/dev/branches/lucene6780/lucene/sandbox/src/java/org/apache/lucene/util/GeoDistanceUtils.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6780/lucene/sandbox/src/java/org/apache/lucene/util/GeoDistanceUtils.java?rev=1703062&r1=1703061&r2=1703062&view=diff
==============================================================================
--- lucene/dev/branches/lucene6780/lucene/sandbox/src/java/org/apache/lucene/util/GeoDistanceUtils.java (original)
+++ lucene/dev/branches/lucene6780/lucene/sandbox/src/java/org/apache/lucene/util/GeoDistanceUtils.java Mon Sep 14 21:21:16 2015
@@ -121,23 +121,30 @@ public class GeoDistanceUtils {
closestPt[0] = 0;
closestPt[1] = 0;
+ boolean xSet = true;
+ boolean ySet = true;
+
if (lon > rMaxX) {
closestPt[0] = rMaxX;
} else if (lon < rMinX) {
closestPt[0] = rMinX;
+ } else {
+ xSet = false;
}
if (lat > rMaxY) {
closestPt[1] = rMaxY;
} else if (lat < rMinY) {
closestPt[1] = rMinY;
+ } else {
+ ySet = false;
}
- if (closestPt[0] == 0) {
+ if (closestPt[0] == 0 && xSet == false) {
closestPt[0] = lon;
}
- if (closestPt[1] == 0) {
+ if (closestPt[1] == 0 && ySet == false) {
closestPt[1] = lat;
}
}
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=1703062&r1=1703061&r2=1703062&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 Mon Sep 14 21:21:16 2015
@@ -341,6 +341,7 @@ public final class GeoUtils {
* @return whether the provided line segment is a secant of the
*/
// nocommit can/should we remove this?
+ // todo not used for 2d at the moment. used for 3d w/ altitude (we can keep or add back)
private static boolean lineCrossesSphere(double lon1, double lat1, double alt1, double lon2,
double lat2, double alt2, double centerLon, double centerLat,
double centerAlt, double radiusMeters) {
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=1703062&r1=1703061&r2=1703062&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 Mon Sep 14 21:21:16 2015
@@ -21,9 +21,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
-import org.apache.lucene.search.TestGeoPointQuery;
import org.junit.BeforeClass;
-import org.junit.Test;
/**
* Tests class for methods in GeoUtils
@@ -253,13 +251,18 @@ public class TestGeoUtils extends Lucene
double centerLon = randomLon();
double radiusMeters = 10000000*random().nextDouble();
- boolean expected;
- if (GeoUtils.rectCrossesCircle(minLon, minLat, maxLon, maxLon, centerLon, centerLat, radiusMeters) == false) {
+ boolean expected = false;
+ boolean circleFullyInside = false;
+ BBox bbox = computeBBox(centerLon, centerLat, radiusMeters);
+ if (GeoUtils.rectCrossesCircle(minLon, minLat, maxLon, maxLat, centerLon, centerLat, radiusMeters) == false) {
// Rect and circle are disjoint
expected = false;
- } else if (GeoUtils.rectWithinCircle(minLon, minLat, maxLon, maxLon, centerLon, centerLat, radiusMeters)) {
+ } else if (GeoUtils.rectWithinCircle(minLon, minLat, maxLon, maxLat, centerLon, centerLat, radiusMeters)) {
// Rect fully contained inside circle
expected = true;
+ } else if (GeoUtils.rectWithin(bbox.minLon, bbox.minLat, bbox.maxLon, bbox.maxLat, minLon, minLat, maxLon, maxLat)) {
+ // circle fully contained inside rect
+ circleFullyInside = true;
} else {
// TODO: would be nice to somehow test this case too
continue;
@@ -269,6 +272,8 @@ public class TestGeoUtils extends Lucene
System.out.println("\nTEST: iter=" + iter + " rect: lon=" + minLon + " TO " + maxLon + ", lat=" + minLat + " TO " + maxLat + "; circle: lon=" + centerLon + " lat=" + centerLat + " radiusMeters=" + radiusMeters);
if (expected) {
System.out.println(" circle fully contains rect");
+ } else if (circleFullyInside) {
+ System.out.println(" rect fully contains circle");
} else {
System.out.println(" circle and rect are disjoint");
}
@@ -283,6 +288,10 @@ public class TestGeoUtils extends Lucene
double lat = minLat + random().nextDouble() * (maxLat - minLat);
double distanceMeters = SloppyMath.haversin(centerLat, centerLon, lat, lon)*1000.0;
boolean actual = distanceMeters < radiusMeters;
+ if (circleFullyInside) {
+ // nocommit why even test this? expected will always be == actual when circleFullyInside
+ expected = circleFullyInside && actual;
+ }
if (expected != actual) {
System.out.println(" lon=" + lon + " lat=" + lat + " distanceMeters=" + distanceMeters);
assertEquals(expected, actual);
@@ -291,5 +300,52 @@ 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));
+ }
+ 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;
+ }
+ }
}