mirror of
https://github.com/andreytkachenko/kdtree-rust.git
synced 2024-11-22 01:16:25 +04:00
Working on add tree, fixed an issue on build tree where it did not build using sliding midpoint value
This commit is contained in:
parent
d6647606ca
commit
b236cd2595
@ -49,6 +49,20 @@ impl<KdtreePoint: KdtreePointTrait> Kdtree<KdtreePoint> {
|
||||
squared_euclidean(&self.nearest_search(node).dims(), node.dims()) <= squared_range
|
||||
}
|
||||
|
||||
pub fn insert_node(&mut self, node_to_add : &KdtreePoint) {
|
||||
|
||||
let current_index = 0;
|
||||
loop {
|
||||
let current_node = &self.nodes[current_index];
|
||||
if node_to_add.dims()[current_node.dimension] <= current_node.split_on {
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
fn nearest_search_impl(&self, p: &KdtreePoint, searched_index: usize, best_distance_squared: &mut f64, best_leaf_found: &mut usize) {
|
||||
let node = &self.nodes[searched_index];
|
||||
|
||||
@ -95,7 +109,7 @@ impl<KdtreePoint: KdtreePointTrait> Kdtree<KdtreePoint> {
|
||||
fn build_tree(&mut self, nodes: &mut [KdtreePoint], bounds: &Bounds) -> usize {
|
||||
let (splitting_index, pivot_value) = partition::partition_sliding_midpoint(nodes, bounds.get_midvalue_of_widest_dim(), bounds.get_widest_dim());
|
||||
|
||||
let node_id = self.add_node(nodes[splitting_index], bounds.get_widest_dim(), bounds.get_midvalue_of_widest_dim());
|
||||
let node_id = self.add_node(nodes[splitting_index], bounds.get_widest_dim(), pivot_value);
|
||||
let nodes_len = nodes.len();
|
||||
|
||||
if splitting_index > 0 {
|
||||
@ -214,6 +228,18 @@ mod tests {
|
||||
assert_eq!(true,tree.has_neighbor_in_range(&Point2WithId::new(0,0.,0.), 300.));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn incremental_add_adds_as_expected() {
|
||||
let mut vec = vec![Point2WithId::new(0,0.,0.)];
|
||||
|
||||
let mut tree = Kdtree::new(&mut vec);
|
||||
|
||||
tree.insert_node(&Point2WithId::new(0,1.,0.));
|
||||
tree.insert_node(&Point2WithId::new(0,-1.,0.));
|
||||
|
||||
assert_eq!(tree.nodes.len(), 3);
|
||||
}
|
||||
|
||||
fn qc_value_vec_to_2d_points_vec(xs: &Vec<f64>) -> Vec<Point2WithId> {
|
||||
let mut vec: Vec<Point2WithId> = vec![];
|
||||
for i in 0..xs.len() {
|
||||
|
Loading…
Reference in New Issue
Block a user