Example #1
0
 public void RemoveExclusive(int lower, int upper)
 {
     if ((upper - lower) > (2 * double.Epsilon))
     {
         var rng = DoubleRange.FromEndpoints(lower + double.Epsilon, upper - double.Epsilon);
         this.RemoveInclusive(rng);
     }
 }
Example #2
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 DoubleRange JoinWith(DoubleRange range)
 {
     if (this.IntersectsExclusive(range) || this.Touches(range))
     {
         double new_Upper = System.Math.Max(this.Upper, range.Upper);
         double new_Lower = System.Math.Min(this.Lower, range.Lower);
         return(DoubleRange.FromEndpoints(new_Lower, new_Upper));
     }
     else
     {
         throw new System.ArgumentException("Ranges cannot be joined because they do not touch or overlap");
     }
 }
Example #3
0
        public void RemoveInclusive(DoubleRange range)
        {
            // if the range doesn't intersect this collection do nothing
            if (!range.IntersectsInclusive(DoubleRange.FromEndpoints(this.Lower, this.Upper)))
            {
                return;
            }

            var middle = new List <DoubleRange>();

            foreach (var S in this.ranges)
            {
                if (!range.IntersectsInclusive(S))
                {
                    middle.Add(S);
                    continue;
                }

                if ((range.Lower <= S.Lower) && (range.Upper >= S.Upper))
                {
                    // disregard S completely
                    continue;
                }

                if (range.Lower > S.Lower)
                {
                    if (S.Lower <= (range.Lower - double.Epsilon))
                    {
                        var X = DoubleRange.FromEndpoints(S.Lower, range.Lower);
                        middle.Add(X);
                    }
                }

                if (range.Upper <= S.Upper)
                {
                    if ((range.Upper + double.Epsilon) <= S.Upper)
                    {
                        var X = DoubleRange.FromEndpoints(range.Upper, S.Upper);
                        middle.Add(X);
                    }
                }
                else
                {
                    throw new System.InvalidOperationException("internal error");
                }
            }

            this.ranges = middle;
        }
Example #4
0
        public void AddInclusive(double lower, double upper)
        {
            var rng = DoubleRange.FromEndpoints(lower, upper);

            this.Add(rng);
        }
Example #5
0
        public void RemoveInclusive(int lower, int upper)
        {
            var rng = DoubleRange.FromEndpoints(lower, upper);

            this.RemoveInclusive(rng);
        }