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
use crate::interval::*;
use std::arch::x86_64::*;
impl Interval {
pub fn convex_hull(self, rhs: Self) -> Self {
if self.is_empty() {
return rhs;
}
if rhs.is_empty() {
return self;
}
Self {
rep: unsafe { _mm_max_pd(self.rep, rhs.rep) },
}
}
pub fn intersection(self, rhs: Self) -> Self {
if self.is_empty() || rhs.is_empty() {
return Self::EMPTY;
}
let i = Self {
rep: unsafe { _mm_min_pd(self.rep, rhs.rep) },
};
if i.inf_raw() > i.sup_raw() {
Self::EMPTY
} else {
i
}
}
}
macro_rules! impl_dec {
($f:ident) => {
pub fn $f(self, rhs: Self) -> Self {
if self.is_nai() || rhs.is_nai() {
return Self::NAI;
}
Self::new_unchecked(self.x.$f(rhs.x), Decoration::Trv)
}
};
}
impl DecoratedInterval {
impl_dec!(convex_hull);
impl_dec!(intersection);
}
#[cfg(test)]
mod tests {
use super::*;
type DI = DecoratedInterval;
type I = Interval;
#[test]
fn empty() {
assert_eq!(I::EMPTY.convex_hull(I::PI), I::PI);
assert_eq!(I::PI.convex_hull(I::EMPTY), I::PI);
assert!(I::EMPTY.intersection(I::PI).is_empty());
assert!(I::PI.intersection(I::EMPTY).is_empty());
assert_eq!(DI::EMPTY.convex_hull(DI::PI), DI::PI);
assert_eq!(DI::PI.convex_hull(DI::EMPTY), DI::PI);
assert!(DI::EMPTY.intersection(DI::PI).is_empty());
assert!(DI::PI.intersection(DI::EMPTY).is_empty());
}
#[test]
fn nai() {
assert!(DI::NAI.convex_hull(DI::PI).is_nai());
assert!(DI::PI.convex_hull(DI::NAI).is_nai());
assert!(DI::NAI.intersection(DI::PI).is_nai());
assert!(DI::PI.intersection(DI::NAI).is_nai());
}
}