Esempio n. 1
0
        /// <summary>
        /// Tests if this range touches another. For example (1-2) touches (3,5) but (1,2) does not touch (4,5)
        /// </summary>
        /// <param name="range">the other range</param>
        /// <returns>true if they touch</returns>
        public bool Touches(IntRange range)
        {
            var val = _touches(this, range) || _touches(range, this);

            return(val);
        }
Esempio n. 2
0
 private static bool _intersects(IntRange range1, IntRange range2)
 {
     return((range1.Lower <= range2.Lower) && (range1.Upper >= range2.Lower));
 }
Esempio n. 3
0
 /// <summary>
 /// Tests if this range interests with another
 /// </summary>
 /// <param name="range">the other range</param>
 /// <returns>true if they intersect</returns>
 public bool Intersects(IntRange range)
 {
     return(_intersects(this, range) || _intersects(range, this));
 }
Esempio n. 4
0
        private static bool _touches(IntRange range1, IntRange range2)
        {
            var val = (range1.Upper + Delta) == range2.Lower;

            return(val);
        }
Esempio n. 5
0
 /// <summary>
 /// Join this range with another and return a single range that contains them both. The ranges must either touch or interest.
 /// for example (0,2) amd (3,7) will yield (0,7)
 /// </summary>
 /// <param name="range">the other range</param>
 /// <returns>the merged range</returns>
 public IntRange JoinWith(IntRange range)
 {
     if (this.Intersects(range) || this.Touches(range))
     {
         int new_Upper = System.Math.Max(this.Upper, range.Upper);
         int new_Lower = System.Math.Min(this.Lower, range.Lower);
         return IntRange.FromEndpoints(new_Lower, new_Upper);
     }
     else
     {
         throw new System.ArgumentException();
     }
 }
Esempio n. 6
0
 private static bool _intersects(IntRange range1, IntRange range2)
 {
     return ((range1.Lower <= range2.Lower) && (range1.Upper >= range2.Lower));
 }
Esempio n. 7
0
 private static bool _touches(IntRange range1, IntRange range2)
 {
     var val = (range1.Upper + Delta) == range2.Lower;
     return val;
 }
Esempio n. 8
0
 /// <summary>
 /// Tests if this range touches another. For example (1-2) touches (3,5) but (1,2) does not touch (4,5)
 /// </summary>
 /// <param name="range">the other range</param>
 /// <returns>true if they touch</returns>
 public bool Touches(IntRange range)
 {
     var val = _touches(this, range) || _touches(range, this);
     return val;
 }
Esempio n. 9
0
 /// <summary>
 /// Tests if this range interests with another
 /// </summary>
 /// <param name="range">the other range</param>
 /// <returns>true if they intersect</returns>
 public bool Intersects(IntRange range)
 {
     return (_intersects(this, range) || _intersects(range, this));
 }
Esempio n. 10
0
        public void AddInclusive(int lower, int upper)
        {
            var rng = IntRange.FromEndpoints(lower, upper);

            this.Add(rng);
        }
Esempio n. 11
0
        public void Add(int n)
        {
            var rng = IntRange.FromInteger(n);

            this.Add(rng);
        }
Esempio n. 12
0
        public void RemoveInclusive(int lower, int upper)
        {
            var rng = IntRange.FromEndpoints(lower, upper);

            this.Remove(rng);
        }
Esempio n. 13
0
        public void Remove(int value)
        {
            var rng = IntRange.FromInteger(value);

            this.Remove(rng);
        }