Implementation uses sliding midpoint variation of the tree. [More Info here](http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.74.210&rep=rep1&type=pdf)
###Usage
Tree can only be used with types implementing trait:
```
pub trait KdtreePointTrait : Copy {
fn dims(&self) -> &[f64];
}
```
Thanks to this trait you can use any dimension. Keep in mind that the tree currently only supports up to 3D.
Examplary implementation would be:
```
pub struct Point3WithId {
dims: [f64; 3],
pub id: i32,
}
impl KdtreePointTrait for Point3WithId {
fn dims(&self) -> &[f64] {
return &self.dims;
}
}
```
Where id is just a example of the way in which I carry the data.
With that trait implemented you are good to go to use the tree. Keep in mind that the kdtree is not a self balancing tree, so it should not support continous add. right now the tree just handles the build up from Vec. Basic usage can be found in the integration test, fragment copied below:
```
let tree = kdtree::kdtree::Kdtree::new(&mut points.clone());
//test points pushed into the tree, id should be equal.
for i in 0 .. point_count {
let p = &points[i];
assert_eq!(p.id, tree.nearest_search(p).id );
}
```
##Benchmark
`cargo bench` using travis :)
```
running 3 tests
test bench_creating_1000_000_node_tree ... bench: 275,155,622 ns/iter (+/- 32,713,321)
test bench_creating_1000_node_tree ... bench: 121,314 ns/iter (+/- 1,977)
test bench_single_loop_times_for_1000_node_tree ... bench: 162 ns/iter (+/- 76)
test result: ok. 0 passed; 0 failed; 0 ignored; 3 measured
```
~275ms to create a 1000_000 node tree. <<thisbenchisnowdisabled.
~120us to create a 1000 node tree.
160ns to query the tree.
###Benchmark - comparison with CGAL.
Since raw values arent saying much I've created the benchmark comparing this implementation against CGAL. code of the benchmark is available here: https://github.com/fulara/kdtree-benchmarks
Rust_tree_lookup has some overhead since the libraries are being invoked from C code into Rust, and there is minor overhead of that in between, my experience indicates around 50 ns overhead.