예제 #1
0
        public static Rectangle Union( params Rectangle[] rects )
        {
            Rectangle union = new Rectangle( 0, 0, 0, 0 );

            foreach( Rectangle rect in rects )
            {
                if( union.Width == 0 || union.Height == 0 )
                {
                    union = rect;
                }
                else if( rect.Width != 0 && rect.Height != 0 )
                {
                    double x = Math.Min( union.X, rect.X);
                    double y = Math.Min( union.Y, rect.Y );
                    double right = Math.Max( union.Right, rect.Right );
                    double bottom = Math.Max( union.Bottom, rect.Bottom );

                    union = new Rectangle( x, y, right - x, bottom - y );
                }
            }

            return union;
        }
예제 #2
0
 public static Rectangle Shrink( Rectangle rect, double by )
 {
     return new Rectangle( rect.X + by, rect.Y + by, rect.Width - by * 2, rect.Height - by * 2 );
 }
예제 #3
0
 public static Rectangle Offset( Rectangle rect, Point offset )
 {
     return new Rectangle( rect.X + offset.X, rect.Y + offset.Y, rect.Width, rect.Height );
 }
예제 #4
0
        public static bool Overlap( Rectangle r1, Rectangle r2 )
        {
            if( r1 == null )
            {
                throw new ArgumentNullException( "r1" );
            }
            if( r2 == null )
            {
                throw new ArgumentNullException( "r2" );
            }

            if( r1.Right < r2.Left || r2.Right < r1.Left )
            {
                return false;
            }
            if( r1.Bottom < r2.Top || r2.Bottom < r1.Top )
            {
                return false;
            }

            return true;
        }
예제 #5
0
 public static Rectangle Expand( Rectangle rect, double by )
 {
     return new Rectangle( rect.X - by, rect.Y - by, rect.Width + by * 2, rect.Height + by * 2 );
 }