overlaps

Function overlaps 

Source
pub fn overlaps<T: Copy + PartialOrd>(
    a: Interval<T>,
    b: Interval<T>,
) -> Option<Interval<T>>
Expand description

Calculate the if and where two Intervals overlap..

  • a, b the Intervals.

returns the overlap, i.e. or None if the overlap is not valid.

ยงExamples

use generic_interval::{Interval, overlaps};

#[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 = overlaps(a, b);
assert!(result.is_none());

let c = Interval::try_from((Metres(4.0), Metres(9.0))).unwrap();
let result = overlaps(a, c).unwrap();
assert_eq!(Metres(4.0), result.lower());
assert_eq!(Metres(4.0), result.upper());