Skip to main content

Quadtree2D

Struct Quadtree2D 

Source
pub struct Quadtree2D { /* private fields */ }
Expand description

Adaptive 2D quadtree supporting dynamic insert/remove/update, rect, radius, and k-NN queries.

Implementations§

Source§

impl Quadtree2D

Dynamic insertion, update, removal, and spatial queries for Quadtree2D.

Source

pub fn new(root_bounds: Bounds2D, config: QuadtreeConfig) -> Self

Creates an empty Quadtree2D spanning root_bounds.

§Arguments
  • Bounds2D - World-space root bounds.
  • QuadtreeConfig - Leaf capacity and depth parameters.
§Returns
  • Self - Empty adaptive 2D quadtree.
Source

pub fn len(&self) -> usize

Returns the total number of indexed items currently stored in this quadtree.

§Returns
  • usize - Number of stored items.
Source

pub fn is_empty(&self) -> bool

Returns true when the quadtree contains no items.

§Returns
  • bool - Whether the quadtree is empty.
Source

pub fn clear(&mut self)

Removes all items and resets the tree to a single empty root node.

Source

pub fn insert(&mut self, id: u64, position: Vec2) -> bool

Inserts or updates an item (id, position); returns false if position is outside root bounds or non-finite.

§Arguments
  • u64 - Unique item identifier.
  • Vec2 - World-space 2D position.
§Returns
  • bool - true when inserted or updated inside root bounds.
Source

pub fn remove(&mut self, id: u64) -> bool

Removes the item with identifier id from the quadtree.

§Arguments
  • u64 - Item identifier to remove.
§Returns
  • bool - true if the item existed and was removed.
Source

pub fn update(&mut self, id: u64, new_position: Vec2) -> bool

Moves an existing item id to new_position, updating in place when remaining in the same leaf.

§Arguments
  • u64 - Existing item identifier.
  • Vec2 - New world-space 2D position.
§Returns
  • bool - true when id existed and new_position lies inside root bounds.
Source

pub fn query_rect(&self, query_bounds: Bounds2D, out: &mut Vec<u64>)

Queries all items whose positions lie inside query_bounds, writing IDs into out.

§Arguments
  • Bounds2D - Axis-aligned query rectangle.
  • &mut Vec<u64> - Reusable output identifier buffer (cleared first).
Source

pub fn query_radius(&self, center: Vec2, radius: f32, out: &mut Vec<u64>)

Queries all items within Euclidean distance <= radius of center, writing IDs into out.

§Arguments
  • Vec2 - Query circle center.
  • f32 - Query radius (non-negative).
  • &mut Vec<u64> - Reusable output identifier buffer (cleared first).
Source

pub fn query_k_nearest( &mut self, center: Vec2, k: usize, out: &mut Vec<(u64, f32)>, )

Finds the exact k nearest items to center using best-first branch-and-bound traversal.

§Arguments
  • Vec2 - Query center point.
  • usize - Maximum number of nearest neighbors to return.
  • &mut Vec<(u64, f32)> - Reusable output receiving (id, euclidean_distance) sorted ascending.
Source§

impl Quadtree2D

Implements impl #impl_generics #name #ty_generics #where_clause.

Source

pub fn get_root_bounds(&self) -> Bounds2D

Source

pub fn get_mut_root_bounds(&mut self) -> &mut Bounds2D

Source

pub fn set_root_bounds(&mut self, val: Bounds2D) -> &mut Self

Source

pub fn get_config(&self) -> QuadtreeConfig

Source

pub fn get_mut_config(&mut self) -> &mut QuadtreeConfig

Source

pub fn set_config(&mut self, val: QuadtreeConfig) -> &mut Self

Trait Implementations§

Source§

impl Clone for Quadtree2D

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Quadtree2D

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Forget for Quadtree2D

§

impl Freeze for Quadtree2D

§

impl Move for Quadtree2D

§

impl RefUnwindSafe for Quadtree2D

§

impl Send for Quadtree2D
where RawVecInner: Send, RawTable<(u64, Vec2)>: Send,

§

impl Sync for Quadtree2D
where RawVecInner: Sync, RawTable<(u64, Vec2)>: Sync,

§

impl Unpin for Quadtree2D
where *const u8 is !null: Unpin,

§

impl UnsafeUnpin for Quadtree2D

§

impl UnwindSafe for Quadtree2D
where RawVecInner: UnwindSafe, HashMap<u64, Vec2>: UnwindSafe,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.