Skip to content

Commit

Permalink
Centroid: Avoid crash with empty hole (#1075)
Browse files Browse the repository at this point in the history
Resolves #1073
  • Loading branch information
dbaston authored Apr 20, 2024
1 parent c8b889b commit d2c196b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/algorithm/Centroid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ Centroid::addShell(const CoordinateSequence& pts)
void
Centroid::addHole(const CoordinateSequence& pts)
{
if (pts.isEmpty()) {
return;
}

bool isPositiveArea = Orientation::isCCW(&pts);
for(std::size_t i = 0, e = pts.size() - 1; i < e; ++i) {
addTriangle(*areaBasePt, pts.getAt<CoordinateXY>(i), pts.getAt<CoordinateXY>(i + 1), isPositiveArea);
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/algorithm/CentroidTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,11 @@ void object::test<5>() {
"POLYGON EMPTY");
}

template<>
template<>
void object::test<6>() {
checkCentroid("POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0), EMPTY)", 0.5, 0.5);
}

} // namespace tut

0 comments on commit d2c196b

Please sign in to comment.