Beispiel #1
0
        /// <summary>
        /// Gets the intersection of two rectangles.
        /// </summary>
        /// <param name="rect">The other rectangle.</param>
        /// <returns>The intersection.</returns>
        public PixelRect Intersect(PixelRect rect)
        {
            var newLeft   = (rect.X > X) ? rect.X : X;
            var newTop    = (rect.Y > Y) ? rect.Y : Y;
            var newRight  = (rect.Right < Right) ? rect.Right : Right;
            var newBottom = (rect.Bottom < Bottom) ? rect.Bottom : Bottom;

            if ((newRight > newLeft) && (newBottom > newTop))
            {
                return(new PixelRect(newLeft, newTop, newRight - newLeft, newBottom - newTop));
            }
            else
            {
                return(Empty);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Gets the union of two rectangles.
        /// </summary>
        /// <param name="rect">The other rectangle.</param>
        /// <returns>The union.</returns>
        public PixelRect Union(PixelRect rect)
        {
            if (IsEmpty)
            {
                return(rect);
            }
            else if (rect.IsEmpty)
            {
                return(this);
            }
            else
            {
                var x1 = Math.Min(X, rect.X);
                var x2 = Math.Max(Right, rect.Right);
                var y1 = Math.Min(Y, rect.Y);
                var y2 = Math.Max(Bottom, rect.Bottom);

                return(new PixelRect(new PixelPoint(x1, y1), new PixelPoint(x2, y2)));
            }
        }
Beispiel #3
0
 /// <summary>
 /// Determines whether a rectangle intersects with this rectangle.
 /// </summary>
 /// <param name="rect">The other rectangle.</param>
 /// <returns>
 /// True if the specified rectangle intersects with this one; otherwise false.
 /// </returns>
 public bool Intersects(PixelRect rect)
 {
     return((rect.X < Right) && (X < rect.Right) && (rect.Y < Bottom) && (Y < rect.Bottom));
 }
Beispiel #4
0
 /// <summary>
 /// Determines whether the rectangle fully contains another rectangle.
 /// </summary>
 /// <param name="r">The rectangle.</param>
 /// <returns>true if the rectangle is fully contained; otherwise false.</returns>
 public bool Contains(PixelRect r)
 {
     return(Contains(r.TopLeft) && Contains(r.BottomRight));
 }