use crate::*; /// # A trait for time overlapping /// /// Two time windows overlap if the /// intersection is not empty. pub trait TimeOverlapping { fn overlaps(&self, rhs: &TW) -> bool; } impl TimeOverlapping for TW1 where TW2: TimeBounds { #[inline] fn overlaps(&self, rhs: &TW2) -> bool { self.lower_bound() <= rhs.upper_bound() && rhs.lower_bound() <= self.upper_bound() } } impl TimeOverlapping> for TW { #[inline] fn overlaps(&self, rhs: &TimeSet) -> bool { rhs.overlaps(self) } } impl TimeOverlapping for TimeSet where TW: TimeConvex { #[inline] fn overlaps(&self, rhs: &TW) -> bool { self.0.iter() .find(|ts| ts.upper_bound() >= rhs.lower_bound()) .map(|ts| ts.lower_bound() <= rhs.upper_bound()) .unwrap_or(false) } } impl TimeOverlapping for TimeSet { fn overlaps(&self, rhs: &Self) -> bool { // todo: optimise it by using order of inner intervals rhs.into_iter().any(|tw| self.overlaps(&tw)) } }