pub struct Bvh<K> { /* private fields */ }Expand description
Immutable median-split AABB hierarchy over opaque caller keys.
Invalid input bounds are not silently indexed: empty and non-finite boxes
are rejected during construction and counted by Self::rejected_items.
Accepted keys keep their input position, which makes pair output stable even
though node layout is optimized for pruning.
Implementations§
Source§impl<K> Bvh<K>
impl<K> Bvh<K>
Sourcepub fn build(items: impl IntoIterator<Item = SpatialItem<K>>) -> Self
pub fn build(items: impl IntoIterator<Item = SpatialItem<K>>) -> Self
Build a deterministic median-split hierarchy.
Sourcepub fn rejected_items(&self) -> usize
pub fn rejected_items(&self) -> usize
Number of source items rejected for empty or non-finite bounds.
Sourcepub fn item(&self, index: usize) -> Option<&SpatialItem<K>>
pub fn item(&self, index: usize) -> Option<&SpatialItem<K>>
Access an accepted item by its stable input position.
Source§impl<K: Clone> Bvh<K>
impl<K: Clone> Bvh<K>
Sourcepub fn query_aabb(&self, probe: &Aabb, out: &mut Vec<usize>)
pub fn query_aabb(&self, probe: &Aabb, out: &mut Vec<usize>)
Return pairs whose AABBs overlap with at least min_penetration on all
axes. A zero threshold includes touching boxes.
§Panics
Panics when min_penetration is negative or non-finite; an invalid query
must not masquerade as an evaluated empty result.
Keys whose bounds overlap probe.
The existing pair queries are self-joins within one tree. A clash test joins TWO meshes, so it probes one tree with the other’s boxes. Without this a caller has no option but a quadratic scan.
pub fn overlap_pairs(&self, min_penetration: Scalar) -> PairCandidates<K>
Sourcepub fn pairs_within_distance(&self, max_distance: Scalar) -> PairCandidates<K>
pub fn pairs_within_distance(&self, max_distance: Scalar) -> PairCandidates<K>
Return pairs whose AABB lower-bound distance is at most max_distance.
§Panics
Panics when max_distance is negative or non-finite; an invalid query
must not masquerade as an evaluated empty result.
Sourcepub fn nearest_to(
&self,
query: &Aabb,
accept: impl Fn(&K) -> bool,
) -> Option<NearestCandidate<K>>
pub fn nearest_to( &self, query: &Aabb, accept: impl Fn(&K) -> bool, ) -> Option<NearestCandidate<K>>
Find the accepted key with the smallest AABB lower-bound distance.
Equal distances resolve to the earliest accepted input item. Invalid query bounds panic rather than being misreported as an evaluated empty result.