Skip to content

Commit

Permalink
IndexedFacetDistance: Avoid crash on Inf inputs
Browse files Browse the repository at this point in the history
Fixes #821
  • Loading branch information
dbaston committed Feb 28, 2023
1 parent 4948794 commit 1154044
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ xxxx-xx-xx
- GEOSUnaryUnion: Fix crash on collection containing empty point (GH-830, Dan Baston)
- 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)


## Changes in 3.11.0
Expand Down
2 changes: 1 addition & 1 deletion src/operation/distance/FacetSequence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ FacetSequence::computeDistancePointLine(const Coordinate& pt,
const Coordinate& q0 = facetSeq.pts->getAt(i);
const Coordinate& q1 = facetSeq.pts->getAt(i + 1);
double dist = Distance::pointToSegment(pt, q0, q1);
if(dist < minDistance) {
if(dist < minDistance || (locs != nullptr && locs->empty())) {
minDistance = dist;
if (locs != nullptr) {
updateNearestLocationsPointLine(pt, facetSeq, i, q0, q1, locs);
Expand Down
25 changes: 25 additions & 0 deletions tests/unit/operation/distance/IndexedFacetDistanceTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#define M_PI 3.14159265358979323846
#endif

using geos::operation::distance::IndexedFacetDistance;

namespace tut {
//
// Test Group
Expand Down Expand Up @@ -382,6 +384,29 @@ void object::test<11>
catch (const GEOSException&) { }
}

// Test with Inf coords
template<>
template<>
void object::test<12>()
{
auto g1 = _wktreader.read("POINT (0 0)");
auto g2 = _wktreader.read("LINESTRING (3 Inf, 5 Inf)");

IndexedFacetDistance ifd1(g1.get());

auto pts = ifd1.nearestPoints(g2.get());
ensure_equals(pts->size(), 2u);

auto ls = _factory->createLineString(std::move(pts));
ls->normalize();

const auto& normPts = *ls->getCoordinatesRO();

ensure_equals(normPts.getX(0), 0);
ensure_equals(normPts.getY(0), 0);
ensure_equals(normPts.getY(1), geos::DoubleInfinity);
}



// TODO: finish the tests by adding:
Expand Down

0 comments on commit 1154044

Please sign in to comment.