[−][src]Struct dinotree_alg::DinoTree
The data structure this crate revoles around.
Methods
impl<'a, T: Aabb> DinoTree<DefaultA, NodeMut<'a, T>>
[src]
pub fn new(bots: &'a mut [T]) -> DinoTree<DefaultA, NodeMut<'a, 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<DefaultA, NodeMut<'a, T>>
[src]
pub fn new_par(bots: &'a mut [T]) -> DinoTree<DefaultA, NodeMut<'a, 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, NodeMut<'a, T>>
[src]
pub fn with_axis(axis: A, bots: &'a mut [T]) -> DinoTree<A, NodeMut<'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, NodeMut<'a, T>>
[src]
pub fn with_axis_par(axis: A, bots: &'a mut [T]) -> DinoTree<A, NodeMut<'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: Axis, N: Node + Send + Sync> DinoTree<A, N> where
N::T: Send + Sync,
[src]
N::T: Send + Sync,
pub fn find_collisions_mut_par(
&mut self,
func: impl Fn(PMut<N::T>, PMut<N::T>) + Send + Sync
)
[src]
&mut self,
func: impl Fn(PMut<N::T>, PMut<N::T>) + Send + Sync
)
Examples
use dinotree_alg::prelude::*; 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_collisions_mut_par(|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: Axis, N: Node> DinoTree<A, N>
[src]
pub fn k_nearest_mut(
&mut self,
point: Vec2<N::Num>,
num: usize,
distance: impl Fn(Vec2<N::Num>, &Rect<N::Num>) -> N::Num,
border: Rect<N::Num>
) -> Vec<KnearestResult<N::T>>
[src]
&mut self,
point: Vec2<N::Num>,
num: usize,
distance: impl Fn(Vec2<N::Num>, &Rect<N::Num>) -> N::Num,
border: Rect<N::Num>
) -> Vec<KnearestResult<N::T>>
Examples
use dinotree_alg::prelude::*; use axgeom::*; let border = rect(0,100,0,100); let mut bots = [rect(0,10,0,10), rect(2,5,2,5), rect(4,10,4,10)]; let mut bots_copy=bots.clone(); let mut tree = DinoTree::new(&mut bots); let res = tree.k_nearest_mut(vec2(0,0),2,|a,b|b.distance_squared_to_point(a).unwrap_or(0),border); assert_eq!(res.len(),2); assert_eq!(res[0].bot.get(),&bots_copy[0]); assert_eq!(res[1].bot.get(),&bots_copy[1]);
pub fn k_nearest_fine_mut(
&mut self,
point: Vec2<N::Num>,
num: usize,
knear: &mut impl Knearest<N = N::Num, T = N::T>,
border: Rect<N::Num>
) -> Vec<KnearestResult<N::T>>
[src]
&mut self,
point: Vec2<N::Num>,
num: usize,
knear: &mut impl Knearest<N = N::Num, T = N::T>,
border: Rect<N::Num>
) -> Vec<KnearestResult<N::T>>
Examples
use dinotree_alg::prelude::*; use axgeom::*; let border = rect(0,100,0,100); struct Foo; impl Knearest for Foo{ type T=BBox<i32,Vec2<i32>>; type N=i32; fn distance_to_rect(&self, point: Vec2<Self::N>, rect: &Rect<Self::N>) -> Self::N{ rect.distance_squared_to_point(point).unwrap_or(0) } fn distance_to_bot(&self, point: Vec2<Self::N>, bot: &Self::T) -> Self::N{ //Do more fine-grained checking here. //At this point we know the aabbs intersect. //Do additional checking to see if they intersect as circles bot.inner.distance_squared_to_point(point) } } 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 res = tree.k_nearest_fine_mut(vec2(0,0),2,&mut Foo,border); assert_eq!(res.len(),2); assert_eq!(res[0].bot.get(),bots_copy[0].get()); assert_eq!(res[1].bot.get(),bots_copy[2].get());
pub fn raycast_fine_mut(
&mut self,
ray: Ray<N::Num>,
rtrait: &mut impl RayCast<N = N::Num, T = N::T>,
border: Rect<N::Num>
) -> RayCastResult<N::T>
[src]
&mut self,
ray: Ray<N::Num>,
rtrait: &mut impl RayCast<N = N::Num, T = N::T>,
border: Rect<N::Num>
) -> RayCastResult<N::T>
Examples
use dinotree_alg::prelude::*; use axgeom::*; struct Foo; impl RayCast for Foo{ type T=BBox<i32,Vec2<i32>>; type N=i32; fn compute_distance_to_rect(&self, ray: &Ray<Self::N>, a: &Rect<Self::N>) -> CastResult<Self::N>{ ray.cast_to_rect(a) } fn compute_distance_to_bot(&self, ray: &Ray<Self::N>, a: &Self::T) -> CastResult<Self::N> { //Do more fine-grained collision checking. //Here we know the two aabbs intersect, but do an additional check //to see if they intersect as circles. ray.inner_as::<f32>().cast_to_circle(a.inner.inner_as(),5.).map(|a|a as i32) } } 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 res = tree.raycast_fine_mut(ray,&mut Foo,border); let (bots,dis)=res.unwrap(); assert_eq!(dis,4); assert_eq!(bots.len(),1); assert_eq!(bots[0].get(),&rect(2,5,2,5));
pub fn raycast_mut(
&mut self,
ray: Ray<N::Num>,
rtrait: impl Fn(&Ray<N::Num>, &Rect<N::Num>) -> CastResult<N::Num>,
border: Rect<N::Num>
) -> RayCastResult<N::T>
[src]
&mut self,
ray: Ray<N::Num>,
rtrait: impl Fn(&Ray<N::Num>, &Rect<N::Num>) -> CastResult<N::Num>,
border: Rect<N::Num>
) -> RayCastResult<N::T>
Examples
use dinotree_alg::prelude::*; use axgeom::*; let border = rect(0,100,0,100); let mut bots = [rect(0,10,0,10), rect(2,5,2,5), rect(4,10,4,10)]; let mut bots_copy=bots.clone(); let mut tree = DinoTree::new(&mut bots); let ray=ray(vec2(5,-5),vec2(0,1)); let res = tree.raycast_mut(ray,|ray,r|ray.cast_to_rect(r),border); let (bots,dis)=res.unwrap(); assert_eq!(dis,5); assert_eq!(bots.len(),1); assert_eq!(bots[0].get(),&rect(0,10,0,10));
pub fn draw(
&self,
drawer: &mut impl DividerDrawer<N = N::Num>,
rect: &Rect<N::Num>
)
[src]
&self,
drawer: &mut impl DividerDrawer<N = N::Num>,
rect: &Rect<N::Num>
)
Examples
use dinotree_alg::prelude::*; use axgeom::*; struct Drawer; impl 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);
pub fn intersect_with_mut<X: Aabb<Num = N::Num>>(
&mut self,
other: &mut [X],
func: impl Fn(PMut<N::T>, PMut<X>)
)
[src]
&mut self,
other: &mut [X],
func: impl Fn(PMut<N::T>, PMut<X>)
)
Examples
use dinotree_alg::prelude::*; 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,|mut a,mut b|{ *a.inner_mut()+=1; *b.inner_mut()+=2; }); assert_eq!(bots1[0].inner,1); assert_eq!(bots2[0].inner,2);
#[must_use]
pub fn multi_rect(&mut self) -> MultiRectMut<A, N>
[src]
Examples
use dinotree_alg::prelude::*; 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(RectIntersectErr));
pub fn for_all_not_in_rect_mut(
&mut self,
rect: &Rect<N::Num>,
func: impl FnMut(PMut<N::T>)
)
[src]
&mut self,
rect: &Rect<N::Num>,
func: impl FnMut(PMut<N::T>)
)
Examples
use dinotree_alg::prelude::*; 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),|mut a|{ *a.inner_mut()+=1; }); assert_eq!(bots[0].inner,1);
pub fn for_all_intersect_rect_mut(
&mut self,
rect: &Rect<N::Num>,
func: impl FnMut(PMut<N::T>)
)
[src]
&mut self,
rect: &Rect<N::Num>,
func: impl FnMut(PMut<N::T>)
)
Examples
use dinotree_alg::prelude::*; 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),|mut a|{ *a.inner_mut()+=1; }); assert_eq!(bots[0].inner,1);
pub fn for_all_intersect_rect<'a>(
&'a self,
rect: &Rect<N::Num>,
func: impl FnMut(&'a N::T)
)
[src]
&'a self,
rect: &Rect<N::Num>,
func: impl FnMut(&'a N::T)
)
Examples
use dinotree_alg::prelude::*; 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_mut(
&mut self,
rect: &Rect<N::Num>,
func: impl FnMut(PMut<N::T>)
)
[src]
&mut self,
rect: &Rect<N::Num>,
func: impl FnMut(PMut<N::T>)
)
Examples
use dinotree_alg::prelude::*; 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),|mut a|{ *a.inner_mut()+=1; }); assert_eq!(bots[0].inner,1);
pub fn for_all_in_rect<'a>(
&'a self,
rect: &Rect<N::Num>,
func: impl FnMut(&'a N::T)
)
[src]
&'a self,
rect: &Rect<N::Num>,
func: impl FnMut(&'a N::T)
)
Examples
use dinotree_alg::prelude::*; 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));
pub fn find_collisions_mut(&mut self, func: impl FnMut(PMut<N::T>, PMut<N::T>))
[src]
Examples
use dinotree_alg::prelude::*; 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_collisions_mut(|mut a,mut b|{ *a.inner_mut()+=1; *b.inner_mut()+=1; }); assert_eq!(bots[0].inner,1); assert_eq!(bots[1].inner,1);
pub fn axis(&self) -> A
[src]
Examples
use dinotree_alg::prelude::*; 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<N>
[src]
Examples
use dinotree_alg::prelude::*; 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<N>
[src]
Examples
use dinotree_alg::prelude::*; 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::prelude::*; 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::prelude::*; 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() ));
Auto Trait Implementations
impl<A, N> RefUnwindSafe for DinoTree<A, N> where
A: RefUnwindSafe,
N: RefUnwindSafe,
A: RefUnwindSafe,
N: RefUnwindSafe,
impl<A, N> Send for DinoTree<A, N> where
N: Send,
N: Send,
impl<A, N> Sync for DinoTree<A, N> where
N: Sync,
N: Sync,
impl<A, N> Unpin for DinoTree<A, N> where
A: Unpin,
N: Unpin,
A: Unpin,
N: Unpin,
impl<A, N> UnwindSafe for DinoTree<A, N> where
A: UnwindSafe,
N: UnwindSafe,
A: UnwindSafe,
N: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
ⓘImportant traits for &'_ mut Ifn borrow_mut(&mut self) -> &mut T
[src]
ⓘImportant traits for &'_ mut I
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,