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
#[inline]
pub fn min<'out, T>(out: &'out mut [T; 2], a: &[T; 2], b: &[T; 2]) -> &'out mut [T; 2]
where
T: Clone + PartialOrd,
{
out[0] = if &b[0] < &a[0] {
b[0].clone()
} else {
a[0].clone()
};
out[1] = if &b[1] < &a[1] {
b[1].clone()
} else {
a[1].clone()
};
out
}
#[inline]
pub fn max<'out, T>(out: &'out mut [T; 2], a: &[T; 2], b: &[T; 2]) -> &'out mut [T; 2]
where
T: Clone + PartialOrd,
{
out[0] = if &b[0] > &a[0] {
b[0].clone()
} else {
a[0].clone()
};
out[1] = if &b[1] > &a[1] {
b[1].clone()
} else {
a[1].clone()
};
out
}
#[inline]
pub fn clamp<'out, T>(out: &'out mut [T; 2], a: &[T; 2], b: &[T; 2]) -> &'out mut [T; 2]
where
T: Clone + PartialOrd,
{
let mut tmp = out.clone();
max(out, &tmp, a);
tmp = out.clone();
min(out, &tmp, b)
}