/// <summary> /// Return the union of two contiguous ranges. /// /// A union is a range or series of ranges that contains both ranges. /// </summary> /// <param name="x">The first range.</param> /// <param name="y">The second range.</param> /// <returns>The union, or both ranges if the two ranges are not contiguous, or no ranges if both ranges are empty.</returns> public static FInt32Range[] Union(FInt32Range x, FInt32Range y) { if (x.Contains(y)) { return(new FInt32Range[] { new FInt32Range( FInt32RangeBound.MinLower(x.LowerBound, y.LowerBound), FInt32RangeBound.MaxUpper(x.UpperBound, y.UpperBound)) }); } else { if (!x.IsEmpty()) { if (!y.IsEmpty()) { return(new FInt32Range[] { x, y }); } else { return(new FInt32Range[] { x }); } } if (!y.IsEmpty()) { return(new FInt32Range[] { y }); } return(new FInt32Range[0]); } }
/// <summary> /// Compute the hull of two ranges. /// /// The hull is the smallest range that contains both ranges. /// </summary> /// <param name="x">The first range.</param> /// <param name="y">The second range.</param> /// <returns>The hull.</returns> public static FInt32Range Hull(FInt32Range x, FInt32Range y) { if (x.IsEmpty()) { return(y); } if (y.IsEmpty()) { return(x); } return(new FInt32Range( FInt32RangeBound.MinLower(x.LowerBound, y.LowerBound), FInt32RangeBound.MaxUpper(x.UpperBound, y.UpperBound))); }
/// <summary> /// Check whether this range contains another range. /// </summary> /// <param name="other">The range to check.</param> /// <returns>true if the range contains the other range, false otherwise.</returns> public bool Contains(FInt32Range other) { return((FInt32RangeBound.MinLower(LowerBound, other.LowerBound) == LowerBound) && (FInt32RangeBound.MaxUpper(UpperBound, other.UpperBound) == UpperBound)); }
/// <summary> /// Check whether this range contains the specified element. /// </summary> /// <param name="element">The element to check.</param> /// <returns>true if the range contains the element, false otherwise.</returns> public bool Contains(int element) { return((FInt32RangeBound.MinLower(LowerBound, new FInt32RangeBound(element)) == LowerBound) && (FInt32RangeBound.MaxUpper(UpperBound, new FInt32RangeBound(element)) == UpperBound)); }