diff --git a/NEWS.md b/NEWS.md index c081684514..65a3d00ca2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/src/algorithm/distance/DistanceToPoint.cpp b/src/algorithm/distance/DistanceToPoint.cpp index c80a8daf73..1891b63f83 100644 --- a/src/algorithm/distance/DistanceToPoint.cpp +++ b/src/algorithm/distance/DistanceToPoint.cpp @@ -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(&geom); computeDistance(*ls, pt, ptDist); diff --git a/tests/unit/algorithm/distance/DiscreteHausdorffDistanceTest.cpp b/tests/unit/algorithm/distance/DiscreteHausdorffDistanceTest.cpp index 0fb063ef85..188cd35e9c 100644 --- a/tests/unit/algorithm/distance/DiscreteHausdorffDistanceTest.cpp +++ b/tests/unit/algorithm/distance/DiscreteHausdorffDistanceTest.cpp @@ -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