pub struct Quadtree { /* private fields */ }Expand description
An axis-aligned 2D spatial partitioning tree.
§Contract
- Insertions that fall entirely outside
boundsare silently dropped. retrievereturns ALL rects in leaf nodes that overlap the query rect; callers must perform their own exact AABB test on the returned set.- Maximum recursion depth is capped at
max_depth(default 5) to bound memory usage even with degenerate inputs (all rects at one point).
Implementations§
Source§impl Quadtree
impl Quadtree
Sourcepub fn new(bounds: Rect) -> Self
pub fn new(bounds: Rect) -> Self
Create a new root QuadTree node covering the given bounds.
Default capacity per leaf is 10 rects, maximum depth is 5 levels.
Sourcepub fn insert(&mut self, rect: Rect)
pub fn insert(&mut self, rect: Rect)
Insert a rect into the tree.
The rect is dropped if it does not intersect this node’s bounds. If this is an interior node (already subdivided), the rect is propagated to all overlapping children. Otherwise it is stored in this leaf; if the leaf is now over capacity and below max depth, the node is subdivided and existing rects redistributed.
Sourcepub fn retrieve(&self, rect: Rect, out: &mut Vec<Rect>)
pub fn retrieve(&self, rect: Rect, out: &mut Vec<Rect>)
Collect all candidate rects that may overlap rect into out.
This is a broad-phase query: returned rects are candidates from overlapping
leaf nodes. Callers MUST perform their own exact intersection test on results.
The out vec is appended to — it is never cleared.
Auto Trait Implementations§
impl Freeze for Quadtree
impl RefUnwindSafe for Quadtree
impl Send for Quadtree
impl Sync for Quadtree
impl Unpin for Quadtree
impl UnsafeUnpin for Quadtree
impl UnwindSafe for Quadtree
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.