diff --git a/src/acceleration_data.rs b/src/acceleration_data.rs index b1ac865..334061d 100644 --- a/src/acceleration_data.rs +++ b/src/acceleration_data.rs @@ -96,7 +96,7 @@ impl<'a> AccelerationData<'a> { if self.recursive { self.traverse_tree_recursively(f, 0); } else { - self.traverse_tree_iteratively(f); + self.traverse_tree_iteratively(f, 0); } } @@ -117,38 +117,27 @@ impl<'a> AccelerationData<'a> { } } - fn traverse_tree_iteratively(&self, f: &mut F) + fn traverse_tree_iteratively(&self, f: &mut F, index: usize) where F: FnMut(usize, &AABB) -> bool, { - let mut discovered = vec![false; 1024]; let mut stack = Vec::new(); // push root node - stack.push(0); + stack.push(index); while !stack.is_empty() { let v = stack.pop().unwrap(); - if discovered[v] { - continue; - } - - discovered[v] = true; - if (*f)(v, &self.data[v]) { let left_child = self.data[v].left_child; if left_child != -1 { - if !discovered[left_child as usize] { - stack.push(left_child as usize); - } + stack.push(left_child as usize); } let right_child = self.data[v].right_child; if right_child != -1 { - if !discovered[right_child as usize] { - stack.push(right_child as usize); - } + stack.push(right_child as usize); } } }