public static RectangleG Union(RectangleG left, RectangleG right) { int x1 = Math.Min(left.X, right.X); int x2 = Math.Max(left.Right, right.Right); int y1 = Math.Min(left.Y, right.Y); int y2 = Math.Max(left.Bottom, right.Bottom); return new RectangleG(x1, y1, x2 - x1, y2 - y1); }
public void Union(RectangleG rect) { RectangleG result = RectangleG.Union(this, rect); this.X = result.X; this.Y = result.Y; this.Width = result.Width; this.Height = result.Height; }
// Does this rectangle intersect with the one specified? public bool IntersectsWith(RectangleG rect) { return (rect.X < Right) && (this.X < rect.Right) && (rect.Y < this.Bottom) && (this.Y < rect.Bottom); }
// Generic routine to create the intersection between // two rectangles. // public static RectangleG Intersect(RectangleG left, RectangleG right) { int x1 = Math.Max(left.X, right.X); int x2 = Math.Min(left.Right, right.Right); int y1 = Math.Max(left.Y, right.Y); int y2 = Math.Min(left.Bottom, right.Bottom); if (x2 >= x1 && y2 >= y1) { return new RectangleG(x1, y1, x2 - x1, y2 - y1); } return RectangleG.Empty; }
// Change the shape of this rectangle by intersecting // it with another one. public void Intersect(RectangleG rect) { RectangleG result = RectangleG.Intersect(rect, this); this.X = result.X; this.Y = result.Y; this.Width = result.Width; this.Height = result.Height; }
public bool Contains(RectangleG rect) { return (this.X <= rect.X) && ((rect.Right) <= (this.Right)) && (this.Y <= rect.Y) && ((rect.Bottom) <= (this.Bottom)); }