LUCENE-10437: Improve error message in the Tessellator for polygon with all points collinear (#703)

Polygon tessellator throws a more informative error message when the provided polygon does not contain enough no-collinear points.
This commit is contained in:
Ignacio Vera 2022-02-23 13:51:44 +01:00 committed by GitHub
parent f8040d565f
commit ab47db4fee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 0 deletions

View File

@ -301,6 +301,9 @@ Other
* LUCENE-10413: Make Ukrainian default stop words list available as a public getter. (Alan Woodward)
* LUCENE-10437: Polygon tessellator throws a more informative error message when the provided polygon
does not contain enough no-collinear points. (Ignacio Vera)
======================= Lucene 9.0.0 =======================
New Features

View File

@ -102,6 +102,9 @@ public final class Tessellator {
if (outerNode == null) {
throw new IllegalArgumentException("Malformed shape detected in Tessellator!");
}
if (outerNode == outerNode.next || outerNode == outerNode.next.next) {
throw new IllegalArgumentException("at least three non-collinear points required");
}
// Determine if the specified list of points contains holes
if (polygon.numHoles() > 0) {
@ -154,6 +157,9 @@ public final class Tessellator {
if (outerNode == null) {
throw new IllegalArgumentException("Malformed shape detected in Tessellator!");
}
if (outerNode == outerNode.next || outerNode == outerNode.next.next) {
throw new IllegalArgumentException("at least three non-collinear points required");
}
// Determine if the specified list of points contains holes
if (polygon.numHoles() > 0) {

View File

@ -169,6 +169,15 @@ public class TestTessellator extends LuceneTestCase {
checkPolygon(wkt);
}
public void testInvalidPolygonCollinear() throws Exception {
String wkt =
"POLYGON ((18.9401790919516 -33.9681188869036, 18.9401790919516 -33.9681188869036, 18.9401790919517 -33.9681188869036, 18.9401790919517 -33.9681188869036, 18.9401790919516 -33.9681188869036))";
Polygon polygon = (Polygon) SimpleWKTShapeParser.parse(wkt);
IllegalArgumentException ex =
expectThrows(IllegalArgumentException.class, () -> Tessellator.tessellate(polygon, true));
assertEquals("at least three non-collinear points required", ex.getMessage());
}
public void testComplexPolygon01() throws Exception {
String wkt =
"POLYGON((58.8792517 54.9160937, 58.8762477 54.9154524, 58.8735011 54.9140217, 58.8726428 54.9127389, 58.8731146 54.9122507, 58.8741877 54.9120482, 58.8771918 54.9117028, 58.88011 54.913331, 58.8801175 54.9137036, 58.8805885 54.9143186, 58.8807109 54.9148604, 58.88011 54.915551, 58.8792517 54.9160937), "