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/27 21:26:51 UTC

lucene-solr:branch_6x: slightly improve polygon testing: test something other than boxes

Repository: lucene-solr
Updated Branches:
  refs/heads/branch_6x 28a433581 -> bd74f4250


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/bd74f425
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/bd74f425
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/bd74f425

Branch: refs/heads/branch_6x
Commit: bd74f42503c72d87a16474e03f5a26d3c250c6c2
Parents: 28a4335
Author: Robert Muir <rm...@apache.org>
Authored: Sun Mar 27 15:27:17 2016 -0400
Committer: Robert Muir <rm...@apache.org>
Committed: Sun Mar 27 15:28:04 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/bd74f425/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