mirror of
https://github.com/andreytkachenko/kdtree-rust.git
synced 2024-11-22 01:16:25 +04:00
Add method
This commit is contained in:
parent
73bacad7ba
commit
99e465ba6e
@ -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;
|
||||||
|
Loading…
Reference in New Issue
Block a user