Skip to content

Commit b3d6d20

Browse files
authored
Fix and test for LargestEmptyCircle crash on malformed input (#1004)
* 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.
1 parent ddba88a commit b3d6d20

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/algorithm/construct/IndexedDistanceToPoint.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ IndexedDistanceToPoint::IndexedDistanceToPoint(const Geometry& geom)
3636
void IndexedDistanceToPoint::init()
3737
{
3838
if (facetDistance != nullptr)
39-
return;
39+
return;
4040
ptLocator.reset(new IndexedPointInPolygonsLocator(targetGeometry));
4141
facetDistance.reset(new IndexedFacetDistance(&targetGeometry));
4242
}
@@ -62,7 +62,8 @@ bool IndexedDistanceToPoint::isInArea(const Point& pt)
6262
std::unique_ptr<geom::CoordinateSequence>
6363
IndexedDistanceToPoint::nearestPoints(const Point& pt)
6464
{
65+
init();
6566
return facetDistance->nearestPoints(&pt);
6667
}
6768

68-
}}}
69+
}}}

tests/unit/algorithm/construct/LargestEmptyCircleTest.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,4 +316,30 @@ void object::test<19>()
316316
0.01, 5.5, 4.5, 2.12 );
317317
}
318318

319+
320+
// https://trac.osgeo.org/postgis/ticket/5626
321+
template<>
322+
template<>
323+
void object::test<20>()
324+
{
325+
checkCircle(
326+
"POINT(-11 40)", // input
327+
"POLYGON((-71.1 42.3,-71.1 42.4,-71.2 42.3,-71.1 42.3))", // boundary
328+
0.1, // test tolerance
329+
-71.15, 42.34, 60.19588 ); // expected x, y, radius
330+
}
331+
332+
333+
// https://trac.osgeo.org/postgis/ticket/5626
334+
template<>
335+
template<>
336+
void object::test<21>()
337+
{
338+
checkCircle(
339+
"POINT(-11.1111111 40)", // input
340+
"POLYGON((-71.0821 42.3036,-71.0821 42.3936,-71.0901 42.3036,-71.0821 42.3036))", // boundary
341+
1, // test tolerance
342+
-71.15, 42.34, 60.19588 ); // expected x, y, radius
343+
}
344+
319345
} // namespace tut

0 commit comments

Comments
 (0)