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 Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionConstructs 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 Summary
Modifier and TypeMethodDescriptionint
bottom()
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
Returnstrue
if the given rectangle is contained within the boundaries of this Rectangle.Deprecated.boolean
equals
(int x, int y, int width, int height) Returnstrue
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.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.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 ofthis
Rectangle, 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.int
getPosition
(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.int
hashCode()
int
height()
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.boolean
intersects
(Rectangle rect) Returnstrue
if the input Rectangle intersects this Rectangle.boolean
isEmpty()
Returnstrue
if this Rectangle's width or height is less than or equal to 0.int
left()
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 bydx
and vertically bydy
.double
Returnsdouble
heightdouble
Returnsdouble
widthdouble
preciseX()
Returnsdouble
x coordinatedouble
preciseY()
Returnsdouble
y 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.int
right()
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 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()
.int
top()
Returns the Y-coordinate of the top side of this Rectangle.toString()
Returns the description of this Rectangle.boolean
Returnstrue
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
width()
Returns the current width of this Rectangleint
x()
Returns the x value of this Rectangle.int
y()
Returns the y value of the RectangleMethods 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
A singleton for use in short calculations. Use to avoid newing unnecessary objects. -
height
public int heightThe height -
width
public int widthThe width -
x
public int xThe x value -
y
public int yThe 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 locationy
- Y locationwidth
- Width of the rectangleheight
- Height of the rectangle- Since:
- 2.0
-
Rectangle
Constructs a copy of the provided SWTRectangle
.- Parameters:
rect
- The SWT Rectangle being copied- Since:
- 2.0
-
Rectangle
Constructs a Rectangle given a location and size.- Parameters:
p
- the locationsize
- the size- Since:
- 2.0
-
Rectangle
Constructs the smallest Rectangle that contains the specified Points.- Parameters:
p1
- Upper left hand cornerp2
- Lower right hand corner- Since:
- 2.0
-
Rectangle
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 valuey
- 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 valuey
- Y value- Returns:
- true if the coordinates are within this Rectangle
- Since:
- 2.0
-
contains
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
Returnstrue
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.Useshrink(Insets)
instead.Crops this rectangle by the amount specified ininsets
.- 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) Returnstrue
if this Rectangle's x, y, width, and height values are identical to the provided ones.- Parameters:
x
- The x value to testy
- The y value to testwidth
- The width value to testheight
- 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
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. -
expand
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 incrementv
- Vertical increment- Returns:
this
for convenience- Since:
- 3.8
-
expand
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
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 incrementv
- Vertical increment- Returns:
this
for convenience- Since:
- 2.0
-
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
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
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
Returns a new point representing the center of this Rectangle.- Returns:
- Point at the center of the 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.UsegetShrinked(Insets)
instead.Returns a new Rectangle with the specified insets cropped.- Parameters:
insets
- Insets being cropped from the Rectangle- Returns:
- Cropped new Rectangle
-
getExpanded
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 incrementv
- Vertical increment- Returns:
- A new expanded Rectangle
- Since:
- 3.8
-
getExpanded
Creates and returns a new Rectangle with the bounds ofthis
Rectangle, expanded by the given Insets.- Parameters:
insets
- The insets used to expand this rectangle- Returns:
- A new expanded Rectangle
- Since:
- 2.0
-
getExpanded
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 incrementv
- Vertical increment- Returns:
- A new expanded Rectangle
- Since:
- 2.0
-
getIntersection
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
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
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
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
Returns the upper left hand corner of the rectangle.- Returns:
- Location of the rectangle
- See Also:
-
getPosition
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
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
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 resizedh
- Amount by which height is to be resized- Returns:
- a new rectangle with its width and height modified
- Since:
- 3.8
-
getResized
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 resizedh
- Amount by which height is to be resized- Returns:
- a new rectangle with its width and height modified
-
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
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 amountv
- Vertical reduction amount- Returns:
this
for convenience- Since:
- 3.8
-
getShrinked
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
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 amountv
- Vertical reduction amount- Returns:
this
for convenience- Since:
- 3.7
-
getSize
Retuns the dimensions of this Rectangle.- Returns:
- Size of this Rectangle as a Dimension
- Since:
- 2.0
-
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
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
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
Returns a new Rectangle which is shifted along each axis by the passed values.- Parameters:
dx
- Displacement along X axisdy
- Displacement along Y axis- Returns:
- The new translated rectangle
- Since:
- 3.8
-
getTranslated
Returns a new Rectangle which is shifted along each axis by the passed values.- Parameters:
dx
- Displacement along X axisdy
- Displacement along Y axis- Returns:
- The new translated rectangle
- Since:
- 2.0
-
getTranslated
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
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
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
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() -
height
public int height()Returns the current height of this Rectangle- Returns:
- The current height
- Since:
- 3.7
-
intersect
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
Returnstrue
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()Returnstrue
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 interfaceTranslatable
- Parameters:
factor
- The scale factor- See Also:
-
performTranslate
public void performTranslate(int dx, int dy) Description copied from interface:Translatable
Translates this object horizontally bydx
and vertically bydy
.- Specified by:
performTranslate
in interfaceTranslatable
- Parameters:
dx
- The amount to translate horizontallydy
- The amount to translate vertically- See Also:
-
preciseHeight
public double preciseHeight()Returnsdouble
height- Returns:
double
height- Since:
- 3.4
-
preciseWidth
public double preciseWidth()Returnsdouble
width- Returns:
double
width- Since:
- 3.4
-
preciseX
public double preciseX()Returnsdouble
x coordinate- Returns:
double
x coordinate- Since:
- 3.4
-
preciseY
public double preciseY()Returnsdouble
y coordinate- Returns:
double
y coordinate- Since:
- 3.4
-
resize
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
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 resizedh
- Amount by which height is to be resized- Returns:
this
for convenience- Since:
- 3.8
-
resize
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 resizedh
- 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
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
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 scaledscaleY
- the factor by which the Y dimension has to be scaled- Returns:
this
for convenience- Since:
- 2.0
-
setBounds
Sets the x, y, width, and height values of this Rectangle to the provided values.- Parameters:
x
- The new xy
- The new ywidth
- The new widthheight
- The new height- Returns:
- this for convenience
- Since:
- 3.7
-
setBounds
Sets the location and size of this rectangle to the provided ones.- Parameters:
location
- The new locationsize
- The new size- Returns:
- this for convenience
- Since:
- 3.7
-
setBounds
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
Updates 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:
this
for convenience- Since:
- 3.13
-
setHeight
Sets the height of this Rectangle to the specified one.- Parameters:
height
- The new height- Returns:
- this for convenience.
- Since:
- 3.7
-
setLocation
Sets the location of this Rectangle to the coordinates given as input and returns this for convenience.- Parameters:
x
- The new X coordinatey
- The new Y coordinate- Returns:
this
for convenience- Since:
- 2.0
-
setLocation
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
Updates 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:
this
for convenience- Since:
- 3.13
-
setSize
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
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 widthh
- The new height- Returns:
this
for convenience- Since:
- 2.0
-
setWidth
Sets the width of this Rectangle to the specified one.- Parameters:
width
- The new width- Returns:
- this for convenience.
- Since:
- 3.7
-
setX
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
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
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 amountv
- Vertical reduction amount- Returns:
this
for convenience- Since:
- 3.8
-
shrink
Shrinks this rectangle by the amount specified ininsets
.- Parameters:
insets
- Insets to be removed from the Rectangle- Returns:
this
for convenience- Since:
- 3.7
-
shrink
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 currentwidth()
orheight()
of the rectangle,0
is used instead. The center of this Rectangle is kept constant.- Parameters:
h
- Horizontal reduction amountv
- Vertical reduction amount- Returns:
this
for convenience- Since:
- 2.0
-
shrinkLeft
Shrinks 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:
this
for convenience- Since:
- 3.13
-
shrinkTop
Shrinks 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:
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
Returns the description of this Rectangle. -
touches
Returnstrue
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
Moves this Rectangle horizontally by dx and vertically by dy, then returns this Rectangle for convenience.- Parameters:
dx
- Shift along X axisdy
- Shift along Y axis- Returns:
this
for convenience- Since:
- 3.8
-
translate
Moves this Rectangle horizontally by dx and vertically by dy, then returns this Rectangle for convenience.- Parameters:
dx
- Shift along X axisdy
- Shift along Y axis- Returns:
this
for convenience- Since:
- 2.0
-
translate
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
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.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:
this
for convenience- Since:
- 2.0
-
union
Updates this Rectangle's bounds to the minimum size which can hold both this Rectangle and the coordinate (x,y).- Parameters:
x
- X coordinatey
- Y coordinate- Returns:
this
for convenience- Since:
- 3.8
-
union
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
Updates this Rectangle's bounds to the minimum size which can hold both this Rectangle and the coordinate (x,y).- Parameters:
x1
- X coordinatey1
- Y coordinate- Returns:
this
for convenience- Since:
- 2.0
-
union
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
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
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
-
shrink(Insets)
instead.