Package org.eclipse.draw2d.geometry
Class Rectangle
java.lang.Object
org.eclipse.draw2d.geometry.Rectangle
- All Implemented Interfaces:
- Serializable,- Cloneable,- Translatable
- Direct Known Subclasses:
- PrecisionRectangle
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 SummaryFields
- 
Constructor SummaryConstructorsConstructorDescriptionConstructs 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 SWTRectangle.
- 
Method SummaryModifier and TypeMethodDescriptionintbottom()Returns the y-coordinate of the bottom of this Rectangle.booleancontains(double x, double y) Returns whether the given coordinates are within the boundaries of this Rectangle.booleancontains(int x, int y) Returns whether the given coordinates are within the boundaries of this Rectangle.booleanReturns whether the given point is within the boundaries of this Rectangle.booleanReturnstrueif the given rectangle is contained within the boundaries of this Rectangle.Deprecated, for removal: This API element is subject to removal in a future version.booleanequals(int x, int y, int width, int height) Returnstrueif this Rectangle's x, y, width, and height values are identical to the provided ones.booleanReturns 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.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.getCopy()Returns a new Rectangle which has the exact same parameters as this Rectangle.getCropped(Insets insets) Deprecated, for removal: This API element is subject to removal in a future version.UsegetShrinked(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.getExpanded(Insets insets) Creates and returns a new Rectangle with the bounds ofthisRectangle, expanded by the given Insets.Returns a new Interval beginning at the x coordinate with the width as length.getIntersection(Rectangle rect) Returns a new Rectangle which has the intersection of this Rectangle and the rectangle provided as input.getLeft()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.intgetPosition(Point p) 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.getRight()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.getShrinked(Insets insets) Returns a new Rectangle shrinked by the specified insets.getSize()Retuns the dimensions of this Rectangle.getTop()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.getTranslated(Point pt) 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.inthashCode()intheight()Returns the current height of this RectangleSets the size of this Rectangle to the intersection region with the Rectangle supplied as input, and returns this for convenience.booleanintersects(Rectangle rect) Returnstrueif the input Rectangle intersects this Rectangle.booleanisEmpty()Returnstrueif this Rectangle's width or height is less than or equal to 0.intleft()Returns the X-coordinate of the left side of this Rectangle.voidperformScale(double factor) Scales this object by the scale factor.voidperformTranslate(int dx, int dy) Translates this object horizontally bydxand vertically bydy.doubleReturnsdoubleheightdoubleReturnsdoublewidthdoublepreciseX()Returnsdoublex coordinatedoublepreciseY()Returnsdoubley coordinateresize(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.intright()Returns the x-coordinate of the right side of this Rectangle.final Rectanglescale(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 specifiedbottom()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.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.setLocation(Point p) 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 specifiedright()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.Shrinks this rectangle by the amount specified ininsets.shrinkLeft(int deltaX) Shrinks the width of the rectangle by the given amount, keepingright().shrinkTop(int deltaY) Shrinks the height of the rectangle by the given amount, keepingbottom().inttop()Returns the Y-coordinate of the top side of this Rectangle.toString()Returns the description of this Rectangle.booleanReturnstrueif 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, for removal: This API element is subject to removal in a future version.Union with a dimension generally does not make much sense, thus deprecating this.voidUpdates 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.intwidth()Returns the current width of this Rectangleintx()Returns the x value of this Rectangle.inty()Returns the y value of the RectangleMethods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.eclipse.draw2d.geometry.TranslatableperformTranslate, performTranslate, performTranslate
- 
Field Details- 
SINGLETONA singleton for use in short calculations. Use to avoid newing unnecessary objects.
- 
heightpublic int heightThe height
- 
widthpublic int widthThe width
- 
xpublic int xThe x value
- 
ypublic int yThe y value
 
- 
- 
Constructor Details- 
Rectanglepublic Rectangle()Constructs a Rectangle at the origin with zero width and height.- Since:
- 2.0
 
- 
Rectanglepublic 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
 
- 
RectangleConstructs a copy of the provided SWTRectangle.- Parameters:
- rect- The SWT Rectangle being copied
- Since:
- 2.0
 
- 
RectangleConstructs a Rectangle given a location and size.- Parameters:
- p- the location
- size- the size
- Since:
- 2.0
 
- 
RectangleConstructs the smallest Rectangle that contains the specified Points.- Parameters:
- p1- Upper left hand corner
- p2- Lower right hand corner
- Since:
- 2.0
 
- 
RectangleConstructs a copy of the provided Rectangle.- Parameters:
- rect- Rectangle supplying the initial values
- Since:
- 2.0
 
 
- 
- 
Method Details- 
bottompublic int bottom()Returns the y-coordinate of the bottom of this Rectangle.- Returns:
- The Y coordinate of the bottom
- Since:
- 2.0
 
- 
containspublic 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
 
- 
containspublic 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
 
- 
containsReturns 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
 
- 
containsReturnstrueif 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
 
- 
cropDeprecated, for removal: This API element is subject to removal in a future version.Useshrink(Insets)instead.Crops this rectangle by the amount specified ininsets.- Parameters:
- insets- Insets to be removed from the Rectangle
- Returns:
- thisfor convenience
- Since:
- 2.0
- @noreference
- This method is not intended to be referenced by clients.
 
- 
equalspublic boolean equals(int x, int y, int width, int height) Returnstrueif 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:
- trueif this Rectangle's x, y, width, and height values are identical to the provided ones,- falseotherwise
- Since:
- 3.7
 
- 
equalsReturns 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.
- 
expandExpands 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:
- thisfor convenience
- Since:
- 3.8
 
- 
expandExpands 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:
- thisfor convenience
- Since:
- 2.0
 
- 
expandExpands 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:
- thisfor convenience
- Since:
- 2.0
 
- 
getBottomReturns 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
 
- 
getBottomLeftReturns a new Point representing the bottom left point of this Rectangle.- Returns:
- Point at the bottom left of the rectangle
- Since:
- 2.0
 
- 
getBottomRightReturns a new Point representing the bottom right point of this Rectangle.- Returns:
- Point at the bottom right of the rectangle
- Since:
- 2.0
 
- 
getCenterReturns a new point representing the center of this Rectangle.- Returns:
- Point at the center of the rectangle
 
- 
getCopyReturns a new Rectangle which has the exact same parameters as this Rectangle.- Returns:
- Copy of this Rectangle
- Since:
- 2.0
 
- 
getCroppedDeprecated, for removal: This API element is subject to removal in a future version.UsegetShrinked(Insets)instead.Returns a new Rectangle with the specified insets cropped.- Parameters:
- insets- Insets being cropped from the Rectangle
- Returns:
- Cropped new Rectangle
- @noreference
- This method is not intended to be referenced by clients.
 
- 
getExpandedReturns 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
 
- 
getExpandedCreates and returns a new Rectangle with the bounds ofthisRectangle, expanded by the given Insets.- Parameters:
- insets- The insets used to expand this rectangle
- Returns:
- A new expanded Rectangle
- Since:
- 2.0
 
- 
getExpandedReturns 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
 
- 
getIntersectionReturns 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
 
- 
getHorizontalIntervalReturns a new Interval beginning at the x coordinate with the width as length.- Returns:
- the Intervalof projection on X axis.
- Since:
- 3.13
 
- 
getVerticalIntervalReturns a new Interval beginning at the y coordinate with the height as length.- Returns:
- the Intervalof projection on Y axis.
- Since:
- 3.13
 
- 
getLeftReturns a new Point representing the middle point of the left hand side of this Rectangle.- Returns:
- Point at the left of the Rectangle
 
- 
getLocationReturns the upper left hand corner of the rectangle.- Returns:
- Location of the rectangle
- See Also:
 
- 
getPositionReturns 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 intwhich is a PositionConstant
- Since:
- 2.0
- See Also:
 
- 
getResizedReturns 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
 
- 
getResizedReturns 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
 
- 
getResizedReturns 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
 
- 
getRightReturns 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
 
- 
getShrinkedReturns 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:
- thisfor convenience
- Since:
- 3.8
 
- 
getShrinkedReturns a new Rectangle shrinked by the specified insets.- Parameters:
- insets- Insets being cropped from the Rectangle
- Returns:
- Shrinked new Rectangle
- Since:
- 3.7
 
- 
getShrinkedReturns 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:
- thisfor convenience
- Since:
- 3.7
 
- 
getSizeRetuns the dimensions of this Rectangle.- Returns:
- Size of this Rectangle as a Dimension
- Since:
- 2.0
 
- 
getTopReturns 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
 
- 
getTopLeftReturns 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
 
- 
getTopRightReturns 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
 
- 
getTranslatedReturns 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
 
- 
getTranslatedReturns 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
 
- 
getTranslatedReturns 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
 
- 
getTransposedReturns 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
 
- 
getUnionReturns 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
 
- 
getUnionReturns 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
 
- 
hashCodepublic int hashCode()
- 
heightpublic int height()Returns the current height of this Rectangle- Returns:
- The current height
- Since:
- 3.7
 
- 
intersectSets 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:
- thisfor convenience
- Since:
- 2.0
 
- 
intersectsReturnstrueif the input Rectangle intersects this Rectangle.- Parameters:
- rect- Rectangle for the intersection test
- Returns:
- trueif the input Rectangle intersects this Rectangle
- Since:
- 2.0
 
- 
leftpublic int left()Returns the X-coordinate of the left side of this Rectangle.- Returns:
- The X coordinate of the left side
- Since:
- 3.13
 
- 
isEmptypublic boolean isEmpty()Returnstrueif this Rectangle's width or height is less than or equal to 0.- Returns:
- trueif this Rectangle is empty
- Since:
- 2.0
 
- 
performScalepublic void performScale(double factor) Description copied from interface:TranslatableScales this object by the scale factor.- Specified by:
- performScalein interface- Translatable
- Parameters:
- factor- The scale factor
- See Also:
 
- 
performTranslatepublic void performTranslate(int dx, int dy) Description copied from interface:TranslatableTranslates this object horizontally bydxand vertically bydy.- Specified by:
- performTranslatein interface- Translatable
- Parameters:
- dx- The amount to translate horizontally
- dy- The amount to translate vertically
- See Also:
 
- 
preciseHeightpublic double preciseHeight()Returnsdoubleheight- Returns:
- doubleheight
- Since:
- 3.4
 
- 
preciseWidthpublic double preciseWidth()Returnsdoublewidth- Returns:
- doublewidth
- Since:
- 3.4
 
- 
preciseXpublic double preciseX()Returnsdoublex coordinate- Returns:
- doublex coordinate
- Since:
- 3.4
 
- 
preciseYpublic double preciseY()Returnsdoubley coordinate- Returns:
- doubley coordinate
- Since:
- 3.4
 
- 
resizeResizes 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:
- thisfor convenience
- Since:
- 2.0
 
- 
resizeResizes 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:
- thisfor convenience
- Since:
- 3.8
 
- 
resizeResizes 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:
- thisfor convenience
- Since:
- 2.0
 
- 
rightpublic int right()Returns the x-coordinate of the right side of this Rectangle.- Returns:
- The X coordinate of the right side
- Since:
- 2.0
 
- 
scaleScales 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:
- thisfor convenience
- Since:
- 2.0
 
- 
scaleScales 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:
- thisfor convenience
- Since:
- 2.0
 
- 
setBoundsSets 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
 
- 
setBoundsSets 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
 
- 
setBoundsSets the parameters of this Rectangle from the Rectangle passed in and returns this for convenience.- Parameters:
- rect- Rectangle providing the bounding values
- Returns:
- thisfor convenience
- Since:
- 2.0
 
- 
setBottomUpdates the height to match the specifiedbottom()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 to0.- Parameters:
- newBottom- The Y coordinate of the bottom
- Returns:
- thisfor convenience
- Since:
- 3.13
 
- 
setHeightSets the height of this Rectangle to the specified one.- Parameters:
- height- The new height
- Returns:
- this for convenience.
- Since:
- 3.7
 
- 
setLocationSets 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:
- thisfor convenience
- Since:
- 2.0
 
- 
setLocationSets the location of this Rectangle to the point given as input and returns this for convenience.- Parameters:
- p- New position of this Rectangle
- Returns:
- thisfor convenience
- Since:
- 2.0
 
- 
setRightUpdates the width to match the specifiedright()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 to0.- Parameters:
- newRight- The X coordinate of the right
- Returns:
- thisfor convenience
- Since:
- 3.13
 
- 
setSizeSets 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:
- thisfor convenience
- Since:
- 2.0
 
- 
setSizeSets 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:
- thisfor convenience
- Since:
- 2.0
 
- 
setWidthSets the width of this Rectangle to the specified one.- Parameters:
- width- The new width
- Returns:
- this for convenience.
- Since:
- 3.7
 
- 
setXSets the x value of the Rectangle and returns this for convenience.- Parameters:
- x- The new x value
- Returns:
- thisfor convenience
- Since:
- 3.7
 
- 
setYSets the y value of the Rectangle and returns this for convenience.- Parameters:
- y- The new y value
- Returns:
- thisfor convenience
- Since:
- 3.7
 
- 
shrinkShrinks 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:
- thisfor convenience
- Since:
- 3.8
 
- 
shrinkShrinks this rectangle by the amount specified ininsets.- Parameters:
- insets- Insets to be removed from the Rectangle
- Returns:
- thisfor convenience
- Since:
- 3.7
 
- 
shrinkShrinks 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 currentwidth()orheight()of the rectangle,0is used instead. The center of this Rectangle is kept constant.- Parameters:
- h- Horizontal reduction amount
- v- Vertical reduction amount
- Returns:
- thisfor convenience
- Since:
- 2.0
 
- 
shrinkLeftShrinks the width of the rectangle by the given amount, keepingright(). If the delta happens to be larger than thewidth()of the rectangle, the new width is set to0.- Parameters:
- deltaX- The horizontal reduction amount
- Returns:
- thisfor convenience
- Since:
- 3.13
 
- 
shrinkTopShrinks the height of the rectangle by the given amount, keepingbottom(). If the delta happens to be larger than theheight()of the rectangle, the new height is set to0.- Parameters:
- deltaY- The vertical reduction amount
- Returns:
- thisfor convenience
- Since:
- 3.13
 
- 
toppublic int top()Returns the Y-coordinate of the top side of this Rectangle.- Returns:
- The Y coordinate of the top
- Since:
- 3.13
 
- 
toStringReturns the description of this Rectangle.
- 
touchesReturnstrueif the input Rectangle touches this Rectangle.- Parameters:
- rect- Rectangle being checked for contact
- Returns:
- trueif rect touches this Rectangle
- Since:
- 2.0
 
- 
translateMoves 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:
- thisfor convenience
- Since:
- 3.8
 
- 
translateMoves 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:
- thisfor convenience
- Since:
- 2.0
 
- 
translateMoves 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:
- thisfor convenience
 
- 
transposeSwitches the x and y values, as well as the width and height of this Rectangle. Useful for orientation changes.- Returns:
- thisfor convenience
- Since:
- 2.0
 
- 
unionDeprecated, for removal: This API element is subject to removal in a future version.Union with a dimension generally does not make much sense, thus deprecating this. UseDimension.max(Dimension, Dimension)andsetSize(Dimension)to implement the desired behavior instead.Unions this Rectangle's width and height with the specified Dimension.- Parameters:
- d- Dimension being unioned
- Returns:
- thisfor convenience
- Since:
- 2.0
- @noreference
- This method is not intended to be referenced by clients.
 
- 
unionUpdates 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:
- thisfor convenience
- Since:
- 3.8
 
- 
unionUpdates 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:
- thisfor convenience
- Since:
- 3.8
 
- 
unionUpdates 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:
- thisfor convenience
- Since:
- 2.0
 
- 
unionUpdates 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:
- thisfor convenience
- Since:
- 2.0
 
- 
unionUpdates 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
 
- 
unionUpdates 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:
- thisfor convenience
- Since:
- 2.0
 
- 
widthpublic int width()Returns the current width of this Rectangle- Returns:
- The current width
- Since:
- 3.7
 
- 
xpublic int x()Returns the x value of this Rectangle.- Returns:
- The current x value
- Since:
- 3.7
 
- 
ypublic int y()Returns the y value of the Rectangle- Returns:
- The current y value
- Since:
- 3.7
 
 
- 
shrink(Insets)instead.