Exemple #1
0
        /// <summary>
        /// Intersects the specified rectangle.
        /// </summary>
        /// <param name="rectangle">The rectangle.</param>
        public Rectangle Intersect(Rectangle rectangle)
        {
            if (!this.Intersects(rectangle))
            {
                return Rectangle.Empty;
            }

            float[] horizontal = { this.Left, this.Right, rectangle.Left, rectangle.Right };
            float[] vertical = { this.Bottom, this.Top, rectangle.Bottom, rectangle.Top };

            Array.Sort(horizontal);
            Array.Sort(vertical);

            float left = horizontal[1];
            float bottom = vertical[1];
            float right = horizontal[2];
            float top = vertical[2];

            return new Rectangle(left, top, right - left, bottom - top);
        }
Exemple #2
0
 /// <summary>
 /// Intersectses the specified rectangle.
 /// </summary>
 /// <param name="rectangle">The rectangle.</param>
 public bool Intersects(Rectangle rectangle)
 {
     return
         !(this.Left > rectangle.Right ||
         this.Right < rectangle.Left ||
         this.Top > rectangle.Bottom ||
         this.Bottom < rectangle.Top);
 }
Exemple #3
0
 /// <summary>
 /// Determines whether this instance contains the specified rectangle.
 /// </summary>
 /// <param name="value">The value.</param>
 public bool Contains(Rectangle value)
 {
     return
         value.X >= this.X &&
         value.Y >= this.Y &&
         value.X + value.Width <= this.Right &&
         value.Y + this.Height <= this.Bottom;
 }