vox_geometry_rust/
nearest_neighbor_query_engine2.rs

1/*
2 * // Copyright (c) 2021 Feng Yang
3 * //
4 * // I am making my contributions/submissions to this project solely in my
5 * // personal capacity and am not conveying any rights to any intellectual
6 * // property of any third parties.
7 */
8
9use crate::vector2::Vector2D;
10
11/// Nearest neighbor query result.
12pub struct NearestNeighborQueryResult2<T> {
13    pub item: Option<T>,
14    pub distance: f64,
15}
16
17impl<T> NearestNeighborQueryResult2<T> {
18    pub fn new() -> NearestNeighborQueryResult2<T> {
19        return NearestNeighborQueryResult2 {
20            item: None,
21            distance: f64::MAX,
22        };
23    }
24}
25
26/// Nearest neighbor distance measure function.
27pub trait NearestNeighborDistanceFunc2<T>: FnMut(&T, &Vector2D) -> f64 {}
28
29impl<T, Super: FnMut(&T, &Vector2D) -> f64> NearestNeighborDistanceFunc2<T> for Super {}
30
31/// Abstract base class for 2-D nearest neighbor query engine.
32pub trait NearestNeighborQueryEngine2<T> {
33    /// Returns the nearest neighbor for given point and distance measure function.
34    fn nearest<Callback>(&self, pt: &Vector2D,
35                         distance_func: &mut Callback) -> NearestNeighborQueryResult2<T>
36        where Callback: NearestNeighborDistanceFunc2<T>;
37}