Skip to main content

RegionTree

Struct RegionTree 

Source
pub struct RegionTree<const D: usize> { /* private fields */ }
Expand description

A point tree over an axis-aligned region of D-space. Each leaf holds up to capacity points before splitting into 2^D equal sub-boxes (down to max_depth levels, so coincident points cannot cause unbounded splitting). Entries are (id, point) pairs; ids are chosen by the caller.

See QuadTree (D = 2) and OctTree (D = 3).

Implementations§

Source§

impl<const D: usize> RegionTree<D>

Source

pub fn new(min: [f64; D], max: [f64; D]) -> Self

An empty tree covering [min, max] with leaf capacity 8 and depth limit 20.

Source

pub fn with_limits( min: [f64; D], max: [f64; D], capacity: usize, max_depth: usize, ) -> Self

Source

pub fn from_points(points: &[[f64; D]]) -> Self

Builds a tree sized to the bounding box of points, using each point’s index as its id.

Source

pub fn insert(&mut self, id: usize, point: [f64; D]) -> bool

Adds a point; returns false (and stores nothing) if it is non-finite or outside the region.

Source

pub fn remove(&mut self, id: usize, point: [f64; D]) -> bool

Removes the entry with this id and point; returns whether it was present.

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn query_box(&self, min: [f64; D], max: [f64; D]) -> Vec<usize>

Ids of all points in the box [min, max] (inclusive).

Source

pub fn query_radius(&self, centre: [f64; D], radius: f64) -> Vec<usize>

Ids of all points within radius of centre (inclusive).

Source

pub fn k_nearest(&self, query: [f64; D], k: usize) -> Vec<(usize, f64)>

The k nearest points as (id, distance), nearest first (ties by id).

Source

pub fn nearest(&self, query: [f64; D]) -> Option<(usize, f64)>

Source

pub fn depth(&self) -> usize

Deepest level reached by any leaf (0 for a single leaf), for diagnostics.

Trait Implementations§

Source§

impl<const D: usize> Clone for RegionTree<D>

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<const D: usize> Debug for RegionTree<D>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<const D: usize> Freeze for RegionTree<D>

§

impl<const D: usize> RefUnwindSafe for RegionTree<D>

§

impl<const D: usize> Send for RegionTree<D>

§

impl<const D: usize> Sync for RegionTree<D>

§

impl<const D: usize> Unpin for RegionTree<D>

§

impl<const D: usize> UnsafeUnpin for RegionTree<D>

§

impl<const D: usize> UnwindSafe for RegionTree<D>

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> MaybeSerialize for T
where T: ?Sized,

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.