public void Bind(Rect r) { if (IsNull() || r.IsNull()) { return; } if (Right() > r.Right()) { MoveRight(r.Right()); } if (Bottom() > r.Bottom()) { MoveBottom(r.Bottom()); } if (Left() < r.Left()) { MoveLeft(r.Left()); } if (Top() < r.Top()) { MoveTop(r.Top()); } }
public Rect Intersection(Rect r) { if (IsNull()) { return(r); } if (r.IsNull()) { return(this); } int l1 = _x1; int r1 = _x1; if (_x2 - _x1 + 1 < 0) { l1 = _x2; } else { r1 = _x2; } int l2 = r._x1; int r2 = r._x1; if (r._x2 - r._x1 + 1 < 0) { l2 = r._x2; } else { r2 = r._x2; } int t1 = _y1; int b1 = _y1; if (_y2 - _y1 + 1 < 0) { t1 = _y2; } else { b1 = _y2; } int t2 = r._y1; int b2 = r._y1; if (r._y2 - r._y1 + 1 < 0) { t2 = r._y2; } else { b2 = r._y2; } Rect tmp = new Rect(); tmp._x1 = System.Math.Max(l1, l2); tmp._x2 = System.Math.Min(r1, r2); tmp._y1 = System.Math.Max(t1, t2); tmp._y2 = System.Math.Min(b1, b2); return(tmp); }
public bool Intersects(Rect r) { if (IsNull() || r.IsNull()) { return(false); } int l1 = _x1; int r1 = _x1; if (_x2 - _x1 + 1 < 0) { l1 = _x2; } else { r1 = _x2; } int l2 = r._x1; int r2 = r._x1; if (r._x2 - r._x1 + 1 < 0) { l2 = r._x2; } else { r2 = r._x2; } if (l1 > r2 || l2 > r1) { return(false); } int t1 = _y1; int b1 = _y1; if (_y2 - _y1 + 1 < 0) { t1 = _y2; } else { b1 = _y2; } int t2 = r._y1; int b2 = r._y1; if (r._y2 - r._y1 + 1 < 0) { t2 = r._y2; } else { b2 = r._y2; } if (t1 > b2 || t2 > b1) { return(false); } return(true); }