Method from java.awt.geom.Rectangle2D Detail: |
public void add(Point2D pt) {
add(pt.getX(), pt.getY());
}
Adds the Point2D object pt to this
Rectangle2D .
The resulting Rectangle2D is the smallest
Rectangle2D that contains both the original
Rectangle2D and the specified Point2D .
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. |
public void add(Rectangle2D r) {
double x1 = Math.min(getMinX(), r.getMinX());
double x2 = Math.max(getMaxX(), r.getMaxX());
double y1 = Math.min(getMinY(), r.getMinY());
double y2 = Math.max(getMaxY(), r.getMaxY());
setRect(x1, y1, x2 - x1, y2 - y1);
}
Adds a Rectangle2D object to this
Rectangle2D . The resulting Rectangle2D
is the union of the two Rectangle2D objects. |
public void add(double newx,
double newy) {
double x1 = Math.min(getMinX(), newx);
double x2 = Math.max(getMaxX(), newx);
double y1 = Math.min(getMinY(), newy);
double y2 = Math.max(getMaxY(), newy);
setRect(x1, y1, x2 - x1, y2 - y1);
}
Adds a point, specified by the double precision arguments
newx and newy , to this
Rectangle2D . The resulting Rectangle2D
is the smallest Rectangle2D that
contains both the original Rectangle2D and the
specified point.
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. |
public boolean contains(double x,
double y) {
double x0 = getX();
double y0 = getY();
return (x >= x0 &&
y >= y0 &&
x < x0 + getWidth() &&
y < y0 + getHeight());
}
|
public boolean contains(double x,
double y,
double w,
double h) {
if (isEmpty() || w < = 0 || h < = 0) {
return false;
}
double x0 = getX();
double y0 = getY();
return (x >= x0 &&
y >= y0 &&
(x + w) < = x0 + getWidth() &&
(y + h) < = y0 + getHeight());
}
|
abstract public Rectangle2D createIntersection(Rectangle2D r)
Returns a new Rectangle2D object representing the
intersection of this Rectangle2D with the specified
Rectangle2D . |
abstract public Rectangle2D createUnion(Rectangle2D r)
Returns a new Rectangle2D object representing the
union of this Rectangle2D with the specified
Rectangle2D . |
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj instanceof Rectangle2D) {
Rectangle2D r2d = (Rectangle2D) obj;
return ((getX() == r2d.getX()) &&
(getY() == r2d.getY()) &&
(getWidth() == r2d.getWidth()) &&
(getHeight() == r2d.getHeight()));
}
return false;
}
Determines whether or not the specified Object is
equal to this Rectangle2D . The specified
Object is equal to this Rectangle2D
if it is an instance of Rectangle2D and if its
location and size are the same as this Rectangle2D . |
public Rectangle2D getBounds2D() {
return (Rectangle2D) clone();
}
|
public PathIterator getPathIterator(AffineTransform at) {
return new RectIterator(this, at);
}
Returns an iteration object that defines the boundary of this
Rectangle2D .
The iterator for this class is multi-threaded safe, which means
that this Rectangle2D class guarantees that
modifications to the geometry of this Rectangle2D
object do not affect any iterations of that geometry that
are already in process. |
public PathIterator getPathIterator(AffineTransform at,
double flatness) {
return new RectIterator(this, at);
}
Returns an iteration object that defines the boundary of the
flattened Rectangle2D . Since rectangles are already
flat, the flatness parameter is ignored.
The iterator for this class is multi-threaded safe, which means
that this Rectangle2D class guarantees that
modifications to the geometry of this Rectangle2D
object do not affect any iterations of that geometry that
are already in process. |
public int hashCode() {
long bits = java.lang.Double.doubleToLongBits(getX());
bits += java.lang.Double.doubleToLongBits(getY()) * 37;
bits += java.lang.Double.doubleToLongBits(getWidth()) * 43;
bits += java.lang.Double.doubleToLongBits(getHeight()) * 47;
return (((int) bits) ^ ((int) (bits > > 32)));
}
Returns the hashcode for this Rectangle2D . |
public static void intersect(Rectangle2D src1,
Rectangle2D src2,
Rectangle2D dest) {
double x1 = Math.max(src1.getMinX(), src2.getMinX());
double y1 = Math.max(src1.getMinY(), src2.getMinY());
double x2 = Math.min(src1.getMaxX(), src2.getMaxX());
double y2 = Math.min(src1.getMaxY(), src2.getMaxY());
dest.setFrame(x1, y1, x2-x1, y2-y1);
}
Intersects the pair of specified source Rectangle2D
objects and puts the result into the specified destination
Rectangle2D object. One of the source rectangles
can also be the destination to avoid creating a third Rectangle2D
object, but in this case the original points of this source
rectangle will be overwritten by this method. |
public boolean intersects(double x,
double y,
double w,
double h) {
if (isEmpty() || w < = 0 || h < = 0) {
return false;
}
double x0 = getX();
double y0 = getY();
return (x + w > x0 &&
y + h > y0 &&
x < x0 + getWidth() &&
y < y0 + getHeight());
}
|
public boolean intersectsLine(Line2D l) {
return intersectsLine(l.getX1(), l.getY1(), l.getX2(), l.getY2());
}
Tests if the specified line segment intersects the interior of this
Rectangle2D . |
public boolean intersectsLine(double x1,
double y1,
double x2,
double y2) {
int out1, out2;
if ((out2 = outcode(x2, y2)) == 0) {
return true;
}
while ((out1 = outcode(x1, y1)) != 0) {
if ((out1 & out2) != 0) {
return false;
}
if ((out1 & (OUT_LEFT | OUT_RIGHT)) != 0) {
double x = getX();
if ((out1 & OUT_RIGHT) != 0) {
x += getWidth();
}
y1 = y1 + (x - x1) * (y2 - y1) / (x2 - x1);
x1 = x;
} else {
double y = getY();
if ((out1 & OUT_BOTTOM) != 0) {
y += getHeight();
}
x1 = x1 + (y - y1) * (x2 - x1) / (y2 - y1);
y1 = y;
}
}
return true;
}
Tests if the specified line segment intersects the interior of this
Rectangle2D . |
public int outcode(Point2D p) {
return outcode(p.getX(), p.getY());
}
Determines where the specified Point2D lies with
respect to this Rectangle2D .
This method computes a binary OR of the appropriate mask values
indicating, for each side of this Rectangle2D ,
whether or not the specified Point2D is on the same
side of the edge as the rest of this Rectangle2D . |
abstract public int outcode(double x,
double y)
Determines where the specified coordinates lie with respect
to this Rectangle2D .
This method computes a binary OR of the appropriate mask values
indicating, for each side of this Rectangle2D ,
whether or not the specified coordinates are on the same side
of the edge as the rest of this Rectangle2D . |
public void setFrame(double x,
double y,
double w,
double h) {
setRect(x, y, w, h);
}
Sets the location and size of the outer bounds of this
Rectangle2D to the specified rectangular values. |
public void setRect(Rectangle2D r) {
setRect(r.getX(), r.getY(), r.getWidth(), r.getHeight());
}
Sets this Rectangle2D to be the same as the specified
Rectangle2D . |
abstract public void setRect(double x,
double y,
double w,
double h)
Sets the location and size of this Rectangle2D
to the specified double values. |
public static void union(Rectangle2D src1,
Rectangle2D src2,
Rectangle2D dest) {
double x1 = Math.min(src1.getMinX(), src2.getMinX());
double y1 = Math.min(src1.getMinY(), src2.getMinY());
double x2 = Math.max(src1.getMaxX(), src2.getMaxX());
double y2 = Math.max(src1.getMaxY(), src2.getMaxY());
dest.setFrameFromDiagonal(x1, y1, x2, y2);
}
Unions the pair of source Rectangle2D objects
and puts the result into the specified destination
Rectangle2D object. One of the source rectangles
can also be the destination to avoid creating a third Rectangle2D
object, but in this case the original points of this source
rectangle will be overwritten by this method. |