Skip to content
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
42 changes: 42 additions & 0 deletions tests/relations/gcol.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,46 @@
"touches": ["F", "F"]
}
},
// An empty child does not prevent containment of the interior point.
{
"geoms": [
"GEOMETRYCOLLECTION (POINT EMPTY, POINT (1 1))",
"POLYGON ((0 0, 2 0, 2 2, 0 2, 0 0))"
],
"dims": [ 0, 2 ],
"relate": [ "0FFFFF212", "0F2FF1FF2" ],
"predicates": {
"equals": ["F", "F"],
"intersects": ["T", "T"],
"disjoint": ["F", "F"],
"contains": ["F", "T"],
"within": ["T", "F"],
"covers": ["F", "T"],
"coveredby": ["T", "F"],
"crosses": ["F", "F"],
"overlaps": ["F", "F"],
"touches": ["F", "F"]
}
},
// A collection containing only empty points is not within or coveredby the polygon.
{
"geoms": [
"GEOMETRYCOLLECTION (POINT EMPTY, POINT EMPTY)",
"POLYGON ((0 0, 2 0, 2 2, 0 2, 0 0))"
],
"dims": [ 0, 2 ],
"relate": [ "FFFFFF212", "FF2FF1FF2" ],
"predicates": {
"equals": ["F", "F"],
"intersects": ["F", "F"],
"disjoint": ["T", "T"],
"contains": ["F", "F"],
"within": ["F", "F"],
"covers": ["F", "F"],
"coveredby": ["F", "F"],
"crosses": ["F", "F"],
"overlaps": ["F", "F"],
"touches": ["F", "F"]
}
},
]
65 changes: 64 additions & 1 deletion tests/relations/mpoint.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -198,5 +198,68 @@
"overlaps": ["F", "F"],
"touches": ["F", "F"]
}
},
// Within and contains with one interior point and one boundary point.
{
"geoms": [
"MULTIPOINT ((0 0), (1 1))",
"POLYGON ((0 0, 2 0, 2 2, 0 2, 0 0))"
],
"dims": [ 0, 2 ],
"relate": [ "00FFFF212", "0F20F1FF2" ],
"predicates": {
"equals": ["F", "F"],
"intersects": ["T", "T"],
"disjoint": ["F", "F"],
"contains": ["F", "T"],
"within": ["T", "F"],
"covers": ["F", "T"],
"coveredby": ["T", "F"],
"crosses": ["F", "F"],
"overlaps": ["F", "F"],
"touches": ["F", "F"]
}
},
// All points lie on the polygon boundary, so coveredby is true but within is false.
{
"geoms": [
"MULTIPOINT ((0 0), (1 0))",
"POLYGON ((0 0, 2 0, 2 2, 0 2, 0 0))"
],
"dims": [ 0, 2 ],
"relate": [ "F0FFFF212", "FF20F1FF2" ],
"predicates": {
"equals": ["F", "F"],
"intersects": ["T", "T"],
"disjoint": ["F", "F"],
"contains": ["F", "F"],
"within": ["F", "F"],
"covers": ["F", "T"],
"coveredby": ["T", "F"],
"crosses": ["F", "F"],
"overlaps": ["F", "F"],
"touches": ["T", "T"]
}
},
// An interior point followed by an outside point is neither within nor coveredby.
{
"geoms": [
"MULTIPOINT ((1 1), (3 3))",
"POLYGON ((0 0, 2 0, 2 2, 0 2, 0 0))"
],
"dims": [ 0, 2 ],
"relate": [ "0F0FFF212", "0F2FF10F2" ],
"predicates": {
"equals": ["F", "F"],
"intersects": ["T", "T"],
"disjoint": ["F", "F"],
"contains": ["F", "F"],
"within": ["F", "F"],
"covers": ["F", "F"],
"coveredby": ["F", "F"],
"crosses": ["T", "T"],
"overlaps": ["F", "F"],
"touches": ["F", "F"]
}
}
]
]
18 changes: 15 additions & 3 deletions tg.c
Original file line number Diff line number Diff line change
Expand Up @@ -5939,12 +5939,18 @@ static bool poly_covers_base_geom(struct tg_poly *poly,
case TG_MULTIPOLYGON:
case TG_GEOMETRYCOLLECTION:
if (!geom->multi || geom->multi->ngeoms == 0) return false;
int empty_count = 0;
for (int i = 0; i < geom->multi->ngeoms; i++) {
if ((geom->multi->geoms[i]->head.flags&IS_EMPTY) == IS_EMPTY) {
++empty_count;
continue;
}

if (!poly_covers_geom(poly, geom->multi->geoms[i])) {
return false;
}
}
return true;
return empty_count != geom->multi->ngeoms;
}
}
return false;
Expand Down Expand Up @@ -6124,12 +6130,18 @@ static bool poly_contains_base_geom(struct tg_poly *poly,
case TG_GEOMETRYCOLLECTION: {
bool contains = false;
if (geom->multi && geom->multi->ngeoms > 0) {
contains = true;
for (int i = 0; i < geom->multi->ngeoms; i++) {
if (!poly_contains_geom(poly, geom->multi->geoms[i])) {
if ((geom->multi->geoms[i]->head.flags&IS_EMPTY) == IS_EMPTY) {
continue;
}

if (!poly_covers_geom(poly, geom->multi->geoms[i])) {
contains = false;
break;
}

// Require at least one interior intersection
contains = contains || poly_contains_geom(poly, geom->multi->geoms[i]);
}
}
return contains;
Expand Down
Loading