pub trait KdPoint {
type Scalar: NumAssign + Copy + PartialOrd;
type Dim: Unsigned;
fn at(&self, i: usize) -> Self::Scalar;
fn dim() -> usize { ... }
}
Expand description
A trait to represent k-dimensional point.
Example
struct MyItem {
point: [f64; 3],
id: usize,
}
impl kd_tree::KdPoint for MyItem {
type Scalar = f64;
type Dim = typenum::U3;
fn at(&self, k: usize) -> f64 { self.point[k] }
}
let kdtree: kd_tree::KdTree<MyItem> = kd_tree::KdTree::build_by_ordered_float(vec![
MyItem { point: [1.0, 2.0, 3.0], id: 111 },
MyItem { point: [3.0, 1.0, 2.0], id: 222 },
MyItem { point: [2.0, 3.0, 1.0], id: 333 },
]);
assert_eq!(kdtree.nearest(&[3.1, 0.1, 2.2]).unwrap().item.id, 222);