Skip to main content

sphere_knn/
lla_node.rs

1use crate::utils::spherical_to_cartesian;
2use positionable::positionable;
3
4pub type CartesianPosition = [f64; 3];
5
6pub trait SphereKnnGetters {
7    fn get_lat(&self) -> f64;
8    fn get_lng(&self) -> f64;
9}
10
11#[derive(Clone, Debug)]
12pub enum NodeOrData<T: Clone> {
13    Node(LLANode<T>),
14    Data(LocationData<T>),
15}
16
17#[derive(Clone, Debug)]
18pub struct LLANode<T: Clone> {
19    pub axis: usize,
20    pub split: f64,
21    pub left: Box<NodeOrData<T>>,
22    pub right: Box<NodeOrData<T>>,
23}
24
25#[positionable]
26pub struct LocationData<T: Clone> {
27    pub position: CartesianPosition,
28    pub lat: f64,
29    pub lng: f64,
30    pub data: T,
31}
32
33impl<T: Clone> LocationData<T> {
34    pub fn new(lat: f64, lng: f64, data: T) -> Self {
35        LocationData {
36            position: spherical_to_cartesian(lat, lng),
37            lat,
38            lng,
39            data,
40        }
41    }
42}
43
44/// Options for filtering results
45#[positionable]
46pub struct Opts {
47    /// Distance in meters to consider in calculation.
48    /// Results that exceed this threshold will be omitted
49    pub max_distance_threshold_meters: Option<f64>,
50    /// Total number of results required.
51    /// There is no default, so you likely want to set this
52    pub number_results: Option<usize>,
53}