Add method

This commit is contained in:
Andrey Tkachenko 2020-12-22 17:00:43 +04:00
parent 73bacad7ba
commit 99e465ba6e

View File

@ -90,7 +90,6 @@ impl<'a, F: Float, T> Iterator for NearestNeighboursIter<'a, F, T>
pub struct KdTree<F: Float, KP> { pub struct KdTree<F: Float, KP> {
nodes: Vec<KdTreeNode<F, KP>>, nodes: Vec<KdTreeNode<F, KP>>,
node_adding_dimension: usize, node_adding_dimension: usize,
node_depth_during_last_rebuild: usize, node_depth_during_last_rebuild: usize,
current_node_depth: usize, current_node_depth: usize,
@ -299,17 +298,25 @@ impl<F: Float, KP: KdTreePoint<F>> KdTree<F, KP> {
} }
#[inline] #[inline]
fn into_iter(self) -> impl Iterator<Item = KP> { pub fn into_iter(self) -> impl Iterator<Item = KP> {
self.nodes self.nodes
.into_iter() .into_iter()
.map(|node|node.point) .map(|node|node.point)
} }
#[inline]
pub fn iter(&self) -> impl Iterator<Item = &KP> {
self.nodes
.iter()
.map(|node|&node.point)
}
} }
pub struct KdTreeNode<F: Float, T> { pub struct KdTreeNode<F: Float, T> {
left_node: Option<usize>, left_node: Option<usize>,
right_node: Option<usize>, right_node: Option<usize>,
point: T, point: T,
dimension: usize, dimension: usize,
split_on: F split_on: F
@ -328,6 +335,8 @@ impl<F: Float, T: KdTreePoint<F>> KdTreeNode<F, T> {
} }
} }
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::kdtree::test_common::Point2WithId; use crate::kdtree::test_common::Point2WithId;