[][src]Struct dinotree_alg::DinoTree

pub struct DinoTree<'a, A: Axis, T: Aabb> { /* fields omitted */ }

The data structure this crate revoles around.

Methods

impl<'a, T: Aabb> DinoTree<'a, DefaultA, T>[src]

pub fn new(bots: &'a mut [T]) -> DinoTree<'a, DefaultA, T>[src]

Examples

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

impl<'a, T: Aabb + Send + Sync> DinoTree<'a, DefaultA, T>[src]

pub fn new_par(bots: &'a mut [T]) -> DinoTree<'a, DefaultA, T>[src]

Examples

let mut bots = [axgeom::rect(0,10,0,10)];
let tree = dinotree_alg::DinoTree::new_par(&mut bots);

impl<'a, A: Axis, T: Aabb> DinoTree<'a, A, T>[src]

pub fn with_axis(axis: A, bots: &'a mut [T]) -> DinoTree<'a, A, T>[src]

Examples

let mut bots = [axgeom::rect(0,10,0,10)];
let tree = dinotree_alg::DinoTree::with_axis(axgeom::XAXIS,&mut bots);

impl<'a, A: Axis, T: Aabb + Send + Sync> DinoTree<'a, A, T>[src]

pub fn with_axis_par(axis: A, bots: &'a mut [T]) -> DinoTree<'a, A, T>[src]

Examples

let mut bots = [axgeom::rect(0,10,0,10)];
let tree = dinotree_alg::DinoTree::with_axis(axgeom::XAXIS,&mut bots);

impl<'a, A: Axis, T: Aabb + HasInner + Send + Sync> DinoTree<'a, A, T>[src]

pub fn assert_find_intersections_mut(&mut self)[src]

pub fn assert_k_nearest_mut<Acc>(
    &mut self,
    point: Vec2<T::Num>,
    num: usize,
    acc: &mut Acc,
    broad: impl FnMut(&mut Acc, Vec2<T::Num>, &Rect<T::Num>) -> T::Num,
    fine: impl FnMut(&mut Acc, Vec2<T::Num>, &T) -> T::Num,
    rect: Rect<T::Num>
)
[src]

pub fn assert_raycast_mut<Acc>(
    &mut self,
    ray: Ray<T::Num>,
    start: &mut Acc,
    broad: impl FnMut(&mut Acc, &Ray<T::Num>, &Rect<T::Num>) -> CastResult<T::Num>,
    fine: impl FnMut(&mut Acc, &Ray<T::Num>, &T) -> CastResult<T::Num>,
    border: Rect<T::Num>
) where
    <T as Aabb>::Num: Debug
[src]

pub fn assert_for_all_in_rect_mut(&mut self, rect: &Rect<T::Num>)[src]

pub fn assert_for_all_not_in_rect_mut(&mut self, rect: &Rect<T::Num>)[src]

pub fn assert_for_all_intersect_rect_mut(&mut self, rect: &Rect<T::Num>)[src]

impl<'a, A: Axis, T: Aabb + HasInner + Send + Sync> DinoTree<'a, A, T>[src]

pub fn find_intersections_mut_par(
    &mut self,
    func: impl Fn(&mut T::Inner, &mut T::Inner) + Send + Sync + Copy
)
[src]

Find all intersections in parallel

Examples

use dinotree_alg::*;
let mut bots = [bbox(axgeom::rect(0,10,0,10),0u8),bbox(axgeom::rect(5,15,5,15),0u8)];
let mut tree = DinoTree::new(&mut bots);
tree.find_intersections_mut_par(|a,b|{
    *a+=1;
    *b+=1;
});

assert_eq!(bots[0].inner,1);
assert_eq!(bots[1].inner,1);

pub fn find_intersections_par_ext<B: Send + Sync>(
    &mut self,
    split: impl Fn(&mut B) -> B + Send + Sync + Copy,
    fold: impl Fn(&mut B, B) + Send + Sync + Copy,
    collision: impl Fn(&mut B, &mut T::Inner, &mut T::Inner) + Send + Sync + Copy,
    acc: B
) -> B
[src]

Allows the user to potentially collect some aspect of every intersection in parallel.

Examples

use dinotree_alg::*;
let mut bots = [bbox(axgeom::rect(0,10,0,10),0u8),bbox(axgeom::rect(5,15,5,15),1u8)];
let mut tree = DinoTree::new(&mut bots);
let intersections=tree.find_intersections_par_ext(
     |_|Vec::new(),              //Start a new thread 
     |a,mut b|a.append(&mut b),  //Combine two threads
     |v,a,b|v.push((*a,*b)),     //What to do for each intersection for a thread. 
     Vec::new()                  //Starting thread
);

assert_eq!(intersections.len(),1);

impl<'a, A: Axis, T: Aabb + HasInner> DinoTree<'a, A, T>[src]

pub fn raycast_mut<Acc>(
    &mut self,
    ray: Ray<T::Num>,
    start: &mut Acc,
    broad: impl FnMut(&mut Acc, &Ray<T::Num>, &Rect<T::Num>) -> CastResult<T::Num>,
    fine: impl FnMut(&mut Acc, &Ray<T::Num>, &T) -> CastResult<T::Num>,
    border: Rect<T::Num>
) -> RayCastResult<T::Inner, T::Num>
[src]

Examples

use dinotree_alg::*;
use axgeom::*;

let border = rect(0,100,0,100);

let mut bots = [bbox(rect(0,10,0,10),vec2(5,5)),
                bbox(rect(2,5,2,5),vec2(4,4)),
                bbox(rect(4,10,4,10),vec2(5,5))];

let mut bots_copy=bots.clone();
let mut tree = DinoTree::new(&mut bots);
let ray=ray(vec2(5,-5),vec2(0,1));
let mut counter =0;
let res = tree.raycast_mut(
     ray,&mut counter,
     |c,ray,r|{*c+=1;ray.cast_to_rect(r)},
     |c,ray,t|{*c+=1;ray.inner_as::<f32>().cast_to_circle(t.inner.inner_as(),5.).map(|a|a as i32)},   //Do more fine-grained checking here.
     border);

let (bots,dis)=res.unwrap();
assert_eq!(dis,4);
assert_eq!(bots.len(),1);
assert_eq!(bots[0],&vec2(4,4));
assert_eq!(counter,3);

pub fn k_nearest_mut<Acc>(
    &mut self,
    point: Vec2<T::Num>,
    num: usize,
    start: &mut Acc,
    broad: impl FnMut(&mut Acc, Vec2<T::Num>, &Rect<T::Num>) -> T::Num,
    fine: impl FnMut(&mut Acc, Vec2<T::Num>, &T) -> T::Num,
    border: Rect<T::Num>
) -> Vec<KnearestResult<T::Inner, T::Num>>
[src]

Examples

use dinotree_alg::*;
use axgeom::*;
let border = rect(0,100,0,100);

let mut bots = [bbox(rect(0,10,0,10),vec2(0,0)),
                bbox(rect(2,5,2,5),vec2(0,5)),
                bbox(rect(4,10,4,10),vec2(3,3))];

let mut bots_copy=bots.clone();
let mut tree = DinoTree::new(&mut bots);

let mut counter = 0;
let res = tree.k_nearest_mut(
     vec2(0,0),
     2,
     &mut counter,
     |c,p,r|{*c+=1;r.distance_squared_to_point(p).unwrap_or(0)},
     |c,p,t|{*c+=1;t.inner.distance_squared_to_point(p)},    //Do more fine-grained checking here.
     border);

assert_eq!(res.len(),2);
assert_eq!(*res[0].bot,bots_copy[0].inner);
assert_eq!(*res[1].bot,bots_copy[2].inner);
assert_eq!(counter,3);

pub fn intersect_with_mut<X: Aabb<Num = T::Num> + HasInner>(
    &mut self,
    other: &mut [X],
    func: impl Fn(&mut T::Inner, &mut X::Inner)
)
[src]

Examples

use dinotree_alg::*;
let mut bots1 = [bbox(axgeom::rect(0,10,0,10),0u8)];
let mut bots2 = [bbox(axgeom::rect(5,15,5,15),0u8)];
let mut tree = DinoTree::new(&mut bots1);

tree.intersect_with_mut(&mut bots2,|a,b|{
    *a+=1;
    *b+=2;    
});

assert_eq!(bots1[0].inner,1);
assert_eq!(bots2[0].inner,2);

pub fn for_all_not_in_rect_mut(
    &mut self,
    rect: &Rect<T::Num>,
    func: impl FnMut(&mut T::Inner)
)
[src]

Examples

use dinotree_alg::*;
let mut bots = [bbox(axgeom::rect(0,10,0,10),0u8)];
let mut tree = DinoTree::new(&mut bots);
tree.for_all_not_in_rect_mut(&axgeom::rect(10,20,10,20),|a|{
    *a+=1;    
});

assert_eq!(bots[0].inner,1);

pub fn for_all_intersect_rect_mut(
    &mut self,
    rect: &Rect<T::Num>,
    func: impl FnMut(&mut T::Inner)
)
[src]

Examples

use dinotree_alg::*;
let mut bots = [bbox(axgeom::rect(0,10,0,10),0u8)];
let mut tree = DinoTree::new(&mut bots);
tree.for_all_intersect_rect_mut(&axgeom::rect(9,20,9,20),|a|{
    *a+=1;    
});

assert_eq!(bots[0].inner,1);

pub fn for_all_in_rect_mut(
    &mut self,
    rect: &Rect<T::Num>,
    func: impl FnMut(&mut T::Inner)
)
[src]

Examples

use dinotree_alg::*;
let mut bots = [bbox(axgeom::rect(0,10,0,10),0u8)];
let mut tree = DinoTree::new(&mut bots);
tree.for_all_in_rect_mut(&axgeom::rect(0,10,0,10),|a|{
    *a+=1;    
});

assert_eq!(bots[0].inner,1);

pub fn find_intersections_mut(
    &mut self,
    func: impl FnMut(&mut T::Inner, &mut T::Inner)
)
[src]

Find all aabb intersections

Examples

use dinotree_alg::*;
let mut bots = [bbox(axgeom::rect(0,10,0,10),0u8),bbox(axgeom::rect(5,15,5,15),0u8)];
let mut tree = DinoTree::new(&mut bots);
tree.find_intersections_mut(|a,b|{
    *a+=1;
    *b+=1;
});

assert_eq!(bots[0].inner,1);
assert_eq!(bots[1].inner,1);

pub fn find_intersections_pmut(&mut self, func: impl FnMut(PMut<T>, PMut<T>))[src]

Find all aabb intersections and return a PMut of it. Unlike the regular find_intersections_mut, this allows the user to access a read only reference of the AABB.

Examples

use dinotree_alg::*;
let mut bots = [bbox(axgeom::rect(0,10,0,10),0u8),bbox(axgeom::rect(5,15,5,15),0u8)];
let mut tree = DinoTree::new(&mut bots);
tree.find_intersections_pmut(|mut a,mut b|{
    *a.inner_mut()+=1;
    *b.inner_mut()+=1;
});

assert_eq!(bots[0].inner,1);
assert_eq!(bots[1].inner,1);

impl<'a, A: Axis, T: Aabb> DinoTree<'a, A, T>[src]

pub fn get_bots(&self) -> &[T][src]

pub fn get_bots_mut(&mut self) -> PMut<[T]>[src]

pub fn axis(&self) -> A[src]

Examples

use dinotree_alg::*;
let mut bots = [axgeom::rect(0,10,0,10)];
let mut tree = DinoTree::new(&mut bots);

use axgeom::Axis;
assert!(tree.axis().is_equal_to(default_axis()));

pub fn vistr_mut(&mut self) -> VistrMut<NodeMut<'a, T>>[src]

Examples

use dinotree_alg::*;
let mut bots = [bbox(axgeom::rect(0,10,0,10),0)];
let mut tree = DinoTree::new(&mut bots);

use compt::Visitor;
for mut b in tree.vistr_mut().dfs_preorder_iter().flat_map(|n|n.get_mut().bots.iter_mut()){
    *b.inner_mut()+=1;    
}
assert_eq!(bots[0].inner,1);

pub fn vistr(&self) -> Vistr<NodeMut<'a, T>>[src]

Examples

use dinotree_alg::*;
let mut bots = [axgeom::rect(0,10,0,10)];
let mut tree = DinoTree::new(&mut bots);

use compt::Visitor;
let mut test = Vec::new();
for b in tree.vistr().dfs_preorder_iter().flat_map(|n|n.get().bots.iter()){
    test.push(b);
}
assert_eq!(test[0],&axgeom::rect(0,10,0,10));

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

Examples

use dinotree_alg::*;
let mut bots = vec![axgeom::rect(0,10,0,10);400];
let mut tree = DinoTree::new(&mut bots);

assert_eq!(tree.get_height(),analyze::compute_tree_height_heuristic(400,analyze::DEFAULT_NUMBER_ELEM_PER_NODE));

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

Examples

use dinotree_alg::*;
let mut bots = vec![axgeom::rect(0,10,0,10);400];
let mut tree = DinoTree::new(&mut bots);

assert_eq!(tree.num_nodes(),analyze::nodes_left(0,tree.get_height() ));

impl<'a, A: Axis, T: Aabb> DinoTree<'a, A, T>[src]

pub fn draw(
    &self,
    drawer: &mut impl DividerDrawer<N = T::Num>,
    rect: &Rect<T::Num>
)
[src]

Examples

use dinotree_alg::*;
use axgeom::*;

struct Drawer;
impl dinotree_alg::query::DividerDrawer for Drawer{
    type N=i32;
    fn draw_divider<A:Axis>(
            &mut self,
            axis:A,
            div:Self::N,
            cont:[Self::N;2],
            length:[Self::N;2],
            depth:usize)
    {
        if axis.is_xaxis(){
            //draw vertical line
        }else{
            //draw horizontal line
        }
    }
}

let border=rect(0,100,0,100);
let mut bots =[rect(0,10,0,10)];
let tree=DinoTree::new(&mut bots);
tree.draw(&mut Drawer,&border);

#[must_use]pub fn multi_rect<'b>(&'b mut self) -> MultiRectMut<'b, 'a, A, T>[src]

Examples

use dinotree_alg::*;
let mut bots1 = [bbox(axgeom::rect(0,10,0,10),0u8)];
let mut tree = DinoTree::new(&mut bots1);
let mut multi = tree.multi_rect();

multi.for_all_in_rect_mut(axgeom::rect(0,10,0,10),|a|{}).unwrap();
let res = multi.for_all_in_rect_mut(axgeom::rect(5,15,5,15),|a|{});
assert_eq!(res,Err(dinotree_alg::query::RectIntersectErr));

pub fn for_all_intersect_rect<'b>(
    &'b self,
    rect: &Rect<T::Num>,
    func: impl FnMut(&'b T)
)
[src]

Examples

use dinotree_alg::*;
let mut bots = [axgeom::rect(0,10,0,10),axgeom::rect(20,30,20,30)];
let mut tree = DinoTree::new(&mut bots);
let mut test = Vec::new();
tree.for_all_intersect_rect(&axgeom::rect(9,20,9,20),|a|{
    test.push(a);
});

assert_eq!(test[0],&axgeom::rect(0,10,0,10));

pub fn for_all_in_rect<'b>(
    &'b self,
    rect: &Rect<T::Num>,
    func: impl FnMut(&'b T)
)
[src]

Examples

use dinotree_alg::*;
let mut bots = [axgeom::rect(0,10,0,10),axgeom::rect(20,30,20,30)];
let mut tree = DinoTree::new(&mut bots);
let mut test = Vec::new();
tree.for_all_in_rect(&axgeom::rect(0,20,0,20),|a|{
    test.push(a);
});

assert_eq!(test[0],&axgeom::rect(0,10,0,10));

Auto Trait Implementations

impl<'a, A, T> RefUnwindSafe for DinoTree<'a, A, T> where
    A: RefUnwindSafe,
    T: RefUnwindSafe,
    <T as Aabb>::Num: RefUnwindSafe

impl<'a, A, T> Send for DinoTree<'a, A, T> where
    T: Send,
    <T as Aabb>::Num: Send

impl<'a, A, T> Sync for DinoTree<'a, A, T> where
    T: Sync,
    <T as Aabb>::Num: Sync

impl<'a, A, T> Unpin for DinoTree<'a, A, T> where
    A: Unpin,
    <T as Aabb>::Num: Unpin

impl<'a, A, T> !UnwindSafe for DinoTree<'a, A, T>

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, 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.