kdtree

k-dimensional tree data structure implemented with const generics, used for finding k-nearest neighbours (KNN).

Example Usage

```rust use kdt::*; use orderedfloat::OrderedFloat; use rand::{threadrng, Rng};

fn main() { let mut points = { let mut rng = threadrng(); (0..100) .map(|| { Point([ rng.genrange(-50.0..50.0), rng.genrange(-50.0..50.0), rng.genrange(-50.0..50.0), ]) }) .collect::>() }; let kdt = KdTree::fromslice(&mut points); let query = Point([0.0, 0.0, 0.0]); let nearest = kdt .knearestneighbors(&query, 10) .intoiter() // each point is returned as a reference. In most use cases you don't need to clone .map(|(dist, point)| (dist, point.clone())) // by default results are sorted in descending order of squared Eucledian distance to the query point .rev() .collect::>(); // compute by brutal force let mut expected = points .intoiter() .map(|p| (p.squaredeucledian(&query), p)) .collect::>(); expected.sortunstablebykey(|p| OrderedFloat(p.0)); assert_eq!(&nearest[..], &expected[..10]); }

```