Skip to content

Commit

Permalink
Iterate over points in tree
Browse files Browse the repository at this point in the history
  • Loading branch information
clbarnes committed Jan 22, 2024
1 parent 6aef3ee commit b915eda
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,23 @@ impl<T: Scalar, P: Point<T>> KDTree<T, P> {
index: self.indices[neighbour.index as usize],
}
}

/// Iterate over the indices and points in this KDTree.
/// The order is arbitrary;
/// the indices are the point's location in the slice
/// from which the tree was built.
pub fn iter(&self) -> impl Iterator<Item = (u32, P)> + '_ {
self.indices
.iter()
.zip(self.points.as_slice().chunks(P::DIM as usize))
.map(|(idx, x)| {
let mut p = P::default();
for (d, v) in x.iter().enumerate() {
p.set(d as u32, *v);
}
(*idx, p)
})
}
}

#[cfg(test)]
Expand Down

0 comments on commit b915eda

Please sign in to comment.