java.awt.geom
Class Rectangle2D.Double

java.lang.Object
  extended by java.awt.geom.RectangularShape
      extended by java.awt.geom.Rectangle2D
          extended by java.awt.geom.Rectangle2D.Double
All Implemented Interfaces:
Shape, Cloneable
Enclosing class:
Rectangle2D

public static class Rectangle2D.Double
extends Rectangle2D

This class defines a rectangle in double precision.

Since:
1.2

Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.geom.Rectangle2D
Rectangle2D.Double, Rectangle2D.Float
 
Field Summary
 double height
          The height of the rectangle.
 double width
          The width of the rectangle.
 double x
          The x coordinate of the lower left corner.
 double y
          The y coordinate of the lower left corner.
 
Fields inherited from class java.awt.geom.Rectangle2D
OUT_BOTTOM, OUT_LEFT, OUT_RIGHT, OUT_TOP
 
Constructor Summary
Rectangle2D.Double()
          Create a rectangle at (0,0) with width 0 and height 0.
Rectangle2D.Double(double x, double y, double w, double h)
          Create a rectangle with the given values.
 
Method Summary
 Rectangle2D createIntersection(Rectangle2D r)
          Return a new rectangle which is the intersection of this and the given one.
 Rectangle2D createUnion(Rectangle2D r)
          Return a new rectangle which is the union of this and the given one.
 Rectangle2D getBounds2D()
          Returns the bounds of this rectangle.
 double getHeight()
          Return the height.
 double getWidth()
          Return the width.
 double getX()
          Return the X coordinate.
 double getY()
          Return the Y coordinate.
 boolean isEmpty()
          Test if the rectangle is empty.
 int outcode(double x, double y)
          Determine where the point lies with respect to this rectangle.
 void setRect(double x, double y, double w, double h)
          Set the contents of this rectangle to those specified.
 void setRect(Rectangle2D r)
          Set the contents of this rectangle to those specified.
 String toString()
          Returns a string representation of this rectangle.
 
Methods inherited from class java.awt.geom.Rectangle2D
add, add, add, contains, contains, equals, getPathIterator, getPathIterator, hashCode, intersect, intersects, intersectsLine, intersectsLine, outcode, setFrame, union
 
Methods inherited from class java.awt.geom.RectangularShape
clone, contains, contains, getBounds, getCenterX, getCenterY, getFrame, getMaxX, getMaxY, getMinX, getMinY, intersects, setFrame, setFrame, setFrameFromCenter, setFrameFromCenter, setFrameFromDiagonal, setFrameFromDiagonal
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

x

public double x
The x coordinate of the lower left corner.


y

public double y
The y coordinate of the lower left corner.


width

public double width
The width of the rectangle.


height

public double height
The height of the rectangle.

Constructor Detail

Rectangle2D.Double

public Rectangle2D.Double()
Create a rectangle at (0,0) with width 0 and height 0.


Rectangle2D.Double

public Rectangle2D.Double(double x,
                          double y,
                          double w,
                          double h)
Create a rectangle with the given values.

Parameters:
x - the x coordinate
y - the y coordinate
w - the width
h - the height
Method Detail

getX

public double getX()
Return the X coordinate.

Specified by:
getX in class RectangularShape
Returns:
the value of x

getY

public double getY()
Return the Y coordinate.

Specified by:
getY in class RectangularShape
Returns:
the value of y

getWidth

public double getWidth()
Return the width.

Specified by:
getWidth in class RectangularShape
Returns:
the value of width

getHeight

public double getHeight()
Return the height.

Specified by:
getHeight in class RectangularShape
Returns:
the value of height

isEmpty

public boolean isEmpty()
Test if the rectangle is empty.

Specified by:
isEmpty in class RectangularShape
Returns:
true if width or height is not positive

setRect

public void setRect(double x,
                    double y,
                    double w,
                    double h)
Set the contents of this rectangle to those specified.

Specified by:
setRect in class Rectangle2D
Parameters:
x - the x coordinate
y - the y coordinate
w - the width
h - the height

setRect

public void setRect(Rectangle2D r)
Set the contents of this rectangle to those specified.

Overrides:
setRect in class Rectangle2D
Parameters:
r - the rectangle to copy
Throws:
NullPointerException - if r is null

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.

Specified by:
outcode in class Rectangle2D
Parameters:
x - the x coordinate to check
y - the y coordinate to check
Returns:
the binary OR of the result
Since:
1.2
See Also:
Rectangle2D.OUT_LEFT, Rectangle2D.OUT_TOP, Rectangle2D.OUT_RIGHT, Rectangle2D.OUT_BOTTOM

getBounds2D

public Rectangle2D getBounds2D()
Returns the bounds of this rectangle. A pretty useless method, as this is already a rectangle.

Specified by:
getBounds2D in interface Shape
Overrides:
getBounds2D in class Rectangle2D
Returns:
a copy of this rectangle
See Also:
Shape.getBounds()

createIntersection

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

Specified by:
createIntersection in class Rectangle2D
Parameters:
r - the rectangle to be intersected
Returns:
the intersection
Throws:
NullPointerException - if r is null

createUnion

public Rectangle2D createUnion(Rectangle2D r)
Return a new rectangle which is the union of this and the given one.

Specified by:
createUnion in class Rectangle2D
Parameters:
r - the rectangle to be merged
Returns:
the union
Throws:
NullPointerException - if r is null

toString

public String toString()
Returns a string representation of this rectangle. This is in the form getClass().getName() + "[x=" + x + ",y=" + y + ",w=" + width + ",h=" + height + ']'.

Overrides:
toString in class Object
Returns:
a string representation of this rectangle
See Also:
Object.getClass(), Object.hashCode(), Class.getName(), Integer.toHexString(int)