You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2016/03/22 04:12:41 UTC
lucene-solr:branch_6x: move tests from sandbox/ to spatial/ since
they test GeoUtils methods (now with no unwanted quantization)
Repository: lucene-solr
Updated Branches:
refs/heads/branch_6x 5da1ec91d -> c9a197490
move tests from sandbox/ to spatial/ since they test GeoUtils methods (now with no unwanted quantization)
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/c9a19749
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/c9a19749
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/c9a19749
Branch: refs/heads/branch_6x
Commit: c9a197490d446c80a252962c3899da140de520a2
Parents: 5da1ec9
Author: Robert Muir <rm...@apache.org>
Authored: Mon Mar 21 23:09:49 2016 -0400
Committer: Robert Muir <rm...@apache.org>
Committed: Mon Mar 21 23:11:29 2016 -0400
----------------------------------------------------------------------
.../document/TestLatLonPointDistanceQuery.java | 53 -------
.../document/TestLatLonPointDistanceSort.java | 16 --
.../lucene/search/TestLatLonPointQueries.java | 84 -----------
.../lucene/spatial/util/TestGeoUtils.java | 150 +++++++++++++++++++
4 files changed, 150 insertions(+), 153 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c9a19749/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonPointDistanceQuery.java
----------------------------------------------------------------------
diff --git a/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonPointDistanceQuery.java b/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonPointDistanceQuery.java
index 193c2a3..983b1a7 100644
--- a/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonPointDistanceQuery.java
+++ b/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonPointDistanceQuery.java
@@ -34,8 +34,6 @@ import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.Sort;
import org.apache.lucene.search.TopDocs;
-import org.apache.lucene.spatial.util.GeoRect;
-import org.apache.lucene.spatial.util.GeoUtils;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.SloppyMath;
@@ -189,55 +187,4 @@ public class TestLatLonPointDistanceQuery extends LuceneTestCase {
writer.close();
dir.close();
}
-
- public void testBoundingBoxOpto() {
- for (int i = 0; i < 1000; i++) {
- double lat = -90 + 180.0 * random().nextDouble();
- double lon = -180 + 360.0 * random().nextDouble();
- double radius = 50000000 * random().nextDouble();
- GeoRect box = GeoUtils.circleToBBox(lon, lat, radius);
- final GeoRect box1;
- final GeoRect box2;
- if (box.crossesDateline()) {
- box1 = new GeoRect(-180, box.maxLon, box.minLat, box.maxLat);
- box2 = new GeoRect(box.minLon, 180, box.minLat, box.maxLat);
- } else {
- box1 = box;
- box2 = null;
- }
-
- for (int j = 0; j < 10000; j++) {
- double lat2 = -90 + 180.0 * random().nextDouble();
- double lon2 = -180 + 360.0 * random().nextDouble();
- // if the point is within radius, then it should be in our bounding box
- if (SloppyMath.haversinMeters(lat, lon, lat2, lon2) <= radius) {
- assertTrue(lat >= box.minLat && lat <= box.maxLat);
- assertTrue(lon >= box1.minLon && lon <= box1.maxLon || (box2 != null && lon >= box2.minLon && lon <= box2.maxLon));
- }
- }
- }
- }
-
- public void testHaversinOpto() {
- for (int i = 0; i < 1000; i++) {
- double lat = -90 + 180.0 * random().nextDouble();
- double lon = -180 + 360.0 * random().nextDouble();
- double radius = 50000000 * random().nextDouble();
- GeoRect box = GeoUtils.circleToBBox(lon, lat, radius);
-
- if (box.maxLon - lon < 90 && lon - box.minLon < 90) {
- double minPartialDistance = Math.max(SloppyMath.haversinSortKey(lat, lon, lat, box.maxLon),
- SloppyMath.haversinSortKey(lat, lon, box.maxLat, lon));
-
- for (int j = 0; j < 10000; j++) {
- double lat2 = -90 + 180.0 * random().nextDouble();
- double lon2 = -180 + 360.0 * random().nextDouble();
- // if the point is within radius, then it should be <= our sort key
- if (SloppyMath.haversinMeters(lat, lon, lat2, lon2) <= radius) {
- assertTrue(SloppyMath.haversinSortKey(lat, lon, lat2, lon2) <= minPartialDistance);
- }
- }
- }
- }
- }
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c9a19749/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonPointDistanceSort.java
----------------------------------------------------------------------
diff --git a/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonPointDistanceSort.java b/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonPointDistanceSort.java
index 8e8b03d..0e5d898 100644
--- a/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonPointDistanceSort.java
+++ b/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonPointDistanceSort.java
@@ -27,8 +27,6 @@ import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.Sort;
import org.apache.lucene.search.SortField;
import org.apache.lucene.search.TopDocs;
-import org.apache.lucene.spatial.util.GeoRect;
-import org.apache.lucene.spatial.util.GeoUtils;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.SloppyMath;
@@ -252,18 +250,4 @@ public class TestLatLonPointDistanceSort extends LuceneTestCase {
writer.close();
dir.close();
}
-
- /** Test infinite radius covers whole earth */
- public void testInfiniteRect() {
- for (int i = 0; i < 100000; i++) {
- double centerLat = -90 + 180.0 * random().nextDouble();
- double centerLon = -180 + 360.0 * random().nextDouble();
- GeoRect rect = GeoUtils.circleToBBox(centerLat, centerLon, Double.POSITIVE_INFINITY);
- assertEquals(-180.0, rect.minLon, 0.0D);
- assertEquals(180.0, rect.maxLon, 0.0D);
- assertEquals(-90.0, rect.minLat, 0.0D);
- assertEquals(90.0, rect.maxLat, 0.0D);
- assertFalse(rect.crossesDateline());
- }
- }
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c9a19749/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 5831095..e12923f 100644
--- a/lucene/sandbox/src/test/org/apache/lucene/search/TestLatLonPointQueries.java
+++ b/lucene/sandbox/src/test/org/apache/lucene/search/TestLatLonPointQueries.java
@@ -21,7 +21,6 @@ import org.apache.lucene.document.LatLonPoint;
import org.apache.lucene.spatial.util.BaseGeoPointTestCase;
import org.apache.lucene.spatial.util.GeoRect;
import org.apache.lucene.spatial.util.GeoRelationUtils;
-import org.apache.lucene.spatial.util.GeoUtils;
import org.apache.lucene.util.SloppyMath;
public class TestLatLonPointQueries extends BaseGeoPointTestCase {
@@ -103,87 +102,4 @@ public class TestLatLonPointQueries extends BaseGeoPointTestCase {
final double d = SloppyMath.haversinMeters(centerLat, centerLon, pointLat, pointLon);
return d >= minRadiusMeters && d <= radiusMeters;
}
-
- /** Returns random double min to max or up to 1% outside of that range */
- private double randomRangeMaybeSlightlyOutside(double min, double max) {
- return min + (random().nextDouble() + (0.5 - random().nextDouble()) * .02) * (max - min);
- }
-
- // We rely heavily on GeoUtils.circleToBBox so we test it here:
- public void testRandomCircleToBBox() throws Exception {
- int iters = atLeast(1000);
- for(int iter=0;iter<iters;iter++) {
-
- boolean useSmallRanges = random().nextBoolean();
-
- double radiusMeters;
-
- double centerLat = randomLat(useSmallRanges);
- double centerLon = randomLon(useSmallRanges);
-
- if (useSmallRanges) {
- // Approx 4 degrees lon at the equator:
- radiusMeters = random().nextDouble() * 444000;
- } else {
- radiusMeters = random().nextDouble() * 50000000;
- }
-
- // TODO: randomly quantize radius too, to provoke exact math errors?
-
- GeoRect bbox = GeoUtils.circleToBBox(centerLon, centerLat, radiusMeters);
-
- int numPointsToTry = 1000;
- for(int i=0;i<numPointsToTry;i++) {
-
- double lat;
- double lon;
-
- if (random().nextBoolean()) {
- lat = randomLat(useSmallRanges);
- 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)));
- if (bbox.crossesDateline()) {
- if (random().nextBoolean()) {
- lon = quantizeLon(GeoUtils.normalizeLon(randomRangeMaybeSlightlyOutside(bbox.maxLon, -180)));
- } else {
- lon = quantizeLon(GeoUtils.normalizeLon(randomRangeMaybeSlightlyOutside(0, bbox.minLon)));
- }
- } else {
- lon = quantizeLon(GeoUtils.normalizeLon(randomRangeMaybeSlightlyOutside(bbox.minLon, bbox.maxLon)));
- }
- }
-
- double distanceMeters = SloppyMath.haversinMeters(centerLat, centerLon, lat, lon);
-
- // Haversin says it's within the circle:
- boolean haversinSays = distanceMeters <= radiusMeters;
-
- // BBox says its within the box:
- boolean bboxSays;
- if (bbox.crossesDateline()) {
- if (lat >= bbox.minLat && lat <= bbox.maxLat) {
- bboxSays = lon <= bbox.maxLon || lon >= bbox.minLon;
- } else {
- bboxSays = false;
- }
- } else {
- bboxSays = lat >= bbox.minLat && lat <= bbox.maxLat && lon >= bbox.minLon && lon <= bbox.maxLon;
- }
-
- if (haversinSays) {
- if (bboxSays == false) {
- System.out.println("small=" + useSmallRanges + " centerLat=" + centerLat + " cetnerLon=" + centerLon + " radiusMeters=" + radiusMeters);
- System.out.println(" bbox: lat=" + bbox.minLat + " to " + bbox.maxLat + " lon=" + bbox.minLon + " to " + bbox.maxLon);
- System.out.println(" point: lat=" + lat + " lon=" + lon);
- System.out.println(" haversin: " + distanceMeters);
- fail("point was within the distance according to haversin, but the bbox doesn't contain it");
- }
- } else {
- // it's fine if haversin said it was outside the radius and bbox said it was inside the box
- }
- }
- }
- }
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c9a19749/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 bc76852..5529cdf 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
@@ -563,4 +563,154 @@ public class TestGeoUtils extends LuceneTestCase {
}
}
}
+
+ /** Returns random double min to max or up to 1% outside of that range */
+ private double randomRangeMaybeSlightlyOutside(double min, double max) {
+ return min + (random().nextDouble() + (0.5 - random().nextDouble()) * .02) * (max - min);
+ }
+
+ // We rely heavily on GeoUtils.circleToBBox so we test it here:
+ public void testRandomCircleToBBox() throws Exception {
+ int iters = atLeast(1000);
+ for(int iter=0;iter<iters;iter++) {
+
+ boolean useSmallRanges = random().nextBoolean();
+
+ double radiusMeters;
+
+ double centerLat = randomLat(useSmallRanges);
+ double centerLon = randomLon(useSmallRanges);
+
+ if (useSmallRanges) {
+ // Approx 4 degrees lon at the equator:
+ radiusMeters = random().nextDouble() * 444000;
+ } else {
+ radiusMeters = random().nextDouble() * 50000000;
+ }
+
+ // TODO: randomly quantize radius too, to provoke exact math errors?
+
+ GeoRect bbox = GeoUtils.circleToBBox(centerLon, centerLat, radiusMeters);
+
+ int numPointsToTry = 1000;
+ for(int i=0;i<numPointsToTry;i++) {
+
+ double lat;
+ double lon;
+
+ if (random().nextBoolean()) {
+ lat = randomLat(useSmallRanges);
+ 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));
+ if (bbox.crossesDateline()) {
+ if (random().nextBoolean()) {
+ lon = GeoUtils.normalizeLon(randomRangeMaybeSlightlyOutside(bbox.maxLon, -180));
+ } else {
+ lon = GeoUtils.normalizeLon(randomRangeMaybeSlightlyOutside(0, bbox.minLon));
+ }
+ } else {
+ lon = GeoUtils.normalizeLon(randomRangeMaybeSlightlyOutside(bbox.minLon, bbox.maxLon));
+ }
+ }
+
+ double distanceMeters = SloppyMath.haversinMeters(centerLat, centerLon, lat, lon);
+
+ // Haversin says it's within the circle:
+ boolean haversinSays = distanceMeters <= radiusMeters;
+
+ // BBox says its within the box:
+ boolean bboxSays;
+ if (bbox.crossesDateline()) {
+ if (lat >= bbox.minLat && lat <= bbox.maxLat) {
+ bboxSays = lon <= bbox.maxLon || lon >= bbox.minLon;
+ } else {
+ bboxSays = false;
+ }
+ } else {
+ bboxSays = lat >= bbox.minLat && lat <= bbox.maxLat && lon >= bbox.minLon && lon <= bbox.maxLon;
+ }
+
+ if (haversinSays) {
+ if (bboxSays == false) {
+ System.out.println("small=" + useSmallRanges + " centerLat=" + centerLat + " cetnerLon=" + centerLon + " radiusMeters=" + radiusMeters);
+ System.out.println(" bbox: lat=" + bbox.minLat + " to " + bbox.maxLat + " lon=" + bbox.minLon + " to " + bbox.maxLon);
+ System.out.println(" point: lat=" + lat + " lon=" + lon);
+ System.out.println(" haversin: " + distanceMeters);
+ fail("point was within the distance according to haversin, but the bbox doesn't contain it");
+ }
+ } else {
+ // it's fine if haversin said it was outside the radius and bbox said it was inside the box
+ }
+ }
+ }
+ }
+
+ // similar to testRandomCircleToBBox, but different, less evil, maybe simpler
+ public void testBoundingBoxOpto() {
+ for (int i = 0; i < 1000; i++) {
+ double lat = -90 + 180.0 * random().nextDouble();
+ double lon = -180 + 360.0 * random().nextDouble();
+ double radius = 50000000 * random().nextDouble();
+ GeoRect box = GeoUtils.circleToBBox(lon, lat, radius);
+ final GeoRect box1;
+ final GeoRect box2;
+ if (box.crossesDateline()) {
+ box1 = new GeoRect(-180, box.maxLon, box.minLat, box.maxLat);
+ box2 = new GeoRect(box.minLon, 180, box.minLat, box.maxLat);
+ } else {
+ box1 = box;
+ box2 = null;
+ }
+
+ for (int j = 0; j < 10000; j++) {
+ double lat2 = -90 + 180.0 * random().nextDouble();
+ double lon2 = -180 + 360.0 * random().nextDouble();
+ // if the point is within radius, then it should be in our bounding box
+ if (SloppyMath.haversinMeters(lat, lon, lat2, lon2) <= radius) {
+ assertTrue(lat >= box.minLat && lat <= box.maxLat);
+ assertTrue(lon >= box1.minLon && lon <= box1.maxLon || (box2 != null && lon >= box2.minLon && lon <= box2.maxLon));
+ }
+ }
+ }
+ }
+
+ // test we can use haversinSortKey() for distance queries.
+ public void testHaversinOpto() {
+ for (int i = 0; i < 1000; i++) {
+ double lat = -90 + 180.0 * random().nextDouble();
+ double lon = -180 + 360.0 * random().nextDouble();
+ double radius = 50000000 * random().nextDouble();
+ GeoRect box = GeoUtils.circleToBBox(lon, lat, radius);
+
+ if (box.maxLon - lon < 90 && lon - box.minLon < 90) {
+ double minPartialDistance = Math.max(SloppyMath.haversinSortKey(lat, lon, lat, box.maxLon),
+ SloppyMath.haversinSortKey(lat, lon, box.maxLat, lon));
+
+ for (int j = 0; j < 10000; j++) {
+ double lat2 = -90 + 180.0 * random().nextDouble();
+ double lon2 = -180 + 360.0 * random().nextDouble();
+ // if the point is within radius, then it should be <= our sort key
+ if (SloppyMath.haversinMeters(lat, lon, lat2, lon2) <= radius) {
+ assertTrue(SloppyMath.haversinSortKey(lat, lon, lat2, lon2) <= minPartialDistance);
+ }
+ }
+ }
+ }
+ }
+
+ /** Test infinite radius covers whole earth */
+ public void testInfiniteRect() {
+ for (int i = 0; i < 1000; i++) {
+ double centerLat = -90 + 180.0 * random().nextDouble();
+ double centerLon = -180 + 360.0 * random().nextDouble();
+ GeoRect rect = GeoUtils.circleToBBox(centerLat, centerLon, Double.POSITIVE_INFINITY);
+ assertEquals(-180.0, rect.minLon, 0.0D);
+ assertEquals(180.0, rect.maxLon, 0.0D);
+ assertEquals(-90.0, rect.minLat, 0.0D);
+ assertEquals(90.0, rect.maxLat, 0.0D);
+ assertFalse(rect.crossesDateline());
+ }
+ }
}