diff --git a/src/bvh.rs b/src/bvh.rs index e4f0bf6..e5427f9 100644 --- a/src/bvh.rs +++ b/src/bvh.rs @@ -25,10 +25,10 @@ pub struct BvhNode{ aabb:Aabb, } -impl BvhNode{ - pub fn the_tester(&self,aabb:&Aabb,f:&mut F){ +impl BvhNode{ + pub fn the_tester(&self,aabb:&Aabb,f:&mut F){ match &self.content{ - &BvhNodeContent::Leaf(model)=>f(model), + BvhNodeContent::Leaf(model)=>f(model), BvhNodeContent::Branch(children)=>for child in children{ //this test could be moved outside the match statement //but that would test the root node aabb @@ -50,11 +50,11 @@ impl BvhNode{ } } -pub fn generate_bvh(boxen:Vec<(T,Aabb)>)->BvhNode{ +pub fn generate_bvh(boxen:Vec<(T,Aabb)>)->BvhNode{ generate_bvh_node(boxen,false) } -fn generate_bvh_node(boxen:Vec<(T,Aabb)>,force:bool)->BvhNode{ +fn generate_bvh_node(boxen:Vec<(T,Aabb)>,force:bool)->BvhNode{ let n=boxen.len(); if force||n<20{ let mut aabb=Aabb::default(); @@ -74,12 +74,12 @@ fn generate_bvh_node(boxen:Vec<(T,Aabb)>,force:bool)- let mut sort_x=Vec::with_capacity(n); let mut sort_y=Vec::with_capacity(n); let mut sort_z=Vec::with_capacity(n); - for (i,aabb) in boxen.iter(){ + for (i,(_,aabb)) in boxen.iter().enumerate(){ let center=aabb.center(); - octant.insert(*i,0); - sort_x.push((*i,center.x())); - sort_y.push((*i,center.y())); - sort_z.push((*i,center.z())); + octant.insert(i,0); + sort_x.push((i,center.x())); + sort_y.push((i,center.y())); + sort_z.push((i,center.z())); } sort_x.sort_by(|tup0,tup1|tup0.1.cmp(&tup1.1)); sort_y.sort_by(|tup0,tup1|tup0.1.cmp(&tup1.1)); @@ -106,7 +106,7 @@ fn generate_bvh_node(boxen:Vec<(T,Aabb)>,force:bool)- //generate lists for unique octant values let mut list_list=Vec::with_capacity(8); let mut octant_list=Vec::with_capacity(8); - for (i,aabb) in boxen.into_iter(){ + for (i,(data,aabb)) in boxen.into_iter().enumerate(){ let octant_id=octant[&i]; let list_id=if let Some(list_id)=octant_list.iter().position(|&id|id==octant_id){ list_id @@ -116,7 +116,7 @@ fn generate_bvh_node(boxen:Vec<(T,Aabb)>,force:bool)- list_list.push(Vec::new()); list_id }; - list_list[list_id].push((i,aabb)); + list_list[list_id].push((data,aabb)); } let mut aabb=Aabb::default(); if list_list.len()==1{