is new.
java.lang.Objectjava.awt.geom.RectangularShape
java.awt.geom.Rectangle2D
public abstract class Rectangle2D
The Rectangle2D class describes a rectangle defined by a location
(x,y)
(x, y)
and dimension
(w x h).
(w x h).
This class is only the abstract superclass for all objects that store a 2D rectangle. The actual storage representation of the coordinates is left to the subclass.
Since:
1.2
| Nested Class Summary | |
|---|---|
| static class |
Rectangle2D.Double
The Double class defines a rectangle specified in double coordinates. |
| static class |
Rectangle2D.Float
The Float class defines a rectangle specified in float coordinates. |
| Field Summary | |
|---|---|
| static int |
OUT_BOTTOM
The bitmask that indicates that a point lies below this Rectangle2D. |
| static int |
OUT_LEFT
The bitmask that indicates that a point lies to the left of this Rectangle2D. |
| static int |
OUT_RIGHT
The bitmask that indicates that a point lies to the right of this Rectangle2D. |
| static int |
OUT_TOP
The bitmask that indicates that a point lies above this Rectangle2D. |
| Constructor Summary | |
|---|---|
| protected |
Rectangle2D
() This is an abstract class that cannot be instantiated directly. |
| Method Summary | |
|---|---|
| void |
add
(double newx, double newy) Adds a point, specified by the double precision arguments newx and newy, to this Rectangle2D. |
| void |
add
(
Point2D
pt) Adds the Point2D object pt to this Rectangle2D. |
| void |
add
(
Rectangle2D
r) Adds a Rectangle2D object to this Rectangle2D. |
| boolean |
contains
(double x, double y) Tests if
the
coordinates are
the Shape.
|
| boolean |
contains
(double x, double y, double w, double h) Tests if the interior of
the Shape
area.
|
| abstract Rectangle2D |
createIntersection
(
Rectangle2D
r) Returns a new Rectangle2D object representing the intersection of this Rectangle2D with the specified Rectangle2D. |
| abstract Rectangle2D |
createUnion
(
Rectangle2D
r) Returns a new Rectangle2D object representing the union of this Rectangle2D with the specified Rectangle2D. |
| boolean |
equals
(
Object
obj) Determines whether or not the specified Object is equal to this Rectangle2D. |
| Rectangle2D |
getBounds2D
() Returns
a
and more accurate
bounding box of
the Shape than the getBounds method.
|
| PathIterator |
getPathIterator
(
AffineTransform
at) Returns an iteration object that defines the boundary of this Rectangle2D. |
| PathIterator |
getPathIterator
(
AffineTransform
at, double flatness) Returns an iteration object that defines the boundary of the flattened Rectangle2D. |
| int |
hashCode
() Returns the hashcode for this Rectangle2D. |
| static void |
intersect
(
Rectangle2D
src1,
Rectangle2D
src2,
Rectangle2D
dest) Intersects the pair of specified source Rectangle2D objects and puts the result into the specified destination Rectangle2D object. |
| boolean |
intersects
(double x, double y, double w, double h) Tests if the interior of
the Shape
area.
|
| boolean |
intersectsLine
(double x1, double y1, double x2, double y2) Tests if the specified line segment intersects the interior of this Rectangle2D. |
| boolean |
intersectsLine
(
Line2D
l) Tests if the specified line segment intersects the interior of this Rectangle2D. |
| abstract int |
outcode
(double x, double y) Determines where the specified coordinates lie with respect to this Rectangle2D. |
| int |
outcode
(
Point2D
p) Determines where the specified Point2D lies with respect to this Rectangle2D. |
| void |
setFrame
(double x, double y, double w, double h) Sets the location and size of the outer bounds of this Rectangle2D to the specified rectangular values. |
| abstract void |
setRect
(double x, double y, double w, double h) Sets the location and size of this Rectangle2D to the specified double values. |
| void |
setRect
(
Rectangle2D
r) Sets this Rectangle2D to be the same as the specified Rectangle2D. |
| static void |
union
(
Rectangle2D
src1,
Rectangle2D
src2,
Rectangle2D
dest) Unions the pair of source Rectangle2D objects and puts the result into the specified destination Rectangle2D object. |
| Methods inherited from class java.awt.geom. RectangularShape |
|---|
| clone , contains , contains , getBounds , getCenterX , getCenterY , getFrame , getHeight , getMaxX , getMaxY , getMinX , getMinY , getWidth , getX , getY , intersects , isEmpty , setFrame , setFrame , setFrameFromCenter , setFrameFromCenter , setFrameFromDiagonal , setFrameFromDiagonal |
| Methods inherited from class java.lang. Object |
|---|
| finalize , getClass , notify , notifyAll , toString , wait , wait , wait |
| Field Detail |
|---|
public static final int OUT_LEFT
public static final int OUT_TOP
public static final int OUT_RIGHT
public static final int OUT_BOTTOM
| Constructor Detail |
|---|
protected Rectangle2D()
Since:
1.2
| Method Detail |
|---|
public abstract void setRect(double x,
double y,
double w,
double h)
x
X coordinate
upper-left
y - the Y coordinate of the upper-left corner of this Rectangle2D
w
width of this Rectangle2D
h -
public void setRect(Rectangle2D r)
public boolean intersectsLine(double x1,
double y1,
double x2,
double y2)
x1
X coordinate
start point of the
specified line segment
y1 - the Y coordinate of the start point of the specified line segment
x2 - the X coordinate of the end point of the specified line segment
y2 - the Y coordinate of the end point of the specified line segment
public boolean intersectsLine(Line2D l)
public abstract int outcode(double x,
double y)
x - the specified X coordinate
y - the specified Y coordinate
public int outcode(Point2D p)
public void setFrame(double x,
double y,
double w,
double h)
x - the X coordinate of the upper-left corner of this Rectangle2D
y - the Y coordinate of the upper-left corner of this Rectangle2D
w - the width of this Rectangle2D
h - the height of this Rectangle2D
public Rectangle2D getBounds2D()
Returns a high precision and more accurate bounding box of the Shape than the getBounds method. Note that there is no guarantee that the returned
Rectangle2D
is the smallest bounding box that encloses the Shape, only that the Shape lies entirely within the indicated Rectangle2D. The bounding box returned by this method is usually tighter than that returned by the getBounds method and never fails due to overflow problems since the return value can be an instance of the Rectangle2D that uses double precision values to store the dimensions.
an instance of Rectangle2D that is a high-precision bounding box of the Shape.
public boolean contains(double x,
double y)
the
coordinates are
the Shape.
x - the specified X coordinate to be tested
y - the specified Y coordinate to be tested
Shape boundary;
public boolean intersects(double x,
double y,
double w,
double h)
Tests if the interior of the Shape intersects the interior of a specified rectangular area. The rectangular area is considered to intersect the Shape if any point is contained in both the interior of the Shape and the specified rectangular area.
The Shape.intersects() method allows a Shape implementation to conservatively return true when:
there is a high probability that the rectangular area and the Shape intersect, but
the calculations to accurately determine this intersection are prohibitively expensive.
This means that for some Shapes this method might return true even though the rectangular area does not intersect the Shape. The
Area
class performs more accurate computations of geometric intersection than most Shape objects and therefore can be used if a more precise answer is required.
x
X coordinate
upper-left
area
y - the Y coordinate of the upper-left corner of the specified rectangular area
w - the width of the specified rectangular area
area
true if the interior of the Shape and the interior of the rectangular area intersect, or are both highly likely to intersect and intersection calculations would be too expensive to perform; false otherwise.
public boolean contains(double x,
double y,
double w,
double h)
Tests if the interior of the Shape entirely contains the specified rectangular area. All coordinates that lie inside the rectangular area must lie within the Shape for the entire rectanglar area to be considered contained within the Shape.
The Shape.contains() method allows a Shape implementation to conservatively return false when:
the intersect method returns true and
the calculations to determine whether or not the Shape entirely contains the rectangular area are prohibitively expensive.
This means that for some Shapes this method might return false even though the Shape contains the rectangular area. The
Area
class performs more accurate geometric computations than most Shape objects and therefore can be used if a more precise answer is required.
x
X coordinate
upper-left
area
y - the Y coordinate of the upper-left corner of the specified rectangular area
w - the width of the specified rectangular area
area
true if the interior of the Shape entirely contains the specified rectangular area; false otherwise or, if the Shape contains the rectangular area and the intersects method returns true and the containment calculations would be too expensive to perform.
public abstract Rectangle2D createIntersection(Rectangle2D r)
public static void intersect(Rectangle2D src1,
Rectangle2D src2,
Rectangle2D dest)
public abstract Rectangle2D createUnion(Rectangle2D r)
public static void union(Rectangle2D src1,
Rectangle2D src2,
Rectangle2D dest)
public void add(double newx,
double newy)
After adding a point, a call to contains with the added point as an argument does not necessarily return true. The contains method does not return true for points on the right or bottom edges of a rectangle. Therefore, if the added point falls on the left or bottom edge of the enlarged rectangle, contains returns false for that point.
newx - the X coordinate of the new point
newy - the Y coordinate of the new point
1.2
public void add(Point2D pt)
After adding a point, a call to contains with the added point as an argument does not necessarily return true. The contains method does not return true for points on the right or bottom edges of a rectangle. Therefore, if the added point falls on the left or bottom edge of the enlarged rectangle, contains returns false for that point.
1.2
public void add(Rectangle2D r)
1.2
public PathIterator getPathIterator(AffineTransform at)
public PathIterator getPathIterator(AffineTransform at,
double flatness)
public int hashCode()
Since:
1.2
public boolean equals(Object obj)