add Octant::visit_self_and_descendants
@@ -383,6 +383,25 @@ impl Octant {
edge_length: half_edge_length,
}
}
+
+ /// Visit `self` and all octants descending from `self` (children and children's children).
+ pub fn visit_self_and_descendants(self, visitor: &mut impl OctantVisitor) -> VisitStatus {
+ let status = visitor.visit_octant(self);
+
+ if self.edge_length == 1 || status != VisitStatus::Continue {
+ return status;
+ }
+
+ for child_index in 0..8 {
+ match self.child(child_index).visit_self_and_descendants(visitor) {
+ VisitStatus::Continue => (),
+ VisitStatus::ExitEarly => return VisitStatus::ExitEarly,
+ VisitStatus::Stop => continue,
+ }
+ }
+
+ VisitStatus::Continue
+ }
}
impl From<Octant> for Extent3i {
@@ -392,6 +411,20 @@ impl From<Octant> for Extent3i {
}
}
+pub trait OctantVisitor {
+ fn visit_octant(&mut self, octant: Octant) -> VisitStatus;
+}
+
+impl<F> OctantVisitor for F
+where
+ F: FnMut(Octant) -> VisitStatus,
+{
+ #[inline]
+ fn visit_octant(&mut self, octant: Octant) -> VisitStatus {
+ (self)(octant)
+ }
+}
+
pub trait OctreeVisitor {
/// Visit any octant that contains points in the octree.
fn visit_octant(&mut self, octant: Octant, is_leaf: bool) -> VisitStatus;
