Beispiel #1
0
        public static RECT Intersection(this RECT r1, RECT r2)
        {
            if (
                // r2 has no points inside r1
                (r1.InsideRect(r2.Left, r2.Top) == false &&
                 r1.InsideRect(r2.Left, r2.Bottom) == false &&
                 r1.InsideRect(r2.Right, r2.Top) == false &&
                 r1.InsideRect(r2.Right, r2.Bottom) == false) &&
                // r1 has no points inside r2
                (r2.InsideRect(r1.Left, r1.Top) == false &&
                 r2.InsideRect(r1.Left, r1.Bottom) == false &&
                 r2.InsideRect(r1.Right, r1.Top) == false &&
                 r2.InsideRect(r1.Right, r1.Bottom) == false)
                )
            {
                return(new RECT(0, 0, 0, 0));
            }

            int left   = Math.Max(r1.Left, r2.Left);
            int top    = Math.Max(r1.Top, r2.Top);
            int right  = Math.Min(r1.Right, r2.Right);
            int bottom = Math.Min(r1.Bottom, r2.Bottom);

            return(new RECT(left, top, right, bottom));
        }