From 962f59a4459e51296e1d3a1d0e223ba8ca520a6c Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Wed, 9 Oct 2024 17:37:32 -0700 Subject: [PATCH] Empty geoms have equal topo Note, this is a divergence from JTS.Geometry.isEqualTopo, but it seems like the right thing to do. Supportive discussion with Dr. JTS: https://github.com/locationtech/jts/issues/1087#issuecomment-2403630534 It also aligns with the new Overlay semantics in GEOS (OverlayNG). --- .../relate/geomgraph/intersection_matrix.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/geo/src/algorithm/relate/geomgraph/intersection_matrix.rs b/geo/src/algorithm/relate/geomgraph/intersection_matrix.rs index c365edf807..16ac5aece5 100644 --- a/geo/src/algorithm/relate/geomgraph/intersection_matrix.rs +++ b/geo/src/algorithm/relate/geomgraph/intersection_matrix.rs @@ -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 @@ -754,4 +759,11 @@ mod tests { fn matches_wildcard() { assert!(subject().matches("F0011122*").unwrap()); } + + #[test] + fn empty_is_equal_topo() { + let empty_polygon = Polygon::::new(LineString::new(vec![]), vec![]); + let im = empty_polygon.relate(&empty_polygon); + assert!(im.is_equal_topo()); + } }