java.awt.geom
Class Rectangle2D
- Cloneable, Shape
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.
static int | OUT_BOTTOM - The point lies below of the rectangle (p.y > r.maxY).
|
static int | OUT_LEFT - The point lies left of the rectangle (p.x < r.x).
|
static int | OUT_RIGHT - The point lies right of the rectangle (p.x > r.maxX).
|
static int | OUT_TOP - The point lies above the rectangle (p.y < r.y).
|
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.
|
void | add(Point2D p) - Modifies this rectangle so that it represents the smallest rectangle
that contains both the existing rectangle and the specified point.
|
void | add(Rectangle2D r) - Modifies this rectangle so that it represents the smallest rectangle
that contains both the existing rectangle and the specified rectangle.
|
boolean | contains(double x, double y) - Test if the given point is contained in the rectangle.
|
boolean | contains(double x, double y, double w, double h) - Tests if this rectangle contains the given one.
|
abstract Rectangle2D | createIntersection(Rectangle2D r) - Return a new rectangle which is the intersection of this and the given
one.
|
abstract Rectangle2D | createUnion(Rectangle2D r) - Return a new rectangle which is the union of this and the given one.
|
boolean | equals(Object obj) - Tests this rectangle for equality against the specified object.
|
Rectangle2D | getBounds2D() - Returns the bounds of this rectangle.
|
PathIterator | getPathIterator(AffineTransform at) - Return an iterator along the shape boundary.
|
PathIterator | getPathIterator(AffineTransform at, double flatness) - Return an iterator along the shape boundary.
|
int | hashCode() - Return the hashcode for this rectangle.
|
static void | intersect(Rectangle2D src1, Rectangle2D src2, Rectangle2D dest) - Intersects a pair of rectangles, and places the result in the
destination; this can be used to avoid object creation.
|
boolean | intersects(double x, double y, double w, double h) - Tests if the given rectangle intersects this one.
|
boolean | intersectsLine(double x1, double y1, double x2, double y2) - Tests if the specified line intersects the interior of this rectangle.
|
boolean | intersectsLine(Line2D l) - Tests if the specified line intersects the interior of this rectangle.
|
abstract int | outcode(double x, double y) - Determine where the point lies with respect to this rectangle.
|
int | outcode(Point2D p) - Determine where the point lies with respect to this rectangle.
|
void | setFrame(double x, double y, double w, double h) - Set the bounding box of this rectangle.
|
abstract void | setRect(double x, double y, double w, double h) - Set the bounding box of this rectangle.
|
void | setRect(Rectangle2D r) - Set the bounding box of this rectangle from the given one.
|
static void | union(Rectangle2D src1, Rectangle2D src2, Rectangle2D dest) - Joins a pair of rectangles, and places the result in the destination;
this can be used to avoid object creation.
|
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 |
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
OUT_BOTTOM
public static final int OUT_BOTTOM
The point lies below of the rectangle (p.y > r.maxY).
OUT_LEFT
public static final int OUT_LEFT
The point lies left of the rectangle (p.x < r.x).
OUT_RIGHT
public static final int OUT_RIGHT
The point lies right of the rectangle (p.x > r.maxX).
OUT_TOP
public static final int OUT_TOP
The point lies above the rectangle (p.y < r.y).
Rectangle2D
protected Rectangle2D()
Default constructor.
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.
newx
- the X coordinate of the point to add to this rectanglenewy
- the Y coordinate of the point to add to this rectangle
add
public void add(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.
p
- the point to add to this rectangle
add
public void add(Rectangle2D r)
Modifies this rectangle so that it represents the smallest rectangle
that contains both the existing rectangle and the specified rectangle.
r
- the rectangle to add to this rectangle
contains
public boolean contains(double x,
double y)
Test if the given point is contained in the rectangle.
- contains in interface Shape
x
- the x coordinate of the pointy
- the y coordinate of the point
- true if (x,y) is in the rectangle
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.
- contains in interface Shape
x
- the x coordinate of the other rectangley
- the y coordinate of the other rectanglew
- the width of the other rectangleh
- the height of the other rectangle
- true if this rectangle contains the other
createIntersection
public abstract Rectangle2D createIntersection(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.
r
- the rectangle to be intersected
createUnion
public abstract Rectangle2D createUnion(Rectangle2D r)
Return a new rectangle which is the union of this and the given one.
r
- the rectangle to be merged
equals
public boolean equals(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.
- equals in interface Object
obj
- the object to test against for equality
- true if the specified object is equal to this one
getPathIterator
public PathIterator getPathIterator(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.
- getPathIterator in interface Shape
at
- an optional transform to apply to the iterator
- a new iterator over the boundary
getPathIterator
public PathIterator getPathIterator(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.
- getPathIterator in interface Shape
- getPathIterator in interface RectangularShape
at
- an optional transform to apply to the iteratorflatness
- the maximum distance for deviation from the real boundary
- a new iterator over the boundary
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);
- hashCode in interface Object
intersect
public static void intersect(Rectangle2D src1,
Rectangle2D src2,
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.
src1
- the first sourcesrc2
- the second sourcedest
- the destination for the intersection
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.
- intersects in interface Shape
x
- the x coordinate of the other rectangley
- the y coordinate of the other rectanglew
- the width of the other rectangleh
- the height of the other rectangle
- true if the rectangles intersect
intersectsLine
public boolean intersectsLine(double x1,
double y1,
double x2,
double y2)
Tests if the specified line intersects the interior of this rectangle.
x1
- the first x coordinate of line segmenty1
- the first y coordinate of line segmentx2
- the second x coordinate of line segmenty2
- the second y coordinate of line segment
- true if the line intersects the rectangle
intersectsLine
public boolean intersectsLine(Line2D l)
Tests if the specified line intersects the interior of this rectangle.
- true if the line intersects the rectangle
outcode
public abstract 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.
x
- the x coordinate to checky
- the y coordinate to check
- the binary OR of the result
outcode
public int outcode(Point2D p)
Determine where the point lies with respect to this rectangle. The
result will be the binary OR of the appropriate bit masks.
- the binary OR of the result
setFrame
public void setFrame(double x,
double y,
double w,
double h)
Set the bounding box of this rectangle.
- setFrame in interface RectangularShape
x
- the new X coordinatey
- the new Y coordinatew
- the new widthh
- the new height
setRect
public abstract void setRect(double x,
double y,
double w,
double h)
Set the bounding box of this rectangle.
x
- the new X coordinatey
- the new Y coordinatew
- the new widthh
- the new height
setRect
public void setRect(Rectangle2D r)
Set the bounding box of this rectangle from the given one.
union
public static void union(Rectangle2D src1,
Rectangle2D src2,
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.
src1
- the first sourcesrc2
- the second sourcedest
- the destination for the union
Rectangle2D.java -- generic rectangles in 2-D space
Copyright (C) 2000, 2001, 2002, 2004 Free Software Foundation
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version.