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

Empty geoms have equal topo #1223

Merged
merged 1 commit into from
Oct 10, 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
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());
}
}
Loading