From 2027591d361f45223b521552aedb1ff31a7f1b4a Mon Sep 17 00:00:00 2001 From: Andrey Tkachenko Date: Wed, 12 Dec 2018 17:05:43 +0400 Subject: [PATCH] make search point sent by value --- src/kdtree/mod.rs | 12 ++++++------ tests/integration_tests.rs | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/kdtree/mod.rs b/src/kdtree/mod.rs index 3d0dcb0..5c08fd1 100644 --- a/src/kdtree/mod.rs +++ b/src/kdtree/mod.rs @@ -22,20 +22,20 @@ pub trait KdTreePoint: Copy + PartialEq { } } -pub struct NearestNeighboursIter<'a, 'b, T> { +pub struct NearestNeighboursIter<'a, T> { range: f64, kdtree: &'a KdTree, - ref_node: &'b T, + ref_node: T, node_stack: Vec, } -impl<'a, 'b, T> Iterator for NearestNeighboursIter<'a, 'b, T> +impl<'a, T> Iterator for NearestNeighboursIter<'a, T> where T: KdTreePoint { type Item = (f64, &'a T); fn next(&mut self) -> Option { - let p = self.ref_node; + let p = &self.ref_node; loop { let node_idx = self.node_stack.pop()?; @@ -130,13 +130,13 @@ impl KdTree { (best_distance, &self.nodes[nearest_neighbor].point) } - pub fn nearest_search_dist<'a, 'b>(&'a self, node: &'b KP, dist: f64) -> NearestNeighboursIter<'a, 'b, KP> { + pub fn nearest_search_dist(&self, node: KP, dist: f64) -> NearestNeighboursIter<'_, KP> { let mut node_stack = Vec::with_capacity(16); node_stack.push(0); NearestNeighboursIter { range: dist, - kdtree: &self, + kdtree: self, ref_node: node, node_stack, } diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 4154015..844be6f 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -120,7 +120,7 @@ fn test_neighbour_search_with_distance() { let p = Point3WithId::new(0i32, gen_random(), gen_random(), gen_random()); let mut found_by_linear_search = find_neigbours_with_linear_search(&points, p, dist * dist); - let mut point_found_by_kdtree: Vec<_> = tree.nearest_search_dist(&p, dist * dist).collect(); + let mut point_found_by_kdtree: Vec<_> = tree.nearest_search_dist(p, dist * dist).collect(); assert_eq!(found_by_linear_search.len(), point_found_by_kdtree.len());