This documentation differs from the official API. Jadeite adds extra features to the API including: variable font sizes, constructions examples, placeholders for classes and methods, and auto-generated “See Also” links. Additionally it is missing some items found in standard Javadoc documentation, including: generics type information, “Deprecated” tags and comments, “See Also” links, along with other minor differences. Please send any questions or feedback to bam@cs.cmu.edu.


java.awt.geom
class Rectangle2D

java.lang.Object extended by java.awt.geom.RectangularShape extended by java.awt.geom.Rectangle2D
All Implemented Interfaces:
Shape, Cloneable
Direct Known Subclasses:
Rectangle, Rectangle2D.Double, Rectangle2D.Float

Most common way to construct:

Shape moving = …;

Rectangle2D movingBounds = moving.getBounds2D();

Based on 36 examples


public abstract class Rectangle2D
extends RectangularShape

The Rectangle2D class describes a rectangle defined by a location {@code (x,y)} and dimension {@code (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.


Nested Class Summary
static class

           The Double class defines a rectangle specified in double coordinates.
static class

           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

          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

          Adds the Point2D object pt to this Rectangle2D.
 void

          Adds a Rectangle2D object to this Rectangle2D.
 boolean
contains(double x, double y)

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

          
abstract Rectangle2D

          Returns a new Rectangle2D object representing the intersection of this Rectangle2D with the specified Rectangle2D.
abstract Rectangle2D

          Returns a new Rectangle2D object representing the union of this Rectangle2D with the specified Rectangle2D.
 boolean

          Determines whether or not the specified Object is equal to this Rectangle2D.
 Rectangle2D

          
 PathIterator

          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

          Returns the hashcode for this Rectangle2D.
static void

          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)

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

          Tests if the specified line segment intersects the interior of this Rectangle2D.
 boolean

          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

          Determines where the specified java.awt.geom.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

          Sets this Rectangle2D to be the same as the specified Rectangle2D.
static void

          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, getPathIterator, getWidth, getX, getY, intersects, isEmpty, setFrame, setFrame, setFrame, setFrameFromCenter, setFrameFromCenter, setFrameFromDiagonal, setFrameFromDiagonal
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OUT_BOTTOM

public static final int OUT_BOTTOM
The bitmask that indicates that a point lies below this Rectangle2D.

OUT_LEFT

public static final int OUT_LEFT
The bitmask that indicates that a point lies to the left of this Rectangle2D.

OUT_RIGHT

public static final int OUT_RIGHT
The bitmask that indicates that a point lies to the right of this Rectangle2D.

OUT_TOP

public static final int OUT_TOP
The bitmask that indicates that a point lies above this Rectangle2D.
Constructor Detail

Rectangle2D

protected Rectangle2D()
This is an abstract class that cannot be instantiated directly. Type-specific implementation subclasses are available for instantiation and provide a number of formats for storing the information necessary to satisfy the various accessor methods below.

Method Detail

add

public void add(double newx,
                double newy)
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.

Parameters:
newx - the X coordinate of the new point
newy - the Y coordinate of the new point

add

public void add(Point2D pt)
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.

Parameters:
pt - the new Point2D to add to this Rectangle2D.

add

public void add(Rectangle2D r)
Adds a Rectangle2D object to this Rectangle2D. The resulting Rectangle2D is the union of the two Rectangle2D objects.

Parameters:
r - the Rectangle2D to add to this Rectangle2D.

contains

public boolean contains(double x,
                        double y)
{@inheritDoc}

Parameters:
x
y

contains

public boolean contains(double x,
                        double y,
                        double w,
                        double h)
{@inheritDoc}

Parameters:
x
y
w
h

createIntersection

public abstract Rectangle2D createIntersection(Rectangle2D r)
Returns a new Rectangle2D object representing the intersection of this Rectangle2D with the specified Rectangle2D.

Parameters:
r - the Rectangle2D to be intersected with this Rectangle2D
Returns:
the largest Rectangle2D contained in both the specified Rectangle2D and in this Rectangle2D.

createUnion

public abstract Rectangle2D createUnion(Rectangle2D r)
Returns a new Rectangle2D object representing the union of this Rectangle2D with the specified Rectangle2D.

Parameters:
r - the Rectangle2D to be combined with this Rectangle2D
Returns:
the smallest Rectangle2D containing both the specified Rectangle2D and this Rectangle2D.

equals

public boolean equals(Object obj)
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.

Overrides:
equals in class Object
Parameters:
obj - an Object to be compared with this Rectangle2D.
Returns:
true if obj is an instance of Rectangle2D and has the same values; false otherwise.

getBounds2D

public Rectangle2D getBounds2D()
{@inheritDoc}


getPathIterator

public PathIterator getPathIterator(AffineTransform 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.

Parameters:
at - an optional AffineTransform to be applied to the coordinates as they are returned in the iteration, or null if untransformed coordinates are desired
Returns:
the PathIterator object that returns the geometry of the outline of this Rectangle2D, one segment at a time.

getPathIterator

public PathIterator getPathIterator(AffineTransform at,
                                    double flatness)
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.

Overrides:
getPathIterator in class RectangularShape
Parameters:
at - an optional AffineTransform to be applied to the coordinates as they are returned in the iteration, or null if untransformed coordinates are desired
flatness - the maximum distance that the line segments used to approximate the curved segments are allowed to deviate from any point on the original curve. Since rectangles are already flat, the flatness parameter is ignored.
Returns:
the PathIterator object that returns the geometry of the outline of this Rectangle2D, one segment at a time.

hashCode

public int hashCode()
Returns the hashcode for this Rectangle2D.

Overrides:
hashCode in class Object
Returns:
the hashcode for this Rectangle2D.

intersect

public 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. 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.

Parameters:
src1 - the first of a pair of Rectangle2D objects to be intersected with each other
src2 - the second of a pair of Rectangle2D objects to be intersected with each other
dest - the Rectangle2D that holds the results of the intersection of src1 and src2

intersects

public boolean intersects(double x,
                          double y,
                          double w,
                          double h)
{@inheritDoc}

Parameters:
x
y
w
h

intersectsLine

public boolean intersectsLine(double x1,
                              double y1,
                              double x2,
                              double y2)
Tests if the specified line segment intersects the interior of this Rectangle2D.

Parameters:
x1 - the X coordinate of the 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
Returns:
true if the specified line segment intersects the interior of this Rectangle2D; false otherwise.

intersectsLine

public boolean intersectsLine(Line2D l)
Tests if the specified line segment intersects the interior of this Rectangle2D.

Parameters:
l - the specified {@link Line2D} to test for intersection with the interior of this Rectangle2D
Returns:
true if the specified Line2D intersects the interior of this Rectangle2D; false otherwise.

outcode

public abstract 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.

Parameters:
x - the specified X coordinate
y - the specified Y coordinate
Returns:
the logical OR of all appropriate out codes.

outcode

public int outcode(Point2D p)
Determines where the specified {@link 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.

Parameters:
p - the specified Point2D
Returns:
the logical OR of all appropriate out codes.

setFrame

public 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.

Overrides:
setFrame in class RectangularShape
Parameters:
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

setRect

public abstract void setRect(double x,
                             double y,
                             double w,
                             double h)
Sets the location and size of this Rectangle2D to the specified double values.

Parameters:
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

setRect

public void setRect(Rectangle2D r)
Sets this Rectangle2D to be the same as the specified Rectangle2D.

Parameters:
r - the specified Rectangle2D

union

public 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. 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.

Parameters:
src1 - the first of a pair of Rectangle2D objects to be combined with each other
src2 - the second of a pair of Rectangle2D objects to be combined with each other
dest - the Rectangle2D that holds the results of the union of src1 and src2


This documentation differs from the official API. Jadeite adds extra features to the API including: variable font sizes, constructions examples, placeholders for classes and methods, and auto-generated “See Also” links. Additionally it is missing some items found in standard Javadoc documentation, including: generics type information, “Deprecated” tags and comments, “See Also” links, along with other minor differences. Please send any questions or feedback to bam@cs.cmu.edu.
This page displays the Jadeite version of the documention, which is derived from the offical documentation that contains this copyright notice:
Copyright 2008 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
The official Sun™ documentation can be found here at http://java.sun.com/javase/6/docs/api/.