mirror of
https://github.com/andreytkachenko/kdtree-rust.git
synced 2024-11-21 17:06:24 +04:00
make search point sent by value
This commit is contained in:
parent
ed6a9b6a8e
commit
2027591d36
@ -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<T>,
|
||||
ref_node: &'b T,
|
||||
ref_node: T,
|
||||
node_stack: Vec<usize>,
|
||||
}
|
||||
|
||||
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<Self::Item> {
|
||||
let p = self.ref_node;
|
||||
let p = &self.ref_node;
|
||||
|
||||
loop {
|
||||
let node_idx = self.node_stack.pop()?;
|
||||
@ -130,13 +130,13 @@ impl<KP: KdTreePoint> KdTree<KP> {
|
||||
(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,
|
||||
}
|
||||
|
@ -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());
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user