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 Mar 1, 2023
1 parent 9e295c0 commit 05e6b8f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions NEWS
Expand Up @@ -4,6 +4,7 @@ Changes in 3.9.5
- Bug fixes / improvements:
- GEOSUnaryUnion: Fix crash on collection containing empty point (GH-830, Dan Baston)
- IndexedFacetDistance: Fix crash with Inf coordinates (GH-821, Dan Baston)
- HausdorffDistance: Fix crash on collection containing empty point (GH-840, Dan Baston)
- DistanceOp: Fix crash on collection containing empty point (GH-842, Dan Baston)


Expand Down
4 changes: 4 additions & 0 deletions src/algorithm/distance/DistanceToPoint.cpp
Expand Up @@ -40,6 +40,10 @@ DistanceToPoint::computeDistance(const geom::Geometry& geom,
const geom::Coordinate& pt,
PointPairDistance& ptDist)
{
if (geom.isEmpty()) {
ptDist.initialize();
return;
}
if(const LineString* ls = dynamic_cast<const LineString*>(&geom)) {
computeDistance(*ls, pt, ptDist);
}
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/algorithm/distance/DiscreteHausdorffDistanceTest.cpp
Expand Up @@ -156,5 +156,21 @@ void object::test<5>
}



// 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 05e6b8f

Please sign in to comment.