FileDocCategorySizeDatePackage
Rectangle2D.javaAPI DocAndroid 1.5 API25810Wed May 06 22:41:54 BST 2009java.awt.geom

Rectangle2D

public abstract class Rectangle2D extends RectangularShape
The Class Rectangle2D represents a rectangle whose coordinates are given with the correct precision to be used with the Graphics2D classes.
since
Android 1.0

Fields Summary
public static final int
OUT_LEFT
The Constant OUT_LEFT is a mask that is used to indicate that a given point is outside the rectangle and to its left.
public static final int
OUT_TOP
The Constant OUT_TOP is a mask that is used to indicate that a given point is outside the rectangle and above it.
public static final int
OUT_RIGHT
The Constant OUT_RIGHT is a mask that is used to indicate that a given point is outside the rectangle and to its right.
public static final int
OUT_BOTTOM
The Constant OUT_BOTTOM is a mask that is used to indicate that a given point is outside the rectangle and above it.
Constructors Summary
protected Rectangle2D()
Instantiates a new Rectangle2D.

    
Methods Summary
public voidadd(double x, double y)
Enlarges the rectangle so that it includes the given point.

param
x the x coordinate of the new point to be covered by the rectangle.
param
y the y coordinate of the new point to be covered by the rectangle.

        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 voidadd(java.awt.geom.Point2D p)
Enlarges the rectangle so that it includes the given point.

param
p the new point to be covered by the rectangle.

        add(p.getX(), p.getY());
    
public voidadd(java.awt.geom.Rectangle2D r)
Enlarges the rectangle so that it covers the given rectangle.

param
r the new rectangle to be covered by this rectangle.

        union(this, r, this);
    
public booleancontains(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 booleancontains(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.Rectangle2DcreateIntersection(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.

param
r the rectangle to intersect with this rectangle.
return
the new rectangle given by intersection.

public abstract java.awt.geom.Rectangle2DcreateUnion(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.

param
r the rectangle to combine with this rectangle.
return
the new rectangle given by union.

public booleanequals(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.Rectangle2DgetBounds2D()

        return (Rectangle2D)clone();
    
public java.awt.geom.PathIteratorgetPathIterator(java.awt.geom.AffineTransform t)

        return new Iterator(this, t);
    
public java.awt.geom.PathIteratorgetPathIterator(java.awt.geom.AffineTransform t, double flatness)

        return new Iterator(this, t);
    
public inthashCode()

        HashCode hash = new HashCode();
        hash.append(getX());
        hash.append(getY());
        hash.append(getWidth());
        hash.append(getHeight());
        return hash.hashCode();
    
public static voidintersect(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.

param
src1 one of the two source rectangles giving the data to intersect.
param
src2 one of the two source rectangles giving the data to intersect.
param
dst the destination object where the data of the intersection is written.

        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 booleanintersects(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 booleanintersectsLine(java.awt.geom.Line2D l)
Determines whether any part of the specified line segment touches any part of the rectangle, including its boundary.

param
l the line segment to test.
return
true, if at least one point of the given line segment matches any point of the interior of the rectangle or the rectangle's boundary.

        return intersectsLine(l.getX1(), l.getY1(), l.getX2(), l.getY2());
    
public booleanintersectsLine(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.

param
x1 the x coordinate of one of the points that determines the line segment to test.
param
y1 the y coordinate of one of the points that determines the line segment to test.
param
x2 the x coordinate of one of the points that determines the line segment to test.
param
y2 the y coordinate of one of the points that determines the line segment to test.
return
true, if at least one point of the line segment between the two points matches any point of the interior of the rectangle or the rectangle's 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 intoutcode(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.

param
p the point to check.
return
the point's location with respect to the rectangle.

        return outcode(p.getX(), p.getY());
    
public abstract intoutcode(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.

param
x the x coordinate of the point to check.
param
y the y coordinate of the point to check.
return
the point's location with respect to the rectangle.

public voidsetFrame(double x, double y, double width, double height)

        setRect(x, y, width, height);
    
public abstract voidsetRect(double x, double y, double width, double height)
Sets the rectangle's location and dimension.

param
x the x coordinate of the rectangle's upper left corner.
param
y the y coordinate of the rectangle's upper left corner.
param
width the width of the rectangle.
param
height the height of the rectangle.

public voidsetRect(java.awt.geom.Rectangle2D r)
Sets the data of this rectangle to match the data of the given rectangle.

param
r the rectangle whose data is to be copied into this rectangle's fields.

        setRect(r.getX(), r.getY(), r.getWidth(), r.getHeight());
    
public static voidunion(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.

param
src1 one of the two source rectangles giving the data.
param
src2 one of the two source rectangles giving the data.
param
dst the destination object where the data of the union is written.

        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);