Methods Summary |
---|
public void | add(double x, double y)Enlarges the rectangle so that it includes the given point.
double x1 = Math.min(getMinX(), x);
double y1 = Math.min(getMinY(), y);
double x2 = Math.max(getMaxX(), x);
double y2 = Math.max(getMaxY(), y);
setRect(x1, y1, x2 - x1, y2 - y1);
|
public void | add(java.awt.geom.Point2D p)Enlarges the rectangle so that it includes the given point.
add(p.getX(), p.getY());
|
public void | add(java.awt.geom.Rectangle2D r)Enlarges the rectangle so that it covers the given rectangle.
union(this, r, this);
|
public boolean | contains(double x, double y)
if (isEmpty()) {
return false;
}
double x1 = getX();
double y1 = getY();
double x2 = x1 + getWidth();
double y2 = y1 + getHeight();
return x1 <= x && x < x2 && y1 <= y && y < y2;
|
public boolean | contains(double x, double y, double width, double height)
if (isEmpty() || width <= 0.0 || height <= 0.0) {
return false;
}
double x1 = getX();
double y1 = getY();
double x2 = x1 + getWidth();
double y2 = y1 + getHeight();
return x1 <= x && x + width <= x2 && y1 <= y && y + height <= y2;
|
public abstract java.awt.geom.Rectangle2D | createIntersection(java.awt.geom.Rectangle2D r)Creates an new rectangle that is the intersection of this rectangle with
the given rectangle. The resulting rectangle may be empty. The data of
this rectangle is left unchanged.
|
public abstract java.awt.geom.Rectangle2D | createUnion(java.awt.geom.Rectangle2D r)Creates an new rectangle that is the union of this rectangle with the
given rectangle. The new rectangle is the smallest rectangle which
contains both this rectangle and the rectangle specified as a parameter.
The data of this rectangle is left unchanged.
|
public boolean | equals(java.lang.Object obj)
if (obj == this) {
return true;
}
if (obj instanceof Rectangle2D) {
Rectangle2D r = (Rectangle2D)obj;
return getX() == r.getX() && getY() == r.getY() && getWidth() == r.getWidth()
&& getHeight() == r.getHeight();
}
return false;
|
public java.awt.geom.Rectangle2D | getBounds2D()
return (Rectangle2D)clone();
|
public java.awt.geom.PathIterator | getPathIterator(java.awt.geom.AffineTransform t)
return new Iterator(this, t);
|
public java.awt.geom.PathIterator | getPathIterator(java.awt.geom.AffineTransform t, double flatness)
return new Iterator(this, t);
|
public int | hashCode()
HashCode hash = new HashCode();
hash.append(getX());
hash.append(getY());
hash.append(getWidth());
hash.append(getHeight());
return hash.hashCode();
|
public static void | intersect(java.awt.geom.Rectangle2D src1, java.awt.geom.Rectangle2D src2, java.awt.geom.Rectangle2D dst)Changes the data values of the destination rectangle to match the
intersection of the two source rectangles, leaving the two source
rectangles unchanged. The resulting rectangle may be empty.
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());
dst.setFrame(x1, y1, x2 - x1, y2 - y1);
|
public boolean | intersects(double x, double y, double width, double height)
if (isEmpty() || width <= 0.0 || height <= 0.0) {
return false;
}
double x1 = getX();
double y1 = getY();
double x2 = x1 + getWidth();
double y2 = y1 + getHeight();
return x + width > x1 && x < x2 && y + height > y1 && y < y2;
|
public boolean | intersectsLine(java.awt.geom.Line2D l)Determines whether any part of the specified line segment touches any
part of the rectangle, including its boundary.
return intersectsLine(l.getX1(), l.getY1(), l.getX2(), l.getY2());
|
public boolean | intersectsLine(double x1, double y1, double x2, double y2)Determines whether any part of the line segment between (and including)
the two given points touches any part of the rectangle, including its
boundary.
double rx1 = getX();
double ry1 = getY();
double rx2 = rx1 + getWidth();
double ry2 = ry1 + getHeight();
return (rx1 <= x1 && x1 <= rx2 && ry1 <= y1 && y1 <= ry2)
|| (rx1 <= x2 && x2 <= rx2 && ry1 <= y2 && y2 <= ry2)
|| Line2D.linesIntersect(rx1, ry1, rx2, ry2, x1, y1, x2, y2)
|| Line2D.linesIntersect(rx2, ry1, rx1, ry2, x1, y1, x2, y2);
|
public int | outcode(java.awt.geom.Point2D p)Gets the location of the point with respect to the rectangle and packs
the information into a single integer using the bitmasks
{@link Rectangle2D#OUT_LEFT}, {@link Rectangle2D#OUT_RIGHT},
{@link Rectangle2D#OUT_TOP}, and {@link Rectangle2D#OUT_BOTTOM}. If the
rectangle has zero or negative width, then every point is regarded as
being both to the left and to the right of the rectangle. Similarly, if
the height is zero or negative then all points are considered to be both
both above and below it.
return outcode(p.getX(), p.getY());
|
public abstract int | outcode(double x, double y)Gets the location of the point with respect to the rectangle and packs
the information into a single integer using the bitmasks
{@link Rectangle2D#OUT_LEFT}, {@link Rectangle2D#OUT_RIGHT},
{@link Rectangle2D#OUT_TOP}, and {@link Rectangle2D#OUT_BOTTOM}. If the
rectangle has zero or negative width, then every point is regarded as
being both to the left and to the right of the rectangle. Similarly, if
the height is zero or negative then all points are considered to be both
both above and below it.
|
public void | setFrame(double x, double y, double width, double height)
setRect(x, y, width, height);
|
public abstract void | setRect(double x, double y, double width, double height)Sets the rectangle's location and dimension.
|
public void | setRect(java.awt.geom.Rectangle2D r)Sets the data of this rectangle to match the data of the given rectangle.
setRect(r.getX(), r.getY(), r.getWidth(), r.getHeight());
|
public static void | union(java.awt.geom.Rectangle2D src1, java.awt.geom.Rectangle2D src2, java.awt.geom.Rectangle2D dst)Changes the data values of the destination rectangle to match the union
of the two source rectangles, leaving the two source rectangles
unchanged. The union is the smallest rectangle that completely covers the
two source rectangles.
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());
dst.setFrame(x1, y1, x2 - x1, y2 - y1);
|