Type Definition tpntree::tpntree::SpatialTree
source · Expand description
A helper type to work with spatial data bins.
Implementations§
source§impl<T: Coordinates<N>, const N: usize> SpatialTree<T, N>
impl<T: Coordinates<N>, const N: usize> SpatialTree<T, N>
sourcepub fn spans(&self, data: &T) -> bool
pub fn spans(&self, data: &T) -> bool
Checks if the tree spans over the coordinates of the provided data.
let tree = Tree3D::root(1.0);
assert_eq!(tree.spans(&[0.5,0.5,0.5]), true);
assert_eq!(tree.spans(&[1.5,0.5,0.5]), false);
sourcepub fn insert_by_coordinates(
&mut self,
data: T,
division_condition: &dyn Fn(&Self) -> bool
) -> Result<(), TpnTreeError>
pub fn insert_by_coordinates(
&mut self,
data: T,
division_condition: &dyn Fn(&Self) -> bool
) -> Result<(), TpnTreeError>
Inserts data in the tree with its center closest to the data given the constrains of the division_condition
.
The division condition
determines when a tree divides and inserts its data into its children.
Errors if the tree does not span the data.
let mut tree = Tree3D::root(1.0);
assert!(tree.insert_by_coordinates([1.0, 0.0, -1.0], &|_| false).is_ok());
sourcepub fn find_by_coordinates(&self, data: &T) -> Result<&Self, TpnTreeError>
pub fn find_by_coordinates(&self, data: &T) -> Result<&Self, TpnTreeError>
Return the tree closest to the given data coordinates.
Errors if the tree does not span the data.
let mut tree = Tree3D::root(1.0);
tree.insert_by_coordinates([1.0, 0.0, -1.0], &|_| false).expect("Couldn't insert.");
assert!(tree
.find_by_coordinates(&[0.0, 0.0, 0.0])
.ok()
.and_then(|tree| tree.data().map(|vec| vec.contains(&[1.0, 0.0, -1.0])))
.unwrap());