[][src]Trait broccoli::query::QueriesInner

pub trait QueriesInner<'a>: Queries<'a> where
    Self::T: HasInner<Inner = Self::Inner>, 
{ type Inner; fn find_colliding_pairs_mut(
        &mut self,
        func: impl FnMut(&mut Self::Inner, &mut Self::Inner)
    ) { ... }
fn find_colliding_pairs_mut_par(
        &mut self,
        func: impl Fn(&mut Self::Inner, &mut Self::Inner) + Clone + Send + Sync
    )
    where
        Self::T: Send + Sync
, { ... }
fn find_colliding_pairs_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 Self::Inner, &mut Self::Inner) + Send + Sync + Copy,
        acc: B
    ) -> B
    where
        Self::T: Send + Sync
, { ... }
fn for_all_not_in_rect_mut<'b>(
        &'b mut self,
        rect: &Rect<Self::Num>,
        func: impl FnMut(&'b mut Self::Inner)
    )
    where
        'a: 'b
, { ... }
fn for_all_intersect_rect_mut<'b>(
        &'b mut self,
        rect: &Rect<Self::Num>,
        func: impl FnMut(&'b mut Self::Inner)
    )
    where
        'a: 'b
, { ... }
fn for_all_in_rect_mut<'b>(
        &'b mut self,
        rect: &Rect<Self::Num>,
        func: impl FnMut(&'b mut Self::Inner)
    )
    where
        'a: 'b
, { ... }
#[must_use] fn raycast_mut<'b, Acc>(
        &'b mut self,
        ray: Ray<Self::Num>,
        start: &mut Acc,
        broad: impl FnMut(&mut Acc, &Ray<Self::Num>, &Rect<Self::Num>) -> CastResult<Self::Num>,
        fine: impl FnMut(&mut Acc, &Ray<Self::Num>, &Self::T) -> CastResult<Self::Num>,
        border: Rect<Self::Num>
    ) -> RayCastResult<'b, Self::Inner, Self::Num>
    where
        'a: 'b
, { ... }
#[must_use] fn k_nearest_mut<'b, Acc>(
        &'b mut self,
        point: Vec2<Self::Num>,
        num: usize,
        start: &mut Acc,
        broad: impl FnMut(&mut Acc, Vec2<Self::Num>, &Rect<Self::Num>) -> Self::Num,
        fine: impl FnMut(&mut Acc, Vec2<Self::Num>, &Self::T) -> Self::Num,
        border: Rect<Self::Num>
    ) -> Vec<Option<KnearestResult<'b, Self::Inner, Self::Num>>>

Notable traits for Vec<u8>

impl Write for Vec<u8>

    where
        'a: 'b
, { ... }
fn intersect_with_mut<X: Aabb<Num = Self::Num> + HasInner>(
        &mut self,
        other: &mut [X],
        func: impl Fn(&mut Self::Inner, &mut X::Inner)
    ) { ... } }

Associated Types

type Inner

Loading content...

Provided methods

fn find_colliding_pairs_mut(
    &mut self,
    func: impl FnMut(&mut Self::Inner, &mut Self::Inner)
)

Find all aabb intersections

Examples

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

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

fn find_colliding_pairs_mut_par(
    &mut self,
    func: impl Fn(&mut Self::Inner, &mut Self::Inner) + Clone + Send + Sync
) where
    Self::T: Send + Sync

Find all intersections in parallel

Examples

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

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

fn find_colliding_pairs_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 Self::Inner, &mut Self::Inner) + Send + Sync + Copy,
    acc: B
) -> B where
    Self::T: Send + Sync

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

Examples

use broccoli::prelude::*;
let mut bots = [bbox(axgeom::rect(0,10,0,10),0u8),bbox(axgeom::rect(5,15,5,15),1u8)];
let mut tree = broccoli::new(&mut bots);
let intersections=tree.find_colliding_pairs_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);

fn for_all_not_in_rect_mut<'b>(
    &'b mut self,
    rect: &Rect<Self::Num>,
    func: impl FnMut(&'b mut Self::Inner)
) where
    'a: 'b, 

Examples

use broccoli::prelude::*;
let mut bots = [bbox(axgeom::rect(0,10,0,10),0u8)];
let mut tree = broccoli::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);

fn for_all_intersect_rect_mut<'b>(
    &'b mut self,
    rect: &Rect<Self::Num>,
    func: impl FnMut(&'b mut Self::Inner)
) where
    'a: 'b, 

Examples

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

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

fn for_all_in_rect_mut<'b>(
    &'b mut self,
    rect: &Rect<Self::Num>,
    func: impl FnMut(&'b mut Self::Inner)
) where
    'a: 'b, 

Examples

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

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

#[must_use]fn raycast_mut<'b, Acc>(
    &'b mut self,
    ray: Ray<Self::Num>,
    start: &mut Acc,
    broad: impl FnMut(&mut Acc, &Ray<Self::Num>, &Rect<Self::Num>) -> CastResult<Self::Num>,
    fine: impl FnMut(&mut Acc, &Ray<Self::Num>, &Self::T) -> CastResult<Self::Num>,
    border: Rect<Self::Num>
) -> RayCastResult<'b, Self::Inner, Self::Num> where
    'a: 'b, 

Examples

use broccoli::prelude::*;
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 = broccoli::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);

#[must_use]fn k_nearest_mut<'b, Acc>(
    &'b mut self,
    point: Vec2<Self::Num>,
    num: usize,
    start: &mut Acc,
    broad: impl FnMut(&mut Acc, Vec2<Self::Num>, &Rect<Self::Num>) -> Self::Num,
    fine: impl FnMut(&mut Acc, Vec2<Self::Num>, &Self::T) -> Self::Num,
    border: Rect<Self::Num>
) -> Vec<Option<KnearestResult<'b, Self::Inner, Self::Num>>>

Notable traits for Vec<u8>

impl Write for Vec<u8>
where
    'a: 'b, 

Examples

use broccoli::prelude::*;
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 = broccoli::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(),3);
assert_eq!(*res[0].as_ref().unwrap().bot,bots_copy[0].inner);
assert_eq!(*res[2].as_ref().unwrap().bot,bots_copy[2].inner);
assert_eq!(counter,3);

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

Examples

use broccoli::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 = broccoli::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);
Loading content...

Implementors

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

type Inner = T::Inner

Loading content...