lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rm...@apache.org
Subject lucene-solr:master: slightly improve polygon testing: test something other than boxes
Date Sun, 27 Mar 2016 19:25:24 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/master 7b93fc46b -> 6ac0c43b9


slightly improve polygon testing: test something other than boxes


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

Branch: refs/heads/master
Commit: 6ac0c43b97d39cd4d1a8c7a58096beb6277d19f1
Parents: 7b93fc4
Author: Robert Muir <rmuir@apache.org>
Authored: Sun Mar 27 15:27:17 2016 -0400
Committer: Robert Muir <rmuir@apache.org>
Committed: Sun Mar 27 15:27:17 2016 -0400

----------------------------------------------------------------------
 .../spatial/util/BaseGeoPointTestCase.java      | 57 +++++++++++---------
 1 file changed, 32 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/6ac0c43b/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 fd97207..c22b79c 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
@@ -695,18 +695,7 @@ public abstract class BaseGeoPointTestCase extends LuceneTestCase {
     }
   }
   
-  static final boolean polyRectContainsPoint(GeoRect rect, double pointLat, double pointLon)
{
-    // TODO write better random polygon tests
-    
-    // note: logic must be slightly different than rectContainsPoint, to satisfy
-    // insideness for cases exactly on boundaries.
-    
-    assert Double.isNaN(pointLat) == false;
-    assert rect.crossesDateline() == false;
-    double polyLats[] = new double[] { rect.minLat, rect.maxLat, rect.maxLat, rect.minLat,
rect.minLat };
-    double polyLons[] = new double[] { rect.minLon, rect.minLon, rect.maxLon, rect.maxLon,
rect.minLon };
-
-    // TODO: separately test this method is 100% correct, here treat it like a black box
(like haversin)
+  static final boolean polygonContainsPoint(double polyLats[], double polyLons[], double
pointLat, double pointLon) {
     return GeoRelationUtils.pointInPolygon(polyLats, polyLons, pointLat, pointLon);
   }
 
@@ -940,24 +929,42 @@ public abstract class BaseGeoPointTestCase extends LuceneTestCase {
         final GeoRect bbox = randomRect(small, false);
 
         // Polygon
-        double[] polyLats = new double[5];
-        double[] polyLons = new double[5];
-        polyLats[0] = bbox.minLat;
-        polyLons[0] = bbox.minLon;
-        polyLats[1] = bbox.maxLat;
-        polyLons[1] = bbox.minLon;
-        polyLats[2] = bbox.maxLat;
-        polyLons[2] = bbox.maxLon;
-        polyLats[3] = bbox.minLat;
-        polyLons[3] = bbox.maxLon;
-        polyLats[4] = bbox.minLat;
-        polyLons[4] = bbox.minLon;
+        final double[] polyLats;
+        final double[] polyLons;
+        // TODO: factor this out, maybe if we add Polygon class?
+        if (random().nextBoolean()) {
+          // box
+          polyLats = new double[5];
+          polyLons = new double[5];
+          polyLats[0] = bbox.minLat;
+          polyLons[0] = bbox.minLon;
+          polyLats[1] = bbox.maxLat;
+          polyLons[1] = bbox.minLon;
+          polyLats[2] = bbox.maxLat;
+          polyLons[2] = bbox.maxLon;
+          polyLats[3] = bbox.minLat;
+          polyLons[3] = bbox.maxLon;
+          polyLats[4] = bbox.minLat;
+          polyLons[4] = bbox.minLon;
+        } else {
+          // right triangle
+          polyLats = new double[4];
+          polyLons = new double[4];
+          polyLats[0] = bbox.minLat;
+          polyLons[0] = bbox.minLon;
+          polyLats[1] = bbox.maxLat;
+          polyLons[1] = bbox.minLon;
+          polyLats[2] = bbox.maxLat;
+          polyLons[2] = bbox.maxLon;
+          polyLats[3] = bbox.minLat;
+          polyLons[3] = bbox.minLon;
+        }
         query = newPolygonQuery(FIELD_NAME, polyLats, polyLons);
 
         verifyHits = new VerifyHits() {
           @Override
           protected boolean shouldMatch(double pointLat, double pointLon) {
-            return polyRectContainsPoint(bbox, pointLat, pointLon);
+            return polygonContainsPoint(polyLats, polyLons, pointLat, pointLon);
           }
 
           @Override


Mime
View raw message