Optimize iterative search
This commit is contained in:
parent
e3dd4861d2
commit
f6b11e56b8
1 changed files with 5 additions and 16 deletions
|
@ -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<F>(&self, f: &mut F)
|
||||
fn traverse_tree_iteratively<F>(&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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue