public Rect(Rect r) { Location = new Point(r.Location); Size = new Point(r.Size); }
public void Set(Rect R) { this.Location.Set(R.Location); this.Size.Set(R.Size); }
public void Unite(Rect ToContain) { int x1 = ToContain.mLocation.X; int y1 = ToContain.mLocation.Y; int x2 = ToContain.Right; int y2 = ToContain.Bottom; if (x1 < this.Location.X) { this.Size.X += this.Location.X - x1; this.Location.X = x1; } if (y1 < this.Location.Y) { this.Size.Y += this.Location.Y - y1; this.Location.Y = y1; } if (x2 > this.Right) { this.Size.X = x2 - this.Location.X; } if (y2 > this.Bottom) { this.Size.Y = y2 - this.Location.Y; } }
public bool IntersectsRectY(Rect Reference) { int y1 = Reference.Location.Y; int y2 = Reference.Bottom; int top = this.Location.Y; int bottom = this.Bottom; return (bottom > y1 && top < y2); }
public int RelativeToRectY(Rect Reference) { int y1 = Reference.Location.Y; int y2 = Reference.Bottom; int top = this.Location.Y; int bottom = this.Bottom; if (top >= y2) return 5; if (bottom <= y1) return 1; if (top < y1) { if (bottom <= y2) return 2; return 0; } if (bottom > y2) return 4; return 3; }
public bool IntersectsRectX(Rect Reference) { int x1 = Reference.Location.X; int x2 = Reference.Right; int left = this.Location.X; int right = this.Right; return (right > x1 && left < x2); }
public bool IntersectsRect(Rect Reference) { return IntersectsRectX(Reference) && IntersectsRectY(Reference); }
public bool Contains(Rect inner) { return inner.Location.X >= this.Location.X && inner.Location.Y >= this.Location.Y && inner.Right <= this.Right && inner.Bottom <= this.Bottom; }
public PointClassification ClassifyVertically(Rect r) { if (Y < r.Top) { return PointClassification.Before; } else if (Y <= r.Bottom) { return PointClassification.Inside; } else { return PointClassification.After; } }
public PointClassification ClassifyHorizontally(Rect r) { if (X < r.Left) { return PointClassification.Before; } else if (X <= r.Right) { return PointClassification.Inside; } else { return PointClassification.After; } }