Struct tpntree::tpntree::TpnTree

source ·
pub struct TpnTree<T, const N: usize> { /* private fields */ }

Implementations§

Iterate the tree breadth first, starting with the root.

Iterate the tree depth first, starting with the root.

Calculate the variance of TpnTrees with f64 data.

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);

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());

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());

Creates a new TpnTree.

Use this function if you need explicit control over the initial coordinates or a span with various length along different axis. Usually the TpnTree::root function should suffice and is simpler to use.

Examples

Here we create a one dimensional tree, i.e. with one axis sitting on the center [0.0] with a span of 1.0 in each direction [1.0]. This is equal to a line segment spanning from -1.0 to 1.0 with its midpoint at 0.0. The level of the root is usually zero.


let root = TpnTree::<(), 1>::new([0.0], [1.0], 0);

Now lets create a two dimensional tree. The tree root corresponds to a square with its center sitting at the coordinates (1.0/1.0) with edges one edge being 4.0 the other being 1.0 units long. The edges equate to twice the span as it originates from the midpoint.

let root = TpnTree::<(), 2>::new([1.0, 1.0], [2.0, 0.5], 0);

Creates a new TpnTree with equal span in all dimension at the center of the space at level zero.

Use this function if you want your TpnTree to represenst a centered N-dimensional hypercube.

Examples

Here we create a three dimensional TpnTree with a span of 1.0 in ervery dimension. That is equal to a cube with edges of length 2.0.

let root = TpnTree::<(), 3>::root(1.0);

Divides the TpnTree into subregions creating new TpnTrees as children.

Returns true if division happened, returns false when already divided.

Each created child has its center moved by half the parents span up or down along the axis. Every child is equal to one unique combination of such half span moves.

Examples

Dividing in the 2D case is creating four smaller squares.

// +---+    +-+-+
// |   | => +-+-+
// +---+    +-+-+
let mut root = TpnTree::<(), 2>::root(1.0);

assert!(root.divide().is_ok());
assert_eq!(root.child_count(), 4);

Get a reference to a child TpnTree if it exists.

Get a mutable reference to a child TpnTree if it exists.

Returns the count of direct children.

Iterates all direct children by reference.

Iterates all direct children by mutable reference.

Returns the coordinates of the center of the TpnTree.

Returns the span of the TpnTree.

Returns the data by reference of the TpnTree.

Returns the data by mutable reference of the TpnTree.

Returns the level of the TpnTree.

Returns wheter the tree is a root.

Returns wheter the tree is a leaf.

Returns a list of adjacent trees along each dimension.

The trees appear in order of dimension and that first the tree above self, then the one below. Thereby there will be dimension times two TpnTrees returned.

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Converts self into T using Into<T>. Read more
Causes self to use its Binary implementation when Debug-formatted.
Causes self to use its Display implementation when Debug-formatted.
Causes self to use its LowerExp implementation when Debug-formatted.
Causes self to use its LowerHex implementation when Debug-formatted.
Causes self to use its Octal implementation when Debug-formatted.
Causes self to use its Pointer implementation when Debug-formatted.
Causes self to use its UpperExp implementation when Debug-formatted.
Causes self to use its UpperHex implementation when Debug-formatted.
Formats each item in a sequence. Read more

Returns the argument unchanged.

Calls U::from(self).

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

Pipes by value. This is generally the method you want to use. Read more
Borrows self and passes that borrow into the pipe function. Read more
Mutably borrows self and passes that borrow into the pipe function. Read more
Borrows self, then passes self.borrow() into the pipe function. Read more
Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
Borrows self, then passes self.as_ref() into the pipe function.
Mutably borrows self, then passes self.as_mut() into the pipe function.
Borrows self, then passes self.deref() into the pipe function.
Mutably borrows self, then passes self.deref_mut() into the pipe function.
Should always be Self
The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Checks if self is actually part of its subset T (and can be converted to it).
Use with care! Same as self.to_subset but without any property checks. Always succeeds.
The inclusion map: converts self to the equivalent element of its superset.
Immutable access to a value. Read more
Mutable access to a value. Read more
Immutable access to the Borrow<B> of a value. Read more
Mutable access to the BorrowMut<B> of a value. Read more
Immutable access to the AsRef<R> view of a value. Read more
Mutable access to the AsMut<R> view of a value. Read more
Immutable access to the Deref::Target of a value. Read more
Mutable access to the Deref::Target of a value. Read more
Calls .tap() only in debug builds, and is erased in release builds.
Calls .tap_mut() only in debug builds, and is erased in release builds.
Calls .tap_borrow() only in debug builds, and is erased in release builds.
Calls .tap_borrow_mut() only in debug builds, and is erased in release builds.
Calls .tap_ref() only in debug builds, and is erased in release builds.
Calls .tap_ref_mut() only in debug builds, and is erased in release builds.
Calls .tap_deref() only in debug builds, and is erased in release builds.
Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Attempts to convert self into T using TryInto<T>. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.