chronologic/relns/
overlap.rs1use crate::*;
2
3pub trait TimeOverlapping<TW> {
8 fn overlaps(&self, rhs: &TW) -> bool;
9}
10
11
12impl<TW1:TimeConvex,TW2:TimeConvex> TimeOverlapping<TW2> for TW1
13 where TW2: TimeBounds<TimePoint=TW1::TimePoint>
14{
15 #[inline]
16 fn overlaps(&self, rhs: &TW2) -> bool {
17 self.lower_bound() <= rhs.upper_bound() && rhs.lower_bound() <= self.upper_bound()
18 }
19}
20
21
22impl<TW:TimeConvex> TimeOverlapping<TimeSet<TW::TimePoint>> for TW
23{
24 #[inline]
25 fn overlaps(&self, rhs: &TimeSet<TW::TimePoint>) -> bool {
26 rhs.overlaps(self)
27 }
28}
29
30impl<T:TimePoint, TW> TimeOverlapping<TW> for TimeSet<T>
31 where TW: TimeConvex<TimePoint=T>
32{
33 #[inline]
34 fn overlaps(&self, rhs: &TW) -> bool
35 {
36 self.0.iter()
37 .find(|ts| ts.upper_bound() >= rhs.lower_bound())
38 .map(|ts| ts.lower_bound() <= rhs.upper_bound())
39 .unwrap_or(false)
40 }
41}
42
43impl<T:TimePoint> TimeOverlapping<Self> for TimeSet<T>
44{
45 fn overlaps(&self, rhs: &Self) -> bool {
46 rhs.into_iter().any(|tw| self.overlaps(&tw))
48 }
49}