Skip to content
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
1 change: 1 addition & 0 deletions rstar/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- 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)).
- Added `root` doc examples and traversal docs
- Implemented `RTreeObject` for `Arc<T>` and `Rc<T>`
- Added `Envelope::is_empty`. ([PR](https://github.com/georust/rstar/pull/190))
- New `AABB::from_center` utility constructor

## Fixed
Expand Down
13 changes: 13 additions & 0 deletions rstar/src/aabb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ where
}
}

fn is_empty(&self) -> bool {
self.lower.nth(0) > self.upper.nth(0)
}

fn contains_point(&self, point: &P) -> bool {
self.lower.all_component_wise(point, |x, y| x <= y)
&& self.upper.all_component_wise(point, |x, y| x >= y)
Expand Down Expand Up @@ -281,4 +285,13 @@ mod test {
let aabb = AABB::from_points(&[(3., 3., 3.), (4., 4., 4.)]);
assert_eq!(aabb, AABB::from_corners((3., 3., 3.), (4., 4., 4.)));
}

#[test]
fn test_is_empty() {
let empty = AABB::<[f32; 2]>::new_empty();
assert!(empty.is_empty());

let not_empty = AABB::from_corners([1.0, 1.0], [1.0, 1.0]);
assert!(!not_empty.is_empty());
}
}
5 changes: 5 additions & 0 deletions rstar/src/envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ pub trait Envelope: Clone + PartialEq + ::core::fmt::Debug {
/// Creates a new, empty envelope that does not encompass any child.
fn new_empty() -> Self;

/// Returns true if there are no points in the Envelope
fn is_empty(&self) -> bool {
self == &Self::new_empty()
}

/// Returns true if a point is contained within this envelope.
fn contains_point(&self, point: &Self::Point) -> bool;

Expand Down