From 2eeec2f6be2e72076f7161d66582ddcc65638301 Mon Sep 17 00:00:00 2001 From: iverase Date: Thu, 17 Dec 2020 09:59:11 +0100 Subject: [PATCH] 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 55dc57c5f1f..f640591cf3e 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) {