[][src]Struct broccoli::container::TreeInd

#[repr(C)]pub struct TreeInd<'a, 'b, N: Num, T> { /* fields omitted */ }

A less general tree that providess collect functions and also derefs to a Tree.

TreeInd assumes there is a layer of indirection where all the pointers point to the same slice. It uses this assumption to provide collect functions that allow storing query results that can then be iterated through multiple times quickly.

Implementations

impl<'a, 'b, N: Num, T> TreeInd<'a, 'b, N, T>[src]

pub fn get_inner_elements_mut(&mut self) -> &mut [T]

Notable traits for &'_ [u8]

impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
[src]

Retrieve the underlying list of elements. Unlike Tree::get_elements_mut() which returns the aabbs of the tree, this returns the list of T that each aabb points to.

Examples

 let mut aabbs = [
    broccoli::bbox(broccoli::rect(0isize, 10, 0, 10), 0),
 ];

 let mut base=broccoli::container::TreeIndBase::new(&mut aabbs,|a|a.rect); 
 let mut tree = base.build();
 let bots=tree.get_inner_elements_mut();

pub fn get_inner_elements(&self) -> &[T]

Notable traits for &'_ [u8]

impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
[src]

Retrieve the underlying list of elements. Unlike Tree::get_elements_mut() which returns the aabbs of the tree, this returns the list of T that each aabb points to.

Examples

 let mut aabbs = [
    broccoli::bbox(broccoli::rect(0isize, 10, 0, 10), 0),
 ];

 let mut base=broccoli::container::TreeIndBase::new(&mut aabbs,|a|a.rect); 
 let mut tree = base.build();
 let bots=tree.get_inner_elements();

pub fn collect_all<D: Send + Sync>(
    &mut self,
    mut func: impl FnMut(&Rect<N>, &mut T) -> Option<D>
) -> FilteredElements<T, D>
[src]

Collect all elements based off of a predicate and return a FilteredElements.

Examples

 let mut aabbs = [
    broccoli::bbox(broccoli::rect(0isize, 10, 0, 10), 0),
    broccoli::bbox(broccoli::rect(15, 20, 15, 20), 1),
    broccoli::bbox(broccoli::rect(5, 15, 5, 15), 2),
 ];

 let mut base=broccoli::container::TreeIndBase::new(&mut aabbs,|a|a.rect); 
 let mut tree = base.build();

 //Find a group of elements only once.
 let mut pairs=tree.collect_all(|_,b| {
    if b.inner % 2 ==0{
        Some(())
    }else{
        None
    }
 });

 //Iterate over that group multiple times
 for _ in 0..3{
     //mutate every colliding pair.
     for (a,()) in pairs.get_mut(&mut aabbs){
         a.inner+=1;
     }
 }

pub fn collect_colliding_pairs<D: Send + Sync>(
    &mut self,
    mut func: impl FnMut(&mut T, &mut T) -> Option<D> + Send + Sync
) -> CollidingPairs<T, D>
[src]

Find all colliding pairs based on a predicate and return a CollidingPairs.

Examples

 let mut aabbs = [
     broccoli::bbox(broccoli::rect(0isize, 10, 0, 10), 0),
     broccoli::bbox(broccoli::rect(15, 20, 15, 20), 1),
     broccoli::bbox(broccoli::rect(5, 15, 5, 15), 2),
 ];

 let mut base=broccoli::container::TreeIndBase::new(&mut aabbs,|a|a.rect); 
 let mut tree = base.build();

 //Find all colliding aabbs only once.
 let mut pairs=tree.collect_colliding_pairs(|a, b| {
    a.inner += 1;
    b.inner += 1;
    Some(())
 });

 //Iterate over the pairs multiple times
 for _ in 0..3{
     //mutate every colliding pair.
     pairs.for_every_pair_mut(&mut aabbs,|a,b,()|{
         a.inner+=1;
         b.inner+=1;
     })
 }

pub fn collect_colliding_pairs_par<D: Send + Sync>(
    &mut self,
    func: impl Fn(&mut T, &mut T) -> Option<D> + Send + Sync + Copy
) -> CollidingPairsPar<T, D> where
    N: Send + Sync,
    T: Send + Sync
[src]

The parallel version of TreeInd::collect_colliding_pairs that instead returns a CollidingPairsPar.

Examples

 let mut aabbs = [
     broccoli::bbox(broccoli::rect(0isize, 10, 0, 10), 0),
     broccoli::bbox(broccoli::rect(15, 20, 15, 20), 1),
     broccoli::bbox(broccoli::rect(5, 15, 5, 15), 2),
 ];

 let mut base=broccoli::container::TreeIndBase::new(&mut aabbs,|a|a.rect); 
 let mut tree = base.build();

 //Find all colliding aabbs only once.
 let mut pairs=tree.collect_colliding_pairs_par(|a, b| {
    a.inner += 1;
    b.inner += 1;
    Some(())
 });

 //Iterate over the pairs multiple times
 for _ in 0..3{
     //mutate every colliding pair.
     pairs.for_every_pair_mut_par(&mut aabbs,|a,b,()|{
         a.inner+=1;
         b.inner+=1;
     })
 }

Methods from Deref<Target = Tree<'b, BBox<N, &'a mut T>>>

#[must_use]pub fn get_height(&self) -> usize[src]

Examples

 use broccoli::build;
 const NUM_ELEMENT:usize=40;
 let mut bots = [axgeom::rect(0,10,0,10);NUM_ELEMENT];
 let mut tree = broccoli::new(&mut bots);

 assert_eq!(tree.get_height(),build::TreePreBuilder::new(NUM_ELEMENT).get_height());

#[must_use]pub fn num_aabbs(&self) -> usize[src]

Examples

 use broccoli::build;
 const NUM_ELEMENT:usize=7;
 let mut bots = [axgeom::rect(0,10,0,10);NUM_ELEMENT];
 let mut tree = broccoli::new(&mut bots);

 assert_eq!(tree.num_aabbs(),7);

#[must_use]pub fn num_nodes(&self) -> usize[src]

Examples

 use broccoli::build;
 let mut bots = [axgeom::rect(0,10,0,10)];
 let mut tree = broccoli::new(&mut bots);

 assert_eq!(tree.num_nodes(),build::TreePreBuilder::new(1).num_nodes());

#[must_use]pub fn get_nodes(&self) -> &[Node<'a, T>]

Notable traits for &'_ [u8]

impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
[src]

Examples

 let mut bots = [axgeom::rect(0,10,0,10)];
 let mut tree = broccoli::new(&mut bots);

 assert_eq!(tree.get_nodes()[0].range[0], axgeom::rect(0,10,0,10));

#[must_use]pub fn get_nodes_mut(&mut self) -> PMut<'_, [Node<'a, T>]>[src]

Examples

 let mut bots = [axgeom::rect(0,10,0,10)];
 let mut tree = broccoli::new(&mut bots);

 assert_eq!(tree.get_nodes_mut().get_index_mut(0).range[0], axgeom::rect(0,10,0,10));

#[must_use]pub fn get_elements_mut(&mut self) -> PMut<'_, [T]>[src]

Return the underlying slice of aabbs in the order sorted during tree construction.

Examples

 let mut bots = [axgeom::rect(0,10,0,10)];
 let mut tree = broccoli::new(&mut bots);

 assert_eq!(*tree.get_elements_mut().get_index_mut(0), axgeom::rect(0,10,0,10));

#[must_use]pub fn get_elements(&self) -> &[T]

Notable traits for &'_ [u8]

impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
[src]

Return the underlying slice of aabbs in the order sorted during tree construction.

Examples

 let mut bots = [axgeom::rect(0,10,0,10)];
 let tree = broccoli::new(&mut bots);

 assert_eq!(tree.get_elements()[0], axgeom::rect(0,10,0,10));

Trait Implementations

impl<'a, 'b, N: Num, T> Deref for TreeInd<'a, 'b, N, T>[src]

type Target = Tree<'b, BBox<N, &'a mut T>>

The resulting type after dereferencing.

impl<'a, 'b, N: Num, T> DerefMut for TreeInd<'a, 'b, N, T>[src]

impl<'a, 'b, N: Num, T> From<TreeInd<'a, 'b, N, T>> for Tree<'b, BBox<N, &'a mut T>>[src]

Auto Trait Implementations

impl<'a, 'b, N, T> RefUnwindSafe for TreeInd<'a, 'b, N, T> where
    N: RefUnwindSafe,
    T: RefUnwindSafe
[src]

impl<'a, 'b, N, T> Send for TreeInd<'a, 'b, N, T> where
    N: Send,
    T: Send
[src]

impl<'a, 'b, N, T> Sync for TreeInd<'a, 'b, N, T> where
    N: Sync,
    T: Sync
[src]

impl<'a, 'b, N, T> Unpin for TreeInd<'a, 'b, N, T>[src]

impl<'a, 'b, N, T> !UnwindSafe for TreeInd<'a, 'b, N, T>[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pointable for T

type Init = T

The type for initializers.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.