Skip to content

Commit f83ada6

Browse files
add Envelope::is_empty (#190)
- [X] I agree to follow the project's [code of conduct](https://github.com/georust/geo/blob/master/CODE_OF_CONDUCT.md). - [x] I added an entry to `rstar/CHANGELOG.md` if knowledge of this change could be valuable to users. --- This just adds a little convenience method. With the default implementation, this should be a non-breaking change. --------- Co-authored-by: Adam Reichold <adamreichold@users.noreply.github.com>
1 parent 8dd39c3 commit f83ada6

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

rstar/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- Added nearest neighbor search with distance squared: `nearest_neighbor_with_distance_2` and `nearest_neighbors_with_distance_2` methods ([PR](https://github.com/georust/rstar/pull/191)).
66
- Added `root` doc examples and traversal docs
77
- Implemented `RTreeObject` for `Arc<T>` and `Rc<T>`
8+
- Added `Envelope::is_empty`. ([PR](https://github.com/georust/rstar/pull/190))
89
- New `AABB::from_center` utility constructor
910

1011
## Fixed

rstar/src/aabb.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ where
126126
}
127127
}
128128

129+
fn is_empty(&self) -> bool {
130+
self.lower.nth(0) > self.upper.nth(0)
131+
}
132+
129133
fn contains_point(&self, point: &P) -> bool {
130134
self.lower.all_component_wise(point, |x, y| x <= y)
131135
&& self.upper.all_component_wise(point, |x, y| x >= y)
@@ -281,4 +285,13 @@ mod test {
281285
let aabb = AABB::from_points(&[(3., 3., 3.), (4., 4., 4.)]);
282286
assert_eq!(aabb, AABB::from_corners((3., 3., 3.), (4., 4., 4.)));
283287
}
288+
289+
#[test]
290+
fn test_is_empty() {
291+
let empty = AABB::<[f32; 2]>::new_empty();
292+
assert!(empty.is_empty());
293+
294+
let not_empty = AABB::from_corners([1.0, 1.0], [1.0, 1.0]);
295+
assert!(!not_empty.is_empty());
296+
}
284297
}

rstar/src/envelope.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ pub trait Envelope: Clone + PartialEq + ::core::fmt::Debug {
1313
/// Creates a new, empty envelope that does not encompass any child.
1414
fn new_empty() -> Self;
1515

16+
/// Returns true if there are no points in the Envelope
17+
fn is_empty(&self) -> bool {
18+
self == &Self::new_empty()
19+
}
20+
1621
/// Returns true if a point is contained within this envelope.
1722
fn contains_point(&self, point: &Self::Point) -> bool;
1823

0 commit comments

Comments
 (0)