You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ds...@apache.org on 2016/04/27 20:22:04 UTC
[20/50] [abbrv] lucene-solr:solr-5750: LUCENE-7250: Handle holes
properly for distance and relationship calculation.
LUCENE-7250: Handle holes properly for distance and relationship calculation.
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/97e8f1ae
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/97e8f1ae
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/97e8f1ae
Branch: refs/heads/solr-5750
Commit: 97e8f1aeadd29207b8fdc6284ec7b6e4c60cce11
Parents: 38ebd90
Author: Karl Wright <Da...@gmail.com>
Authored: Sat Apr 23 06:44:42 2016 -0400
Committer: Karl Wright <Da...@gmail.com>
Committed: Sat Apr 23 06:44:42 2016 -0400
----------------------------------------------------------------------
.../org/apache/lucene/spatial3d/Geo3DPoint.java | 17 ++++------
.../spatial3d/geom/GeoConcavePolygon.java | 33 +++++++++++++++++---
.../lucene/spatial3d/geom/GeoConvexPolygon.java | 33 +++++++++++++++++---
.../spatial3d/geom/GeoPolygonFactory.java | 6 ++--
4 files changed, 68 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/97e8f1ae/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/Geo3DPoint.java
----------------------------------------------------------------------
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/Geo3DPoint.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/Geo3DPoint.java
index 4b5ab92..0f2395c 100644
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/Geo3DPoint.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/Geo3DPoint.java
@@ -142,7 +142,7 @@ public final class Geo3DPoint extends Field {
}
final GeoShape shape;
if (polygons.length == 1) {
- final GeoShape component = fromPolygon(polygons[0], false);
+ final GeoShape component = fromPolygon(polygons[0]);
if (component == null) {
// Polygon is degenerate
shape = new GeoCompositePolygon();
@@ -152,7 +152,7 @@ public final class Geo3DPoint extends Field {
} else {
final GeoCompositePolygon poly = new GeoCompositePolygon();
for (final Polygon p : polygons) {
- final GeoPolygon component = fromPolygon(p, false);
+ final GeoPolygon component = fromPolygon(p);
if (component != null) {
poly.addShape(component);
}
@@ -192,17 +192,16 @@ public final class Geo3DPoint extends Field {
* Convert a Polygon object into a GeoPolygon.
* This method uses
* @param polygon is the Polygon object.
- * @param reverseMe is true if the order of the points should be reversed.
* @return the GeoPolygon.
*/
- private static GeoPolygon fromPolygon(final Polygon polygon, final boolean reverseMe) {
+ private static GeoPolygon fromPolygon(final Polygon polygon) {
// First, assemble the "holes". The geo3d convention is to use the same polygon sense on the inner ring as the
// outer ring, so we process these recursively with reverseMe flipped.
final Polygon[] theHoles = polygon.getHoles();
final List<GeoPolygon> holeList = new ArrayList<>(theHoles.length);
for (final Polygon hole : theHoles) {
//System.out.println("Hole: "+hole);
- final GeoPolygon component = fromPolygon(hole, !reverseMe);
+ final GeoPolygon component = fromPolygon(hole);
if (component != null) {
holeList.add(component);
}
@@ -216,12 +215,8 @@ public final class Geo3DPoint extends Field {
final List<GeoPoint> points = new ArrayList<>(polyLats.length-1);
// We skip the last point anyway because the API requires it to be repeated, and geo3d doesn't repeat it.
for (int i = 0; i < polyLats.length - 1; i++) {
- if (reverseMe) {
- points.add(new GeoPoint(PlanetModel.WGS84, fromDegrees(polyLats[i]), fromDegrees(polyLons[i])));
- } else {
- final int index = polyLats.length - 2 - i;
- points.add(new GeoPoint(PlanetModel.WGS84, fromDegrees(polyLats[index]), fromDegrees(polyLons[index])));
- }
+ final int index = polyLats.length - 2 - i;
+ points.add(new GeoPoint(PlanetModel.WGS84, fromDegrees(polyLats[index]), fromDegrees(polyLons[index])));
}
//System.err.println(" building polygon with "+points.size()+" points...");
final GeoPolygon rval = GeoPolygonFactory.makeGeoPolygon(PlanetModel.WGS84, points, holeList);
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/97e8f1ae/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoConcavePolygon.java
----------------------------------------------------------------------
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.java
index 8eaea1a..c18d40f 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
@@ -224,8 +224,25 @@ class GeoConcavePolygon extends GeoBasePolygon {
eitherBounds.put(edge, new EitherBound(invertedEdges[legalIndex(bound1Index)], invertedEdges[legalIndex(bound2Index)]));
}
- // Pick an edge point arbitrarily
- edgePoints = new GeoPoint[]{points.get(0)};
+ // Pick an edge point arbitrarily from the outer polygon. Glom this together with all edge points from
+ // inner polygons.
+ int edgePointCount = 1;
+ if (holes != null) {
+ for (final GeoPolygon hole : holes) {
+ edgePointCount += hole.getEdgePoints().length;
+ }
+ }
+ edgePoints = new GeoPoint[edgePointCount];
+ edgePointCount = 0;
+ edgePoints[edgePointCount++] = points.get(0);
+ if (holes != null) {
+ for (final GeoPolygon hole : holes) {
+ final GeoPoint[] holeEdgePoints = hole.getEdgePoints();
+ for (final GeoPoint p : holeEdgePoints) {
+ edgePoints[edgePointCount++] = p;
+ }
+ }
+ }
if (isWithinHoles(points.get(0))) {
throw new IllegalArgumentException("Polygon edge intersects a polygon hole; not allowed");
@@ -240,7 +257,7 @@ class GeoConcavePolygon extends GeoBasePolygon {
protected boolean isWithinHoles(final GeoPoint point) {
if (holes != null) {
for (final GeoPolygon hole : holes) {
- if (hole.isWithin(point)) {
+ if (!hole.isWithin(point)) {
return true;
}
}
@@ -268,7 +285,7 @@ class GeoConcavePolygon extends GeoBasePolygon {
}
if (holes != null) {
for (final GeoPolygon polygon : holes) {
- if (polygon.isWithin(x, y, z)) {
+ if (!polygon.isWithin(x, y, z)) {
return false;
}
}
@@ -405,6 +422,14 @@ class GeoConcavePolygon extends GeoBasePolygon {
minimumDistance = newDist;
}
}
+ if (holes != null) {
+ for (final GeoPolygon hole : holes) {
+ double holeDistance = hole.computeOutsideDistance(distanceStyle, x, y, z);
+ if (holeDistance != 0.0 && holeDistance < minimumDistance) {
+ minimumDistance = holeDistance;
+ }
+ }
+ }
return minimumDistance;
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/97e8f1ae/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoConvexPolygon.java
----------------------------------------------------------------------
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoConvexPolygon.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoConvexPolygon.java
index 17a2120..6f71d18 100755
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoConvexPolygon.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoConvexPolygon.java
@@ -219,8 +219,25 @@ class GeoConvexPolygon extends GeoBasePolygon {
eitherBounds.put(edge, new EitherBound(edges[legalIndex(bound1Index)], edges[legalIndex(bound2Index)]));
}
- // Pick an edge point arbitrarily
- edgePoints = new GeoPoint[]{points.get(0)};
+ // Pick an edge point arbitrarily from the outer polygon. Glom this together with all edge points from
+ // inner polygons.
+ int edgePointCount = 1;
+ if (holes != null) {
+ for (final GeoPolygon hole : holes) {
+ edgePointCount += hole.getEdgePoints().length;
+ }
+ }
+ edgePoints = new GeoPoint[edgePointCount];
+ edgePointCount = 0;
+ edgePoints[edgePointCount++] = points.get(0);
+ if (holes != null) {
+ for (final GeoPolygon hole : holes) {
+ final GeoPoint[] holeEdgePoints = hole.getEdgePoints();
+ for (final GeoPoint p : holeEdgePoints) {
+ edgePoints[edgePointCount++] = p;
+ }
+ }
+ }
if (isWithinHoles(points.get(0))) {
throw new IllegalArgumentException("Polygon edge intersects a polygon hole; not allowed");
@@ -235,7 +252,7 @@ class GeoConvexPolygon extends GeoBasePolygon {
protected boolean isWithinHoles(final GeoPoint point) {
if (holes != null) {
for (final GeoPolygon hole : holes) {
- if (hole.isWithin(point)) {
+ if (!hole.isWithin(point)) {
return true;
}
}
@@ -263,7 +280,7 @@ class GeoConvexPolygon extends GeoBasePolygon {
}
if (holes != null) {
for (final GeoPolygon polygon : holes) {
- if (polygon.isWithin(x, y, z)) {
+ if (!polygon.isWithin(x, y, z)) {
return false;
}
}
@@ -393,6 +410,14 @@ class GeoConvexPolygon extends GeoBasePolygon {
minimumDistance = newDist;
}
}
+ if (holes != null) {
+ for (final GeoPolygon hole : holes) {
+ double holeDistance = hole.computeOutsideDistance(distanceStyle, x, y, z);
+ if (holeDistance != 0.0 && holeDistance < minimumDistance) {
+ minimumDistance = holeDistance;
+ }
+ }
+ }
return minimumDistance;
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/97e8f1ae/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoPolygonFactory.java
----------------------------------------------------------------------
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoPolygonFactory.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoPolygonFactory.java
index 99fc7c9..609c864 100755
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoPolygonFactory.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoPolygonFactory.java
@@ -56,7 +56,8 @@ public class GeoPolygonFactory {
* @param pointList is a list of the GeoPoints to build an arbitrary polygon out of. If points go
* clockwise from a given pole, then that pole should be within the polygon. If points go
* counter-clockwise, then that pole should be outside the polygon.
- * @param holes is a list of polygons representing "holes" in the outside polygon. Null == none.
+ * @param holes is a list of polygons representing "holes" in the outside polygon. Holes describe the area outside
+ * each hole as being "in set". Null == none.
* @return a GeoPolygon corresponding to what was specified, or null if a valid polygon cannot be generated
* from this input.
*/
@@ -73,7 +74,8 @@ public class GeoPolygonFactory {
* @param pointList is a list of the GeoPoints to build an arbitrary polygon out of. If points go
* clockwise from a given pole, then that pole should be within the polygon. If points go
* counter-clockwise, then that pole should be outside the polygon.
- * @param holes is a list of polygons representing "holes" in the outside polygon. Null == none.
+ * @param holes is a list of polygons representing "holes" in the outside polygon. Holes describe the area outside
+ * each hole as being "in set". Null == none.
* @param leniencyValue is the maximum distance (in units) that a point can be from the plane and still be considered as
* belonging to the plane. Any value greater than zero may cause some of the provided points that are in fact outside
* the strict definition of co-planarity, but are within this distance, to be discarded for the purposes of creating a