Apache Solr open-source search software
LUCENE-8736: Fix line detection bug in Polygon2D and Line2D componentRelateTriangle
Nicholas Knize8975ae5954ba
diff --git a/lucene/core/src/java/org/apache/lucene/geo/Polygon2D.java b/lucene/core/src/java/org/apache/lucene/geo/Polygon2D.javaindex c0931b03df3..7db8287f61b 100644--- a/lucene/core/src/java/org/apache/lucene/geo/Polygon2D.java+++ b/lucene/core/src/java/org/apache/lucene/geo/Polygon2D.java@@ -124,13 +124,9 @@ public final class Polygon2D extends EdgeTree {}}if (ax == bx && bx == cx && ay == by && by == cy) {- // indexed "triangle" is a point:- if (Rectangle.containsPoint(ay, ax, minLat, maxLat, minLon, maxLon) == false) {- return Relation.CELL_OUTSIDE_QUERY;- }- // shortcut by checking contains+ // indexed "triangle" is a point: shortcut by checking containsreturn 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 methodreturn relateIndexedLineSegment(ax, ay, bx, by);}diff --git a/lucene/sandbox/src/java/org/apache/lucene/geo/Line2D.java b/lucene/sandbox/src/java/org/apache/lucene/geo/Line2D.javaindex 797892e40c5..9f413195b8f 100644--- a/lucene/sandbox/src/java/org/apache/lucene/geo/Line2D.java+++ b/lucene/sandbox/src/java/org/apache/lucene/geo/Line2D.java@@ -57,7 +57,7 @@ public final class Line2D extends EdgeTree {if (isPointOnLine(tree, ax, ay)) {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:if (tree.crossesLine(ax, ay, bx, by)) {return Relation.CELL_CROSSES_QUERY;