Struct QuadTree

Source
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>

Source

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.
Source

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: true
  • min_children: 4
  • max_children: 16
  • max_depth: 8
Source

pub fn insert_with_box( &mut self, t: T, aabb: TypedRect<f32, S>, ) -> Option<ItemId>

Inserts an element with the provided bounding box.

Source

pub fn first(&self) -> Option<ItemId>

Returns an ItemId for the first element that was inserted into the tree.

Source

pub fn insert(&mut self, t: T) -> Option<ItemId>
where T: Spatial<S>,

Inserts an element into the tree.

Source

pub fn get(&self, id: ItemId) -> Option<&T>

Retrieves an element by looking it up from the ItemId.

Source

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.

Source

pub fn custom_query<'a, B, F>( &'a self, query_aabb: TypedRect<f32, S>, on_find: &mut F, ) -> QueryResult<B>
where F: FnMut(ItemId, TypedRect<f32, S>) -> QueryResult<B>,

Executes ‘on_find’ for every element found in the bounding-box

Source

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)

Source

pub fn iter(&self) -> Iter<'_, ItemId, (T, TypedRect<f32, S>)>

Returns an iterator over all the items in the tree.

Source

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 node
  • usize: The current depth
  • bool: True if the node is a leaf-node, False if the node is a branch node.
Source

pub fn len(&self) -> usize

Returns the number of elements in the tree

Source

pub fn is_empty(&self) -> bool

Returns true if the tree is empty.

Source

pub fn bounding_box(&self) -> TypedRect<f32, S>

Returns the enclosing bounding-box for the entire tree.

Trait Implementations§

Source§

impl<T: Clone, S: Clone, A: Clone + Array<Item = (ItemId, TypedRect<f32, S>)>> Clone for QuadTree<T, S, A>

Source§

fn clone(&self) -> QuadTree<T, S, A>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug, S, A: Array<Item = (ItemId, TypedRect<f32, S>)>> Debug for QuadTree<T, S, A>

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T, S, A> Freeze for QuadTree<T, S, A>
where A: Freeze,

§

impl<T, S, A> RefUnwindSafe for QuadTree<T, S, A>

§

impl<T, S, A> Send for QuadTree<T, S, A>
where S: Send, T: Send,

§

impl<T, S, A> Sync for QuadTree<T, S, A>
where A: Sync, S: Sync, T: Sync,

§

impl<T, S, A> Unpin for QuadTree<T, S, A>
where S: Unpin, A: Unpin, T: Unpin,

§

impl<T, S, A> UnwindSafe for QuadTree<T, S, A>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.