From c6ee309b2dfcc4334279c915be43952f75620ceb Mon Sep 17 00:00:00 2001 From: Martin Davis Date: Wed, 22 Nov 2023 07:44:32 -0800 Subject: [PATCH] Fix DiscreteHausdorffDistance for LinearRing (#1000) --- .../algorithm/distance/DiscreteHausdorffDistance.h | 8 -------- src/algorithm/distance/DistanceToPoint.cpp | 2 +- .../distance/DiscreteHausdorffDistanceTest.cpp | 11 +++++++++++ 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/include/geos/algorithm/distance/DiscreteHausdorffDistance.h b/include/geos/algorithm/distance/DiscreteHausdorffDistance.h index 5dc1dd0a65..be136edeeb 100644 --- a/include/geos/algorithm/distance/DiscreteHausdorffDistance.h +++ b/include/geos/algorithm/distance/DiscreteHausdorffDistance.h @@ -36,19 +36,11 @@ #endif namespace geos { -namespace algorithm { -//class RayCrossingCounter; -} namespace geom { class Geometry; class Coordinate; //class CoordinateSequence; } -namespace index { -namespace intervalrtree { -//class SortedPackedIntervalRTree; -} -} } namespace geos { diff --git a/src/algorithm/distance/DistanceToPoint.cpp b/src/algorithm/distance/DistanceToPoint.cpp index 1891b63f83..b983432292 100644 --- a/src/algorithm/distance/DistanceToPoint.cpp +++ b/src/algorithm/distance/DistanceToPoint.cpp @@ -45,7 +45,7 @@ DistanceToPoint::computeDistance(const geom::Geometry& geom, return; } - if(geom.getGeometryTypeId() == GEOS_LINESTRING) { + if(geom.getGeometryTypeId() == GEOS_LINESTRING || geom.getGeometryTypeId() == GEOS_LINEARRING) { 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 5f21fe420b..735344cd59 100644 --- a/tests/unit/algorithm/distance/DiscreteHausdorffDistanceTest.cpp +++ b/tests/unit/algorithm/distance/DiscreteHausdorffDistanceTest.cpp @@ -216,5 +216,16 @@ void object::test<7> DiscreteHausdorffDistance::distance(*g2, *g3)); } +// see https://github.com/libgeos/geos/issues/987 +template<> +template<> +void object::test<8> +() +{ + runTest("LINEARRING (0 0, 0 10, 10 10, 10 0, 0 0)", + "LINEARRING (1 1, 1 9, 8 8, 9 1, 1 1)", + 2.8284271247461903); +} + } // namespace tut