Skip to content

Instantly share code, notes, and snippets.

@djmcgill
Created October 7, 2017 15:58
Show Gist options
  • Save djmcgill/e0a81b702d2924a0df9f0b98bc2eb3bd to your computer and use it in GitHub Desktop.
Save djmcgill/e0a81b702d2924a0df9f0b98bc2eb3bd to your computer and use it in GitHub Desktop.
kd_tree simplification
mod kd_tree {
use na::*;
use na::allocator::Allocator;
/// kd-Tree implementation structure
pub(super) enum KdTreeImpl<N> where N: DimName, DefaultAllocator: Allocator<f64, N> {
Node(usize, Box<KdTreeImpl<N>>, Box<VectorN<f64, N>>, Box<KdTreeImpl<N>>),
Empty()
}
impl<N> KdTreeImpl<N> where N: DimName, DefaultAllocator: Allocator<f64, N> {
/// mutably enunerate points from a kd tree into a vector - TODO: expose as iterator instead?
pub fn add_points_to_vector(&self, pts : &mut Vec<VectorN<f64, N>>) {
if let KdTreeImpl::Node(_, l, pt, r) = *self {
l.add_points_to_vector(pts);
pts.push(*pt);
r.add_points_to_vector(pts);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment