Skip to content

Commit

Permalink
MinimumClearance: Avoid crash on NaN inputs (#1082)
Browse files Browse the repository at this point in the history
Resolves #1079
  • Loading branch information
dbaston authored Apr 25, 2024
1 parent cbf94fe commit 9d41562
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/precision/MinimumClearance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ MinimumClearance::compute()
MinClearanceDistance mcd;
auto nearest = tree->nearestNeighbour(mcd);

if (nearest.first == nullptr || nearest.second == nullptr) {
throw util::GEOSException("Failed to find nearest items");
}

minClearance = mcd.distance(nearest.first, nearest.second);

const std::vector<Coordinate>* minClearancePtsVec = mcd.getCoordinates();
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/capi/GEOSMinimumClearanceTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,14 @@ void object::test<5>
geos::DoubleInfinity);
}

template<>
template<>
void object::test<6>
()
{
input_ = GEOSGeom_createPointFromXY(std::numeric_limits<double>::quiet_NaN(), 1);
double d;
ensure_equals(GEOSMinimumClearance(input_, &d), 2);
}

} // namespace tut

0 comments on commit 9d41562

Please sign in to comment.