Skip to content

Commit

Permalink
Allow empty geoms to test equal
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-jts committed Aug 2, 2024
1 parent 41bd100 commit 2c9b3cd
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 29 deletions.
10 changes: 9 additions & 1 deletion include/geos/operation/relateng/RelatePredicate.h
Original file line number Diff line number Diff line change
Expand Up @@ -490,12 +490,20 @@ class EqualsTopoPredicate : public IMPredicate {
return std::string("equals");
}

bool requireInteraction() const override {
//-- allow EMPTY = EMPTY
return false;
};

void init(int _dimA, int _dimB) override {
IMPredicate::init(_dimA, _dimB);
require(dimA == dimB);
//-- don't require equal dims, because EMPTY = EMPTY for all dims
}

void init(const Envelope& envA, const Envelope& envB) override {
//-- handle EMPTY = EMPTY cases
setValueIf(true, envA.isNull() && envB.isNull());

require(envA.equals(&envB));
}

Expand Down
4 changes: 0 additions & 4 deletions src/operation/relateng/RelateNG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,6 @@ RelateNG::evaluate(const Geometry* b, TopologyPredicate& predicate)

RelateGeometry geomB(b, boundaryNodeRule);

if (geomA.isEmpty() && geomB.isEmpty()) {
//TODO: what if predicate is disjoint? Perhaps use result on disjoint envs?
return finishValue(predicate);
}
int dimA = geomA.getDimensionReal();
int dimB = geomB.getDimensionReal();

Expand Down
43 changes: 19 additions & 24 deletions tests/unit/operation/relateng/RelateNGTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -841,37 +841,32 @@ void object::test<60> ()

//================ Empty Geometries ==============

//-- test equals against all combinations of empty geometries
template<>
template<>
void object::test<61> ()
{
std::string a = "POINT EMPTY";
std::string b = "POINT EMPTY";
checkRelate(a, b, "FFFFFFFF2");
checkEquals(a, b, true);
}

template<>
template<>
void object::test<62> ()
{
std::string a = "LINESTRING EMPTY";
std::string b = "LINESTRING EMPTY";
checkRelate(a, b, "FFFFFFFF2");
checkEquals(a, b, true);
}
std::string empties[] = {
"POINT EMPTY",
"LINESTRING EMPTY",
"POLYGON EMPTY",
"MULTIPOINT EMPTY",
"MULTILINESTRING EMPTY",
"MULTIPOLYGON EMPTY",
"GEOMETRYCOLLECTION EMPTY"
};
int nempty = 7;
for (int i = 0; i < nempty; i++) {
for (int j = 0; j < nempty; j++) {
std::string a = empties[i];
std::string b = empties[j];
checkRelate(a, b, "FFFFFFFF2");
checkEquals(a, b, true);
}
}

template<>
template<>
void object::test<63> ()
{
std::string a = "GEOMETRYCOLLECTION EMPTY";
std::string b = "GEOMETRYCOLLECTION EMPTY";
checkRelate(a, b, "FFFFFFFF2");
checkEquals(a, b, true);
}




} // namespace tut

0 comments on commit 2c9b3cd

Please sign in to comment.