Skip to main content

LooseOctree

Struct LooseOctree 

Source
pub struct LooseOctree<T: Clone> {
    pub center: [f64; 3],
    pub half_size: f64,
    pub depth: u32,
    pub items: Vec<(usize, [f64; 3], T)>,
    pub children: Option<Box<[LooseOctree<T>; 8]>>,
}
Expand description

A loose octree node that stores items at every level.

Fields§

§center: [f64; 3]

World-space centre of this node.

§half_size: f64

Half-size of the tight cell (the loose cell is 2 * half_size).

§depth: u32

Remaining subdivision depth (0 = leaf).

§items: Vec<(usize, [f64; 3], T)>

Items stored at this node (not yet pushed to children).

§children: Option<Box<[LooseOctree<T>; 8]>>

Eight children, present after the first subdivision.

Implementations§

Source§

impl<T: Clone> LooseOctree<T>

Source

pub fn new(center: [f64; 3], half_size: f64, max_depth: u32) -> Self

Creates a new root node.

Source

pub fn child_index(&self, pos: [f64; 3]) -> usize

Returns the octant index (0..7) for pos relative to self.center.

Source

pub fn insert(&mut self, id: usize, pos: [f64; 3], data: T, max_items: usize)

Inserts (id, pos, data) into the tree.

Source

pub fn query_sphere(&self, center: [f64; 3], radius: f64) -> Vec<(usize, &T)>

Returns all items whose stored position is within radius of center.

Source

pub fn query_aabb(&self, min: [f64; 3], max: [f64; 3]) -> Vec<(usize, &T)>

Returns all items within an axis-aligned box.

Source

pub fn item_count(&self) -> usize

Counts all items stored in this node and all descendants.

Source

pub fn max_depth_reached(&self) -> u32

Returns the maximum depth reached in the tree.

Source

pub fn node_count(&self) -> usize

Count the total number of nodes in the tree.

Source

pub fn k_nearest(&self, center: [f64; 3], k: usize) -> Vec<(usize, f64, &T)>

K-nearest neighbours search via the octree.

Auto Trait Implementations§

§

impl<T> Freeze for LooseOctree<T>

§

impl<T> RefUnwindSafe for LooseOctree<T>
where T: RefUnwindSafe,

§

impl<T> Send for LooseOctree<T>
where T: Send,

§

impl<T> Sync for LooseOctree<T>
where T: Sync,

§

impl<T> Unpin for LooseOctree<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for LooseOctree<T>

§

impl<T> UnwindSafe for LooseOctree<T>
where T: 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> 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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.