/// <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); }
private static bool _intersects(IntRange range1, IntRange range2) { return((range1.Lower <= range2.Lower) && (range1.Upper >= range2.Lower)); }
/// <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)); }
private static bool _touches(IntRange range1, IntRange range2) { var val = (range1.Upper + Delta) == range2.Lower; return(val); }
/// <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(); } }
private static bool _intersects(IntRange range1, IntRange range2) { return ((range1.Lower <= range2.Lower) && (range1.Upper >= range2.Lower)); }
private static bool _touches(IntRange range1, IntRange range2) { var val = (range1.Upper + Delta) == range2.Lower; return val; }
/// <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; }
/// <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)); }
public void AddInclusive(int lower, int upper) { var rng = IntRange.FromEndpoints(lower, upper); this.Add(rng); }
public void Add(int n) { var rng = IntRange.FromInteger(n); this.Add(rng); }
public void RemoveInclusive(int lower, int upper) { var rng = IntRange.FromEndpoints(lower, upper); this.Remove(rng); }
public void Remove(int value) { var rng = IntRange.FromInteger(value); this.Remove(rng); }