pub fn overlap<T: Copy + PartialOrd>(
a: Interval<T>,
b: Interval<T>,
) -> Interval<T>Expand description
Calculate the overlap of the two Intervals.
a,btheIntervals.
returns the overlap, or None if the overlap is not valid.
ยงExamples
use generic_interval::{Interval, overlap};
#[derive(Clone, Copy, Debug, PartialEq, PartialOrd)]
pub struct Metres(pub f64);
let a = Interval::try_from((Metres(1.0), Metres(4.0))).unwrap();
let b = Interval::try_from((Metres(6.0), Metres(9.0))).unwrap();
let result = overlap(a, b);
assert!(result.is_empty());
let c = Interval::try_from((Metres(4.0), Metres(9.0))).unwrap();
let result = overlap(a, c);
assert_eq!(Metres(4.0), result.lower());
assert_eq!(Metres(4.0), result.upper());