예제 #1
0
        /// <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 FFloatRange[] Union(FFloatRange x, FFloatRange y)
        {
            if (x.Contains(y))
            {
                return(new FFloatRange[]
                {
                    new FFloatRange(
                        FFloatRangeBound.MinLower(x.LowerBound, y.LowerBound),
                        FFloatRangeBound.MaxUpper(x.UpperBound, y.UpperBound))
                });
            }
            else
            {
                if (!x.IsEmpty())
                {
                    if (!y.IsEmpty())
                    {
                        return(new FFloatRange[] { x, y });
                    }
                    else
                    {
                        return(new FFloatRange[] { x });
                    }
                }

                if (!y.IsEmpty())
                {
                    return(new FFloatRange[] { y });
                }

                return(new FFloatRange[0]);
            }
        }
예제 #2
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 FFloatRange Hull(FFloatRange x, FFloatRange y)
        {
            if (x.IsEmpty())
            {
                return(y);
            }

            if (y.IsEmpty())
            {
                return(x);
            }

            return(new FFloatRange(
                       FFloatRangeBound.MinLower(x.LowerBound, y.LowerBound),
                       FFloatRangeBound.MaxUpper(x.UpperBound, y.UpperBound)));
        }
예제 #3
0
 /// <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(FFloatRange other)
 {
     return((FFloatRangeBound.MinLower(LowerBound, other.LowerBound) == LowerBound) &&
            (FFloatRangeBound.MaxUpper(UpperBound, other.UpperBound) == UpperBound));
 }
예제 #4
0
 /// <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(float element)
 {
     return((FFloatRangeBound.MinLower(LowerBound, new FFloatRangeBound(element)) == LowerBound) &&
            (FFloatRangeBound.MaxUpper(UpperBound, new FFloatRangeBound(element)) == UpperBound));
 }