private static List <Interval <T> > SingleIntervalComplement <T>(Interval <T> interval) where T : IComparable { if (interval.IsEmpty()) { return(new List <Interval <T> > { Interval <T> .FromBounds(Bound <T> .NegativeInfinity(), Bound <T> .PositiveInfinity()) }); } if (interval.LowerBound.IsNegativeInfinity()) { if (interval.UpperBound.IsPositiveInfinity()) { return(new List <Interval <T> > { Interval <T> .Empty() }); } return(new List <Interval <T> > { UpperUnbounded() }); } if (interval.UpperBound.IsPositiveInfinity()) { return(new List <Interval <T> > { LowerUnbounded() }); } return(new List <Interval <T> > { LowerUnbounded(), UpperUnbounded() }); // Local functions Interval <T> UpperUnbounded() { return(Interval <T> .FromBounds(interval.UpperBound.IsOpen() ?Bound <T> .Closed(interval.UpperBound) : Bound <T> .Open(interval.UpperBound), Bound <T> .PositiveInfinity())); } Interval <T> LowerUnbounded() { return(Interval <T> .FromBounds(Bound <T> .NegativeInfinity(), interval.LowerBound.IsOpen() ?Bound <T> .Closed(interval.LowerBound) : Bound <T> .Open(interval.LowerBound))); } }
/// <summary> /// Creates an interval with a closed lower bound and an open upper bound. /// </summary> /// <param name="lowerBound">The lower bound.</param> /// <param name="upperBound">The upper bound.</param> public static Interval <T> ClosedOpen(T lowerBound, T upperBound) { return(FromBounds(Bound <T> .Closed(lowerBound), Bound <T> .Open(upperBound))); }