use alloc::vec::Vec;
use crate::Rect;
use crate::dynamic::DynamicIndex;
use crate::dynamic::node::Child;
impl DynamicIndex {
pub fn query(&self, window: &Rect, mut visit: impl FnMut(u32)) {
let Some(root) = self.root else {
return;
};
let mut stack: Vec<usize> = Vec::new();
stack.push(root);
while let Some(slot) = stack.pop() {
let node = &self.arena[slot];
if !node.rect.intersects(window) {
continue;
}
if node.level == 0 {
for child in node.children() {
if let Child::Entry(rect, id) = *child {
if rect.intersects(window) {
visit(id);
}
}
}
} else {
for child in node.children().rev() {
if let Child::Node(child_slot) = *child {
stack.push(child_slot);
}
}
}
}
}
}