You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by kw...@apache.org on 2016/04/22 22:38:50 UTC

lucene-solr:master: LUCENE-7244: Complain if the holes are outside the polygon.

Repository: lucene-solr
Updated Branches:
  refs/heads/master 88c9da6c8 -> 38ebd906e


LUCENE-7244: Complain if the holes are outside the polygon.


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

Branch: refs/heads/master
Commit: 38ebd906e830e793d7df364163f0baab049ffa47
Parents: 88c9da6
Author: Karl Wright <Da...@gmail.com>
Authored: Fri Apr 22 16:35:51 2016 -0400
Committer: Karl Wright <Da...@gmail.com>
Committed: Fri Apr 22 16:37:31 2016 -0400

----------------------------------------------------------------------
 .../spatial3d/geom/GeoConcavePolygon.java       | 35 +++++++++++---------
 .../lucene/spatial3d/geom/GeoConvexPolygon.java | 35 +++++++++++---------
 2 files changed, 40 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/38ebd906/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoConcavePolygon.java
----------------------------------------------------------------------
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoConcavePolygon.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoConcavePolygon.java
index 124b46b..8eaea1a 100644
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoConcavePolygon.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoConcavePolygon.java
@@ -207,21 +207,6 @@ class GeoConcavePolygon extends GeoBasePolygon {
       invertedEdges[i] = new SidedPlane(edges[i]);
       notableEdgePoints[i] = new GeoPoint[]{start, end};
     }
-    /* Disable since GeoPolygonFactory does this too.
-    // In order to naively confirm that the polygon is concave, I would need to
-    // check every edge, and verify that every point (other than the edge endpoints)
-    // is within the edge's sided plane.  This is an order n^2 operation.  That's still
-    // not wrong, though, because everything else about polygons has a similar cost.
-    for (int edgeIndex = 0; edgeIndex < edges.length; edgeIndex++) {
-      final SidedPlane edge = edges[edgeIndex];
-      for (int pointIndex = 0; pointIndex < points.size(); pointIndex++) {
-        if (pointIndex != edgeIndex && pointIndex != legalIndex(edgeIndex + 1)) {
-          if (edge.isWithin(points.get(pointIndex)))
-            throw new IllegalArgumentException("Polygon is not concave: Point " + points.get(pointIndex) + " Edge " + edge);
-        }
-      }
-    }
-    */
     
     // For each edge, create a bounds object.
     eitherBounds = new HashMap<>(edges.length);
@@ -241,6 +226,26 @@ class GeoConcavePolygon extends GeoBasePolygon {
 
     // Pick an edge point arbitrarily
     edgePoints = new GeoPoint[]{points.get(0)};
+
+    if (isWithinHoles(points.get(0))) {
+      throw new IllegalArgumentException("Polygon edge intersects a polygon hole; not allowed");
+    }
+
+  }
+
+  /** Check if a point is within the provided holes.
+   *@param point point to check.
+   *@return true if the point is within any of the holes.
+   */
+  protected boolean isWithinHoles(final GeoPoint point) {
+    if (holes != null) {
+      for (final GeoPolygon hole : holes) {
+        if (hole.isWithin(point)) {
+          return true;
+        }
+      }
+    }
+    return false;
   }
 
   /** Compute a legal point index from a possibly illegal one, that may have wrapped.

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/38ebd906/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoConvexPolygon.java
----------------------------------------------------------------------
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoConvexPolygon.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoConvexPolygon.java
index 64aa7c4..17a2120 100755
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoConvexPolygon.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoConvexPolygon.java
@@ -203,21 +203,6 @@ class GeoConvexPolygon extends GeoBasePolygon {
       edges[i] = sp;
       notableEdgePoints[i] = new GeoPoint[]{start, end};
     }
-    /* Disabled since GeoPolygonFactory does the checking too.
-    // In order to naively confirm that the polygon is convex, I would need to
-    // check every edge, and verify that every point (other than the edge endpoints)
-    // is within the edge's sided plane.  This is an order n^2 operation.  That's still
-    // not wrong, though, because everything else about polygons has a similar cost.
-    for (int edgeIndex = 0; edgeIndex < edges.length; edgeIndex++) {
-      final SidedPlane edge = edges[edgeIndex];
-      for (int pointIndex = 0; pointIndex < points.size(); pointIndex++) {
-        if (pointIndex != edgeIndex && pointIndex != legalIndex(edgeIndex + 1)) {
-          if (!edge.isWithin(points.get(pointIndex)))
-            throw new IllegalArgumentException("Polygon is not convex: Point " + points.get(pointIndex) + " Edge " + edge);
-        }
-      }
-    }
-    */
     
     // For each edge, create a bounds object.
     eitherBounds = new HashMap<>(edges.length);
@@ -236,8 +221,28 @@ class GeoConvexPolygon extends GeoBasePolygon {
     
     // Pick an edge point arbitrarily
     edgePoints = new GeoPoint[]{points.get(0)};
+    
+    if (isWithinHoles(points.get(0))) {
+      throw new IllegalArgumentException("Polygon edge intersects a polygon hole; not allowed");
+    }
+
   }
 
+  /** Check if a point is within the provided holes.
+   *@param point point to check.
+   *@return true if the point is within any of the holes.
+   */
+  protected boolean isWithinHoles(final GeoPoint point) {
+    if (holes != null) {
+      for (final GeoPolygon hole : holes) {
+        if (hole.isWithin(point)) {
+          return true;
+        }
+      }
+    }
+    return false;
+  }
+  
   /** Compute a legal point index from a possibly illegal one, that may have wrapped.
    *@param index is the index.
    *@return the normalized index.