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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
use super::*;
#[derive(Copy, Clone)]
pub struct Area<X, Y> {
x: Option<[X; 2]>,
y: Option<[Y; 2]>,
}
impl<X: PlotNum, Y: PlotNum> Area<X, Y> {
pub(crate) fn new() -> Area<X, Y> {
Area { x: None, y: None }
}
pub fn grow_area(&mut self, other: &Area<X, Y>) {
match (&mut self.x, &other.x) {
(Some([a_min, a_max]), Some([b_min, b_max])) => {
if *b_max > *a_max {
*a_max = *b_max;
}
if *b_min < *a_min {
*a_min = *b_min;
}
}
(Some(_), None) => {
//do nothing
}
(None, Some(a)) => {
self.x = Some(*a);
}
(None, None) => {
//do nothing
}
}
match (&mut self.y, &other.y) {
(Some([a_min, a_max]), Some([b_min, b_max])) => {
if *b_max > *a_max {
*a_max = *b_max;
}
if *b_min < *a_min {
*a_min = *b_min;
}
}
(Some(_), None) => {
//do nothing
}
(None, Some(a)) => {
self.y = Some(*a);
}
(None, None) => {
//do nothing
}
}
}
#[inline(always)]
pub fn grow(&mut self, x: Option<&X>, y: Option<&Y>) {
if let Some(x) = x {
if !x.is_hole() {
match &mut self.x {
None => self.x = Some([*x, *x]),
Some([min, max]) => {
if *x < *min {
self.x = Some([*x, *max]);
} else if *x > *max {
self.x = Some([*min, *x]);
}
}
}
}
}
if let Some(y) = y {
if !y.is_hole() {
match &mut self.y {
None => self.y = Some([*y, *y]),
Some([min, max]) => {
if *y < *min {
self.y = Some([*y, *max]);
} else if *y > *max {
self.y = Some([*min, *y]);
}
}
}
}
}
}
pub(crate) fn build(self) -> (DataBound<X>, DataBound<Y>) {
let x = match self.x {
None => X::unit_range(None),
Some([min, max]) => {
if min == max {
X::unit_range(Some(min))
} else {
[min, max]
}
}
};
let y = match self.y {
None => Y::unit_range(None),
Some([min, max]) => {
if min == max {
Y::unit_range(Some(min))
} else {
[min, max]
}
}
};
assert!(x[0] != x[1]);
assert!(y[0] != y[1]);
(
DataBound {
min: x[0],
max: x[1],
},
DataBound {
min: y[0],
max: y[1],
},
)
}
}