overlap

Function overlap 

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

Calculate the overlap of the two Intervals.

  • a, b the Intervals.

returns the overlap, i.e. the max lower and min upper.

ยง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());