Skip to content

Commit

Permalink
Empty geoms have equal topo
Browse files Browse the repository at this point in the history
Note, this is a divergence from JTS.Geometry.isEqualTopo, but it seems
like the right thing to do.

Supportive discussion with Dr. JTS:
locationtech/jts#1087 (comment)

It also aligns with the new Overlay semantics in GEOS (OverlayNG).
  • Loading branch information
michaelkirk committed Oct 10, 2024
1 parent ccf2ffd commit 1748fcf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions geo/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
Haversine::distance(p1, p2)
```
* <https://github.com/georust/geo/pull/1216>
* Change IntersectionMatrix::is_equal_topo to now consider empty geometries as equal.
* <https://github.com/georust/geo/pull/1223>

## 0.28.0

Expand Down
12 changes: 12 additions & 0 deletions geo/src/algorithm/relate/geomgraph/intersection_matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,11 @@ impl IntersectionMatrix {
/// - Matches `[T*F**FFF*]`
/// - This predicate is **reflexive, symmetric, and transitive**
pub fn is_equal_topo(&self) -> bool {
if self == &Self::empty_disjoint() {
// Any two empty geometries are topologically equal
return true;
}

self.0[CoordPos::Inside][CoordPos::Inside] != Dimensions::Empty
&& self.0[CoordPos::Inside][CoordPos::Outside] == Dimensions::Empty
&& self.0[CoordPos::Outside][CoordPos::Inside] == Dimensions::Empty
Expand Down Expand Up @@ -754,4 +759,11 @@ mod tests {
fn matches_wildcard() {
assert!(subject().matches("F0011122*").unwrap());
}

#[test]
fn empty_is_equal_topo() {
let empty_polygon = Polygon::<f64>::new(LineString::new(vec![]), vec![]);
let im = empty_polygon.relate(&empty_polygon);
assert!(im.is_equal_topo());
}
}

0 comments on commit 1748fcf

Please sign in to comment.