Skip to content
Open
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 @@ -2,6 +2,7 @@

## Added
- Added missing re-exports of nearest neighbor iterators so they can be named in downstream crates. ([PR](https://github.com/georust/rstar/pull/186))
- Added `Envelope::is_empty`. ([PR](https://github.com/georust/rstar/pull/190))

## Changed
- Made `RStar` methods take `Point` and `Envelope` as owned values where it makes sense ([PR](https://github.com/georust/rstar/pull/189))
Expand Down
13 changes: 13 additions & 0 deletions rstar/src/aabb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,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 @@ -269,4 +273,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