Apache Lucene open-source search software
LUCENE-8220: Fix yet another case where we cannot tile.
Karl Wright26ba705a4f25
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.javaindex d8938dcefb5..a5a4406bc65 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@@ -175,20 +175,20 @@ public class GeoPolygonFactory {holes = null;}- // 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<GeoPoint> firstFilteredPointList = filterPoints(description.points);- if (firstFilteredPointList == null) {- return null;- }- final List<GeoPoint> filteredPointList = filterEdges(firstFilteredPointList, leniencyValue);- //System.err.println(" ...done in "+(System.currentTimeMillis()-startTime)+"ms ("+((filteredPointList==null)?"degenerate":(filteredPointList.size()+" points"))+")");- if (filteredPointList == null) {- return null;- }+ if (description.points.size() <= SMALL_POLYGON_CUTOFF_EDGES) {+ // 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<GeoPoint> firstFilteredPointList = filterPoints(description.points);+ if (firstFilteredPointList == null) {+ return null;+ }+ final List<GeoPoint> filteredPointList = filterEdges(firstFilteredPointList, leniencyValue);+ //System.err.println(" ...done in "+(System.currentTimeMillis()-startTime)+"ms ("+((filteredPointList==null)?"degenerate":(filteredPointList.size()+" points"))+")");+ if (filteredPointList == null) {+ return null;+ }- if (filteredPointList.size() <= SMALL_POLYGON_CUTOFF_EDGES) {try {//First approximation to find a pointfinal GeoPoint centerOfMass = getCenterOfMass(planetModel, filteredPointList);@@ -1144,7 +1144,7 @@ public class GeoPolygonFactory {final MutableBoolean seenConcave,final EdgeBuffer edgeBuffer,final List<GeoPolygon> holes,- final GeoPoint testPoint) {+ final GeoPoint testPoint) throws TileException {if (edgeBuffer.size() == 0) {return true;@@ -1182,25 +1182,27 @@ public class GeoPolygonFactory {edge = edgeBuffer.getNext(edge);}- // Since we attempt to prevent the addition of any edge that shows up as colinear, and we filter out colinear edge parts- // beforehand, it isn't possible to have a colinear edge at this point.- if (testPoint != null && holes != null && holes.size() > 0) {- // No holes, for test- final GeoPolygon testPolygon = new GeoConcavePolygon(planetModel, points, null, internalEdges, isInternal);- if (testPolygon.isWithin(testPoint)) {- return false;+ try {+ if (testPoint != null && holes != null && holes.size() > 0) {+ // No holes, for test+ final GeoPolygon testPolygon = new GeoConcavePolygon(planetModel, points, null, internalEdges, isInternal);+ if (testPolygon.isWithin(testPoint)) {+ return false;+ }}- }-- final GeoPolygon realPolygon = new GeoConcavePolygon(planetModel, points, holes, internalEdges, isInternal);- if (testPoint != null && (holes == null || holes.size() == 0)) {- if (realPolygon.isWithin(testPoint)) {- return false;++ final GeoPolygon realPolygon = new GeoConcavePolygon(planetModel, points, holes, internalEdges, isInternal);+ if (testPoint != null && (holes == null || holes.size() == 0)) {+ if (realPolygon.isWithin(testPoint)) {+ return false;+ }}++ rval.addShape(realPolygon);+ return true;+ } catch (IllegalArgumentException e) {+ throw new TileException(e.getMessage());}-- rval.addShape(realPolygon);- return true;}/** Look for a convex polygon at the specified edge. If we find it, create one and adjust the edge buffer.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.javaindex 9d2aa1e9381..2625ba72d8d 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@@ -1176,4 +1176,32 @@ shape:Collections.reverse(points);polygon = GeoPolygonFactory.makeGeoPolygon(PlanetModel.SPHERE, points);}++ @Test+ public void testCoplanarityConvex2() throws Exception {+ //POLYGON((-3.488658 50.45564,-3.4898987 50.455627,-3.489865 50.455585,-3.489833 50.45551,-3.489808 50.455433,-3.489806 50.455406,-3.4898643 50.45525,-3.4892037 50.455162,-3.4891756 50.455166,-3.4891088 50.455147,-3.4890108 50.455166,-3.4889853 50.455166,-3.48895 50.45516,-3.488912 50.455166,-3.4889014 50.455177,-3.488893 50.455185,-3.488927 50.45523,-3.4890666 50.455456,-3.48905 50.455467,-3.488658 50.45564))+ List<GeoPoint> points = new ArrayList<>();+ points.add(new GeoPoint(PlanetModel.SPHERE, Geo3DUtil.fromDegrees(50.45564), Geo3DUtil.fromDegrees(-3.488658)));+ points.add(new GeoPoint(PlanetModel.SPHERE, Geo3DUtil.fromDegrees(50.455627), Geo3DUtil.fromDegrees(-3.4898987)));+ points.add(new GeoPoint(PlanetModel.SPHERE, Geo3DUtil.fromDegrees(50.455585), Geo3DUtil.fromDegrees(-3.489865)));+ points.add(new GeoPoint(PlanetModel.SPHERE, Geo3DUtil.fromDegrees(50.45551), Geo3DUtil.fromDegrees(-3.489833)));+ points.add(new GeoPoint(PlanetModel.SPHERE, Geo3DUtil.fromDegrees(50.455433), Geo3DUtil.fromDegrees(-3.489808)));+ points.add(new GeoPoint(PlanetModel.SPHERE, Geo3DUtil.fromDegrees(50.455406), Geo3DUtil.fromDegrees(-3.489806)));+ points.add(new GeoPoint(PlanetModel.SPHERE, Geo3DUtil.fromDegrees(50.45525), Geo3DUtil.fromDegrees(-3.4898643)));+ points.add(new GeoPoint(PlanetModel.SPHERE, Geo3DUtil.fromDegrees(50.455162), Geo3DUtil.fromDegrees(-3.4892037)));+ points.add(new GeoPoint(PlanetModel.SPHERE, Geo3DUtil.fromDegrees(50.455166), Geo3DUtil.fromDegrees(-3.4891756)));+ points.add(new GeoPoint(PlanetModel.SPHERE, Geo3DUtil.fromDegrees(50.455147), Geo3DUtil.fromDegrees(-3.4891088)));+ points.add(new GeoPoint(PlanetModel.SPHERE, Geo3DUtil.fromDegrees(50.455166), Geo3DUtil.fromDegrees(-3.4890108)));+ points.add(new GeoPoint(PlanetModel.SPHERE, Geo3DUtil.fromDegrees(50.455166), Geo3DUtil.fromDegrees(-3.4889853)));+ points.add(new GeoPoint(PlanetModel.SPHERE, Geo3DUtil.fromDegrees(50.45516), Geo3DUtil.fromDegrees(-3.48895)));+ points.add(new GeoPoint(PlanetModel.SPHERE, Geo3DUtil.fromDegrees(50.455166), Geo3DUtil.fromDegrees(-3.488912)));+ points.add(new GeoPoint(PlanetModel.SPHERE, Geo3DUtil.fromDegrees(50.455177), Geo3DUtil.fromDegrees(-3.4889014)));+ points.add(new GeoPoint(PlanetModel.SPHERE, Geo3DUtil.fromDegrees(50.455185), Geo3DUtil.fromDegrees( -3.488893)));+ points.add(new GeoPoint(PlanetModel.SPHERE, Geo3DUtil.fromDegrees(50.45523), Geo3DUtil.fromDegrees(-3.488927)));+ points.add(new GeoPoint(PlanetModel.SPHERE, Geo3DUtil.fromDegrees(50.455456), Geo3DUtil.fromDegrees(-3.4890666)));+ points.add(new GeoPoint(PlanetModel.SPHERE, Geo3DUtil.fromDegrees(50.455467), Geo3DUtil.fromDegrees( -3.48905)));+ GeoPolygon polygon = GeoPolygonFactory.makeGeoPolygon(PlanetModel.SPHERE, points);+ Collections.reverse(points);+ polygon = GeoPolygonFactory.makeGeoPolygon(PlanetModel.SPHERE, points);+ }}