Skip to content

Commit

Permalink
Skip over testing empty distances for mixed collections. Closes #979
Browse files Browse the repository at this point in the history
  • Loading branch information
pramsey committed Oct 31, 2023
1 parent d7a5a51 commit ea46eef
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/operation/distance/DistanceOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,10 @@ DistanceOp::computeMinDistanceLines(
{
for(const LineString* line0 : lines0) {
for(const LineString* line1 : lines1) {

if (line0->isEmpty() || line1->isEmpty())
continue;

computeMinDistance(line0, line1, locGeom);
if(minDistance <= terminateDistance) {
return;
Expand All @@ -374,13 +378,11 @@ DistanceOp::computeMinDistancePoints(
std::array<std::unique_ptr<GeometryLocation>, 2> & locGeom)
{
for(const Point* pt0 : points0) {
if (pt0->isEmpty()) {
continue;
}
for(const Point* pt1 : points1) {
if (pt1->isEmpty()) {

if (pt1->isEmpty() || pt0->isEmpty())
continue;
}

double dist = pt0->getCoordinate()->distance(*(pt1->getCoordinate()));

#if GEOS_DEBUG
Expand Down Expand Up @@ -414,6 +416,10 @@ DistanceOp::computeMinDistanceLinesPoints(
{
for(const LineString* line : lines) {
for(const Point* pt : points) {

if (line->isEmpty() || pt->isEmpty())
continue;

computeMinDistance(line, pt, locGeom);
if(minDistance <= terminateDistance) {
return;
Expand Down
56 changes: 56 additions & 0 deletions tests/unit/operation/distance/DistanceOpTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,11 @@ void object::test<21>()
ensure_equals(g1->distance(g2.get()), 1.9996999774966246);
}

//
// Variations on a theme: testing EMPTY and collections with EMPTY
//

// Ignoring empty component
template<>
template<>
void object::test<22>()
Expand All @@ -576,6 +581,57 @@ void object::test<22>()
ensure_equals(g2->distance(g1.get()), 1);
}

// Empty is same as empty so zero...?
template<>
template<>
void object::test<23>()
{
auto g1 = wktreader.read("POINT EMPTY");
auto g2 = wktreader.read("LINESTRING EMPTY");

ensure(g1 != nullptr && g2 != nullptr);
ensure_equals(g1->distance(g2.get()), 0);
ensure_equals(g2->distance(g1.get()), 0);
}

template<>
template<>
void object::test<24>()
{
auto g1 = wktreader.read("GEOMETRYCOLLECTION(POINT EMPTY, LINESTRING EMPTY)");
auto g2 = wktreader.read("LINESTRING EMPTY");

ensure(g1 != nullptr && g2 != nullptr);
ensure_equals(g1->distance(g2.get()), 0);
ensure_equals(g2->distance(g1.get()), 0);
}

// But ignore empty if there's a real distance?
template<>
template<>
void object::test<25>()
{
auto g1 = wktreader.read("GEOMETRYCOLLECTION(LINESTRING EMPTY, POINT(2 1))");
auto g2 = wktreader.read("POINT(1 1)");

ensure(g1 != nullptr && g2 != nullptr);
ensure_equals(g1->distance(g2.get()), 1);
ensure_equals(g2->distance(g1.get()), 1);
}

template<>
template<>
void object::test<26>()
{
auto g1 = wktreader.read("GEOMETRYCOLLECTION(POINT(-2 0), POINT EMPTY)");
auto g2 = wktreader.read("GEOMETRYCOLLECTION(POINT(1 0),LINESTRING(0 0,1 0))");

ensure(g1 != nullptr && g2 != nullptr);
ensure_equals(g1->distance(g2.get()), 2);
ensure_equals(g2->distance(g1.get()), 2);
}


// TODO: finish the tests by adding:
// LINESTRING - *all*
// MULTILINESTRING - *all*
Expand Down

0 comments on commit ea46eef

Please sign in to comment.