You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by kw...@apache.org on 2016/05/01 12:11:30 UTC
lucene-solr:branch_6x: LUCENE-7241: Add basic unit tests for
intersections and bounds.
Repository: lucene-solr
Updated Branches:
refs/heads/branch_6x 8e8f6c1fa -> 990b6241a
LUCENE-7241: Add basic unit tests for intersections and bounds.
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/990b6241
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/990b6241
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/990b6241
Branch: refs/heads/branch_6x
Commit: 990b6241aa2dfa9812ff46302292365bf4f4cd62
Parents: 8e8f6c1
Author: Karl Wright <Da...@gmail.com>
Authored: Sun May 1 06:09:36 2016 -0400
Committer: Karl Wright <Da...@gmail.com>
Committed: Sun May 1 06:11:24 2016 -0400
----------------------------------------------------------------------
.../spatial3d/geom/GeoComplexPolygon.java | 1 +
.../lucene/spatial3d/geom/GeoPolygonTest.java | 50 ++++++++++++++++++++
2 files changed, 51 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/990b6241/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoComplexPolygon.java
----------------------------------------------------------------------
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 c7197d8..ffd39e9 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) {
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/990b6241/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/GeoPolygonTest.java
----------------------------------------------------------------------
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 8063cb0..084bed1 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
@@ -143,6 +143,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;
GeoPoint gp;