You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by iv...@apache.org on 2020/12/17 09:01:50 UTC

[lucene-solr] branch branch_8x updated: LUCENE-9637: Index disjoint multipolygons in TestLatLonMultiPolygonShapeQueries

This is an automated email from the ASF dual-hosted git repository.

ivera pushed a commit to branch branch_8x
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/branch_8x by this push:
     new bf9cf53  LUCENE-9637: Index disjoint multipolygons in TestLatLonMultiPolygonShapeQueries
bf9cf53 is described below

commit bf9cf535dc39e36b0dd19e4ac9e2c28aadfd38a2
Author: iverase <iv...@apache.org>
AuthorDate: Thu Dec 17 09:59:11 2020 +0100

    LUCENE-9637: Index disjoint multipolygons in TestLatLonMultiPolygonShapeQueries
---
 .../TestLatLonMultiPolygonShapeQueries.java        | 32 +++++++++++++++++++++-
 1 file changed, 31 insertions(+), 1 deletion(-)

diff --git a/lucene/core/src/test/org/apache/lucene/document/TestLatLonMultiPolygonShapeQueries.java b/lucene/core/src/test/org/apache/lucene/document/TestLatLonMultiPolygonShapeQueries.java
index 55dc57c..f640591 100644
--- a/lucene/core/src/test/org/apache/lucene/document/TestLatLonMultiPolygonShapeQueries.java
+++ b/lucene/core/src/test/org/apache/lucene/document/TestLatLonMultiPolygonShapeQueries.java
@@ -36,10 +36,40 @@ public class TestLatLonMultiPolygonShapeQueries extends BaseLatLonShapeTestCase
     int n = random().nextInt(4) + 1;
     Polygon[] polygons = new Polygon[n];
     for (int i =0; i < n; i++) {
-      polygons[i] = (Polygon) getShapeType().nextShape();
+      int repetitions = 0;
+      while (true) {
+        Polygon p = (Polygon) getShapeType().nextShape();
+        // polygons are disjoint so CONTAINS works. Note that if we intersect
+        // any shape then contains return false.
+        if (isDisjoint(polygons, p)) {
+          polygons[i] = p;
+          break;
+        }
+        repetitions++;
+        if (repetitions > 50) {
+          // try again
+          return nextShape();
+        }
+      }
     }
     return polygons;
   }
+
+  private boolean isDisjoint(Polygon[] polygons, Polygon check) {
+    // we use bounding boxes so we do not get intersecting polygons.
+    for (Polygon polygon : polygons) {
+      if (polygon != null) {
+        if (getEncoder().quantizeY(polygon.minLat) > getEncoder().quantizeY(check.maxLat)
+                || getEncoder().quantizeY(polygon.maxLat) < getEncoder().quantizeY(check.minLat)
+                || getEncoder().quantizeX(polygon.minLon) > getEncoder().quantizeX(check.maxLon)
+                || getEncoder().quantizeX(polygon.maxLon) < getEncoder().quantizeX(check.minLon)) {
+          continue;
+        }
+        return false;
+      }
+    }
+    return true;
+  }
   
   @Override
   protected Field[] createIndexableFields(String name, Object o) {