コード例 #1
0
 /// <summary>
 /// Returns the intersection of this rectangle and the given rectangle
 /// </summary>
 /// <param name="rect"></param>
 /// <returns></returns>
 public Rectangle Intersect(Rectangle rect)
 {
     float x = Math.Max(this.X, rect.X);
     float width = Math.Min(this.X + this.Width, rect.X + rect.Width);
     float y = Math.Max(this.Y, rect.Y);
     float height = Math.Min(this.Y + this.Height, rect.Y + rect.Height);
     if (width >= x && height >= y)
     {
         return new Rectangle(x, y, y - x, height - y);
     }
     return Rectangle.Empty;
 }
コード例 #2
0
 /// <summary>
 /// Initializes a new rectangle by copying the values of the given rectangle
 /// </summary>
 /// <param name="rect"></param>
 public Rectangle(Rectangle rect)
     : this(rect.X, rect.Y, rect.Width, rect.Height)
 {
 }
コード例 #3
0
 /// <summary>
 /// Returns whether this rectangle intersects with the given rectangle
 /// </summary>
 /// <param name="rect"></param>
 /// <returns></returns>
 public bool IntersectsWith(Rectangle rect)
 {
     return rect.X < this.X + this.Width && this.X < rect.X + rect.Width && rect.Y < this.Y + this.Height && this.Y < rect.Y + rect.Height;
 }