LUCENE-7204: Add a test for (and make a fix for) legitimately coplanar polygon points.

This commit is contained in:
Karl Wright 2016-04-13 02:51:25 -04:00
parent 9a150920a6
commit 69f3d1fe5f
2 changed files with 14 additions and 4 deletions

View File

@ -1094,10 +1094,10 @@ public class GeoPolygonFactory {
final boolean isNewPointWithin;
final GeoPoint pointToPresent;
if (currentEdge.plane.evaluateIsZero(newPoint)) {
// The new point is colinear with the current edge. We'll have to look for the first point that isn't.
// The new point is colinear with the current edge. We'll have to look backwards for the first point that isn't.
int checkPointIndex = -1;
// Compute the arc distance before we try to extend
double accumulatedDistance = 0.0;
// Compute the arc distance before we try to extend, so that we note backtracking when we see it
double accumulatedDistance = newPoint.arcDistance(pointList.get(startIndex));
final Plane checkPlane = new Plane(pointList.get(startIndex), newPoint);
for (int i = 0; i < pointList.size(); i++) {
final int index = getLegalIndex(startIndex - 1 - i, pointList.size());
@ -1106,11 +1106,13 @@ public class GeoPolygonFactory {
break;
} else {
accumulatedDistance += pointList.get(getLegalIndex(index+1, pointList.size())).arcDistance(pointList.get(index));
final double actualDistance = pointList.get(getLegalIndex(startIndex-1, pointList.size())).arcDistance(pointList.get(index));
final double actualDistance = newPoint.arcDistance(pointList.get(index));
if (Math.abs(actualDistance - accumulatedDistance) >= Vector.MINIMUM_RESOLUTION) {
throw new IllegalArgumentException("polygon backtracks over itself");
}
}
}
if (checkPointIndex == -1) {
throw new IllegalArgumentException("polygon is illegal (linear)");
}
pointToPresent = pointList.get(checkPointIndex);

View File

@ -416,6 +416,14 @@ shape:
}
assertTrue(backtracks);
// Now make sure a legit poly with coplanar points works.
polyPoints.clear();
polyPoints.add(new GeoPoint(pm, -0.5516194571595735, 0.0));
polyPoints.add(new GeoPoint(pm, -1.5707963267948966, -2.2780601241431375));
polyPoints.add(new GeoPoint(pm, 0.2669499069140678, -0.31249902828113546));
polyPoints.add(new GeoPoint(pm, 1.538559019421765, 0.0));
GeoPolygonFactory.makeGeoPolygon(pm, polyPoints, 3, null);
}
}