LUCENE-8736: Fix line detection bug in Polygon2D and Line2D componentRelateTriangle

This commit is contained in:
Nicholas Knize 2019-04-15 10:43:56 -05:00
parent e783207535
commit 8975ae5954
2 changed files with 3 additions and 7 deletions

View File

@ -124,13 +124,9 @@ public final class Polygon2D extends EdgeTree {
} }
} }
if (ax == bx && bx == cx && ay == by && by == cy) { if (ax == bx && bx == cx && ay == by && by == cy) {
// indexed "triangle" is a point: // indexed "triangle" is a point: shortcut by checking contains
if (Rectangle.containsPoint(ay, ax, minLat, maxLat, minLon, maxLon) == false) {
return Relation.CELL_OUTSIDE_QUERY;
}
// shortcut by checking contains
return contains(ay, ax) ? Relation.CELL_INSIDE_QUERY : Relation.CELL_OUTSIDE_QUERY; return contains(ay, ax) ? Relation.CELL_INSIDE_QUERY : Relation.CELL_OUTSIDE_QUERY;
} else if (ax == cx && ay == cy) { } else if ((ax == cx && ay == cy) || (bx == cx && by == cy)) {
// indexed "triangle" is a line segment: shortcut by calling appropriate method // indexed "triangle" is a line segment: shortcut by calling appropriate method
return relateIndexedLineSegment(ax, ay, bx, by); return relateIndexedLineSegment(ax, ay, bx, by);
} }

View File

@ -57,7 +57,7 @@ public final class Line2D extends EdgeTree {
if (isPointOnLine(tree, ax, ay)) { if (isPointOnLine(tree, ax, ay)) {
return Relation.CELL_INSIDE_QUERY; return Relation.CELL_INSIDE_QUERY;
} }
} else if (ax == cx && ay == cy) { } else if ((ax == cx && ay == cy) || (bx == cx && by == cy)) {
// indexed "triangle" is a line: // indexed "triangle" is a line:
if (tree.crossesLine(ax, ay, bx, by)) { if (tree.crossesLine(ax, ay, bx, by)) {
return Relation.CELL_CROSSES_QUERY; return Relation.CELL_CROSSES_QUERY;