Apache Solr open-source search software
Use more accurate version of inside cutoff planes.
Karl Wright86be6a67db81
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoComplexPolygon.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoComplexPolygon.javaindex 3a89ee5cc73..06d6dba2868 100644--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoComplexPolygon.java+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoComplexPolygon.java@@ -865,8 +865,10 @@ class GeoComplexPolygon extends GeoBasePolygon {this.testPointCutoffPlane = new SidedPlane(thePoint, testPointPlane, testPoint);this.checkPointCutoffPlane = new SidedPlane(testPoint, travelPlane, thePoint);- this.testPointOtherCutoffPlane = new SidedPlane(testPoint, travelPlane, -(travelPlane.x * intersectionPoint.x + travelPlane.y * intersectionPoint.y + travelPlane.z * intersectionPoint.z));- this.checkPointOtherCutoffPlane = new SidedPlane(thePoint, testPointPlane, -(testPointPlane.x * intersectionPoint.x + testPointPlane.y * intersectionPoint.y + testPointPlane.z * intersectionPoint.z));+ // Convert travel plane to a sided plane+ this.testPointOtherCutoffPlane = new SidedPlane(testPoint, travelPlane, travelPlane.D);+ // Convert testPoint plane to a sided plane+ this.checkPointOtherCutoffPlane = new SidedPlane(thePoint, testPointPlane, testPointPlane.D);// Figure out which of the above/below planes are inside vs. outside. To do this,// we look for the point that is within the bounds of the testPointPlane and travelPlane. The two sides that intersected there are the inside@@ -881,8 +883,8 @@ class GeoComplexPolygon extends GeoBasePolygon {assert belowBelow != null : "Below + below should not be coplanar";final GeoPoint[] belowAbove = travelBelowPlane.findIntersections(planetModel, testPointAbovePlane, testPointCutoffPlane, testPointOtherCutoffPlane, checkPointCutoffPlane, checkPointOtherCutoffPlane);assert belowAbove != null : "Below + above should not be coplanar";-- assert aboveAbove.length + aboveBelow.length + belowBelow.length + belowAbove.length == 1 : "Can be exactly one inside point, instead was: aa="+aboveAbove.length+" ab=" + aboveBelow.length+" bb="+ belowBelow.length+" ba=" + belowAbove.length;++ assert ((aboveAbove.length > 0)?1:0) + ((aboveBelow.length > 0)?1:0) + ((belowBelow.length > 0)?1:0) + ((belowAbove.length > 0)?1:0) == 1 : "Can be exactly one inside point, instead was: aa="+aboveAbove.length+" ab=" + aboveBelow.length+" bb="+ belowBelow.length+" ba=" + belowAbove.length;final GeoPoint insideIntersection;if (aboveAbove.length > 0) {@@ -911,8 +913,8 @@ class GeoComplexPolygon extends GeoBasePolygon {insideIntersection = belowAbove[0];}- insideTravelCutoffPlane = new SidedPlane(thePoint, travelInsidePlane, insideIntersection);- insideTestPointCutoffPlane = new SidedPlane(testPoint, testPointInsidePlane, insideIntersection);+ insideTravelCutoffPlane = new SidedPlane(thePoint, testPointInsidePlane, testPointInsidePlane.D);+ insideTestPointCutoffPlane = new SidedPlane(testPoint, travelInsidePlane, travelInsidePlane.D);}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 a19649528c5..7a152b9c628 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@@ -134,6 +134,12 @@ public class GeoPolygonTest {gp = new GeoPoint(PlanetModel.SPHERE, 0.0, -0.5);assertTrue(c.isWithin(gp));+ shapes = new ArrayList<>();+ shapes.add(new GeoPolygonFactory.PolygonDescription(points));++ c = GeoPolygonFactory.makeLargeGeoPolygon(PlanetModel.SPHERE, shapes);+ assertTrue(c.isWithin(gp));+}@Test@@ -141,6 +147,7 @@ public class GeoPolygonTest {GeoPolygon c;GeoPoint gp;List<GeoPoint> points;+ List<GeoPolygonFactory.PolygonDescription> shapes;points = new ArrayList<GeoPoint>();points.add(new GeoPoint(PlanetModel.SPHERE, 0.0, -0.4));@@ -177,6 +184,43 @@ 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);+ gp = new GeoPoint(PlanetModel.SPHERE, 0.0, -0.65);+ assertFalse(c.isWithin(gp)); //??? fails++ // Sample some points within+ gp = new GeoPoint(PlanetModel.SPHERE, 0.0, -0.45);+ assertTrue(c.isWithin(gp));+ 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.05, -0.5);+ assertTrue(c.isWithin(gp));+ gp = new GeoPoint(PlanetModel.SPHERE, 0.05, -0.5);+ assertTrue(c.isWithin(gp));+ // Sample some nearby points outside+ gp = new GeoPoint(PlanetModel.SPHERE, 0.0, -0.65);+ assertFalse(c.isWithin(gp)); //??? fails+ 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));++ // Next bunch of small polygon pointspoints = new ArrayList<GeoPoint>();points.add(new GeoPoint(PlanetModel.SPHERE, 0.0, -0.4));points.add(new GeoPoint(PlanetModel.SPHERE, 0.1, -0.5));