From ecb0ba542bfec1bd18174933ddfe3c24eb22d203 Mon Sep 17 00:00:00 2001 From: Ignacio Vera Date: Tue, 20 Sep 2022 07:15:38 +0200 Subject: [PATCH] Improve tessellator performance by delaying calls to the method #isIntersectingPolygon (#11786) --- lucene/CHANGES.txt | 3 +++ .../src/java/org/apache/lucene/geo/Tessellator.java | 10 ++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index 4d0bf33ecb6..242bac523d7 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -98,6 +98,9 @@ Improvements * GITHUB#11778: Detailed part-of-speech information for particle(조사) and ending(어미) on Nori is now tagged. (Namgyu Kim) +* GITHUB#11785: Improve Tessellator performance by delaying calls to the method + #isIntersectingPolygon (Ignacio Vera) + Bug Fixes --------------------- * GITHUB#11726: Indexing term vectors on large documents could fail due to diff --git a/lucene/core/src/java/org/apache/lucene/geo/Tessellator.java b/lucene/core/src/java/org/apache/lucene/geo/Tessellator.java index e93958a96d3..8a3fcc16173 100644 --- a/lucene/core/src/java/org/apache/lucene/geo/Tessellator.java +++ b/lucene/core/src/java/org/apache/lucene/geo/Tessellator.java @@ -772,7 +772,6 @@ public final class Tessellator { // a self-intersection where edge (v[i-1],v[i]) intersects (v[i+1],v[i+2]) if (isVertexEquals(a, b) == false - && isIntersectingPolygon(a, a.getX(), a.getY(), b.getX(), b.getY()) == false && linesIntersect( a.getX(), a.getY(), @@ -783,7 +782,9 @@ public final class Tessellator { b.getX(), b.getY()) && isLocallyInside(a, b) - && isLocallyInside(b, a)) { + && isLocallyInside(b, a) + // this call is expensive so do it last + && isIntersectingPolygon(a, a.getX(), a.getY(), b.getX(), b.getY()) == false) { // compute edges from polygon boolean abFromPolygon = (a.next == node) @@ -1117,7 +1118,6 @@ public final class Tessellator { } return a.next.idx != b.idx && a.previous.idx != b.idx - && isIntersectingPolygon(a, a.getX(), a.getY(), b.getX(), b.getY()) == false && isLocallyInside(a, b) && isLocallyInside(b, a) && isLocallyInside(a.previous, b) @@ -1127,7 +1127,9 @@ public final class Tessellator { && area(a.previous.getX(), a.previous.getY(), a.getX(), a.getY(), b.getX(), b.getY()) != 0 && area(a.getX(), a.getY(), b.getX(), b.getY(), b.next.getX(), b.next.getY()) != 0 && area(a.next.getX(), a.next.getY(), a.getX(), a.getY(), b.getX(), b.getY()) != 0 - && area(a.getX(), a.getY(), b.getX(), b.getY(), b.previous.getX(), b.previous.getY()) != 0; + && area(a.getX(), a.getY(), b.getX(), b.getY(), b.previous.getX(), b.previous.getY()) != 0 + // this call is expensive so do it last + && isIntersectingPolygon(a, a.getX(), a.getY(), b.getX(), b.getY()) == false; } /** Determine whether the polygon defined between node start and node end is CW */