LUCENE-8736: Fix Polygon.contains to approriately check longitude range, and pass correct line segment vertices in EdgeTree

This commit is contained in:
Nicholas Knize 2019-04-18 13:14:27 -05:00
parent bd8905150d
commit faa78ad72c
3 changed files with 8 additions and 2 deletions

View File

@ -140,6 +140,8 @@ public abstract class EdgeTree {
double maxLon = StrictMath.max(StrictMath.max(ax, bx), cx);
if (maxLon < this.minLon || minLon > this.maxLon || maxLat < this.minLat || minLat > this.maxLat) {
return Relation.CELL_OUTSIDE_QUERY;
} else if (bx == cx && by == cy) {
return componentRelateTriangle(bx, by, ax, ay, cx, cy);
}
return componentRelateTriangle(ax, ay, bx, by, cx, cy);
}

View File

@ -271,7 +271,9 @@ public final class Polygon2D extends EdgeTree {
if (isOnEdge.get() == false && lat <= edge.max) {
if (lat == edge.lat1 && lat == edge.lat2 ||
(lat <= edge.lat1 && lat >= edge.lat2) != (lat >= edge.lat1 && lat <= edge.lat2)) {
if (GeoUtils.orient(edge.lon1, edge.lat1, edge.lon2, edge.lat2, lon, lat) == 0) {
if ((lon == edge.lon1 && lon == edge.lon2) ||
((lon <= edge.lon1 && lon >= edge.lon2) != (lon >= edge.lon1 && lon <= edge.lon2) &&
GeoUtils.orient(edge.lon1, edge.lat1, edge.lon2, edge.lat2, lon, lat) == 0)) {
// if its on the boundary return true
isOnEdge.set(true);
return true;

View File

@ -698,7 +698,9 @@ public class GeoTestUtil {
for (i = 0, j = 1; j < nvert; ++i, ++j) {
if (testy == verty[j] && testy == verty[i] ||
((testy <= verty[j] && testy >= verty[i]) != (testy >= verty[j] && testy <= verty[i]))) {
if (GeoUtils.orient(vertx[i], verty[i], vertx[j], verty[j], testx, testy) == 0) {
if ((testx == vertx[j] && testx == vertx[i]) ||
((testx <= vertx[j] && testx >= vertx[i]) != (testx >= vertx[j] && testx <= vertx[i]) &&
GeoUtils.orient(vertx[i], verty[i], vertx[j], verty[j], testx, testy) == 0)) {
// return true if point is on boundary
return true;
} else if ( ((verty[i] > testy) != (verty[j] > testy)) &&