예제 #1
0
 public static Interval <V> ClosedStartClosedEnd <V>(V start, V end) where V : IComparable <V>
 {
     ValidatePointValueNotNull <V>(start);
     ValidatePointValueNotNull <V>(end);
     ValidateStartBeforeEnd(start, end);
     return(new Interval <V>(IntervalPoint <V> .Closed(start), IntervalPoint <V> .Closed(end)));
 }
예제 #2
0
 private bool InfinityLessThanComparisons(IntervalPoint <T> other)
 {
     if (!this.IsInfinity() && !other.IsInfinity())
     {
         throw new ArgumentOutOfRangeException("At least one value must be infinity");
     }
     return(!(this.IsPositiveInfinity() || other.IsNegativeInfinity()));
 }
예제 #3
0
 protected bool GreaterOrEqualTo(IntervalPoint <T> other)
 {
     if (this.IsInfinity() || other.IsInfinity())
     {
         return(InfinityGreaterThanComparisons(other));
     }
     return(this.Point.CompareTo(other.Point) > 0 || (!this.IsOpen && !other.IsOpen && this.Point.CompareTo(other.Point) == 0));
 }
예제 #4
0
 protected bool GreaterThan(IntervalPoint <T> other)
 {
     if (this.IsInfinity() || other.IsInfinity())
     {
         return(InfinityGreaterThanComparisons(other));
     }
     return(this.Point.CompareTo(other.Point) > 0);
 }
예제 #5
0
        public bool Contains(T value)
        {
            if (this.IsEmpty())
            {
                return(false);
            }
            var other = IntervalPoint <T> .Closed(value);

            return(other >= Start && other <= End);
        }
예제 #6
0
        public int CompareClosedValueTo(IntervalPoint <T> other)
        {
            if (this.IsNegativeInfinity())
            {
                if (other.IsNegativeInfinity())
                {
                    return(0);
                }
                else
                {
                    return(-1);
                }
            }
            else if (this.IsPositiveInfinity())
            {
                if (other.IsPositiveInfinity())
                {
                    return(0);
                }
                else
                {
                    return(1);
                }
            }
            else if (other.IsNegativeInfinity())
            {
                if (this.IsNegativeInfinity())
                {
                    return(0);
                }
                else
                {
                    return(1);
                }
            }
            else if (other.IsPositiveInfinity())
            {
                if (this.IsPositiveInfinity())
                {
                    return(0);
                }
                else
                {
                    return(-1);
                }
            }

            return(this.Point.CompareTo(other.Point));
        }
예제 #7
0
        public static Interval <V> OpenBetween <V>(Maybe <V> start, Maybe <V> end) where V : IComparable <V>
        {
            var startIntervalPoint = IntervalPoint <V> .PositiveInfinity <V>();

            var endIntervalPoint = IntervalPoint <V> .NegativeInfinity <V>();

            if (start.HasValue)
            {
                ValidatePointValueNotNull <V>(start.Value);
                startIntervalPoint = IntervalPoint <V> .Open(start.Value);
            }
            if (end.HasValue)
            {
                ValidatePointValueNotNull <V>(end.Value);
                endIntervalPoint = IntervalPoint <V> .Open(end.Value);
            }
            if (start.HasValue && end.HasValue)
            {
                ValidateStartBeforeEnd(start.Value, end.Value);
            }
            return(new Interval <V>(startIntervalPoint, endIntervalPoint));
        }
예제 #8
0
        private bool Includes(IntervalPoint <T> point)
        {
            if (this.IsEmpty())
            {
                return(false);
            }

            // no infinits
            var compStart = this.Start.CompareClosedValueTo((point));
            var compEnd   = this.End.CompareClosedValueTo((point));

            if (compStart == 0)
            {
                return(!this.Start.IsOpen && !point.IsOpen);
            }

            if (compEnd == 0)
            {
                return(!this.End.IsOpen && !point.IsOpen);
            }

            return(compStart < 0 && compEnd > 0);
        }
예제 #9
0
 /// <summary>
 /// Creates a degenerated interval. A degenerated interval is an interval of one single value. It is the interval representation of a point.
 /// </summary>
 /// <typeparam name="V"></typeparam>
 /// <param name="value"></param>
 /// <returns></returns>
 public static Interval <V> Degenerated <V>(V value) where V : IComparable <V>
 {
     ValidatePointValueNotNull <V>(value);
     return(new Interval <V>(IntervalPoint <V> .Closed <V>(value), IntervalPoint <V> .Closed <V>(value)));
 }
예제 #10
0
 protected Interval(IntervalPoint <T> start, IntervalPoint <T> end)
 {
     Start = start;
     End   = end;
 }
예제 #11
0
 public static Interval <V> InfinityStartInfinityEnd <V>() where V : IComparable <V>
 {
     return(new Interval <V>(IntervalPoint <V> .NegativeInfinity <V>(), IntervalPoint <V> .PositiveInfinity <V>()));
 }
예제 #12
0
 public static Interval <V> InfinityStartClosedEnd <V>(V end) where V : IComparable <V>
 {
     ValidatePointValueNotNull <V>(end);
     return(new Interval <V>(IntervalPoint <V> .NegativeInfinity <V>(), IntervalPoint <V> .Closed(end)));
 }
예제 #13
0
 public static Interval <V> ClosedStartInfinityEnd <V>(V start) where V : IComparable <V>
 {
     ValidatePointValueNotNull <V>(start);
     return(new Interval <V>(IntervalPoint <V> .Closed(start), IntervalPoint <V> .PositiveInfinity <V>()));
 }