Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IndexedFacetDistance: Avoid crash with Inf coordinates #837

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
17 changes: 17 additions & 0 deletions tests/unit/capi/GEOSMaximumInscribedCircleTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,22 @@ void object::test<2>
}


// Crash with Inf coords
// https://github.com/libgeos/geos/issues/821
template<>
template<>
void object::test<3>
()
{
std::string wkb("0106000020E61000000100000001030000000100000005000000000000000000F07F000000000000F07F000000000000F07F000000000000F07F000000000000F07F000000000000F07F000000000000F07F000000000000F07F000000000000F07F000000000000F07F");
geom1_ = GEOSGeomFromHEX_buf(reinterpret_cast<const unsigned char*>(wkb.c_str()), wkb.size());

result_ = GEOSMaximumInscribedCircle(geom1_, 1);

// no crash
}



} // namespace tut

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