- java.lang.Object
- 
- java.awt.geom.RectangularShape
- 
- java.awt.geom.Rectangle2D
 
 
- 
- Direct Known Subclasses:
- Rectangle,- Rectangle2D.Double,- Rectangle2D.Float
 
 public abstract class Rectangle2D extends RectangularShape TheRectangle2Dclass describes a rectangle defined by a location(x,y)and dimension(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. - Since:
- 1.2
 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classRectangle2D.DoubleTheDoubleclass defines a rectangle specified in double coordinates.static classRectangle2D.FloatTheFloatclass defines a rectangle specified in float coordinates.
 - 
Field SummaryFields Modifier and Type Field Description static intOUT_BOTTOMThe bitmask that indicates that a point lies below thisRectangle2D.static intOUT_LEFTThe bitmask that indicates that a point lies to the left of thisRectangle2D.static intOUT_RIGHTThe bitmask that indicates that a point lies to the right of thisRectangle2D.static intOUT_TOPThe bitmask that indicates that a point lies above thisRectangle2D.
 - 
Constructor SummaryConstructors Modifier Constructor Description protectedRectangle2D()This is an abstract class that cannot be instantiated directly.
 - 
Method SummaryAll Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidadd(double newx, double newy)Adds a point, specified by the double precision argumentsnewxandnewy, to thisRectangle2D.voidadd(Point2D pt)Adds thePoint2Dobjectptto thisRectangle2D.voidadd(Rectangle2D r)Adds aRectangle2Dobject to thisRectangle2D.booleancontains(double x, double y)Tests if the specified coordinates are inside the boundary of theShape, as described by the definition of insideness.booleancontains(double x, double y, double w, double h)Tests if the interior of theShapeentirely contains the specified rectangular area.abstract Rectangle2DcreateIntersection(Rectangle2D r)Returns a newRectangle2Dobject representing the intersection of thisRectangle2Dwith the specifiedRectangle2D.abstract Rectangle2DcreateUnion(Rectangle2D r)Returns a newRectangle2Dobject representing the union of thisRectangle2Dwith the specifiedRectangle2D.booleanequals(Object obj)Determines whether or not the specifiedObjectis equal to thisRectangle2D.Rectangle2DgetBounds2D()Returns a high precision and more accurate bounding box of theShapethan thegetBoundsmethod.PathIteratorgetPathIterator(AffineTransform at)Returns an iteration object that defines the boundary of thisRectangle2D.PathIteratorgetPathIterator(AffineTransform at, double flatness)Returns an iteration object that defines the boundary of the flattenedRectangle2D.inthashCode()Returns the hashcode for thisRectangle2D.static voidintersect(Rectangle2D src1, Rectangle2D src2, Rectangle2D dest)Intersects the pair of specified sourceRectangle2Dobjects and puts the result into the specified destinationRectangle2Dobject.booleanintersects(double x, double y, double w, double h)Tests if the interior of theShapeintersects the interior of a specified rectangular area.booleanintersectsLine(double x1, double y1, double x2, double y2)Tests if the specified line segment intersects the interior of thisRectangle2D.booleanintersectsLine(Line2D l)Tests if the specified line segment intersects the interior of thisRectangle2D.abstract intoutcode(double x, double y)Determines where the specified coordinates lie with respect to thisRectangle2D.intoutcode(Point2D p)Determines where the specifiedPoint2Dlies with respect to thisRectangle2D.voidsetFrame(double x, double y, double w, double h)Sets the location and size of the outer bounds of thisRectangle2Dto the specified rectangular values.abstract voidsetRect(double x, double y, double w, double h)Sets the location and size of thisRectangle2Dto the specifieddoublevalues.voidsetRect(Rectangle2D r)Sets thisRectangle2Dto be the same as the specifiedRectangle2D.static voidunion(Rectangle2D src1, Rectangle2D src2, Rectangle2D dest)Unions the pair of sourceRectangle2Dobjects and puts the result into the specified destinationRectangle2Dobject.- 
Methods declared in class java.awt.geom.RectangularShapeclone, contains, contains, getBounds, getCenterX, getCenterY, getFrame, getHeight, getMaxX, getMaxY, getMinX, getMinY, getWidth, getX, getY, intersects, isEmpty, setFrame, setFrame, setFrameFromCenter, setFrameFromCenter, setFrameFromDiagonal, setFrameFromDiagonal
 
- 
 
- 
- 
- 
Field Detail- 
OUT_LEFTpublic static final int OUT_LEFT The bitmask that indicates that a point lies to the left of thisRectangle2D.- Since:
- 1.2
- See Also:
- Constant Field Values
 
 - 
OUT_TOPpublic static final int OUT_TOP The bitmask that indicates that a point lies above thisRectangle2D.- Since:
- 1.2
- See Also:
- Constant Field Values
 
 - 
OUT_RIGHTpublic static final int OUT_RIGHT The bitmask that indicates that a point lies to the right of thisRectangle2D.- Since:
- 1.2
- See Also:
- Constant Field Values
 
 - 
OUT_BOTTOMpublic static final int OUT_BOTTOM The bitmask that indicates that a point lies below thisRectangle2D.- Since:
- 1.2
- See Also:
- Constant Field Values
 
 
- 
 - 
Constructor Detail- 
Rectangle2Dprotected 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.- Since:
- 1.2
- See Also:
- Rectangle2D.Float,- Rectangle2D.Double,- Rectangle
 
 
- 
 - 
Method Detail- 
setRectpublic abstract void setRect(double x, double y, double w, double h)Sets the location and size of thisRectangle2Dto the specifieddoublevalues.- 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
- Since:
- 1.2
 
 - 
setRectpublic void setRect(Rectangle2D r) Sets thisRectangle2Dto be the same as the specifiedRectangle2D.- Parameters:
- r- the specified- Rectangle2D
- Since:
- 1.2
 
 - 
intersectsLinepublic boolean intersectsLine(double x1, double y1, double x2, double y2)Tests if the specified line segment intersects the interior of thisRectangle2D.- 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:
- trueif the specified line segment intersects the interior of this- Rectangle2D;- falseotherwise.
- Since:
- 1.2
 
 - 
intersectsLinepublic boolean intersectsLine(Line2D l) Tests if the specified line segment intersects the interior of thisRectangle2D.- Parameters:
- l- the specified- Line2Dto test for intersection with the interior of this- Rectangle2D
- Returns:
- trueif the specified- Line2Dintersects the interior of this- Rectangle2D;- falseotherwise.
- Since:
- 1.2
 
 - 
outcodepublic abstract int outcode(double x, double y)Determines where the specified coordinates lie with respect to thisRectangle2D. This method computes a binary OR of the appropriate mask values indicating, for each side of thisRectangle2D, whether or not the specified coordinates are on the same side of the edge as the rest of thisRectangle2D.- Parameters:
- x- the specified X coordinate
- y- the specified Y coordinate
- Returns:
- the logical OR of all appropriate out codes.
- Since:
- 1.2
- See Also:
- OUT_LEFT,- OUT_TOP,- OUT_RIGHT,- OUT_BOTTOM
 
 - 
outcodepublic int outcode(Point2D p) Determines where the specifiedPoint2Dlies with respect to thisRectangle2D. This method computes a binary OR of the appropriate mask values indicating, for each side of thisRectangle2D, whether or not the specifiedPoint2Dis on the same side of the edge as the rest of thisRectangle2D.- Parameters:
- p- the specified- Point2D
- Returns:
- the logical OR of all appropriate out codes.
- Since:
- 1.2
- See Also:
- OUT_LEFT,- OUT_TOP,- OUT_RIGHT,- OUT_BOTTOM
 
 - 
setFramepublic void setFrame(double x, double y, double w, double h)Sets the location and size of the outer bounds of thisRectangle2Dto the specified rectangular values.- Specified by:
- setFramein 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
- Since:
- 1.2
- See Also:
- RectangularShape.getFrame()
 
 - 
getBounds2Dpublic Rectangle2D getBounds2D() Returns a high precision and more accurate bounding box of theShapethan thegetBoundsmethod. Note that there is no guarantee that the returnedRectangle2Dis the smallest bounding box that encloses theShape, only that theShapelies entirely within the indicatedRectangle2D. The bounding box returned by this method is usually tighter than that returned by thegetBoundsmethod and never fails due to overflow problems since the return value can be an instance of theRectangle2Dthat uses double precision values to store the dimensions.Note that the definition of insideness can lead to situations where points on the defining outline of the shapemay not be considered contained in the returnedboundsobject, but only in cases where those points are also not considered contained in the originalshape.If a pointis inside theshapeaccording to thecontains(point)method, then it must be inside the returnedRectangle2Dbounds object according to thecontains(point)method of thebounds. Specifically:shape.contains(p)requiresbounds.contains(p)If a pointis not inside theshape, then it might still be contained in theboundsobject:bounds.contains(p)does not implyshape.contains(p)- Returns:
- an instance of Rectangle2Dthat is a high-precision bounding box of theShape.
- Since:
- 1.2
- See Also:
- Shape.getBounds()
 
 - 
containspublic boolean contains(double x, double y)Tests if the specified coordinates are inside the boundary of theShape, as described by the definition of insideness.- Parameters:
- x- the specified X coordinate to be tested
- y- the specified Y coordinate to be tested
- Returns:
- trueif the specified coordinates are inside the- Shapeboundary;- falseotherwise.
- Since:
- 1.2
 
 - 
intersectspublic boolean intersects(double x, double y, double w, double h)Tests if the interior of theShapeintersects the interior of a specified rectangular area. The rectangular area is considered to intersect theShapeif any point is contained in both the interior of theShapeand the specified rectangular area.The Shape.intersects()method allows aShapeimplementation to conservatively returntruewhen:- 
 there is a high probability that the rectangular area and the
 Shapeintersect, but
- the calculations to accurately determine this intersection are prohibitively expensive.
 Shapesthis method might returntrueeven though the rectangular area does not intersect theShape. TheAreaclass performs more accurate computations of geometric intersection than mostShapeobjects and therefore can be used if a more precise answer is required.- Parameters:
- x- the X coordinate of the upper-left corner of the specified rectangular area
- y- the Y coordinate of the upper-left corner of the specified rectangular area
- w- the width of the specified rectangular area
- h- the height of the specified rectangular area
- Returns:
- trueif the interior of the- Shapeand the interior of the rectangular area intersect, or are both highly likely to intersect and intersection calculations would be too expensive to perform;- falseotherwise.
- Since:
- 1.2
- See Also:
- Area
 
- 
 there is a high probability that the rectangular area and the
 
 - 
containspublic boolean contains(double x, double y, double w, double h)Tests if the interior of theShapeentirely contains the specified rectangular area. All coordinates that lie inside the rectangular area must lie within theShapefor the entire rectangular area to be considered contained within theShape.The Shape.contains()method allows aShapeimplementation to conservatively returnfalsewhen:- 
 the intersectmethod returnstrueand
- 
 the calculations to determine whether or not the
 Shapeentirely contains the rectangular area are prohibitively expensive.
 Shapesthis method might returnfalseeven though theShapecontains the rectangular area. TheAreaclass performs more accurate geometric computations than mostShapeobjects and therefore can be used if a more precise answer is required.- Parameters:
- x- the X coordinate of the upper-left corner of the specified rectangular area
- y- the Y coordinate of the upper-left corner of the specified rectangular area
- w- the width of the specified rectangular area
- h- the height of the specified rectangular area
- Returns:
- trueif the interior of the- Shapeentirely contains the specified rectangular area;- falseotherwise or, if the- Shapecontains the rectangular area and the- intersectsmethod returns- trueand the containment calculations would be too expensive to perform.
- Since:
- 1.2
- See Also:
- Area,- Shape.intersects(double, double, double, double)
 
- 
 the 
 - 
createIntersectionpublic abstract Rectangle2D createIntersection(Rectangle2D r) Returns a newRectangle2Dobject representing the intersection of thisRectangle2Dwith the specifiedRectangle2D.- Parameters:
- r- the- Rectangle2Dto be intersected with this- Rectangle2D
- Returns:
- the largest Rectangle2Dcontained in both the specifiedRectangle2Dand in thisRectangle2D.
- Since:
- 1.2
 
 - 
intersectpublic static void intersect(Rectangle2D src1, Rectangle2D src2, Rectangle2D dest) Intersects the pair of specified sourceRectangle2Dobjects and puts the result into the specified destinationRectangle2Dobject. 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- Rectangle2Dobjects to be intersected with each other
- src2- the second of a pair of- Rectangle2Dobjects to be intersected with each other
- dest- the- Rectangle2Dthat holds the results of the intersection of- src1and- src2
- Since:
- 1.2
 
 - 
createUnionpublic abstract Rectangle2D createUnion(Rectangle2D r) Returns a newRectangle2Dobject representing the union of thisRectangle2Dwith the specifiedRectangle2D.- Parameters:
- r- the- Rectangle2Dto be combined with this- Rectangle2D
- Returns:
- the smallest Rectangle2Dcontaining both the specifiedRectangle2Dand thisRectangle2D.
- Since:
- 1.2
 
 - 
unionpublic static void union(Rectangle2D src1, Rectangle2D src2, Rectangle2D dest) Unions the pair of sourceRectangle2Dobjects and puts the result into the specified destinationRectangle2Dobject. 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- Rectangle2Dobjects to be combined with each other
- src2- the second of a pair of- Rectangle2Dobjects to be combined with each other
- dest- the- Rectangle2Dthat holds the results of the union of- src1and- src2
- Since:
- 1.2
 
 - 
addpublic void add(double newx, double newy)Adds a point, specified by the double precision argumentsnewxandnewy, to thisRectangle2D. The resultingRectangle2Dis the smallestRectangle2Dthat contains both the originalRectangle2Dand the specified point.After adding a point, a call to containswith the added point as an argument does not necessarily returntrue. Thecontainsmethod does not returntruefor 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,containsreturnsfalsefor that point.- Parameters:
- newx- the X coordinate of the new point
- newy- the Y coordinate of the new point
- Since:
- 1.2
 
 - 
addpublic void add(Point2D pt) Adds thePoint2Dobjectptto thisRectangle2D. The resultingRectangle2Dis the smallestRectangle2Dthat contains both the originalRectangle2Dand the specifiedPoint2D.After adding a point, a call to containswith the added point as an argument does not necessarily returntrue. Thecontainsmethod does not returntruefor 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,containsreturnsfalsefor that point.- Parameters:
- pt- the new- Point2Dto add to this- Rectangle2D.
- Since:
- 1.2
 
 - 
addpublic void add(Rectangle2D r) Adds aRectangle2Dobject to thisRectangle2D. The resultingRectangle2Dis the union of the twoRectangle2Dobjects.- Parameters:
- r- the- Rectangle2Dto add to this- Rectangle2D.
- Since:
- 1.2
 
 - 
getPathIteratorpublic PathIterator getPathIterator(AffineTransform at) Returns an iteration object that defines the boundary of thisRectangle2D. The iterator for this class is multi-threaded safe, which means that thisRectangle2Dclass guarantees that modifications to the geometry of thisRectangle2Dobject do not affect any iterations of that geometry that are already in process.- Parameters:
- at- an optional- AffineTransformto be applied to the coordinates as they are returned in the iteration, or- nullif untransformed coordinates are desired
- Returns:
- the PathIteratorobject that returns the geometry of the outline of thisRectangle2D, one segment at a time.
- Since:
- 1.2
 
 - 
getPathIteratorpublic PathIterator getPathIterator(AffineTransform at, double flatness) Returns an iteration object that defines the boundary of the flattenedRectangle2D. Since rectangles are already flat, theflatnessparameter is ignored. The iterator for this class is multi-threaded safe, which means that thisRectangle2Dclass guarantees that modifications to the geometry of thisRectangle2Dobject do not affect any iterations of that geometry that are already in process.- Specified by:
- getPathIteratorin interface- Shape
- Overrides:
- getPathIteratorin class- RectangularShape
- Parameters:
- at- an optional- AffineTransformto be applied to the coordinates as they are returned in the iteration, or- nullif 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- flatnessparameter is ignored.
- Returns:
- the PathIteratorobject that returns the geometry of the outline of thisRectangle2D, one segment at a time.
- Since:
- 1.2
 
 - 
hashCodepublic int hashCode() Returns the hashcode for thisRectangle2D.- Overrides:
- hashCodein class- Object
- Returns:
- the hashcode for this Rectangle2D.
- Since:
- 1.2
- See Also:
- Object.equals(java.lang.Object),- System.identityHashCode(java.lang.Object)
 
 - 
equalspublic boolean equals(Object obj) Determines whether or not the specifiedObjectis equal to thisRectangle2D. The specifiedObjectis equal to thisRectangle2Dif it is an instance ofRectangle2Dand if its location and size are the same as thisRectangle2D.- Overrides:
- equalsin class- Object
- Parameters:
- obj- an- Objectto be compared with this- Rectangle2D.
- Returns:
- trueif- objis an instance of- Rectangle2Dand has the same values;- falseotherwise.
- Since:
- 1.2
- See Also:
- Object.hashCode(),- HashMap
 
 
- 
 
-