[−][src]Trait broccoli::query::Queries
Query functions. User defines vistr()
functions, and the query functions
are automatically provided by this trait.
Associated Types
Loading content...Required methods
#[must_use]pub fn vistr_mut(&mut self) -> VistrMut<'_, Node<'a, Self::T>>
[src]
Examples
use broccoli::{prelude::*,bbox,rect}; let mut bots = [bbox(rect(0,10,0,10),0)]; let mut tree = broccoli::new(&mut bots); use compt::Visitor; for b in tree.vistr_mut().dfs_preorder_iter().flat_map(|n|n.into_range().iter_mut()){ *b.unpack_inner()+=1; } assert_eq!(bots[0].inner,1);
#[must_use]pub fn vistr(&self) -> Vistr<'_, Node<'a, Self::T>>
[src]
Examples
use broccoli::{prelude::*,bbox,rect}; let mut bots = [rect(0,10,0,10)]; let mut tree = broccoli::new(&mut bots); use compt::Visitor; let mut test = Vec::new(); for b in tree.vistr().dfs_preorder_iter().flat_map(|n|n.range.iter()){ test.push(b); } assert_eq!(test[0],&axgeom::rect(0,10,0,10));
#[must_use]pub fn axis(&self) -> Self::A
[src]
Examples
use broccoli::{prelude::*,bbox,rect,analyze}; let mut bots = [rect(0,10,0,10)]; let mut tree = broccoli::new(&mut bots); use axgeom::Axis; assert!(tree.axis().is_equal_to(analyze::default_axis()));
Provided methods
pub fn find_colliding_pairs_mut(
&mut self,
func: impl FnMut(PMut<'_, Self::T>, PMut<'_, Self::T>)
)
[src]
&mut self,
func: impl FnMut(PMut<'_, Self::T>, PMut<'_, Self::T>)
)
Find all aabb intersections and return a PMutfind_colliding_pairs_mut
, this allows the
user to access a read only reference of the AABB.
Examples
use broccoli::{prelude::*,bbox,rect}; let mut bots = [bbox(rect(0,10,0,10),0u8),bbox(rect(5,15,5,15),0u8)]; let mut tree = broccoli::new(&mut bots); tree.find_colliding_pairs_mut(|a,b|{ *a.unpack_inner()+=1; *b.unpack_inner()+=1; }); assert_eq!(bots[0].inner,1); assert_eq!(bots[1].inner,1);
pub fn find_colliding_pairs_mut_par(
&mut self,
func: impl Fn(PMut<'_, Self::T>, PMut<'_, Self::T>) + Send + Sync + Clone
) where
Self::T: Send + Sync,
Self::Num: Send + Sync,
[src]
&mut self,
func: impl Fn(PMut<'_, Self::T>, PMut<'_, Self::T>) + Send + Sync + Clone
) where
Self::T: Send + Sync,
Self::Num: Send + Sync,
The parallel version of Queries::find_colliding_pairs_mut
.
Examples
use broccoli::{prelude::*,bbox,rect}; let mut bots = [bbox(rect(0,10,0,10),0u8),bbox(rect(5,15,5,15),0u8)]; let mut tree = broccoli::new(&mut bots); tree.find_colliding_pairs_mut_par(|a,b|{ *a.unpack_inner()+=1; *b.unpack_inner()+=1; }); assert_eq!(bots[0].inner,1); assert_eq!(bots[1].inner,1);
pub fn new_colfind_builder<'c>(
&'c mut self
) -> QueryBuilder<'c, 'a, Self::A, Self::T>
[src]
&'c mut self
) -> QueryBuilder<'c, 'a, Self::A, Self::T>
For analysis, allows the user to query with custom settings
Examples
use broccoli::{prelude::*,bbox,rect}; let mut bots = [bbox(rect(0,10,0,10),0u8),bbox(rect(5,15,5,15),0u8)]; let mut tree = broccoli::new(&mut bots); let builder=tree.new_colfind_builder(); let builder=builder.with_switch_height(4); builder.query_seq(|a,b|{ *a.unpack_inner()+=1; *b.unpack_inner()+=1; }); assert_eq!(bots[0].inner,1); assert_eq!(bots[1].inner,1);
pub fn for_all_intersect_rect<'b>(
&'b self,
rect: &Rect<Self::Num>,
func: impl FnMut(&'b Self::T)
) where
'a: 'b,
[src]
&'b self,
rect: &Rect<Self::Num>,
func: impl FnMut(&'b Self::T)
) where
'a: 'b,
Examples
use broccoli::{prelude::*,bbox,rect}; let mut bots = [rect(0,10,0,10),rect(20,30,20,30)]; let mut tree = broccoli::new(&mut bots); let mut test = Vec::new(); tree.for_all_intersect_rect(&rect(9,20,9,20),|a|{ test.push(a); }); assert_eq!(test[0],&rect(0,10,0,10));
pub fn for_all_intersect_rect_mut<'b>(
&'b mut self,
rect: &Rect<Self::Num>,
func: impl FnMut(PMut<'b, Self::T>)
) where
'a: 'b,
[src]
&'b mut self,
rect: &Rect<Self::Num>,
func: impl FnMut(PMut<'b, Self::T>)
) where
'a: 'b,
Examples
use broccoli::{prelude::*,bbox,rect}; let mut bots = [bbox(rect(0,10,0,10),0u8)]; let mut tree = broccoli::new(&mut bots); tree.for_all_intersect_rect_mut(&rect(9,20,9,20),|a|{ *a.unpack_inner()+=1; }); assert_eq!(bots[0].inner,1);
pub fn for_all_in_rect<'b>(
&'b self,
rect: &Rect<Self::Num>,
func: impl FnMut(&'b Self::T)
) where
'a: 'b,
[src]
&'b self,
rect: &Rect<Self::Num>,
func: impl FnMut(&'b Self::T)
) where
'a: 'b,
Examples
use broccoli::{prelude::*,bbox,rect}; let mut bots = [rect(0,10,0,10),rect(20,30,20,30)]; let mut tree = broccoli::new(&mut bots); let mut test = Vec::new(); tree.for_all_in_rect(&rect(0,20,0,20),|a|{ test.push(a); }); assert_eq!(test[0],&rect(0,10,0,10));
pub fn for_all_in_rect_mut<'b>(
&'b mut self,
rect: &Rect<Self::Num>,
func: impl FnMut(PMut<'b, Self::T>)
) where
'a: 'b,
[src]
&'b mut self,
rect: &Rect<Self::Num>,
func: impl FnMut(PMut<'b, Self::T>)
) where
'a: 'b,
Examples
use broccoli::{prelude::*,bbox,rect}; let mut bots = [bbox(rect(0,10,0,10),0u8)]; let mut tree = broccoli::new(&mut bots); tree.for_all_in_rect_mut(&rect(0,10,0,10),|a|{ *a.unpack_inner()+=1; }); assert_eq!(bots[0].inner,1);
pub fn for_all_not_in_rect_mut<'b>(
&'b mut self,
rect: &Rect<Self::Num>,
func: impl FnMut(PMut<'b, Self::T>)
) where
'a: 'b,
[src]
&'b mut self,
rect: &Rect<Self::Num>,
func: impl FnMut(PMut<'b, Self::T>)
) where
'a: 'b,
Examples
use broccoli::{prelude::*,bbox,rect}; let mut bots = [bbox(rect(0,10,0,10),0u8)]; let mut tree = broccoli::new(&mut bots); tree.for_all_not_in_rect_mut(&rect(10,20,10,20),|a|{ *a.unpack_inner()+=1; }); assert_eq!(bots[0].inner,1);
#[must_use]pub fn multi_rect<'c>(&'c mut self) -> MultiRectMut<'c, 'a, Self::A, Self::T>
[src]
If we have two non intersecting rectangles, it is safe to return to the user two sets of mutable references of the bots strictly inside each rectangle since it is impossible for a bot to belong to both sets.
Safety
Unsafe code is used. We unsafely convert the references returned by the rect query closure to have a longer lifetime. This allows the user to store mutable references of non intersecting rectangles at the same time. If two requested rectangles intersect, an error is returned.
Handles a multi rect mut "sessions" within which the user can query multiple non intersecting rectangles.
Examples
use broccoli::{prelude::*,bbox,rect}; let mut bots1 = [bbox(rect(0,10,0,10),0u8)]; let mut tree = broccoli::new(&mut bots1); let mut multi = tree.multi_rect(); multi.for_all_in_rect_mut(rect(0,10,0,10),|a|{}).unwrap(); let res = multi.for_all_in_rect_mut(rect(5,15,5,15),|a|{}); assert_eq!(res,Err(broccoli::query::RectIntersectErr));
#[must_use]pub fn raycast_mut<'b, Acc>(
&'b mut self,
ray: Ray<Self::Num>,
acc: &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>
) -> CastResult<(Vec<PMut<'b, Self::T>>, Self::Num)> where
'a: 'b,
[src]
&'b mut self,
ray: Ray<Self::Num>,
acc: &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>
) -> CastResult<(Vec<PMut<'b, Self::T>>, Self::Num)> where
'a: 'b,
Find the elements that are hit by a ray.
The user supplies to functions:
fine
is a function that returns the true length of a ray
cast to an object.
broad
is a function that returns the length of a ray cast to
a axis aligned rectangle. This function
is used as a conservative estimate to prune out elements which minimizes
how often the fine
function gets called.
border
is the starting axis axis aligned rectangle to use. This
rectangle will be split up and used to prune candidated. All candidate elements
should be within this starting rectangle.
The result is returned as a Vec
. In the event of a tie, multiple
elements can be returned.
acc
is a user defined object that is passed to every call to either
the fine
or broad
functions.
Examples
use broccoli::{prelude::*,bbox,rect}; use axgeom::{vec2,ray}; let border = rect(-100,100,-100,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(1,2)); 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.cast_to_rect(&t.rect)}, //Do more fine-grained checking here. border); let (bots,dis)=res.unwrap(); assert_eq!(dis,2); assert_eq!(bots.len(),1); assert_eq!(bots[0].inner,vec2(5,5));
pub fn raycast_trait_mut<'b, Acc, R: RayCast<T = Self::T, N = Self::Num>>(
&'b mut self,
ray: Ray<Self::Num>,
rtrait: R,
border: Rect<Self::Num>
) -> CastResult<(Vec<PMut<'b, Self::T>>, Self::Num)> where
'a: 'b,
[src]
&'b mut self,
ray: Ray<Self::Num>,
rtrait: R,
border: Rect<Self::Num>
) -> CastResult<(Vec<PMut<'b, Self::T>>, Self::Num)> where
'a: 'b,
Companion function to Queries::raycast_mut()
for cases where the use wants to
use the trait instead of closures.
#[must_use]pub fn k_nearest_mut<'b, Acc>(
&'b mut self,
point: Vec2<Self::Num>,
num: usize,
acc: &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>
) -> KResult<'_, Self::T> where
'a: 'b,
[src]
&'b mut self,
point: Vec2<Self::Num>,
num: usize,
acc: &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>
) -> KResult<'_, Self::T> where
'a: 'b,
Find the closest num
elements to the specified point
.
The user provides two functions:
-
fine
is a function that gives the true distance between thepoint
and the specified tree element. -
broad
is a function that gives the distance between thepoint
and the closest point of a axis aligned rectangle. This function is used as a conservative estimate to prune out elements which minimizes how often thefine
function gets called.
border
is the starting axis axis aligned rectangle to use. This
rectangle will be split up and used to prune candidated. All candidate elements
should be within this starting rectangle.
The result is returned as one Vec
. The closest elements will
appear first. Multiple elements can be returned
with the same distance in the event of ties. These groups of elements are seperated by
one entry of Option::None
. In order to iterate over each group,
try using the slice function: arr.split(|a| a.is_none())
acc
is a user defined object that is passed to every call to either
the fine
or broad
functions.
Examples
use broccoli::{prelude::*,bbox,rect}; use axgeom::vec2; let mut inner1=vec2(5,5); let mut inner2=vec2(3,3); let mut inner3=vec2(7,7); let mut bots = [bbox(rect(0,10,0,10),&mut inner1), bbox(rect(2,4,2,4),&mut inner2), bbox(rect(6,8,6,8),&mut inner3)]; let border = broccoli::rect(0, 100, 0, 100); let mut tree = broccoli::new(&mut bots); let mut res = tree.k_nearest_mut( vec2(30, 30), 2, &mut (), |(), a, b| b.distance_squared_to_point(a).unwrap_or(0), |(), a, b| b.inner.distance_squared_to_point(a), border, ); assert_eq!(res.len(),2); assert_eq!(res.total_len(),2); let foo:Vec<_>=res.iter().map(|a|*a[0].bot.inner).collect(); assert_eq!(foo,vec![vec2(7,7),vec2(5,5)])
#[must_use]pub fn k_nearest_trait_mut<'b, Acc, K: Knearest<T = Self::T, N = Self::Num>>(
&'b mut self,
point: Vec2<Self::Num>,
num: usize,
ktrait: K,
border: Rect<Self::Num>
) -> KResult<'_, Self::T> where
'a: 'b,
[src]
&'b mut self,
point: Vec2<Self::Num>,
num: usize,
ktrait: K,
border: Rect<Self::Num>
) -> KResult<'_, Self::T> where
'a: 'b,
Companion function to Queries::k_nearest_mut()
for cases where the use wants to
use the trait instead of closures.
pub fn intersect_with_mut<X: Aabb<Num = Self::Num>>(
&mut self,
other: &mut [X],
func: impl Fn(PMut<'_, Self::T>, PMut<'_, X>)
)
[src]
&mut self,
other: &mut [X],
func: impl Fn(PMut<'_, Self::T>, PMut<'_, X>)
)
Find collisions between elements in this tree, with the specified slice of elements.
Examples
use broccoli::{prelude::*,bbox,rect}; let mut bots1 = [bbox(rect(0,10,0,10),0u8)]; let mut bots2 = [bbox(rect(5,15,5,15),0u8)]; let mut tree = broccoli::new(&mut bots1); tree.intersect_with_mut(&mut bots2,|a,b|{ *a.unpack_inner()+=1; *b.unpack_inner()+=2; }); assert_eq!(bots1[0].inner,1); assert_eq!(bots2[0].inner,2);
pub fn draw_divider(
&self,
drawer: &mut impl DividerDrawer<N = Self::Num>,
rect: &Rect<Self::Num>
)
[src]
&self,
drawer: &mut impl DividerDrawer<N = Self::Num>,
rect: &Rect<Self::Num>
)
Examples
use broccoli::{prelude::*,bbox,rect}; struct Drawer; impl broccoli::query::DividerDrawer for Drawer{ type N=i32; fn draw_divider<A:axgeom::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=broccoli::new(&mut bots); tree.draw_divider(&mut Drawer,&border);
pub fn nbody_mut<X: NodeMassTrait<Num = Self::Num, Item = Self::T> + Send + Sync>(
&mut self,
ncontext: X,
rect: Rect<Self::Num>
) where
X::No: Send,
Self::T: Send + Sync,
Self::Num: Send + Sync,
[src]
&mut self,
ncontext: X,
rect: Rect<Self::Num>
) where
X::No: Send,
Self::T: Send + Sync,
Self::Num: Send + Sync,
Experimental. See broccoli demo
pub fn nbody_mut_par<X: NodeMassTrait<Num = Self::Num, Item = Self::T> + Sync + Send>(
&mut self,
ncontext: X,
rect: Rect<Self::Num>
) where
X::No: Send,
Self::T: Send + Sync,
Self::Num: Send + Sync,
[src]
&mut self,
ncontext: X,
rect: Rect<Self::Num>
) where
X::No: Send,
Self::T: Send + Sync,
Self::Num: Send + Sync,
Experimental. See broccoli demo