/// <summary> /// Split the range into two ranges at the specified element. /// /// If a range [A, C) does not contain the element X, the original range is returned. /// Otherwise the range is split into two ranges [A, X) and [X, C), each of which may be empty. /// </summary> /// <param name="element">The element at which to split the range.</param> /// <returns></returns> public FInt32Range[] Split(int element) { if (Contains(element)) { return(new FInt32Range[] { new FInt32Range(LowerBound, FInt32RangeBound.Exclusive(element)), new FInt32Range(FInt32RangeBound.Inclusive(element), UpperBound) }); } else { return(new FInt32Range[] { this }); } }
/// <summary> /// Create and initializes a new range with the given lower and upper bounds. /// /// The created range is of the form [A, B). /// </summary> /// <param name="a">The range's lower bound value (inclusive).</param> /// <param name="b">The range's upper bound value (exclusive).</param> public FInt32Range(int a, int b) { LowerBound = FInt32RangeBound.Inclusive(a); UpperBound = FInt32RangeBound.Exclusive(b); }
/// <summary> /// Create a right-bounded range that contains all elements less than the specified value. /// </summary> /// <param name="value">The value.</param> /// <returns>A new range.</returns> public static FInt32Range LessThan(int value) { return(new FInt32Range(FInt32RangeBound.Open(), FInt32RangeBound.Exclusive(value))); }
/// <summary> /// Create a range that excludes the given minimum and maximum values. /// </summary> /// <param name="min">The minimum value to be included.</param> /// <param name="max">The maximum value to be included.</param> /// <returns>A new range.</returns> public static FInt32Range Exclusive(int min, int max) { return(new FInt32Range(FInt32RangeBound.Exclusive(min), FInt32RangeBound.Exclusive(max))); }
/// <summary> /// Return an empty range. /// </summary> /// <returns>Empty range.</returns> public static FInt32Range Empty() { return(new FInt32Range(FInt32RangeBound.Exclusive(default(int)), FInt32RangeBound.Exclusive(default(int)))); }