Index (Frames) | Index (No Frames) | Package | Package Tree | Tree
java.awt.geom

Class Rectangle2D

java.lang.Object
|
+--java.awt.geom.RectangularShape
   |
   +--java.awt.geom.Rectangle2D


public abstract class Rectangle2D

extends RectangularShape

This class describes a rectangle by a point (x,y) and dimension (w x h). The actual storage is left up to subclasses.

It is valid for a rectangle to have negative width or height; but it is considered to have no area or internal points. Therefore, the behavior in methods like contains or intersects is undefined unless the rectangle has positive width and height.

Since:Authors:

Field Summary

static intOUT_BOTTOM

The point lies below of the rectangle (p.y > r.maxY).
static intOUT_LEFT

The point lies left of the rectangle (p.x < r.x).
static intOUT_RIGHT

The point lies right of the rectangle (p.x > r.maxX).
static intOUT_TOP

The point lies above the rectangle (p.y < r.y).

Constructor Summary

Rectangle2D()

Default constructor.

Method Summary

voidadd(double newx, double newy)

Modifies this rectangle so that it represents the smallest rectangle that contains both the existing rectangle and the specified point.
voidadd(java.awt.geom.Point2D p)

Modifies this rectangle so that it represents the smallest rectangle that contains both the existing rectangle and the specified point.
voidadd(java.awt.geom.Rectangle2D r)

Modifies this rectangle so that it represents the smallest rectangle that contains both the existing rectangle and the specified rectangle.
booleancontains(double x, double y)

Test if the given point is contained in the rectangle.
booleancontains(double x, double y, double w, double h)

Tests if this rectangle contains the given one.
java.awt.geom.Rectangle2DcreateIntersection(java.awt.geom.Rectangle2D r)

Return a new rectangle which is the intersection of this and the given one.
java.awt.geom.Rectangle2DcreateUnion(java.awt.geom.Rectangle2D r)

Return a new rectangle which is the union of this and the given one.
booleanequals(java.lang.Object obj)

Tests this rectangle for equality against the specified object.
java.awt.geom.Rectangle2DgetBounds2D()

Returns the bounds of this rectangle.
java.awt.geom.PathIteratorgetPathIterator(final AffineTransform at)

Return an iterator along the shape boundary.
java.awt.geom.PathIteratorgetPathIterator(java.awt.geom.AffineTransform at, double flatness)

Return an iterator along the shape boundary.
inthashCode()

Return the hashcode for this rectangle.
static voidintersect(java.awt.geom.Rectangle2D src1, java.awt.geom.Rectangle2D src2, java.awt.geom.Rectangle2D dest)

Intersects a pair of rectangles, and places the result in the destination; this can be used to avoid object creation.
booleanintersects(double x, double y, double w, double h)

Tests if the given rectangle intersects this one.
booleanintersectsLine(double x1, double y1, double x2, double y2)

Tests if the specified line intersects the interior of this rectangle.
booleanintersectsLine(java.awt.geom.Line2D l)

Tests if the specified line intersects the interior of this rectangle.
intoutcode(double x, double y)

Determine where the point lies with respect to this rectangle.
intoutcode(java.awt.geom.Point2D p)

Determine where the point lies with respect to this rectangle.
voidsetFrame(double x, double y, double w, double h)

Set the bounding box of this rectangle.
voidsetRect(double x, double y, double w, double h)

Set the bounding box of this rectangle.
voidsetRect(java.awt.geom.Rectangle2D r)

Set the bounding box of this rectangle from the given one.
static voidunion(java.awt.geom.Rectangle2D src1, java.awt.geom.Rectangle2D src2, java.awt.geom.Rectangle2D dest)

Joins a pair of rectangles, and places the result in the destination; this can be used to avoid object creation.

Field Details

OUT_BOTTOM

public static final int OUT_BOTTOM

The point lies below of the rectangle (p.y > r.maxY).

See Also:


OUT_LEFT

public static final int OUT_LEFT

The point lies left of the rectangle (p.x < r.x).

See Also:


OUT_RIGHT

public static final int OUT_RIGHT

The point lies right of the rectangle (p.x > r.maxX).

See Also:


OUT_TOP

public static final int OUT_TOP

The point lies above the rectangle (p.y < r.y).

See Also:


Constructor Details

Rectangle2D

protected Rectangle2D()

Default constructor.


Method Details

add

public void add(double newx, double newy)

Modifies this rectangle so that it represents the smallest rectangle that contains both the existing rectangle and the specified point. However, if the point falls on one of the two borders which are not inside the rectangle, a subsequent call to contains may return false.

Parameters:


add

public void add(java.awt.geom.Point2D p)

Modifies this rectangle so that it represents the smallest rectangle that contains both the existing rectangle and the specified point. However, if the point falls on one of the two borders which are not inside the rectangle, a subsequent call to contains may return false.

Parameters:

Throws:


add

public void add(java.awt.geom.Rectangle2D r)

Modifies this rectangle so that it represents the smallest rectangle that contains both the existing rectangle and the specified rectangle.

Parameters:

Throws:

See Also:


contains

public boolean contains(double x, double y)

Test if the given point is contained in the rectangle.

Parameters:

Returns:


contains

public boolean contains(double x, double y, double w, double h)

Tests if this rectangle contains the given one. In other words, test if this rectangle contains all points in the given one.

Parameters:

Returns:


createIntersection

public Rectangle2D createIntersection(java.awt.geom.Rectangle2D r)

Return a new rectangle which is the intersection of this and the given one. The result will be empty if there is no intersection.

Parameters:

Returns:

Throws:


createUnion

public Rectangle2D createUnion(java.awt.geom.Rectangle2D r)

Return a new rectangle which is the union of this and the given one.

Parameters:

Returns:

Throws:


equals

public boolean equals(java.lang.Object obj)

Tests this rectangle for equality against the specified object. This will be true if an only if the specified object is an instance of Rectangle2D with the same coordinates and dimensions.

Parameters:

Returns:


getBounds2D

public Rectangle2D getBounds2D()

Returns the bounds of this rectangle. A pretty useless method, as this is already a rectangle.

Returns:


getPathIterator

public PathIterator getPathIterator(final AffineTransform at)

Return an iterator along the shape boundary. If the optional transform is provided, the iterator is transformed accordingly. Each call returns a new object, independent from others in use. This iterator is thread safe; modifications to the rectangle do not affect the results of this path instance.

Since:Parameters:

Returns:


getPathIterator

public PathIterator getPathIterator(java.awt.geom.AffineTransform at, double flatness)

Return an iterator along the shape boundary. If the optional transform is provided, the iterator is transformed accordingly. Each call returns a new object, independent from others in use. This iterator is thread safe; modifications to the rectangle do not affect the results of this path instance. As the rectangle is already flat, the flatness parameter is ignored.

Since:Parameters:

Returns:


hashCode

public int hashCode()

Return the hashcode for this rectangle. The formula is not documented, but appears to be the same as:
 long l = Double.doubleToLongBits(getX())
   + 37 * Double.doubleToLongBits(getY())
   + 43 * Double.doubleToLongBits(getWidth())
   + 47 * Double.doubleToLongBits(getHeight());
 return (int) ((l >> 32) ^ l);
 

Returns:


intersect

public static void intersect(java.awt.geom.Rectangle2D src1, java.awt.geom.Rectangle2D src2, java.awt.geom.Rectangle2D dest)

Intersects a pair of rectangles, and places the result in the destination; this can be used to avoid object creation. This method even works when the destination is also a source, although you stand to lose the original data.

Parameters:

Throws:


intersects

public boolean intersects(double x, double y, double w, double h)

Tests if the given rectangle intersects this one. In other words, test if the two rectangles share at least one internal point.

Parameters:

Returns:


intersectsLine

public boolean intersectsLine(double x1, double y1, double x2, double y2)

Tests if the specified line intersects the interior of this rectangle.

Parameters:

Returns:


intersectsLine

public boolean intersectsLine(java.awt.geom.Line2D l)

Tests if the specified line intersects the interior of this rectangle.

Parameters:

Returns:

Throws:


outcode

public int outcode(double x, double y)

Determine where the point lies with respect to this rectangle. The result will be the binary OR of the appropriate bit masks.

Parameters:

Returns:

See Also:


outcode

public int outcode(java.awt.geom.Point2D p)

Determine where the point lies with respect to this rectangle. The result will be the binary OR of the appropriate bit masks.

Parameters:

Returns:

Throws:

See Also:


setFrame

public void setFrame(double x, double y, double w, double h)

Set the bounding box of this rectangle.

Parameters:


setRect

public void setRect(double x, double y, double w, double h)

Set the bounding box of this rectangle.

Parameters:


setRect

public void setRect(java.awt.geom.Rectangle2D r)

Set the bounding box of this rectangle from the given one.

Parameters:

Throws:


union

public static void union(java.awt.geom.Rectangle2D src1, java.awt.geom.Rectangle2D src2, java.awt.geom.Rectangle2D dest)

Joins a pair of rectangles, and places the result in the destination; this can be used to avoid object creation. This method even works when the destination is also a source, although you stand to lose the original data.

Parameters:

Throws: