lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject [1/2] lucene-solr:master: LUCENE-7412: Make sure no combined edge of a polygon extends for more than 180 degrees.
Date Sat, 20 Aug 2016 11:36:33 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/master ca1ce0b25 -> e32597311


LUCENE-7412: Make sure no combined edge of a polygon extends for more than 180 degrees.


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

Branch: refs/heads/master
Commit: aa9b5204daa75494835a2da947f69f5daf8459a6
Parents: 22eeba9
Author: Karl Wright <DaddyWri@gmail.com>
Authored: Sat Aug 20 07:35:38 2016 -0400
Committer: Karl Wright <DaddyWri@gmail.com>
Committed: Sat Aug 20 07:35:38 2016 -0400

----------------------------------------------------------------------
 .../spatial3d/geom/GeoConcavePolygon.java       | 16 +++++++++++-
 .../lucene/spatial3d/geom/GeoConvexPolygon.java | 16 +++++++++++-
 .../lucene/spatial3d/geom/GeoPolygonTest.java   | 27 +++++++++++++++++---
 3 files changed, 54 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/aa9b5204/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 a133b3e..1abc06c 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
@@ -237,7 +237,21 @@ class GeoConcavePolygon extends GeoBasePolygon {
       while (invertedEdges[legalIndex(bound2Index)].isNumericallyIdentical(invertedEdge))
{
         bound2Index--;
       }
-      eitherBounds.put(edge, new EitherBound(invertedEdges[legalIndex(bound1Index)], invertedEdges[legalIndex(bound2Index)]));
+      bound1Index = legalIndex(bound1Index);
+      bound2Index = legalIndex(bound2Index);
+      // Also confirm that all interior points are within the bounds
+      int startingIndex = bound2Index;
+      while (true) {
+        startingIndex = legalIndex(startingIndex+1);
+        if (startingIndex == bound1Index) {
+          break;
+        }
+        final GeoPoint interiorPoint = points.get(startingIndex);
+        if (!invertedEdges[bound1Index].isWithin(interiorPoint) || !invertedEdges[bound2Index].isWithin(interiorPoint))
{
+          throw new IllegalArgumentException("Concave polygon has a side that is more than
180 degrees");
+        }
+      }
+      eitherBounds.put(edge, new EitherBound(invertedEdges[bound1Index], invertedEdges[bound2Index]));
       // For intersections, we look at the point at the intersection between the previous
edge and this one.  We need to locate the 
       // Intersection bounds needs to look even further forwards/backwards
       if (otherInvertedEdge != null) {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/aa9b5204/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 860eb26..dbf8f9f 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
@@ -230,7 +230,21 @@ class GeoConvexPolygon extends GeoBasePolygon {
       while (edges[legalIndex(bound2Index)].isNumericallyIdentical(edge)) {
         bound2Index--;
       }
-      eitherBounds.put(edge, new EitherBound(edges[legalIndex(bound1Index)], edges[legalIndex(bound2Index)]));
+      bound1Index = legalIndex(bound1Index);
+      bound2Index = legalIndex(bound2Index);
+      // Also confirm that all interior points are within the bounds
+      int startingIndex = bound2Index;
+      while (true) {
+        startingIndex = legalIndex(startingIndex+1);
+        if (startingIndex == bound1Index) {
+          break;
+        }
+        final GeoPoint interiorPoint = points.get(startingIndex);
+        if (!edges[bound1Index].isWithin(interiorPoint) || !edges[bound2Index].isWithin(interiorPoint))
{
+          throw new IllegalArgumentException("Convex polygon has a side that is more than
180 degrees");
+        }
+      }
+      eitherBounds.put(edge, new EitherBound(edges[bound1Index], edges[bound2Index]));
       // For intersections, we look at the point at the intersection between the previous
edge and this one.  We need to locate the 
       // Intersection bounds needs to look even further forwards/backwards
       if (otherEdge != null) {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/aa9b5204/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/GeoPolygonTest.java
----------------------------------------------------------------------
diff --git a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/GeoPolygonTest.java
b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/GeoPolygonTest.java
index a5a0207..6745060 100755
--- a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/GeoPolygonTest.java
+++ b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/GeoPolygonTest.java
@@ -692,7 +692,7 @@ shape:
     polyList.add(p5);
     
     GeoPolygon p = GeoPolygonFactory.makeGeoPolygon(PlanetModel.WGS84, polyList);
-    System.out.println("p = "+p);
+    //System.out.println("p = "+p);
 
     XYZBounds bounds = new XYZBounds();
     p.getBounds(bounds);
@@ -733,8 +733,8 @@ shape:
     
     final GeoPoint point = new GeoPoint(PlanetModel.WGS84, -0.41518838180529244, 3.141592653589793);
     final GeoPoint encodedPoint = new GeoPoint(-0.9155623168963972, 2.3309121299774915E-10,
-0.40359240449795253);
-    System.out.println("point = "+point);
-    System.out.println("encodedPoint = "+encodedPoint);
+    //System.out.println("point = "+point);
+    //System.out.println("encodedPoint = "+encodedPoint);
     
     assertTrue(p.isWithin(point));
     assertTrue(solid.isWithin(point));
@@ -906,5 +906,26 @@ shape:
     assertTrue(solid.isWithin(checkPoint));
     
   }
+
+  @Test
+  public void testPolygonFailureCase1() {
+    final List<GeoPoint> poly2List = new ArrayList<>();
+    poly2List.add(new GeoPoint(PlanetModel.WGS84, -0.6370451769779303, 2.5318373679431616));
+    poly2List.add(new GeoPoint(PlanetModel.WGS84, 1.5707963267948966, -3.141592653589793));
+    poly2List.add(new GeoPoint(PlanetModel.WGS84, -1.0850383189690824, 2.4457272005608357E-47));
+    poly2List.add(new GeoPoint(PlanetModel.WGS84, -0.5703530503197992, -3.141592653589793));
+    final BitSet poly2Bitset = new BitSet();
+    poly2Bitset.set(1);
+    
+    boolean result;
+    try {
+      final GeoConvexPolygon poly2 = new GeoConvexPolygon(PlanetModel.WGS84, poly2List);
+      result = true;
+    } catch (IllegalArgumentException e) {
+      result = false;
+    }
+    
+    assertTrue(!result);
+  }
   
 }


Mime
View raw message