Skip to content

Commit

Permalink
Add RelateNG unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-jts committed Aug 14, 2024
1 parent 4c6a20d commit 7d877b7
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,18 @@ public void testPolygonEmptyMultiLineStringClosed()
runRelate(a, b, BoundaryNodeRule.ENDPOINT_BOUNDARY_RULE, "FFFFFF102" );
}

public void testLineStringInteriorTouchMultivalent()
{
String a = "POLYGON EMPTY";
String b = "MULTILINESTRING ((0 0, 0 1), (0 1, 1 1, 1 0, 0 0))";

// closed line has no boundary under SFS rule
runRelate(a, b, BoundaryNodeRule.OGC_SFS_BOUNDARY_RULE, "FFFFFF1F2" );

// closed line has boundary under ENDPOINT rule
runRelate(a, b, BoundaryNodeRule.ENDPOINT_BOUNDARY_RULE, "FFFFFF102" );
}

void runRelate(String wkt1, String wkt2, BoundaryNodeRule bnRule, String expectedIM)
{
Geometry g1 = read(wkt1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,37 @@ public void testRepeatedPointAA() {
checkRelate(a, b, "212F01FF2");
}


//================ Repeated Points ==============

public void testEmptyEquals() {
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++) {
String a = empties[i];
String b = empties[j];
checkRelate(a, b, "FFFFFFFF2");
//-- currently in JTS empty geometries do NOT test equal
checkEquals(a, b, false);
}
}
}

//================ Prepared Relate ==============

public void testPreparedAA() {
String a = "POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))";
String b = "POLYGON((0.5 0.5, 1.5 0.5, 1.5 1.5, 0.5 1.5, 0.5 0.5))";
checkPrepared(a, b);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,36 @@ protected void checkPredicate(TopologyPredicate pred, String wkta, String wktb,
assertEquals(expectedValue, actualVal);
}

void checkPrepared(String wkta, String wktb)
{
Geometry a = read(wkta);
Geometry b = read(wktb);
RelateNG prep_a = RelateNG.prepare(a);

assertEquals("equalsTopo", prep_a.evaluate(b, RelatePredicate.equalsTopo()),
RelateNG.relate(a, b, RelatePredicate.equalsTopo()));

assertEquals("intersects", prep_a.evaluate(b, RelatePredicate.intersects()),
RelateNG.relate(a, b, RelatePredicate.intersects()));
assertEquals("disjoint", prep_a.evaluate(b, RelatePredicate.disjoint()),
RelateNG.relate(a, b, RelatePredicate.disjoint()));
assertEquals("covers", prep_a.evaluate(b, RelatePredicate.covers()),
RelateNG.relate(a, b, RelatePredicate.covers()));
assertEquals("coveredBy", prep_a.evaluate(b, RelatePredicate.coveredBy()),
RelateNG.relate(a, b, RelatePredicate.coveredBy()));
assertEquals("within", prep_a.evaluate(b, RelatePredicate.within()),
RelateNG.relate(a, b, RelatePredicate.within()));
assertEquals("contains", prep_a.evaluate(b, RelatePredicate.contains()),
RelateNG.relate(a, b, RelatePredicate.contains()));
assertEquals("crosses", prep_a.evaluate(b, RelatePredicate.crosses()),
RelateNG.relate(a, b, RelatePredicate.crosses()));
assertEquals("touches", prep_a.evaluate(b, RelatePredicate.touches()),
RelateNG.relate(a, b, RelatePredicate.touches()));

assertEquals("relate", prep_a.evaluate(b).toString(),
RelateNG.relate(a, b).toString());
}

TopologyPredicate trace(TopologyPredicate pred) {
if (! isTrace)
return pred;
Expand Down

0 comments on commit 7d877b7

Please sign in to comment.