/// <summary> /// If the point is outside the rectangle specified by the two arguments, /// it will be moved horizontally and/or vertically until it falls /// inside the rectangle. /// </summary> /// <param name="topLeft">Minimum values acceptable for X and Y</param> /// <param name="bottomRight">Maximum values acceptable for X and Y</param> /// public void constrainTo(Point topLeft, Point bottomRight) { if (x < topLeft.x) x = topLeft.x; if (y < topLeft.y) y = topLeft.y; if (x > bottomRight.x) x = bottomRight.x; if (y > bottomRight.y) y = bottomRight.y; }
public Point add(Point rhs) { return new Point(x+rhs.x, y+rhs.y); }
public void addToThis(Point p) { x += p.x; y += p.y; }
public Point subtract(Point rhs) { return new Point(x-rhs.x, y-rhs.y); }
public void subtractFromThis(Point p) { x -= p.x; y -= p.y; }
public Rect(Point leftTop, Point rightBottom) { set(leftTop.x, leftTop.y, rightBottom.x, rightBottom.y); }
public bool contains(Point p) { return ((p.x >= left)&&(p.x <= right)&&(p.y >= top)&&(p.y <= bottom)); }
public void setRightBottom(Point p) { right = p.x; bottom = p.y; }
public void setRightTop(Point p) { right = p.x; top = p.y; }
public void setLeftTop(Point p) { left = p.x; top = p.y; }
public void setLeftBottom(Point p) { left = p.x; bottom = p.y; }
/// <summary> /// Translates the rectangle so that its top left corner is at the /// point specified. /// </summary> public void offsetTo(Point p) { offsetTo(p.x, p.y); }
/// <summary> /// Translates the rectangle by the amount specified in both the x and y /// dimensions /// </summary> public void offsetBy(Point p) { offsetBy(p.x, p.y); }
/// <summary> /// Makes the rectangle smaller by the amount specified in both /// the x and y dimensions /// </summary> public void insetBy(Point p) { insetBy(p.x, p.y); }