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

Fix RelateNG IM calculation for EMPTY-nonEMPTY #1090

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,14 @@ public void addPointOnPointExterior(boolean isGeomA, Coordinate pt) {
updateDim(isGeomA, Location.INTERIOR, Location.EXTERIOR, Dimension.P);
}

public void addPointOnGeometry(boolean isA, int locTarget, int dimTarget, Coordinate pt) {
updateDim(isA, Location.INTERIOR, locTarget, Dimension.P);
public void addPointOnGeometry(boolean isPointA, int locTarget, int dimTarget, Coordinate pt) {
//-- update entry for Point interior
updateDim(isPointA, Location.INTERIOR, locTarget, Dimension.P);

//-- an empty geometry has no points to infer entries from
if (getGeometry(! isPointA).isEmpty())
return;

switch (dimTarget) {
case Dimension.P:
return;
Expand All @@ -266,8 +272,8 @@ public void addPointOnGeometry(boolean isA, int locTarget, int dimTarget, Coordi
* If a point intersects an area target, then the area interior and boundary
* must extend beyond the point and thus interact with its exterior.
*/
updateDim(isA, Location.EXTERIOR, Location.INTERIOR, Dimension.A);
updateDim(isA, Location.EXTERIOR, Location.BOUNDARY, Dimension.L);
updateDim(isPointA, Location.EXTERIOR, Location.INTERIOR, Dimension.A);
updateDim(isPointA, Location.EXTERIOR, Location.BOUNDARY, Dimension.L);
return;
}
throw new IllegalStateException("Unknown target dimension: " + dimTarget);
Expand All @@ -289,6 +295,10 @@ public void addLineEndOnGeometry(boolean isLineA, int locLineEnd, int locTarget,
//-- record topology at line end point
updateDim(isLineA, locLineEnd, locTarget, Dimension.P);

//-- an empty geometry has no points to infer entries from
if (getGeometry(! isLineA).isEmpty())
return;

//-- Line and Area targets may have additional topology
switch (dimTarget) {
case Dimension.P:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -599,27 +599,67 @@ public void testRepeatedPointAA() {

//================ EMPTY geometries ==============

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 empties[] = {
"POINT EMPTY",
"LINESTRING EMPTY",
"POLYGON EMPTY",
"MULTIPOINT EMPTY",
"MULTILINESTRING EMPTY",
"MULTIPOLYGON EMPTY",
"GEOMETRYCOLLECTION EMPTY"
};

public void testEmptyEmpty() {
for (int i = 0; i < empties.length; i++) {
String a = empties[i];

for (int j = 0; j < empties.length; j++) {
String b = empties[j];
///-- empty geometries are all topologically equal
checkRelate(a, b, "FFFFFFFF2");
//-- empty geometries are all topologically equal
checkEquals(a, b, true);

checkIntersectsDisjoint(a, b, false);
checkContainsWithin(a, b, false);
}
}
}

public void testEmptyNonEmpty() {
String nonEmptyPoint = "POINT (1 1)";
String nonEmptyLine = "LINESTRING (1 1, 2 2)";
String nonEmptyPolygon = "POLYGON ((1 1, 1 2, 2 1, 1 1))";

for (int i = 0; i < empties.length; i++) {
String empty = empties[i];

checkRelate(empty, nonEmptyPoint, "FFFFFF0F2");
checkRelate(nonEmptyPoint, empty, "FF0FFFFF2");

checkRelate(empty, nonEmptyLine, "FFFFFF102");
checkRelate(nonEmptyLine, empty, "FF1FF0FF2");

checkRelate(empty, nonEmptyPolygon, "FFFFFF212");
checkRelate(nonEmptyPolygon, empty, "FF2FF1FF2");

checkEquals(empty, nonEmptyPoint, false);
checkEquals(empty, nonEmptyLine, false);
checkEquals(empty, nonEmptyPolygon, false);

checkIntersectsDisjoint(empty, nonEmptyPoint, false);
checkIntersectsDisjoint(empty, nonEmptyLine, false);
checkIntersectsDisjoint(empty, nonEmptyPolygon, false);

checkContainsWithin(empty, nonEmptyPoint, false);
checkContainsWithin(empty, nonEmptyLine, false);
checkContainsWithin(empty, nonEmptyPolygon, false);

checkContainsWithin(nonEmptyPoint, empty, false);
checkContainsWithin(nonEmptyLine, empty, false);
checkContainsWithin(nonEmptyPolygon, empty, false);
}
}

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

public void testPreparedAA() {
Expand Down
Loading