Exemplo n.º 1
0
        /// <summary>
        /// Calculate the difference between two ranges, i.e. X - Y.
        /// </summary>
        /// <param name="x">The first range to subtract from.</param>
        /// <param name="y">The second range to subtract with.</param>
        /// <returns>Between 0 and 2 remaining ranges.</returns>
        public static FFloatRange[] Difference(FFloatRange x, FFloatRange y)
        {
            if (x.Overlaps(y))
            {
                FFloatRange lowerRange = new FFloatRange(x.LowerBound, FFloatRangeBound.FlipInclusion(y.LowerBound));
                FFloatRange upperRange = new FFloatRange(FFloatRangeBound.FlipInclusion(y.UpperBound), x.UpperBound);

                if (!lowerRange.IsEmpty())
                {
                    if (!upperRange.IsEmpty())
                    {
                        return(new FFloatRange[] { lowerRange, upperRange });
                    }
                    else
                    {
                        return(new FFloatRange[] { lowerRange });
                    }
                }

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

                return(new FFloatRange[0]);
            }
            else
            {
                return(new FFloatRange[] { x });
            }
        }