Add KdTree::empty constructor

This commit is contained in:
Andrey Tkachenko 2018-12-12 16:33:15 +04:00
parent b67df3d4a1
commit ed6a9b6a8e

View File

@ -80,17 +80,22 @@ pub struct KdTree<KP> {
} }
impl<KP: KdTreePoint> KdTree<KP> { impl<KP: KdTreePoint> KdTree<KP> {
#[inline]
pub fn empty() -> Self {
KdTree {
nodes: vec![],
node_adding_dimension: 0,
node_depth_during_last_rebuild: 0,
current_node_depth: 0,
}
}
pub fn new(mut points: &mut [KP]) -> Self { pub fn new(mut points: &mut [KP]) -> Self {
if points.len() == 0 { if points.len() == 0 {
panic!("empty vector point not allowed"); panic!("empty vector point not allowed");
} }
let mut tree = KdTree { let mut tree = Self::empty();
nodes: vec![],
node_adding_dimension: 0,
node_depth_during_last_rebuild: 0,
current_node_depth: 0,
};
tree.rebuild_tree(&mut points); tree.rebuild_tree(&mut points);