コード例 #1
0
ファイル: FFloatRange.cs プロジェクト: zwywilliam/USharp
        /// <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
ファイル: FFloatRange.cs プロジェクト: zwywilliam/USharp
        /// <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
ファイル: FFloatRange.cs プロジェクト: zwywilliam/USharp
 /// <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
ファイル: FFloatRange.cs プロジェクト: zwywilliam/USharp
 /// <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));
 }