diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoPolygonFactory.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoPolygonFactory.java index 81aaa65c3f6..cb4fcf4f140 100755 --- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoPolygonFactory.java +++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoPolygonFactory.java @@ -88,7 +88,11 @@ public class GeoPolygonFactory { // First, exercise a sanity filter on the provided pointList, and remove identical points, linear points, and backtracks //System.err.println(" filtering "+pointList.size()+" points..."); //final long startTime = System.currentTimeMillis(); - final List filteredPointList = filterEdges(filterPoints(pointList), leniencyValue); + final List firstFilteredPointList = filterPoints(pointList); + if (firstFilteredPointList == null) { + return null; + } + final List filteredPointList = filterEdges(firstFilteredPointList, leniencyValue); //System.err.println(" ...done in "+(System.currentTimeMillis()-startTime)+"ms ("+((filteredPointList==null)?"degenerate":(filteredPointList.size()+" points"))+")"); if (filteredPointList == null) { return null; 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 b325e433491..8063cb01d2d 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 @@ -264,6 +264,39 @@ public class GeoPolygonTest { gp = new GeoPoint(PlanetModel.SPHERE, 0.0, Math.PI); assertFalse(c.isWithin(gp)); + // Now, same thing for large polygon + shapes = new ArrayList<>(); + shapes.add(new GeoPolygonFactory.PolygonDescription(points)); + + c = GeoPolygonFactory.makeLargeGeoPolygon(PlanetModel.SPHERE, shapes); + // Sample some points within + gp = new GeoPoint(PlanetModel.SPHERE, 0.0, -0.5); + assertTrue(c.isWithin(gp)); + gp = new GeoPoint(PlanetModel.SPHERE, 0.0, -0.55); + assertTrue(c.isWithin(gp)); + gp = new GeoPoint(PlanetModel.SPHERE, 0.0, -0.45); + assertTrue(c.isWithin(gp)); + gp = new GeoPoint(PlanetModel.SPHERE, -0.05, -0.5); + assertTrue(c.isWithin(gp)); + gp = new GeoPoint(PlanetModel.SPHERE, 0.05, -0.5); + assertTrue(c.isWithin(gp)); + gp = new GeoPoint(PlanetModel.SPHERE, 0.0, -0.7); + assertTrue(c.isWithin(gp)); + // Sample some nearby points outside + gp = new GeoPoint(PlanetModel.SPHERE, 0.0, -0.35); + assertFalse(c.isWithin(gp)); + gp = new GeoPoint(PlanetModel.SPHERE, -0.15, -0.5); + assertFalse(c.isWithin(gp)); + gp = new GeoPoint(PlanetModel.SPHERE, 0.15, -0.5); + assertFalse(c.isWithin(gp)); + // Random points outside + gp = new GeoPoint(PlanetModel.SPHERE, 0.0, 0.0); + assertFalse(c.isWithin(gp)); + gp = new GeoPoint(PlanetModel.SPHERE, Math.PI * 0.5, 0.0); + assertFalse(c.isWithin(gp)); + gp = new GeoPoint(PlanetModel.SPHERE, 0.0, Math.PI); + assertFalse(c.isWithin(gp)); + } @Test