Skip to content

Commit

Permalink
Centroid: Avoid crash with empty hole
Browse files Browse the repository at this point in the history
Resolves #1073
  • Loading branch information
dbaston committed Jun 17, 2024
1 parent c91cb2e commit 16d443a
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[i], pts[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 @@ -123,5 +123,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 16d443a

Please sign in to comment.