From b7309899e1b94e71c7fc867f79b77dcaed587ca6 Mon Sep 17 00:00:00 2001 From: iverase Date: Wed, 16 Oct 2019 07:20:45 +0200 Subject: [PATCH] LUCENE-8746: Call relate line with points in the same order as they come from the original tessellation. --- .../src/java/org/apache/lucene/geo/Polygon2D.java | 9 ++++++--- .../src/java/org/apache/lucene/geo/Line2D.java | 12 +++++++++--- .../lucene/document/BaseShapeEncodingTestCase.java | 1 - 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lucene/core/src/java/org/apache/lucene/geo/Polygon2D.java b/lucene/core/src/java/org/apache/lucene/geo/Polygon2D.java index 3b06d219e1b..cf06ebd9269 100644 --- a/lucene/core/src/java/org/apache/lucene/geo/Polygon2D.java +++ b/lucene/core/src/java/org/apache/lucene/geo/Polygon2D.java @@ -156,12 +156,15 @@ public class Polygon2D implements Component2D { if (ax == bx && bx == cx && ay == by && by == cy) { // indexed "triangle" is a point: shortcut by checking contains return internalContains(ax, ay) ? Relation.CELL_INSIDE_QUERY : Relation.CELL_OUTSIDE_QUERY; - } else if ((ax == cx && ay == cy) || (bx == cx && by == cy)) { + } else if (ax == cx && ay == cy) { // indexed "triangle" is a line segment: shortcut by calling appropriate method return relateIndexedLineSegment(minX, maxX, minY, maxY, ax, ay, bx, by); - } else if ((ax == bx && ay == by)) { + } else if (ax == bx && ay == by) { // indexed "triangle" is a line segment: shortcut by calling appropriate method - return relateIndexedLineSegment(minX, maxX, minY, maxY, ax, ay, cx, cy); + return relateIndexedLineSegment(minX, maxX, minY, maxY, bx, by, cx, cy); + } else if (bx == cx && by == cy) { + // indexed "triangle" is a line segment: shortcut by calling appropriate method + return relateIndexedLineSegment(minX, maxX, minY, maxY, cx, cy, ax, ay); } // indexed "triangle" is a triangle: return relateIndexedTriangle(minX, maxX, minY, maxY, ax, ay, bx, by, cx, cy); diff --git a/lucene/sandbox/src/java/org/apache/lucene/geo/Line2D.java b/lucene/sandbox/src/java/org/apache/lucene/geo/Line2D.java index 15c923ee791..02d1422d9f4 100644 --- a/lucene/sandbox/src/java/org/apache/lucene/geo/Line2D.java +++ b/lucene/sandbox/src/java/org/apache/lucene/geo/Line2D.java @@ -107,15 +107,21 @@ public final class Line2D implements Component2D { if (tree.isPointOnLine(ax, ay)) { return Relation.CELL_INSIDE_QUERY; } - } else if ((ax == cx && ay == cy) || (bx == cx && by == cy)) { + } else if (ax == cx && ay == cy) { // indexed "triangle" is a line: if (tree.crossesLine(minX, maxX, minY, maxY, ax, ay, bx, by)) { return Relation.CELL_CROSSES_QUERY; } return Relation.CELL_OUTSIDE_QUERY; - } else if ((ax == bx && ay == by)) { + } else if (ax == bx && ay == by) { // indexed "triangle" is a line: - if (tree.crossesLine(minX, maxX, minY, maxY, ax, ay, cx, cy)) { + if (tree.crossesLine(minX, maxX, minY, maxY, bx, by, cx, cy)) { + return Relation.CELL_CROSSES_QUERY; + } + return Relation.CELL_OUTSIDE_QUERY; + } else if (bx == cx && by == cy) { + // indexed "triangle" is a line: + if (tree.crossesLine(minX, maxX, minY, maxY, cx, cy, ax, ay)) { return Relation.CELL_CROSSES_QUERY; } return Relation.CELL_OUTSIDE_QUERY; diff --git a/lucene/sandbox/src/test/org/apache/lucene/document/BaseShapeEncodingTestCase.java b/lucene/sandbox/src/test/org/apache/lucene/document/BaseShapeEncodingTestCase.java index e7642a975d8..ee71047f048 100644 --- a/lucene/sandbox/src/test/org/apache/lucene/document/BaseShapeEncodingTestCase.java +++ b/lucene/sandbox/src/test/org/apache/lucene/document/BaseShapeEncodingTestCase.java @@ -472,7 +472,6 @@ public abstract class BaseShapeEncodingTestCase extends LuceneTestCase { verifyEncoding(ay, ax, ay, ax, ay, ax); } - @AwaitsFix(bugUrl="https://issues.apache.org/jira/browse/LUCENE-8746") public void testRandomLineEncoding() { double ay = nextY(); double ax = nextX();