LUCENE-9275: make TestLatLonMultiPolygonShapeQueries more resilient for CONTAINS queries (#1345)

This commit is contained in:
Ignacio Vera 2020-03-23 07:26:48 +01:00 committed by GitHub
parent 62967039dc
commit aaf08c9c4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 6 deletions

View File

@ -153,6 +153,8 @@ Other
* LUCENE-9270: Update Javadoc about normalizeEntry in the Kuromoji DictionaryBuilder. (Namgyu Kim)
* LUCENE-9275: Make TestLatLonMultiPolygonShapeQueries more resilient for CONTAINS queries. (Ignacio Vera)
======================= Lucene 8.5.0 =======================
API Changes

View File

@ -98,6 +98,7 @@ public class TestLatLonMultiPolygonShapeQueries extends BaseLatLonShapeTestCase
protected class MultiPolygonValidator extends Validator {
TestLatLonPolygonShapeQueries.PolygonValidator POLYGONVALIDATOR;
MultiPolygonValidator(Encoder encoder) {
super(encoder);
POLYGONVALIDATOR = new TestLatLonPolygonShapeQueries.PolygonValidator(encoder);
@ -112,7 +113,7 @@ public class TestLatLonMultiPolygonShapeQueries extends BaseLatLonShapeTestCase
@Override
public boolean testBBoxQuery(double minLat, double maxLat, double minLon, double maxLon, Object shape) {
Polygon[] polygons = (Polygon[])shape;
Polygon[] polygons = (Polygon[]) shape;
for (Polygon p : polygons) {
boolean b = POLYGONVALIDATOR.testBBoxQuery(minLat, maxLat, minLon, maxLon, p);
if (b == true && queryRelation == QueryRelation.INTERSECTS) {
@ -130,7 +131,10 @@ public class TestLatLonMultiPolygonShapeQueries extends BaseLatLonShapeTestCase
@Override
public boolean testComponentQuery(Component2D query, Object shape) {
Polygon[] polygons = (Polygon[])shape;
Polygon[] polygons = (Polygon[]) shape;
if (queryRelation == QueryRelation.CONTAINS) {
return testWithinPolygon(query, polygons);
}
for (Polygon p : polygons) {
boolean b = POLYGONVALIDATOR.testComponentQuery(query, p);
if (b == true && queryRelation == QueryRelation.INTERSECTS) {
@ -145,6 +149,19 @@ public class TestLatLonMultiPolygonShapeQueries extends BaseLatLonShapeTestCase
}
return queryRelation != QueryRelation.INTERSECTS && queryRelation != QueryRelation.CONTAINS;
}
private boolean testWithinPolygon(Component2D query, Polygon[] polygons) {
Component2D.WithinRelation answer = Component2D.WithinRelation.DISJOINT;
for (Polygon p : polygons) {
Component2D.WithinRelation relation = POLYGONVALIDATOR.testWithinPolygon(query, p);
if (relation == Component2D.WithinRelation.NOTWITHIN) {
return false;
} else if (relation == Component2D.WithinRelation.CANDIDATE) {
answer = relation;
}
}
return answer == Component2D.WithinRelation.CANDIDATE;
}
}
@Slow

View File

@ -74,7 +74,7 @@ public class TestLatLonPolygonShapeQueries extends BaseLatLonShapeTestCase {
public boolean testComponentQuery(Component2D query, Object o) {
Polygon shape = (Polygon) o;
if (queryRelation == QueryRelation.CONTAINS) {
return testWithinPolygon(query, shape);
return testWithinPolygon(query, shape) == Component2D.WithinRelation.CANDIDATE;
}
List<Tessellator.Triangle> tessellation = Tessellator.tessellate(shape);
for (Tessellator.Triangle t : tessellation) {
@ -93,7 +93,8 @@ public class TestLatLonPolygonShapeQueries extends BaseLatLonShapeTestCase {
return queryRelation == QueryRelation.INTERSECTS ? false : true;
}
private boolean testWithinPolygon(Component2D component2D, Polygon shape) {
protected Component2D.WithinRelation testWithinPolygon(Component2D component2D, Polygon shape) {
List<Tessellator.Triangle> tessellation = Tessellator.tessellate(shape);
Component2D.WithinRelation answer = Component2D.WithinRelation.DISJOINT;
for (Tessellator.Triangle t : tessellation) {
@ -104,12 +105,12 @@ public class TestLatLonPolygonShapeQueries extends BaseLatLonShapeTestCase {
encoder.decodeX(qTriangle.bX), encoder.decodeY(qTriangle.bY), qTriangle.bc,
encoder.decodeX(qTriangle.cX), encoder.decodeY(qTriangle.cY), qTriangle.ca);
if (relation == Component2D.WithinRelation.NOTWITHIN) {
return false;
return relation;
} else if (relation == Component2D.WithinRelation.CANDIDATE) {
answer = Component2D.WithinRelation.CANDIDATE;
}
}
return answer == Component2D.WithinRelation.CANDIDATE;
return answer;
}
}