pub struct QuadTree<ElementId = u32>where
ElementId: ElementIdType,{ /* private fields */ }
Expand description
A QuadTree implementation as described in Efficient Quadtrees.
§Remarks
This tree uses integral coordinates only in order to speed up box-box intersection tests.
Implementations§
Source§impl<ElementId> QuadTree<ElementId>where
ElementId: ElementIdType,
impl<ElementId> QuadTree<ElementId>where
ElementId: ElementIdType,
pub fn default() -> Self
pub fn new( root_rect: QuadRect, max_depth: u8, max_num_elements: u32, smallest_cell_size: u32, ) -> Self
pub fn insert( &mut self, element: QuadTreeElement<ElementId>, ) -> Result<(), InsertError>
Sourcepub fn remove(&mut self, element: &QuadTreeElement<ElementId>) -> bool
pub fn remove(&mut self, element: &QuadTreeElement<ElementId>) -> bool
Sourcepub fn visit_leaves<F>(&self, visit: F)
pub fn visit_leaves<F>(&self, visit: F)
Visits all leaf nodes in the tree, passing the node information to the provided closure.
Sourcepub fn cleanup(&mut self) -> bool
pub fn cleanup(&mut self) -> bool
Prunes unused child nodes from the tree.
§Remarks
The tree is never pruned automatically for performance reasons. Call this method after all elements were removed or updated.
Sourcepub fn intersect_aabb(&self, rect: &AABB) -> Vec<ElementId>
pub fn intersect_aabb(&self, rect: &AABB) -> Vec<ElementId>
Returns the set of IDs that occupy space within the specified bounding box.
§Arguments
- [
rect
] - The rectangle to test for.
Sourcepub fn intersect_aabb_fn<F>(&self, rect: &AABB, candidate_fn: F)where
F: FnMut(ElementId),
pub fn intersect_aabb_fn<F>(&self, rect: &AABB, candidate_fn: F)where
F: FnMut(ElementId),
Calls a function for each ID that occupies space within the specified bounding box. The function may be called multiple times for the same ID.
§Arguments
- [
rect
] - The rectangle to test for. - [
candidate_fn
] - The function called for each candidate element’s ID.
Sourcepub fn intersect_generic<T>(&self, element: &T) -> Vec<ElementId>where
T: IntersectsWith<AABB>,
pub fn intersect_generic<T>(&self, element: &T) -> Vec<ElementId>where
T: IntersectsWith<AABB>,
Returns the set of IDs that occupy space within the specified bounding box.
§Arguments
- [
element
] - The element to test for.
Sourcepub fn intersect_generic_fn<T, F>(&self, element: &T, candidate_fn: F)
pub fn intersect_generic_fn<T, F>(&self, element: &T, candidate_fn: F)
Calls a function for each ID that occupies space within the specified bounding box. The function may be called multiple times for the same ID.
§Arguments
- [
element
] - The element to test for. - [
candidate_fn
] - The function called for each candidate element’s ID.