points/
points.rs

1#[derive(Copy, Clone)]
2struct Point {
3    x: f32, y: f32,
4}
5
6impl vpsearch::MetricSpace for Point {
7    type UserData = ();
8    type Distance = f32;
9
10    fn distance(&self, other: &Self, _: &Self::UserData) -> Self::Distance {
11        let dx = self.x - other.x;
12        let dy = self.y - other.y;
13
14        dx.hypot(dy) // can't use manhattan nor squared dist
15    }
16}
17
18fn main() {
19
20    let points = vec![Point{x:2.0,y:3.0}, Point{x:0.0,y:1.0}, Point{x:4.0,y:5.0}];
21
22    let vp = vpsearch::Tree::new(&points);
23
24    let (index, _) = vp.find_nearest(&Point{x:1.0,y:2.0});
25
26    println!("The nearest point is at ({}, {})", points[index].x, points[index].y);
27}