Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port lucene fix github-11986 to Elasticsearch 7.17 #92320

Merged
merged 3 commits into from Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/92320.yaml
@@ -0,0 +1,5 @@
pr: 92320
summary: Port lucene fix github-11986 to Elasticsearch 7.17
area: Geo
type: bug
issues: []
44 changes: 12 additions & 32 deletions server/src/main/java/org/apache/lucene/geo/XTessellator.java
Expand Up @@ -358,40 +358,20 @@ private static Node fetchHoleBridge(final Node holeNode, final Node outerNode) {
final double my = connection.getY();
double tanMin = Double.POSITIVE_INFINITY;
double tan;
p = connection.next;
{
while (p != stop) {
if (hx >= p.getX()
&& p.getX() >= mx
&& hx != p.getX()
&& pointInEar(p.getX(), p.getY(), hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy)) {
tan = Math.abs(hy - p.getY()) / (hx - p.getX()); // tangential
if (isVertexEquals(p, connection) && isLocallyInside(p, holeNode)) {
// make sure we are not crossing the polygon. This might happen when several holes have a bridge to the same polygon
// vertex
// and this vertex has different vertex.
boolean crosses = GeoUtils.lineCrossesLine(
p.getX(),
p.getY(),
holeNode.getX(),
holeNode.getY(),
connection.next.getX(),
connection.next.getY(),
connection.previous.getX(),
connection.previous.getY()
);
if (crosses == false) {
connection = p;
tanMin = tan;
}
} else if ((tan < tanMin || (tan == tanMin && p.getX() > connection.getX())) && isLocallyInside(p, holeNode)) {
connection = p;
tanMin = tan;
}
p = connection;
do {
if (hx >= p.getX()
&& p.getX() >= mx
&& hx != p.getX()
&& pointInEar(p.getX(), p.getY(), hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy)) {
tan = Math.abs(hy - p.getY()) / (hx - p.getX()); // tangential
if ((tan < tanMin || (tan == tanMin && p.getX() > connection.getX())) && isLocallyInside(p, holeNode)) {
connection = p;
tanMin = tan;
}
p = p.next;
}
}
p = p.next;
} while (p != stop);
return connection;
}

Expand Down
24 changes: 24 additions & 0 deletions server/src/test/java/org/apache/lucene/geo/XTessellatorTests.java
Expand Up @@ -1066,6 +1066,30 @@ public void testComplexPolygon50_unfixed() throws Exception {
);
}

public void testComplexPolygon53() throws Exception {
String geoJson = GeoTestUtil.readShape("github-11986-1.geojson.gz");
Polygon[] polygons = Polygon.fromGeoJSON(geoJson);
for (Polygon polygon : polygons) {
List<XTessellator.Triangle> tessellation = XTessellator.tessellate(polygon);
assertEquals(area(polygon), area(tessellation), 0.0);
for (XTessellator.Triangle t : tessellation) {
checkTriangleEdgesFromPolygon(polygon, t);
}
}
}

public void testComplexPolygon54() throws Exception {
String geoJson = GeoTestUtil.readShape("github-11986-2.geojson.gz");
Polygon[] polygons = Polygon.fromGeoJSON(geoJson);
for (Polygon polygon : polygons) {
List<XTessellator.Triangle> tessellation = XTessellator.tessellate(polygon);
assertEquals(area(polygon), area(tessellation), 0.0);
for (XTessellator.Triangle t : tessellation) {
checkTriangleEdgesFromPolygon(polygon, t);
}
}
}

private void checkPolygon(String wkt) throws Exception {
Polygon polygon = (Polygon) SimpleWKTShapeParser.parse(wkt);
List<XTessellator.Triangle> tessellation = XTessellator.tessellate(polygon);
Expand Down
Binary file not shown.
Binary file not shown.