Skip to content

Commit

Permalink
Fix and test for LargestEmptyCircle crash on malformed input (#1004)
Browse files Browse the repository at this point in the history
* Fix and tests for GH-1003
* Call to init() was missing? Does not explain why the bug in the original issue seemed tied to particular coordinates, as the fix will apply across all inputs. So be warned, there may still be something hiding in there.
  • Loading branch information
pramsey authored Nov 30, 2023
1 parent ddba88a commit b3d6d20
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/algorithm/construct/IndexedDistanceToPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ IndexedDistanceToPoint::IndexedDistanceToPoint(const Geometry& geom)
void IndexedDistanceToPoint::init()
{
if (facetDistance != nullptr)
return;
return;
ptLocator.reset(new IndexedPointInPolygonsLocator(targetGeometry));
facetDistance.reset(new IndexedFacetDistance(&targetGeometry));
}
Expand All @@ -62,7 +62,8 @@ bool IndexedDistanceToPoint::isInArea(const Point& pt)
std::unique_ptr<geom::CoordinateSequence>
IndexedDistanceToPoint::nearestPoints(const Point& pt)
{
init();
return facetDistance->nearestPoints(&pt);
}

}}}
}}}
26 changes: 26 additions & 0 deletions tests/unit/algorithm/construct/LargestEmptyCircleTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,4 +316,30 @@ void object::test<19>()
0.01, 5.5, 4.5, 2.12 );
}


// https://trac.osgeo.org/postgis/ticket/5626
template<>
template<>
void object::test<20>()
{
checkCircle(
"POINT(-11 40)", // input
"POLYGON((-71.1 42.3,-71.1 42.4,-71.2 42.3,-71.1 42.3))", // boundary
0.1, // test tolerance
-71.15, 42.34, 60.19588 ); // expected x, y, radius
}


// https://trac.osgeo.org/postgis/ticket/5626
template<>
template<>
void object::test<21>()
{
checkCircle(
"POINT(-11.1111111 40)", // input
"POLYGON((-71.0821 42.3036,-71.0821 42.3936,-71.0901 42.3036,-71.0821 42.3036))", // boundary
1, // test tolerance
-71.15, 42.34, 60.19588 ); // expected x, y, radius
}

} // namespace tut

0 comments on commit b3d6d20

Please sign in to comment.