1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use crate::{GeoFloat, Point};
#[cfg_attr(feature = "use-serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Closest<F: GeoFloat> {
Intersection(Point<F>),
SinglePoint(Point<F>),
Indeterminate,
}
impl<F: GeoFloat> Closest<F> {
pub fn best_of_two(&self, other: &Self, p: Point<F>) -> Self {
use crate::algorithm::euclidean_distance::EuclideanDistance;
let left = match *self {
Closest::Indeterminate => return *other,
Closest::Intersection(_) => return *self,
Closest::SinglePoint(l) => l,
};
let right = match *other {
Closest::Indeterminate => return *self,
Closest::Intersection(_) => return *other,
Closest::SinglePoint(r) => r,
};
if left.euclidean_distance(&p) <= right.euclidean_distance(&p) {
*self
} else {
*other
}
}
}