public class Rectangle2D extends Object implements ICloneable
(width x height)
, located at the point (x, y)
.Constructor and Description |
---|
Rectangle2D()
Creates a new rectangle of size
(0 x 0) at the location (0, 0) . |
Rectangle2D(double x,
double y,
double width,
double height)
Creates a new rectangle of the specified size at the specified location.
|
Modifier and Type | Method and Description |
---|---|
void |
add(double px,
double py)
Adds a point, specified by its coordinates, to this rectangle.
|
void |
add(Rectangle2D r)
Adds a rectangle to this rectangle.
|
Rectangle2D |
clone()
Creates a new instance of this class that has the same values as this objects.
|
boolean |
contains(double x,
double y)
Checks if the point specified by the given coordinates is contained in this rectangle.
|
boolean |
contains(double x,
double y,
double width,
double height)
Checks whether this rectangle completely contains the second specified rectangle.
|
boolean |
contains(Rectangle2D rect)
Checks whether this rectangle completely contains the second specified rectangle.
|
Rectangle2D |
createIntersection(Rectangle2D r)
Calculates the intersection of this rectangle with the given rectangle and returns the result as new rectangle.
|
Rectangle2D |
createUnion(Rectangle2D r)
Calculates the union of this rectangle with the given rectangle and returns the result as new rectangle.
|
boolean |
equals(Object obj)
Returns whether this rectangle and
obj are equal. |
Rectangle2D |
getBounds2D()
Gets the bounds of this instance in double precision.
|
double |
getCenterX()
Gets the x coordinate of the center point of this rectangle.
|
double |
getCenterY()
Gets the y coordinate of the center point of this rectangle.
|
Rectangle2D |
getFrame()
Gets the outer bounds of this rectangle in double coordinates.
|
double |
getHeight()
Gets the height of this rectangle.
|
double |
getMaxX()
Gets the largest x coordinate of this rectangle.
|
double |
getMaxY()
Gets the largest y coordinate of this rectangle.
|
double |
getMinX()
Gets the smallest x coordinate of this rectangle.
|
double |
getMinY()
Gets the smallest y coordinate of this rectangle.
|
double |
getWidth()
Gets the width of this rectangle.
|
double |
getX()
Gets the x coordinate of the upper left corner.
|
double |
getY()
Gets the y coordinate of the upper left corner.
|
int |
hashCode() |
static void |
intersect(Rectangle2D src1,
Rectangle2D src2,
Rectangle2D dst)
Calculates the intersection of the first and second specified rectangle and sets the resulting location and size to the
third rectangle.
|
boolean |
intersects(double x,
double y,
double width,
double height)
Checks whether this rectangle and the second specified rectangle intersect.
|
boolean |
intersects(Rectangle2D rect)
Checks whether this rectangle and the second specified rectangle intersect.
|
boolean |
intersectsLine(double x1,
double y1,
double x2,
double y2)
Checks if the line segment specified by the given coordinates intersects this rectangle.
|
boolean |
isEmpty()
Gets whether this instance is empty, i.e.
|
void |
setFrame(double x,
double y,
double width,
double height)
Sets the outer bounds of this rectangle based on the specified location and size.
|
void |
setFrame(Rectangle2D value)
Sets the outer bounds of this rectangle in double coordinates.
|
void |
setFrameFromCenter(double centerX,
double centerY,
double cornerX,
double cornerY)
Sets the outer bounds of this rectangle based on the specified new center and corner.
|
void |
setFrameFromCenter(Point2D center,
Point2D corner)
Sets the outer bounds of this rectangle based on the specified new center and corner.
|
void |
setFrameFromDiagonal(double x1,
double y1,
double x2,
double y2)
Sets the outer bounds of this rectangle based on the end points of one of its diagonals.
|
void |
setFrameFromDiagonal(Point2D p1,
Point2D p2)
Sets the outer bounds of this rectangle based on the end points of one of its diagonals.
|
void |
setRect(double x,
double y,
double width,
double height)
Sets the location and size of this rectangle to the specified values.
|
void |
setRect(Rectangle2D value)
Sets the location and size of this rectangle to be similar to the specified rectangle.
|
String |
toString() |
static void |
union(Rectangle2D src1,
Rectangle2D src2,
Rectangle2D dst)
Calculates the union of the first and second specified rectangle and sets the resulting location and size to the third
rectangle.
|
public Rectangle2D()
(0 x 0)
at the location (0, 0)
.public Rectangle2D(double x, double y, double width, double height)
x
- the x-coordinate of the upper left corner of the created rectangle.y
- the y-coordinate of the upper left corner of the created rectangle.width
- the width of the created rectangle.height
- the height of the created rectangle.public void add(double px, double py)
The rectangle will be grown if necessary. Note that for points that would lie on the right or bottom border of the
rectangle, contains(double, double)
will still return false
for the added point.
px
- the x coordinate of the point to addpy
- the y coordinate of the point to addpublic void add(Rectangle2D r)
The rectangle will be grown to the union of both rectangles
r
- the rectangle to addpublic Rectangle2D clone()
clone
in interface ICloneable
clone
in class Object
Object.clone()
public boolean contains(double x, double y)
x
- the x-coordinate of the point.y
- the y-coordinate of the point.true
if the specified point is contained in this rectangle; false
otherwise.public boolean contains(double x, double y, double width, double height)
x
- the x coordinate of the second rectangle.y
- the y coordinate of the second rectangle.width
- the width coordinate of the second rectangle.height
- the height coordinate of the second rectangle.true
if this rectangle contains the second onepublic boolean contains(Rectangle2D rect)
rect
- the rectangle to check for containmenttrue
if this rectangle contains the second onepublic Rectangle2D createIntersection(Rectangle2D r)
r
- a rectangle to intersect with this rectangle.public Rectangle2D createUnion(Rectangle2D r)
r
- a rectangle to union with this rectangle.public boolean equals(Object obj)
obj
are equal.
Two rectangles are considered equal if the have the same location and size.
public Rectangle2D getBounds2D()
public double getCenterX()
public double getCenterY()
public Rectangle2D getFrame()
setFrame(Rectangle2D)
public double getHeight()
public double getMaxX()
public double getMaxY()
public double getMinX()
public double getMinY()
public double getWidth()
public double getX()
public double getY()
public static final void intersect(Rectangle2D src1, Rectangle2D src2, Rectangle2D dst)
src1
- the first rectangle to intersect.src2
- the second rectangle to intersect.dst
- the rectangle to which the result is set.public boolean intersects(double x, double y, double width, double height)
x
- the x coordinate of the second rectangle.y
- the y coordinate of the second rectangle.width
- the width coordinate of the second rectangle.height
- the height coordinate of the second rectangle.true
if both rectangles intersectpublic boolean intersects(Rectangle2D rect)
rect
- the rectangle to check for intersectiontrue
if both rectangles intersectpublic boolean intersectsLine(double x1, double y1, double x2, double y2)
x1
- the x-coordinate of the first end point of the line.y1
- the y-coordinate of the first end point of the line.x2
- the x-coordinate of the other end point of the line.y2
- the y-coordinate of the other end point of the line.true
if the specified line intersects this rectangle; false
otherwise.public boolean isEmpty()
covers no area.
true
iff this rectangle is empty.public void setFrame(double x, double y, double width, double height)
x
- the new x-coordinate of the upper left corner.y
- the new y-coordinate of the upper left corner.width
- the new width.height
- the new height.public void setFrame(Rectangle2D value)
value
- a new double-precision rectangle which represents the outer bounds of this rectangle.getFrame()
public void setFrameFromCenter(double centerX, double centerY, double cornerX, double cornerY)
centerX
- the x-coordinate of the new center of this rectangle.centerY
- the y-coordinate of the new center of this rectangle.cornerX
- the x-coordinate of any new corner of this rectangle.cornerY
- the y-coordinate of any new corner of this rectangle.public void setFrameFromCenter(Point2D center, Point2D corner)
center
- the new center of this rectangle.corner
- any new corner of this rectangle.public void setFrameFromDiagonal(double x1, double y1, double x2, double y2)
x1
- the x-coordinate of the first end point of a diagonal.y1
- the y-coordinate of the first end point of a diagonal.x2
- the x-coordinate of the other end point of a diagonal.y2
- the y-coordinate of the other end point of a diagonal.public void setFrameFromDiagonal(Point2D p1, Point2D p2)
p1
- the first end point of a diagonal.p2
- the other end point of a diagonal.public void setRect(double x, double y, double width, double height)
x
- the new x-coordinate of the upper left corner.y
- the new y-coordinate of the upper left corner.width
- the new width.height
- the new height.public void setRect(Rectangle2D value)
value
- a rectangle that specifies the new location and size of this rectangle.public static final void union(Rectangle2D src1, Rectangle2D src2, Rectangle2D dst)
src1
- the first rectangle to union.src2
- the second rectangle to union.dst
- the rectangle to which the result is set.