/// <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 range with a single element. /// /// The created range is of the form [A, A]. /// </summary> /// <param name="a">The element in the range.</param> public FInt32Range(int a) { LowerBound = FInt32RangeBound.Inclusive(a); UpperBound = FInt32RangeBound.Inclusive(a); }
/// <summary> /// Create a range that includes 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 Inclusive(int min, int max) { return(new FInt32Range(FInt32RangeBound.Inclusive(min), FInt32RangeBound.Inclusive(max))); }
/// <summary> /// Create a right-bounded range that contains all elements less than or equal to the specified value. /// </summary> /// <param name="value">The value.</param> /// <returns>A new range.</returns> public static FInt32Range AtMost(int value) { return(new FInt32Range(FInt32RangeBound.Open(), FInt32RangeBound.Inclusive(value))); }