Skip to content

Commit

Permalink
HausdorffDistance: Fix crash on collection with empty components
Browse files Browse the repository at this point in the history
  • Loading branch information
dbaston committed Feb 28, 2023
1 parent 38ec326 commit 9c8eb33
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ xxxx-xx-xx
- GEOSBuffer: Fix crash with Inf coordinates (GH-822, Dan Baston)
- GEOSSTRtree_iterate: Do not return removed items (GH-833, Dan Baston)
- IndexedFacetDistance: Fix crash with Inf coordinates (GH-821, Dan Baston)
- HausdorffDistance: Fix crash on collection containing empty point (GH-840, Dan Baston)


## Changes in 3.11.0
Expand Down
5 changes: 5 additions & 0 deletions src/algorithm/distance/DistanceToPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ DistanceToPoint::computeDistance(const geom::Geometry& geom,
const geom::CoordinateXY& pt,
PointPairDistance& ptDist)
{
if (geom.isEmpty()) {
ptDist.initialize();
return;
}

if(geom.getGeometryTypeId() == GEOS_LINESTRING) {
const LineString* ls = static_cast<const LineString*>(&geom);
computeDistance(*ls, pt, ptDist);
Expand Down
15 changes: 15 additions & 0 deletions tests/unit/algorithm/distance/DiscreteHausdorffDistanceTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,5 +201,20 @@ void object::test<6>
ensure("FE_INVALID raised", !std::fetestexcept(FE_INVALID));
}

// Crash on collection with empty components
// https://github.com/libgeos/geos/issues/840
template<>
template<>
void object::test<7>
()
{
auto g1 = reader.read("GEOMETRYCOLLECTION (POINT EMPTY, LINESTRING (0 0, 1 1))");
auto g2 = reader.read("POINT (1 2)");
auto g3 = reader.read("LINESTRING (0 0, 1 1)");

ensure_equals(DiscreteHausdorffDistance::distance(*g1, *g2),
DiscreteHausdorffDistance::distance(*g2, *g3));
}

} // namespace tut

0 comments on commit 9c8eb33

Please sign in to comment.