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>`
- New `AABB::from_center` utility constructor

## Fixed
- Fix excessive memory retention in `bulk_load` from `Vec::split_off` over-capacity
Expand Down
12 changes: 12 additions & 0 deletions rstar/src/aabb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would "width" be better? I feel like "diameter"/"radius" cannotes a circle.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did wonder about this back and forth because of the connotation. I stuck with diameter as it makes it explicit that extent is measured end-to-end instead of from the centre. (And it is an L∞ circle after all... ;))

Since this is unreleased, we can still change it. I wonder if we should expose an distance: P::Scalar parameter and actually remove the / (one + one) computation from the method? The caller presumably knows best whether to half the value and what its interpretation is?

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
Expand Down