Apache Lucene open-source search software
Followup work for #11883
Karl David Wright108462a005fa
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.javaindex f3f1a04d2fb..3b6e6904226 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@@ -42,6 +42,10 @@ class GeoConcavePolygon extends GeoBasePolygon {/** A list of edges */protected SidedPlane[] edges = null;+ /** Start bounds */+ protected SidedPlane[] startBounds = null;+ /** End bounds */+ protected SidedPlane[] endBounds = null;/** A list of inverted edges */protected SidedPlane[] invertedEdges = null;/** The set of notable points for each edge */@@ -50,8 +54,6 @@ class GeoConcavePolygon extends GeoBasePolygon {protected GeoPoint[] edgePoints = null;/** Set to true when the polygon is complete */protected boolean isDone = false;- /** A bounds object for each sided plane */- protected Map<SidedPlane, Membership> eitherBounds = null;/** Map from edge to its previous non-coplanar brother */protected Map<SidedPlane, SidedPlane> prevBrotherMap = null;/** Map from edge to its next non-coplanar brother */@@ -216,6 +218,8 @@ class GeoConcavePolygon extends GeoBasePolygon {// to a segment can provide an exterior measurement. Note: We build the true planes// here and use the logic to return what *isn't* inside all of them.edges = new SidedPlane[points.size()];+ startBounds = new SidedPlane[points.size()];+ endBounds = new SidedPlane[points.size()];invertedEdges = new SidedPlane[points.size()];notableEdgePoints = new GeoPoint[points.size()][];@@ -239,17 +243,18 @@ class GeoConcavePolygon extends GeoBasePolygon {final GeoPoint check = points.get(endPointIndex);// System.out.println("Created edge " + sp + " using start=" + start// + " end=" + end + " check=" + check);- edges[i] = new SidedPlane(check, false, start, end);+ final SidedPlane sp = new SidedPlane(check, false, start, end);+ edges[i] = sp;+ startBounds[i] = SidedPlane.constructSidedPlaneFromOnePoint(end, sp, start);+ endBounds[i] = SidedPlane.constructSidedPlaneFromOnePoint(start, sp, end);invertedEdges[i] = new SidedPlane(edges[i]);notableEdgePoints[i] = new GeoPoint[] {start, end};}// For each edge, create a bounds object.- eitherBounds = CollectionUtil.newHashMap(edges.length);prevBrotherMap = CollectionUtil.newHashMap(edges.length);nextBrotherMap = CollectionUtil.newHashMap(edges.length);for (int edgeIndex = 0; edgeIndex < edges.length; edgeIndex++) {- final SidedPlane edge = edges[edgeIndex];final SidedPlane invertedEdge = invertedEdges[edgeIndex];int bound1Index = legalIndex(edgeIndex + 1);while (invertedEdges[bound1Index].isNumericallyIdentical(invertedEdge)) {@@ -279,8 +284,6 @@ class GeoConcavePolygon extends GeoBasePolygon {"Concave polygon has a side that is more than 180 degrees");}}- eitherBounds.put(- edge, new EitherBound(invertedEdges[bound1Index], invertedEdges[bound2Index]));// When we are done with this cycle, we'll need to build the intersection bound for each edge// and its brother.// For now, keep track of the relationships.@@ -417,14 +420,19 @@ class GeoConcavePolygon extends GeoBasePolygon {// The bounding planes are inverted and complementary. For intersection computation, we// cannot use them as bounds. They are independent hemispheres.for (int edgeIndex = 0; edgeIndex < edges.length; edgeIndex++) {- final SidedPlane edge = edges[edgeIndex];final SidedPlane invertedEdge = invertedEdges[edgeIndex];final GeoPoint[] points = this.notableEdgePoints[edgeIndex];if (!isInternalEdges.get(edgeIndex)) {// System.err.println("Checking concave edge " + edge// + " for intersection against plane " + p);if (invertedEdge.intersects(- planetModel, p, notablePoints, points, bounds, eitherBounds.get(edge))) {+ planetModel,+ p,+ notablePoints,+ points,+ bounds,+ startBounds[edgeIndex],+ endBounds[edgeIndex])) {// System.err.println(" intersects!");return true;}@@ -449,7 +457,7 @@ class GeoConcavePolygon extends GeoBasePolygon {final SidedPlane edge = edges[edgeIndex];final GeoPoint[] points = this.notableEdgePoints[edgeIndex];if (!isInternalEdges.get(edgeIndex)) {- if (geoShape.intersects(edge, points, eitherBounds.get(edge))) {+ if (geoShape.intersects(edge, points, startBounds[edgeIndex], endBounds[edgeIndex])) {return true;}}@@ -464,39 +472,6 @@ class GeoConcavePolygon extends GeoBasePolygon {return false;}- /** A membership implementation representing polygon edges that must apply. */- protected static class EitherBound implements Membership {-- protected final SidedPlane sideBound1;- protected final SidedPlane sideBound2;-- /**- * Constructor.- *- * @param sideBound1 is the first side bound.- * @param sideBound2 is the second side bound.- */- public EitherBound(final SidedPlane sideBound1, final SidedPlane sideBound2) {- this.sideBound1 = sideBound1;- this.sideBound2 = sideBound2;- }-- @Override- public boolean isWithin(final Vector v) {- return sideBound1.isWithin(v) && sideBound2.isWithin(v);- }-- @Override- public boolean isWithin(final double x, final double y, final double z) {- return sideBound1.isWithin(x, y, z) && sideBound2.isWithin(x, y, z);- }-- @Override- public String toString() {- return "(" + sideBound1 + "," + sideBound2 + ")";- }- }-@Overridepublic void getBounds(Bounds bounds) {// Because of holes, we don't want to use superclass method@@ -527,8 +502,9 @@ class GeoConcavePolygon extends GeoBasePolygon {}// Add planes with membership.- for (final SidedPlane edge : edges) {- bounds.addPlane(planetModel, edge, eitherBounds.get(edge));+ for (int edgeIndex = 0; edgeIndex < edges.length; edgeIndex++) {+ final SidedPlane edge = edges[edgeIndex];+ bounds.addPlane(planetModel, edge, startBounds[edgeIndex], endBounds[edgeIndex]);}for (final SidedPlane invertedEdge : invertedEdges) {final SidedPlane nextEdge = nextBrotherMap.get(invertedEdge);@@ -551,10 +527,11 @@ class GeoConcavePolygon extends GeoBasePolygon {minimumDistance = newDist;}}- for (final SidedPlane edgePlane : edges) {+ for (int edgeIndex = 0; edgeIndex < edges.length; edgeIndex++) {+ final SidedPlane edgePlane = edges[edgeIndex];final double newDist =distanceStyle.computeDistance(- planetModel, edgePlane, x, y, z, eitherBounds.get(edgePlane));+ planetModel, edgePlane, x, y, z, startBounds[edgeIndex], endBounds[edgeIndex]);if (newDist < minimumDistance) {minimumDistance = newDist;}