Class Rectangle

java.lang.Object
org.eclipse.draw2d.geometry.Rectangle
All Implemented Interfaces:
Serializable, Cloneable, Translatable
Direct Known Subclasses:
PrecisionRectangle

public class Rectangle extends Object implements Cloneable, Serializable, Translatable
Represents a Rectangle(x, y, width, height). This class provides various methods for manipulating this Rectangle or creating new derived geometrical Objects.
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    int
    The height
    static final Rectangle
    A singleton for use in short calculations.
    int
    The width
    int
    The x value
    int
    The y value
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a Rectangle at the origin with zero width and height.
    Rectangle(int x, int y, int width, int height)
    Constructs a Rectangle with the provided values.
    Constructs a Rectangle given a location and size.
    Constructs the smallest Rectangle that contains the specified Points.
    Constructs a copy of the provided Rectangle.
    Constructs a copy of the provided SWT Rectangle.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Returns the y-coordinate of the bottom of this Rectangle.
    boolean
    contains(double x, double y)
    Returns whether the given coordinates are within the boundaries of this Rectangle.
    boolean
    contains(int x, int y)
    Returns whether the given coordinates are within the boundaries of this Rectangle.
    boolean
    Returns whether the given point is within the boundaries of this Rectangle.
    boolean
    Returns true if the given rectangle is contained within the boundaries of this Rectangle.
    crop(Insets insets)
    Deprecated.
    Use shrink(Insets) instead.
    boolean
    equals(int x, int y, int width, int height)
    Returns true if this Rectangle's x, y, width, and height values are identical to the provided ones.
    boolean
    Returns whether the input object is equal to this Rectangle or not.
    expand(double h, double v)
    Expands the horizontal and vertical sides of this Rectangle with the values provided as input, and returns this for convenience.
    expand(int h, int v)
    Expands the horizontal and vertical sides of this Rectangle with the values provided as input, and returns this for convenience.
    expand(Insets insets)
    Expands the horizontal and vertical sides of this Rectangle by the width and height of the given Insets, and returns this for convenience.
    Returns a new Point representing the middle point of the bottom side of this Rectangle.
    Returns a new Point representing the bottom left point of this Rectangle.
    Returns a new Point representing the bottom right point of this Rectangle.
    Returns a new point representing the center of this Rectangle.
    Returns a new Rectangle which has the exact same parameters as this Rectangle.
    Deprecated.
    Use getShrinked(Insets) instead.
    getExpanded(double h, double v)
    Returns a new incremented Rectangle, where the sides are expanded by the horizontal and vertical values provided.
    getExpanded(int h, int v)
    Returns a new incremented Rectangle, where the sides are expanded by the horizontal and vertical values provided.
    Creates and returns a new Rectangle with the bounds of this Rectangle, expanded by the given Insets.
    Returns a new Interval beginning at the x coordinate with the width as length.
    Returns a new Rectangle which has the intersection of this Rectangle and the rectangle provided as input.
    Returns a new Point representing the middle point of the left hand side of this Rectangle.
    Returns the upper left hand corner of the rectangle.
    int
    Returns an integer which represents the position of the given point with respect to this rectangle.
    getResized(double w, double h)
    Returns a new Rectangle which is equivalent to this Rectangle with its dimensions modified by the passed width w and height h.
    getResized(int w, int h)
    Returns a new Rectangle which is equivalent to this Rectangle with its dimensions modified by the passed width w and height h.
    Returns a new Rectangle which is equivalent to this Rectangle with its dimensions modified by the passed Dimension d.
    Returns a new Point which represents the middle point of the right hand side of this Rectangle.
    getShrinked(double h, double v)
    Returns a new Rectangle, where the sides are shrinked by the horizontal and vertical values supplied.
    getShrinked(int h, int v)
    Returns a new Rectangle, where the sides are shrinked by the horizontal and vertical values supplied.
    Returns a new Rectangle shrinked by the specified insets.
    Retuns the dimensions of this Rectangle.
    Returns a new Point which represents the middle point of the top side of this Rectangle.
    Returns a new Point which represents the top left hand corner of this Rectangle.
    Returns a new Point which represents the top right hand corner of this Rectangle.
    getTranslated(double dx, double dy)
    Returns a new Rectangle which is shifted along each axis by the passed values.
    getTranslated(int dx, int dy)
    Returns a new Rectangle which is shifted along each axis by the passed values.
    Returns a new Rectangle which is shifted by the position of the given Point.
    Returns a new rectangle whose width and height have been interchanged, as well as its x and y values.
    Returns a new Rectangle which contains both this Rectangle and the Point supplied as input.
    Returns a new Rectangle which contains both this Rectangle and the Rectangle supplied as input.
    Returns a new Interval beginning at the y coordinate with the height as length.
    int
     
    int
    Returns the current height of this Rectangle
    Sets the size of this Rectangle to the intersection region with the Rectangle supplied as input, and returns this for convenience.
    boolean
    Returns true if the input Rectangle intersects this Rectangle.
    boolean
    Returns true if this Rectangle's width or height is less than or equal to 0.
    int
    Returns the X-coordinate of the left side of this Rectangle.
    void
    performScale(double factor)
    Scales this object by the scale factor.
    void
    performTranslate(int dx, int dy)
    Translates this object horizontally by dx and vertically by dy.
    double
    Returns double height
    double
    Returns double width
    double
    Returns double x coordinate
    double
    Returns double y coordinate
    resize(double w, double h)
    Resizes this Rectangle by the values supplied as input and returns this for convenience.
    resize(int w, int h)
    Resizes this Rectangle by the values supplied as input and returns this for convenience.
    Resizes this Rectangle by the Dimension provided as input and returns this for convenience.
    int
    Returns the x-coordinate of the right side of this Rectangle.
    final Rectangle
    scale(double scaleFactor)
    Scales the location and size of this Rectangle by the given scale and returns this for convenience.
    scale(double scaleX, double scaleY)
    Scales the location and size of this Rectangle by the given scales and returns this for convenience.
    setBottom(int newBottom)
    Updates the height to match the specified bottom() coordinate.
    setBounds(int x, int y, int width, int height)
    Sets the x, y, width, and height values of this Rectangle to the provided values.
    setBounds(Point location, Dimension size)
    Sets the location and size of this rectangle to the provided ones.
    Sets the parameters of this Rectangle from the Rectangle passed in and returns this for convenience.
    setHeight(int height)
    Sets the height of this Rectangle to the specified one.
    setLocation(int x, int y)
    Sets the location of this Rectangle to the coordinates given as input and returns this for convenience.
    Sets the location of this Rectangle to the point given as input and returns this for convenience.
    setRight(int newRight)
    Updates the width to match the specified right() coordinate.
    setSize(int w, int h)
    Sets the width of this Rectangle to w and the height of this Rectangle to h and returns this for convenience.
    Sets the width and height of this Rectangle to the width and height of the given Dimension and returns this for convenience.
    setWidth(int width)
    Sets the width of this Rectangle to the specified one.
    setX(int x)
    Sets the x value of the Rectangle and returns this for convenience.
    setY(int y)
    Sets the y value of the Rectangle and returns this for convenience.
    shrink(double h, double v)
    Shrinks the sides of this Rectangle by the horizontal and vertical values provided as input, and returns this Rectangle for convenience.
    shrink(int h, int v)
    Shrinks the sides of this Rectangle by the horizontal and vertical values provided as input, and returns this Rectangle for convenience.
    shrink(Insets insets)
    Shrinks this rectangle by the amount specified in insets.
    shrinkLeft(int deltaX)
    Shrinks the width of the rectangle by the given amount, keeping right().
    shrinkTop(int deltaY)
    Shrinks the height of the rectangle by the given amount, keeping bottom().
    int
    top()
    Returns the Y-coordinate of the top side of this Rectangle.
    Returns the description of this Rectangle.
    boolean
    Returns true if the input Rectangle touches this Rectangle.
    translate(double dx, double dy)
    Moves this Rectangle horizontally by dx and vertically by dy, then returns this Rectangle for convenience.
    translate(int dx, int dy)
    Moves this Rectangle horizontally by dx and vertically by dy, then returns this Rectangle for convenience.
    Moves this Rectangle horizontally by the x value of the given Point and vertically by the y value of the given Point, then returns this Rectangle for convenience.
    Switches the x and y values, as well as the width and height of this Rectangle.
    union(double x, double y)
    Updates this Rectangle's bounds to the minimum size which can hold both this Rectangle and the coordinate (x,y).
    union(double x, double y, double w, double h)
    Updates this Rectangle's dimensions to the minimum size which can hold both this Rectangle and the rectangle (x, y, w, h).
    union(int x1, int y1)
    Updates this Rectangle's bounds to the minimum size which can hold both this Rectangle and the coordinate (x,y).
    union(int x, int y, int w, int h)
    Updates this Rectangle's dimensions to the minimum size which can hold both this Rectangle and the rectangle (x, y, w, h).
    Deprecated.
    Union with a dimension generally does not make much sense, thus deprecating this.
    void
    Updates this Rectangle's bounds to the minimum size which can hold both this Rectangle and the given Point.
    Updates this Rectangle's dimensions to the minimum size which can hold both this Rectangle and the given Rectangle.
    int
    Returns the current width of this Rectangle
    int
    x()
    Returns the x value of this Rectangle.
    int
    y()
    Returns the y value of the Rectangle

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.eclipse.draw2d.geometry.Translatable

    performTranslate, performTranslate, performTranslate
  • Field Details

    • SINGLETON

      public static final Rectangle SINGLETON
      A singleton for use in short calculations. Use to avoid newing unnecessary objects.
    • height

      public int height
      The height
    • width

      public int width
      The width
    • x

      public int x
      The x value
    • y

      public int y
      The y value
  • Constructor Details

    • Rectangle

      public Rectangle()
      Constructs a Rectangle at the origin with zero width and height.
      Since:
      2.0
    • Rectangle

      public Rectangle(int x, int y, int width, int height)
      Constructs a Rectangle with the provided values.
      Parameters:
      x - X location
      y - Y location
      width - Width of the rectangle
      height - Height of the rectangle
      Since:
      2.0
    • Rectangle

      public Rectangle(Rectangle rect)
      Constructs a copy of the provided SWT Rectangle.
      Parameters:
      rect - The SWT Rectangle being copied
      Since:
      2.0
    • Rectangle

      public Rectangle(Point p, Dimension size)
      Constructs a Rectangle given a location and size.
      Parameters:
      p - the location
      size - the size
      Since:
      2.0
    • Rectangle

      public Rectangle(Point p1, Point p2)
      Constructs the smallest Rectangle that contains the specified Points.
      Parameters:
      p1 - Upper left hand corner
      p2 - Lower right hand corner
      Since:
      2.0
    • Rectangle

      public Rectangle(Rectangle rect)
      Constructs a copy of the provided Rectangle.
      Parameters:
      rect - Rectangle supplying the initial values
      Since:
      2.0
  • Method Details

    • bottom

      public int bottom()
      Returns the y-coordinate of the bottom of this Rectangle.
      Returns:
      The Y coordinate of the bottom
      Since:
      2.0
    • contains

      public boolean contains(double x, double y)
      Returns whether the given coordinates are within the boundaries of this Rectangle. The boundaries are inclusive of the top and left edges, but exclusive of the bottom and right edges.
      Parameters:
      x - X value
      y - Y value
      Returns:
      true if the coordinates are within this Rectangle
      Since:
      3.8
    • contains

      public boolean contains(int x, int y)
      Returns whether the given coordinates are within the boundaries of this Rectangle. The boundaries are inclusive of the top and left edges, but exclusive of the bottom and right edges.
      Parameters:
      x - X value
      y - Y value
      Returns:
      true if the coordinates are within this Rectangle
      Since:
      2.0
    • contains

      public boolean contains(Point p)
      Returns whether the given point is within the boundaries of this Rectangle. The boundaries are inclusive of the top and left edges, but exclusive of the bottom and right edges.
      Parameters:
      p - Point being tested for containment
      Returns:
      true if the Point is within this Rectangle
      Since:
      2.0
    • contains

      public boolean contains(Rectangle rect)
      Returns true if the given rectangle is contained within the boundaries of this Rectangle.
      Parameters:
      rect - the Rectangle to test
      Returns:
      true if the Rectangle is within this Rectangle
    • crop

      @Deprecated public Rectangle crop(Insets insets)
      Deprecated.
      Use shrink(Insets) instead.
      Crops this rectangle by the amount specified in insets.
      Parameters:
      insets - Insets to be removed from the Rectangle
      Returns:
      this for convenience
      Since:
      2.0
    • equals

      public boolean equals(int x, int y, int width, int height)
      Returns true if this Rectangle's x, y, width, and height values are identical to the provided ones.
      Parameters:
      x - The x value to test
      y - The y value to test
      width - The width value to test
      height - The height value to test
      Returns:
      true if this Rectangle's x, y, width, and height values are identical to the provided ones, false otherwise
      Since:
      3.7
    • equals

      public boolean equals(Object o)
      Returns whether the input object is equal to this Rectangle or not. Rectangles are equivalent if their x, y, height, and width values are the same.
      Overrides:
      equals in class Object
      Parameters:
      o - Object being tested for equality
      Returns:
      Returns the result of the equality test
      Since:
      2.0
    • expand

      public Rectangle expand(double h, double v)
      Expands the horizontal and vertical sides of this Rectangle with the values provided as input, and returns this for convenience. The location of its center is kept constant.
      Parameters:
      h - Horizontal increment
      v - Vertical increment
      Returns:
      this for convenience
      Since:
      3.8
    • expand

      public Rectangle expand(Insets insets)
      Expands the horizontal and vertical sides of this Rectangle by the width and height of the given Insets, and returns this for convenience.
      Parameters:
      insets - contains the amounts to expand on each side
      Returns:
      this for convenience
      Since:
      2.0
    • expand

      public Rectangle expand(int h, int v)
      Expands the horizontal and vertical sides of this Rectangle with the values provided as input, and returns this for convenience. The location of its center is kept constant.
      Parameters:
      h - Horizontal increment
      v - Vertical increment
      Returns:
      this for convenience
      Since:
      2.0
    • getBottom

      public Point getBottom()
      Returns a new Point representing the middle point of the bottom side of this Rectangle.
      Returns:
      Point at the bottom of the Rectangle
      Since:
      2.0
    • getBottomLeft

      public Point getBottomLeft()
      Returns a new Point representing the bottom left point of this Rectangle.
      Returns:
      Point at the bottom left of the rectangle
      Since:
      2.0
    • getBottomRight

      public Point getBottomRight()
      Returns a new Point representing the bottom right point of this Rectangle.
      Returns:
      Point at the bottom right of the rectangle
      Since:
      2.0
    • getCenter

      public Point getCenter()
      Returns a new point representing the center of this Rectangle.
      Returns:
      Point at the center of the rectangle
    • getCopy

      public Rectangle getCopy()
      Returns a new Rectangle which has the exact same parameters as this Rectangle.
      Returns:
      Copy of this Rectangle
      Since:
      2.0
    • getCropped

      @Deprecated public Rectangle getCropped(Insets insets)
      Deprecated.
      Use getShrinked(Insets) instead.
      Returns a new Rectangle with the specified insets cropped.
      Parameters:
      insets - Insets being cropped from the Rectangle
      Returns:
      Cropped new Rectangle
    • getExpanded

      public Rectangle getExpanded(double h, double v)
      Returns a new incremented Rectangle, where the sides are expanded by the horizontal and vertical values provided. The center of the Rectangle is maintained constant.
      Parameters:
      h - Horizontal increment
      v - Vertical increment
      Returns:
      A new expanded Rectangle
      Since:
      3.8
    • getExpanded

      public Rectangle getExpanded(Insets insets)
      Creates and returns a new Rectangle with the bounds of this Rectangle, expanded by the given Insets.
      Parameters:
      insets - The insets used to expand this rectangle
      Returns:
      A new expanded Rectangle
      Since:
      2.0
    • getExpanded

      public Rectangle getExpanded(int h, int v)
      Returns a new incremented Rectangle, where the sides are expanded by the horizontal and vertical values provided. The center of the Rectangle is maintained constant.
      Parameters:
      h - Horizontal increment
      v - Vertical increment
      Returns:
      A new expanded Rectangle
      Since:
      2.0
    • getIntersection

      public Rectangle getIntersection(Rectangle rect)
      Returns a new Rectangle which has the intersection of this Rectangle and the rectangle provided as input. Returns an empty Rectangle if there is no intersection.
      Parameters:
      rect - Rectangle provided to test for intersection
      Returns:
      A new Rectangle representing the intersection
      Since:
      2.0
    • getHorizontalInterval

      public Interval getHorizontalInterval()
      Returns a new Interval beginning at the x coordinate with the width as length.
      Returns:
      the Interval of projection on X axis.
      Since:
      3.13
    • getVerticalInterval

      public Interval getVerticalInterval()
      Returns a new Interval beginning at the y coordinate with the height as length.
      Returns:
      the Interval of projection on Y axis.
      Since:
      3.13
    • getLeft

      public Point getLeft()
      Returns a new Point representing the middle point of the left hand side of this Rectangle.
      Returns:
      Point at the left of the Rectangle
    • getLocation

      public Point getLocation()
      Returns the upper left hand corner of the rectangle.
      Returns:
      Location of the rectangle
      See Also:
    • getPosition

      public int getPosition(Point p)

      Returns an integer which represents the position of the given point with respect to this rectangle. Possible return values are bitwise ORs of the constants WEST, EAST, NORTH, and SOUTH as found in PositionConstants.

      Returns PositionConstant.NONE if the given point is inside this Rectangle.

      Parameters:
      p - The Point whose position has to be determined
      Returns:
      An int which is a PositionConstant
      Since:
      2.0
      See Also:
    • getResized

      public Rectangle getResized(Dimension d)
      Returns a new Rectangle which is equivalent to this Rectangle with its dimensions modified by the passed Dimension d.
      Parameters:
      d - Dimensions by which the rectangle's size should be modified
      Returns:
      The new rectangle with the modified dimensions
      Since:
      2.0
    • getResized

      public Rectangle getResized(double w, double h)
      Returns a new Rectangle which is equivalent to this Rectangle with its dimensions modified by the passed width w and height h.
      Parameters:
      w - Amount by which width is to be resized
      h - Amount by which height is to be resized
      Returns:
      a new rectangle with its width and height modified
      Since:
      3.8
    • getResized

      public Rectangle getResized(int w, int h)
      Returns a new Rectangle which is equivalent to this Rectangle with its dimensions modified by the passed width w and height h.
      Parameters:
      w - Amount by which width is to be resized
      h - Amount by which height is to be resized
      Returns:
      a new rectangle with its width and height modified
    • getRight

      public Point getRight()
      Returns a new Point which represents the middle point of the right hand side of this Rectangle.
      Returns:
      Point at the right of the Rectangle
      Since:
      2.0
    • getShrinked

      public Rectangle getShrinked(double h, double v)
      Returns a new Rectangle, where the sides are shrinked by the horizontal and vertical values supplied. The center of this Rectangle is kept constant.
      Parameters:
      h - Horizontal reduction amount
      v - Vertical reduction amount
      Returns:
      this for convenience
      Since:
      3.8
    • getShrinked

      public Rectangle getShrinked(Insets insets)
      Returns a new Rectangle shrinked by the specified insets.
      Parameters:
      insets - Insets being cropped from the Rectangle
      Returns:
      Shrinked new Rectangle
      Since:
      3.7
    • getShrinked

      public Rectangle getShrinked(int h, int v)
      Returns a new Rectangle, where the sides are shrinked by the horizontal and vertical values supplied. The center of this Rectangle is kept constant.
      Parameters:
      h - Horizontal reduction amount
      v - Vertical reduction amount
      Returns:
      this for convenience
      Since:
      3.7
    • getSize

      public Dimension getSize()
      Retuns the dimensions of this Rectangle.
      Returns:
      Size of this Rectangle as a Dimension
      Since:
      2.0
    • getTop

      public Point getTop()
      Returns a new Point which represents the middle point of the top side of this Rectangle.
      Returns:
      Point at the top of the Rectangle
      Since:
      2.0
    • getTopLeft

      public Point getTopLeft()
      Returns a new Point which represents the top left hand corner of this Rectangle.
      Returns:
      Point at the top left of the rectangle
      Since:
      2.0
    • getTopRight

      public Point getTopRight()
      Returns a new Point which represents the top right hand corner of this Rectangle.
      Returns:
      Point at the top right of the rectangle
      Since:
      2.0
    • getTranslated

      public Rectangle getTranslated(double dx, double dy)
      Returns a new Rectangle which is shifted along each axis by the passed values.
      Parameters:
      dx - Displacement along X axis
      dy - Displacement along Y axis
      Returns:
      The new translated rectangle
      Since:
      3.8
    • getTranslated

      public Rectangle getTranslated(int dx, int dy)
      Returns a new Rectangle which is shifted along each axis by the passed values.
      Parameters:
      dx - Displacement along X axis
      dy - Displacement along Y axis
      Returns:
      The new translated rectangle
      Since:
      2.0
    • getTranslated

      public Rectangle getTranslated(Point pt)
      Returns a new Rectangle which is shifted by the position of the given Point.
      Parameters:
      pt - Point providing the amount of shift along each axis
      Returns:
      The new translated Rectangle
      Since:
      2.0
    • getTransposed

      public Rectangle getTransposed()
      Returns a new rectangle whose width and height have been interchanged, as well as its x and y values. This can be useful in orientation changes.
      Returns:
      The transposed rectangle
      Since:
      2.0
    • getUnion

      public Rectangle getUnion(Point p)
      Returns a new Rectangle which contains both this Rectangle and the Point supplied as input.
      Parameters:
      p - Point for calculating union
      Returns:
      A new unioned Rectangle
      Since:
      3.7
    • getUnion

      public Rectangle getUnion(Rectangle rect)
      Returns a new Rectangle which contains both this Rectangle and the Rectangle supplied as input.
      Parameters:
      rect - Rectangle for calculating union
      Returns:
      A new unioned Rectangle
      Since:
      2.0
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
      See Also:
    • height

      public int height()
      Returns the current height of this Rectangle
      Returns:
      The current height
      Since:
      3.7
    • intersect

      public Rectangle intersect(Rectangle rect)
      Sets the size of this Rectangle to the intersection region with the Rectangle supplied as input, and returns this for convenience. The location and dimensions are set to zero if there is no intersection with the input Rectangle.
      Parameters:
      rect - Rectangle for the calculating intersection.
      Returns:
      this for convenience
      Since:
      2.0
    • intersects

      public boolean intersects(Rectangle rect)
      Returns true if the input Rectangle intersects this Rectangle.
      Parameters:
      rect - Rectangle for the intersection test
      Returns:
      true if the input Rectangle intersects this Rectangle
      Since:
      2.0
    • left

      public int left()
      Returns the X-coordinate of the left side of this Rectangle.
      Returns:
      The X coordinate of the left side
      Since:
      3.13
    • isEmpty

      public boolean isEmpty()
      Returns true if this Rectangle's width or height is less than or equal to 0.
      Returns:
      true if this Rectangle is empty
      Since:
      2.0
    • performScale

      public void performScale(double factor)
      Description copied from interface: Translatable
      Scales this object by the scale factor.
      Specified by:
      performScale in interface Translatable
      Parameters:
      factor - The scale factor
      See Also:
    • performTranslate

      public void performTranslate(int dx, int dy)
      Description copied from interface: Translatable
      Translates this object horizontally by dx and vertically by dy.
      Specified by:
      performTranslate in interface Translatable
      Parameters:
      dx - The amount to translate horizontally
      dy - The amount to translate vertically
      See Also:
    • preciseHeight

      public double preciseHeight()
      Returns double height
      Returns:
      double height
      Since:
      3.4
    • preciseWidth

      public double preciseWidth()
      Returns double width
      Returns:
      double width
      Since:
      3.4
    • preciseX

      public double preciseX()
      Returns double x coordinate
      Returns:
      double x coordinate
      Since:
      3.4
    • preciseY

      public double preciseY()
      Returns double y coordinate
      Returns:
      double y coordinate
      Since:
      3.4
    • resize

      public Rectangle resize(Dimension d)
      Resizes this Rectangle by the Dimension provided as input and returns this for convenience. This Rectange's width will become this.width + sizeDelta.width. Likewise for height.
      Parameters:
      d - Resize data as a Dimension
      Returns:
      this for convenience
      Since:
      2.0
    • resize

      public Rectangle resize(double w, double h)
      Resizes this Rectangle by the values supplied as input and returns this for convenience. This Rectangle's width will become this.width + dw. This Rectangle's height will become this.height + dh.
      Parameters:
      w - Amount by which width is to be resized
      h - Amount by which height is to be resized
      Returns:
      this for convenience
      Since:
      3.8
    • resize

      public Rectangle resize(int w, int h)
      Resizes this Rectangle by the values supplied as input and returns this for convenience. This Rectangle's width will become this.width + dw. This Rectangle's height will become this.height + dh.
      Parameters:
      w - Amount by which width is to be resized
      h - Amount by which height is to be resized
      Returns:
      this for convenience
      Since:
      2.0
    • right

      public int right()
      Returns the x-coordinate of the right side of this Rectangle.
      Returns:
      The X coordinate of the right side
      Since:
      2.0
    • scale

      public final Rectangle scale(double scaleFactor)
      Scales the location and size of this Rectangle by the given scale and returns this for convenience.
      Parameters:
      scaleFactor - The factor by which this rectangle will be scaled
      Returns:
      this for convenience
      Since:
      2.0
    • scale

      public Rectangle scale(double scaleX, double scaleY)
      Scales the location and size of this Rectangle by the given scales and returns this for convenience.
      Parameters:
      scaleX - the factor by which the X dimension has to be scaled
      scaleY - the factor by which the Y dimension has to be scaled
      Returns:
      this for convenience
      Since:
      2.0
    • setBounds

      public Rectangle setBounds(int x, int y, int width, int height)
      Sets the x, y, width, and height values of this Rectangle to the provided values.
      Parameters:
      x - The new x
      y - The new y
      width - The new width
      height - The new height
      Returns:
      this for convenience
      Since:
      3.7
    • setBounds

      public Rectangle setBounds(Point location, Dimension size)
      Sets the location and size of this rectangle to the provided ones.
      Parameters:
      location - The new location
      size - The new size
      Returns:
      this for convenience
      Since:
      3.7
    • setBounds

      public Rectangle setBounds(Rectangle rect)
      Sets the parameters of this Rectangle from the Rectangle passed in and returns this for convenience.
      Parameters:
      rect - Rectangle providing the bounding values
      Returns:
      this for convenience
      Since:
      2.0
    • setBottom

      public Rectangle setBottom(int newBottom)
      Updates the height to match the specified bottom() coordinate. If the new Y coordinate of the bottom happens to be smaller (i.e. above) than the Y coordinate of the top, the height is set to 0.
      Parameters:
      newBottom - The Y coordinate of the bottom
      Returns:
      this for convenience
      Since:
      3.13
    • setHeight

      public Rectangle setHeight(int height)
      Sets the height of this Rectangle to the specified one.
      Parameters:
      height - The new height
      Returns:
      this for convenience.
      Since:
      3.7
    • setLocation

      public Rectangle setLocation(int x, int y)
      Sets the location of this Rectangle to the coordinates given as input and returns this for convenience.
      Parameters:
      x - The new X coordinate
      y - The new Y coordinate
      Returns:
      this for convenience
      Since:
      2.0
    • setLocation

      public Rectangle setLocation(Point p)
      Sets the location of this Rectangle to the point given as input and returns this for convenience.
      Parameters:
      p - New position of this Rectangle
      Returns:
      this for convenience
      Since:
      2.0
    • setRight

      public Rectangle setRight(int newRight)
      Updates the width to match the specified right() coordinate. If the new X coordinate of the right happens to be smaller than the X coordinate of the left (i.e. behind), the width is set to 0.
      Parameters:
      newRight - The X coordinate of the right
      Returns:
      this for convenience
      Since:
      3.13
    • setSize

      public Rectangle setSize(Dimension d)
      Sets the width and height of this Rectangle to the width and height of the given Dimension and returns this for convenience.
      Parameters:
      d - The new Dimension
      Returns:
      this for convenience
      Since:
      2.0
    • setSize

      public Rectangle setSize(int w, int h)
      Sets the width of this Rectangle to w and the height of this Rectangle to h and returns this for convenience.
      Parameters:
      w - The new width
      h - The new height
      Returns:
      this for convenience
      Since:
      2.0
    • setWidth

      public Rectangle setWidth(int width)
      Sets the width of this Rectangle to the specified one.
      Parameters:
      width - The new width
      Returns:
      this for convenience.
      Since:
      3.7
    • setX

      public Rectangle setX(int x)
      Sets the x value of the Rectangle and returns this for convenience.
      Parameters:
      x - The new x value
      Returns:
      this for convenience
      Since:
      3.7
    • setY

      public Rectangle setY(int y)
      Sets the y value of the Rectangle and returns this for convenience.
      Parameters:
      y - The new y value
      Returns:
      this for convenience
      Since:
      3.7
    • shrink

      public Rectangle shrink(double h, double v)
      Shrinks the sides of this Rectangle by the horizontal and vertical values provided as input, and returns this Rectangle for convenience. The center of this Rectangle is kept constant.
      Parameters:
      h - Horizontal reduction amount
      v - Vertical reduction amount
      Returns:
      this for convenience
      Since:
      3.8
    • shrink

      public Rectangle shrink(Insets insets)
      Shrinks this rectangle by the amount specified in insets.
      Parameters:
      insets - Insets to be removed from the Rectangle
      Returns:
      this for convenience
      Since:
      3.7
    • shrink

      public Rectangle shrink(int h, int v)
      Shrinks the sides of this Rectangle by the horizontal and vertical values provided as input, and returns this Rectangle for convenience. If the given reduction amount of larger than the current width() or height() of the rectangle, 0 is used instead. The center of this Rectangle is kept constant.
      Parameters:
      h - Horizontal reduction amount
      v - Vertical reduction amount
      Returns:
      this for convenience
      Since:
      2.0
    • shrinkLeft

      public Rectangle shrinkLeft(int deltaX)
      Shrinks the width of the rectangle by the given amount, keeping right(). If the delta happens to be larger than the width() of the rectangle, the new width is set to 0.
      Parameters:
      deltaX - The horizontal reduction amount
      Returns:
      this for convenience
      Since:
      3.13
    • shrinkTop

      public Rectangle shrinkTop(int deltaY)
      Shrinks the height of the rectangle by the given amount, keeping bottom(). If the delta happens to be larger than the height() of the rectangle, the new height is set to 0.
      Parameters:
      deltaY - The vertical reduction amount
      Returns:
      this for convenience
      Since:
      3.13
    • top

      public int top()
      Returns the Y-coordinate of the top side of this Rectangle.
      Returns:
      The Y coordinate of the top
      Since:
      3.13
    • toString

      public String toString()
      Returns the description of this Rectangle.
      Overrides:
      toString in class Object
      Returns:
      String containing the description
      Since:
      2.0
    • touches

      public boolean touches(Rectangle rect)
      Returns true if the input Rectangle touches this Rectangle.
      Parameters:
      rect - Rectangle being checked for contact
      Returns:
      true if rect touches this Rectangle
      Since:
      2.0
    • translate

      public Rectangle translate(double dx, double dy)
      Moves this Rectangle horizontally by dx and vertically by dy, then returns this Rectangle for convenience.
      Parameters:
      dx - Shift along X axis
      dy - Shift along Y axis
      Returns:
      this for convenience
      Since:
      3.8
    • translate

      public Rectangle translate(int dx, int dy)
      Moves this Rectangle horizontally by dx and vertically by dy, then returns this Rectangle for convenience.
      Parameters:
      dx - Shift along X axis
      dy - Shift along Y axis
      Returns:
      this for convenience
      Since:
      2.0
    • translate

      public Rectangle translate(Point p)
      Moves this Rectangle horizontally by the x value of the given Point and vertically by the y value of the given Point, then returns this Rectangle for convenience.
      Parameters:
      p - Point which provides translation information
      Returns:
      this for convenience
    • transpose

      public Rectangle transpose()
      Switches the x and y values, as well as the width and height of this Rectangle. Useful for orientation changes.
      Returns:
      this for convenience
      Since:
      2.0
    • union

      @Deprecated public Rectangle union(Dimension d)
      Deprecated.
      Union with a dimension generally does not make much sense, thus deprecating this. Use Dimension.max(Dimension, Dimension) and setSize(Dimension) to implement the desired behavior instead.
      Unions this Rectangle's width and height with the specified Dimension.
      Parameters:
      d - Dimension being unioned
      Returns:
      this for convenience
      Since:
      2.0
    • union

      public Rectangle union(double x, double y)
      Updates this Rectangle's bounds to the minimum size which can hold both this Rectangle and the coordinate (x,y).
      Parameters:
      x - X coordinate
      y - Y coordinate
      Returns:
      this for convenience
      Since:
      3.8
    • union

      public Rectangle union(double x, double y, double w, double h)
      Updates this Rectangle's dimensions to the minimum size which can hold both this Rectangle and the rectangle (x, y, w, h).
      Parameters:
      x - X coordinate of desired union.
      y - Y coordinate of desired union.
      w - Width of desired union.
      h - Height of desired union.
      Returns:
      this for convenience
      Since:
      3.8
    • union

      public Rectangle union(int x1, int y1)
      Updates this Rectangle's bounds to the minimum size which can hold both this Rectangle and the coordinate (x,y).
      Parameters:
      x1 - X coordinate
      y1 - Y coordinate
      Returns:
      this for convenience
      Since:
      2.0
    • union

      public Rectangle union(int x, int y, int w, int h)
      Updates this Rectangle's dimensions to the minimum size which can hold both this Rectangle and the rectangle (x, y, w, h).
      Parameters:
      x - X coordinate of desired union.
      y - Y coordinate of desired union.
      w - Width of desired union.
      h - Height of desired union.
      Returns:
      this for convenience
      Since:
      2.0
    • union

      public void union(Point p)
      Updates this Rectangle's bounds to the minimum size which can hold both this Rectangle and the given Point.
      Parameters:
      p - Point to be unioned with this Rectangle
      Since:
      2.0
    • union

      public Rectangle union(Rectangle rect)
      Updates this Rectangle's dimensions to the minimum size which can hold both this Rectangle and the given Rectangle.
      Parameters:
      rect - Rectangle to be unioned with this Rectangle
      Returns:
      this for convenience
      Since:
      2.0
    • width

      public int width()
      Returns the current width of this Rectangle
      Returns:
      The current width
      Since:
      3.7
    • x

      public int x()
      Returns the x value of this Rectangle.
      Returns:
      The current x value
      Since:
      3.7
    • y

      public int y()
      Returns the y value of the Rectangle
      Returns:
      The current y value
      Since:
      3.7