Skip to content

Commit

Permalink
Fix RelateGeometry test for zero-length lines
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-jts committed Jul 23, 2024
1 parent 46326d3 commit 0d5eac9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ private static boolean isZeroLength(LineString line) {
if (line.getNumPoints() >= 2) {
Coordinate p0 = line.getCoordinateN(0);
for (int i = 0 ; i < line.getNumPoints(); i++) {
Coordinate pi = line.getCoordinateN(1);
Coordinate pi = line.getCoordinateN(i);
//-- most non-zero-len lines will trigger this right away
if (! p0.equals2D(pi))
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,19 @@ public void testDimension() {
checkDimension("POINT (0 0)", 0, 0);
checkDimension("LINESTRING (0 0, 0 0)", 1, 0);
checkDimension("LINESTRING (0 0, 9 9)", 1, 1);
checkDimension("LINESTRING (0 0, 0 0, 9 9)", 1, 1);
checkDimension("POLYGON ((1 9, 5 9, 5 5, 1 5, 1 9))", 2, 2);
checkDimension("GEOMETRYCOLLECTION (POLYGON ((1 9, 5 9, 5 5, 1 5, 1 9)), LINESTRING (1 1, 5 4), POINT (6 5))", 2, 2);
checkDimension("GEOMETRYCOLLECTION (POLYGON EMPTY, LINESTRING (1 1, 5 4), POINT (6 5))", 2, 1);
}

private void checkDimension(String wkt, int expectedDim, int expectedDimReal) {
Geometry geom = read(wkt);
RelateGeometry rgeom = new RelateGeometry(geom);
assertEquals(expectedDim, rgeom.getDimension());
assertEquals(expectedDimReal, rgeom.getDimensionReal());
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,19 @@ public void testZeroLengthLineLine() {
checkEquals(a, b, true);
}

// tests bug involving checking for non-zero-length lines
public void testNonZeroLengthLinePoint() {
String a = "LINESTRING (0 0, 0 0, 9 9)";
String b = "POINT (1 1)";
checkRelate(a, b, "0F1FF0FF2");
checkIntersectsDisjoint(a, b, true);
checkContainsWithin(a, b, true);
checkContainsWithin(b, a, false);
checkCoversCoveredBy(a, b, true);
checkCoversCoveredBy(b, a, false);
checkEquals(a, b, false);
}

public void testLinePointIntAndExt() {
String a = "MULTIPOINT((60 60), (100 100))";
String b = "LINESTRING(40 40, 80 80)";
Expand Down

0 comments on commit 0d5eac9

Please sign in to comment.