Skip to content

Commit

Permalink
follow-up on ef14e59: order also holes when creating final result, fo…
Browse files Browse the repository at this point in the history
…r deterministic output
  • Loading branch information
phanecak-maptiler committed Mar 14, 2023
1 parent b7f9ad7 commit f71ee5c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private Ring(Polygon geom) {
public Polygon toPolygon() {
return GeoUtils.JTS_FACTORY.createPolygon(
geom.getExteriorRing(),
holes.stream().map(ring -> ring.geom.getExteriorRing()).toArray(LinearRing[]::new)
holes.stream().sorted(BY_AREA_DESCENDING).map(ring -> ring.geom.getExteriorRing()).toArray(LinearRing[]::new)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,23 @@ void testSimplePolygonWithMultipleHoles() throws GeometryException {
);
}

@Test
void testSimplePolygonWithMultipleHolesOrdering() throws GeometryException {
testBuildMultipolygon(
List.of(
rectangleNodes(0, 10),
rectangleNodes(3, 5),
rectangleNodes(1, 2),
rectangleNodes(6, 9)
),
newPolygon(
rectangleCoordList(0, 10),
List.of(rectangleCoordList(6, 9), rectangleCoordList(3, 5), rectangleCoordList(1, 2))
),
true
);
}

public List<Node> rectangleNodes(double xMin, double yMin, double xMax, double yMax) {
var startEnd = node(xMin, yMin);
return List.of(startEnd, node(xMax, yMin), node(xMax, yMax), node(xMin, yMax), startEnd);
Expand Down

0 comments on commit f71ee5c

Please sign in to comment.