mirror of https://github.com/apache/lucene.git
LUCENE-9637: Index disjoint multipolygons in TestLatLonMultiPolygonShapeQueries
This commit is contained in:
parent
809d15115b
commit
2eeec2f6be
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue