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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
use crate::{CoordinateType, Point};
use num_traits::Float;
#[cfg_attr(feature = "use-serde", derive(Serialize, Deserialize))]
#[derive(PartialEq, Clone, Copy, Debug)]
pub struct Extremes {
pub ymin: usize,
pub xmax: usize,
pub ymax: usize,
pub xmin: usize,
}
impl From<Vec<usize>> for Extremes {
fn from(original: Vec<usize>) -> Extremes {
Extremes {
ymin: original[0],
xmax: original[1],
ymax: original[2],
xmin: original[3],
}
}
}
#[cfg_attr(feature = "use-serde", derive(Serialize, Deserialize))]
#[derive(PartialEq, Clone, Copy, Debug)]
pub struct ExtremePoint<T>
where
T: CoordinateType,
{
pub ymin: Point<T>,
pub xmax: Point<T>,
pub ymax: Point<T>,
pub xmin: Point<T>,
}
#[cfg_attr(feature = "use-serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Closest<F: Float> {
Intersection(Point<F>),
SinglePoint(Point<F>),
Indeterminate,
}
impl<F: Float> 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
}
}
}