pub struct QuadTree<T, S, A: Array<Item = (ItemId, TypedRect<f32, S>)>> { /* private fields */ }
Expand description
The main QuadTree structure. Mainly supports inserting, removing, and querying objects in 3d space.
Implementations§
Source§impl<T, S, A: Array<Item = (ItemId, TypedRect<f32, S>)>> QuadTree<T, S, A>
impl<T, S, A: Array<Item = (ItemId, TypedRect<f32, S>)>> QuadTree<T, S, A>
Sourcepub fn new(
size: TypedRect<f32, S>,
allow_duplicates: bool,
min_children: usize,
max_children: usize,
max_depth: usize,
size_hint: usize,
) -> QuadTree<T, S, A>
pub fn new( size: TypedRect<f32, S>, allow_duplicates: bool, min_children: usize, max_children: usize, max_depth: usize, size_hint: usize, ) -> QuadTree<T, S, A>
Constructs a new QuadTree with customizable options.
size
: the enclosing space for the quad-tree.allow_duplicates
: if false, the quadtree will remove objects that have the same bounding box.min_children
: the minimum amount of children that a tree node will have. *max_children
: the maximum amount of children that a tree node will have before it gets split. *max_depth
: the maximum depth that the tree can grow before it stops.
Sourcepub fn default(size: TypedRect<f32, S>, size_hint: usize) -> QuadTree<T, S, A>
pub fn default(size: TypedRect<f32, S>, size_hint: usize) -> QuadTree<T, S, A>
Constructs a new QuadTree with customizable options.
size
: the enclosing space for the quad-tree.
§Defauts
allow_duplicates
: truemin_children
: 4max_children
: 16max_depth
: 8
Sourcepub fn insert_with_box(
&mut self,
t: T,
aabb: TypedRect<f32, S>,
) -> Option<ItemId>
pub fn insert_with_box( &mut self, t: T, aabb: TypedRect<f32, S>, ) -> Option<ItemId>
Inserts an element with the provided bounding box.
Sourcepub fn first(&self) -> Option<ItemId>
pub fn first(&self) -> Option<ItemId>
Returns an ItemId for the first element that was inserted into the tree.
Sourcepub fn insert(&mut self, t: T) -> Option<ItemId>where
T: Spatial<S>,
pub fn insert(&mut self, t: T) -> Option<ItemId>where
T: Spatial<S>,
Inserts an element into the tree.
Sourcepub fn get(&self, id: ItemId) -> Option<&T>
pub fn get(&self, id: ItemId) -> Option<&T>
Retrieves an element by looking it up from the ItemId.
Sourcepub fn query(
&self,
bounding_box: TypedRect<f32, S>,
) -> SmallVec<[(&T, TypedRect<f32, S>, ItemId); 3]>where
T: Debug,
pub fn query(
&self,
bounding_box: TypedRect<f32, S>,
) -> SmallVec<[(&T, TypedRect<f32, S>, ItemId); 3]>where
T: Debug,
Returns an iterator of (element, bounding-box, id)
for each element whose bounding box intersects
with bounding_box
.
Sourcepub fn custom_query<'a, B, F>(
&'a self,
query_aabb: TypedRect<f32, S>,
on_find: &mut F,
) -> QueryResult<B>
pub fn custom_query<'a, B, F>( &'a self, query_aabb: TypedRect<f32, S>, on_find: &mut F, ) -> QueryResult<B>
Executes ‘on_find’ for every element found in the bounding-box
Sourcepub fn remove(&mut self, item_id: ItemId) -> Option<(T, TypedRect<f32, S>)>
pub fn remove(&mut self, item_id: ItemId) -> Option<(T, TypedRect<f32, S>)>
Attempts to remove the item with id item_id
from
the tree. If that item was present, it returns
a tuple of (element, bounding-box)
Sourcepub fn iter(&self) -> Iter<'_, ItemId, (T, TypedRect<f32, S>)>
pub fn iter(&self) -> Iter<'_, ItemId, (T, TypedRect<f32, S>)>
Returns an iterator over all the items in the tree.
Sourcepub fn inspect<F: FnMut(&TypedRect<f32, S>, usize, bool)>(&self, f: F)
pub fn inspect<F: FnMut(&TypedRect<f32, S>, usize, bool)>(&self, f: F)
Calls f
repeatedly for every node in the tree
with these arguments
&Rect
: The boudning box of that tree nodeusize
: The current depthbool
: True if the node is a leaf-node, False if the node is a branch node.
Sourcepub fn bounding_box(&self) -> TypedRect<f32, S>
pub fn bounding_box(&self) -> TypedRect<f32, S>
Returns the enclosing bounding-box for the entire tree.