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 962f59a
Showing 1 changed file with 12 additions and 0 deletions.
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 962f59a

Please sign in to comment.