diff --git a/rstar/CHANGELOG.md b/rstar/CHANGELOG.md index 2f6d912..e6ae444 100644 --- a/rstar/CHANGELOG.md +++ b/rstar/CHANGELOG.md @@ -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` and `Rc` +- New `AABB::from_center` utility constructor ## Fixed - Fix excessive memory retention in `bulk_load` from `Vec::split_off` over-capacity diff --git a/rstar/src/aabb.rs b/rstar/src/aabb.rs index 09cde52..45d5f43 100644 --- a/rstar/src/aabb.rs +++ b/rstar/src/aabb.rs @@ -64,6 +64,18 @@ where } } + /// Creates a new AABB from a center and a diameter. + pub fn from_center(center: P, diameter: P::Scalar) -> Self { + let one = P::Scalar::one(); + let two = one + one; + let radius = P::from_value(diameter / two); + + let p1 = center.add(&radius); + let p2 = center.sub(&radius); + + Self::from_corners(p1, p2) + } + /// Creates a new AABB encompassing a collection of points. pub fn from_points<'a, I>(i: I) -> Self where