Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

LUCENE-7241: Add basic unit tests for intersections and bounds.

Karl Wright516fb5d19315
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.java
index c7197d82ebb..ffd39e9f3b2 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
@@ -331,6 +331,7 @@ class GeoComplexPolygon extends GeoBasePolygon {
for (final Edge startEdge : shapeStartEdges) {
Edge currentEdge = startEdge;
while (true) {
+ bounds.addPoint(currentEdge.startPoint);
bounds.addPlane(this.planetModel, currentEdge.plane, currentEdge.startPlane, currentEdge.endPlane);
currentEdge = currentEdge.next;
if (currentEdge == startEdge) {
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 8063cb01d2d..084bed182c5 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
@@ -142,6 +142,56 @@ public class GeoPolygonTest {
}
+ @Test
+ public void testPolygonIntersects() {
+ GeoPolygon c;
+ List<GeoPoint> points;
+ List<GeoPolygonFactory.PolygonDescription> shapes;
+ XYZBounds xyzBounds;
+ XYZSolid xyzSolid;
+
+ points = new ArrayList<GeoPoint>();
+ points.add(new GeoPoint(PlanetModel.SPHERE, 0.0, -0.4));
+ points.add(new GeoPoint(PlanetModel.SPHERE, 0.1, -0.5));
+ points.add(new GeoPoint(PlanetModel.SPHERE, 0.0, -0.6));
+ points.add(new GeoPoint(PlanetModel.SPHERE, -0.1, -0.5));
+
+ c = GeoPolygonFactory.makeGeoPolygon(PlanetModel.SPHERE, points);
+
+ xyzBounds = new XYZBounds();
+ c.getBounds(xyzBounds);
+ xyzSolid = XYZSolidFactory.makeXYZSolid(PlanetModel.SPHERE, xyzBounds.getMinimumX(), xyzBounds.getMaximumX(), xyzBounds.getMinimumY(), xyzBounds.getMaximumY(), xyzBounds.getMinimumZ(), xyzBounds.getMaximumZ());
+ assertEquals(GeoArea.WITHIN, xyzSolid.getRelationship(c));
+ xyzSolid = XYZSolidFactory.makeXYZSolid(PlanetModel.SPHERE, xyzBounds.getMinimumX()-0.01, xyzBounds.getMaximumX()-0.01, xyzBounds.getMinimumY()-0.01, xyzBounds.getMaximumY()-0.01, xyzBounds.getMinimumZ()-0.01, xyzBounds.getMaximumZ()-0.01);
+ assertEquals(GeoArea.OVERLAPS, xyzSolid.getRelationship(c));
+ xyzSolid = XYZSolidFactory.makeXYZSolid(PlanetModel.SPHERE, xyzBounds.getMinimumY(), xyzBounds.getMaximumY(), xyzBounds.getMinimumZ(), xyzBounds.getMaximumZ(), xyzBounds.getMinimumX(), xyzBounds.getMaximumX());
+ assertEquals(GeoArea.DISJOINT, xyzSolid.getRelationship(c));
+
+ shapes = new ArrayList<>();
+ shapes.add(new GeoPolygonFactory.PolygonDescription(points));
+
+ c = GeoPolygonFactory.makeLargeGeoPolygon(PlanetModel.SPHERE, shapes);
+
+ // Same bounds should work
+ xyzSolid = XYZSolidFactory.makeXYZSolid(PlanetModel.SPHERE, xyzBounds.getMinimumX(), xyzBounds.getMaximumX(), xyzBounds.getMinimumY(), xyzBounds.getMaximumY(), xyzBounds.getMinimumZ(), xyzBounds.getMaximumZ());
+ assertEquals(GeoArea.WITHIN, xyzSolid.getRelationship(c));
+ xyzSolid = XYZSolidFactory.makeXYZSolid(PlanetModel.SPHERE, xyzBounds.getMinimumX()-0.01, xyzBounds.getMaximumX()-0.01, xyzBounds.getMinimumY()-0.01, xyzBounds.getMaximumY()-0.01, xyzBounds.getMinimumZ()-0.01, xyzBounds.getMaximumZ()-0.01);
+ assertEquals(GeoArea.OVERLAPS, xyzSolid.getRelationship(c));
+ xyzSolid = XYZSolidFactory.makeXYZSolid(PlanetModel.SPHERE, xyzBounds.getMinimumY(), xyzBounds.getMaximumY(), xyzBounds.getMinimumZ(), xyzBounds.getMaximumZ(), xyzBounds.getMinimumX(), xyzBounds.getMaximumX());
+ assertEquals(GeoArea.DISJOINT, xyzSolid.getRelationship(c));
+
+ // Bounds we obtain from the large polygon also should work.
+ xyzBounds = new XYZBounds();
+ c.getBounds(xyzBounds);
+ xyzSolid = XYZSolidFactory.makeXYZSolid(PlanetModel.SPHERE, xyzBounds.getMinimumX(), xyzBounds.getMaximumX(), xyzBounds.getMinimumY(), xyzBounds.getMaximumY(), xyzBounds.getMinimumZ(), xyzBounds.getMaximumZ());
+ assertEquals(GeoArea.WITHIN, xyzSolid.getRelationship(c));
+ xyzSolid = XYZSolidFactory.makeXYZSolid(PlanetModel.SPHERE, xyzBounds.getMinimumX()-0.01, xyzBounds.getMaximumX()-0.01, xyzBounds.getMinimumY()-0.01, xyzBounds.getMaximumY()-0.01, xyzBounds.getMinimumZ()-0.01, xyzBounds.getMaximumZ()-0.01);
+ assertEquals(GeoArea.OVERLAPS, xyzSolid.getRelationship(c));
+ xyzSolid = XYZSolidFactory.makeXYZSolid(PlanetModel.SPHERE, xyzBounds.getMinimumY(), xyzBounds.getMaximumY(), xyzBounds.getMinimumZ(), xyzBounds.getMaximumZ(), xyzBounds.getMinimumX(), xyzBounds.getMaximumX());
+ assertEquals(GeoArea.DISJOINT, xyzSolid.getRelationship(c));
+
+ }
+
@Test
public void testPolygonPointWithin() {
GeoPolygon c;