Esempio n. 1
0
        /// <summary>
        /// Returns a third Rectangle structure that represents the intersection of two other Rectangle structures.
        /// If there is no intersection, an empty Rectangle is returned.
        /// </summary>
        /// <param name="a">A rectangle to intersect.</param>
        /// <param name="b">A rectangle to intersect.</param>
        /// <returns>A rectangle that represents the intersection of a and b.</returns>
        public static Rectangle Intersect(Rectangle a, Rectangle b)
        {
            // MS.NET returns a non-empty rectangle if the two rectangles
            // touch each other
            if (!a.intersectsWithInclusive(b))
            {
                return(Empty);
            }

            return(Rectangle.FromLTRB(
                       Math.Max(a.Left, b.Left),
                       Math.Max(a.Top, b.Top),
                       Math.Min(a.Right, b.Right),
                       Math.Min(a.Bottom, b.Bottom)));
        }
Esempio n. 2
0
        /// <summary>
        /// Returns a third Rectangle structure that represents the intersection of two other Rectangle structures. 
        /// If there is no intersection, an empty Rectangle is returned.
        /// </summary>
        /// <param name="a">A rectangle to intersect.</param>
        /// <param name="b">A rectangle to intersect.</param>
        /// <returns>A rectangle that represents the intersection of a and b.</returns>
        public static Rectangle Intersect(Rectangle a, Rectangle b)
        {
            // MS.NET returns a non-empty rectangle if the two rectangles
            // touch each other
            if (!a.intersectsWithInclusive(b))
                return Empty;

            return Rectangle.FromLTRB(
                Math.Max(a.Left, b.Left),
                Math.Max(a.Top, b.Top),
                Math.Min(a.Right, b.Right),
                Math.Min(a.Bottom, b.Bottom));
        }