Class RectangularShape
- Direct Known Subclasses:
-
Arc2D,Ellipse2D,Rectangle2D,RoundRectangle2D
public abstract class RectangularShape extends Object implements Shape, Cloneable
RectangularShape is the base class for a number of Shape objects whose geometry is defined by a rectangular frame. This class does not directly specify any specific geometry by itself, but merely provides manipulation methods inherited by a whole category of Shape objects. The manipulation methods provided by this class can be used to query and modify the rectangular frame, which provides a reference for the subclasses to define their geometry.- Since:
- 1.2
Constructor Summary
| Modifier | Constructor | Description |
|---|---|---|
protected |
This is an abstract class that cannot be instantiated directly. |
Method Summary
| Modifier and Type | Method | Description |
|---|---|---|
Object |
clone() |
Creates a new object of the same class and with the same contents as this object. |
boolean |
contains |
Tests if a specified Point2D is inside the boundary of the Shape, as described by the definition of insideness. |
boolean |
contains |
Tests if the interior of the Shape entirely contains the specified Rectangle2D. |
Rectangle |
getBounds() |
Returns an integer Rectangle that completely encloses the Shape. |
double |
getCenterX() |
Returns the X coordinate of the center of the framing rectangle of the Shape in double precision. |
double |
getCenterY() |
Returns the Y coordinate of the center of the framing rectangle of the Shape in double precision. |
Rectangle2D |
getFrame() |
Returns the framing Rectangle2D that defines the overall shape of this object. |
abstract double |
getHeight() |
Returns the height of the framing rectangle in double precision. |
double |
getMaxX() |
Returns the largest X coordinate of the framing rectangle of the Shape in double precision. |
double |
getMaxY() |
Returns the largest Y coordinate of the framing rectangle of the Shape in double precision. |
double |
getMinX() |
Returns the smallest X coordinate of the framing rectangle of the Shape in double precision. |
double |
getMinY() |
Returns the smallest Y coordinate of the framing rectangle of the Shape in double precision. |
PathIterator |
getPathIterator |
Returns an iterator object that iterates along the Shape object's boundary and provides access to a flattened view of the outline of the Shape object's geometry. |
abstract double |
getWidth() |
Returns the width of the framing rectangle in double precision. |
abstract double |
getX() |
Returns the X coordinate of the upper-left corner of the framing rectangle in double precision. |
abstract double |
getY() |
Returns the Y coordinate of the upper-left corner of the framing rectangle in double precision. |
boolean |
intersects |
Tests if the interior of the Shape intersects the interior of a specified Rectangle2D. |
abstract boolean |
isEmpty() |
Determines whether the RectangularShape is empty. |
abstract void |
setFrame |
Sets the location and size of the framing rectangle of this Shape to the specified rectangular values. |
void |
setFrame |
Sets the location and size of the framing rectangle of this Shape to the specified Point2D and Dimension2D, respectively. |
void |
setFrame |
Sets the framing rectangle of this Shape to be the specified Rectangle2D. |
void |
setFrameFromCenter |
Sets the framing rectangle of this Shape based on the specified center point coordinates and corner point coordinates. |
void |
setFrameFromCenter |
Sets the framing rectangle of this Shape based on a specified center Point2D and corner Point2D. |
void |
setFrameFromDiagonal |
Sets the diagonal of the framing rectangle of this Shape based on the two specified coordinates. |
void |
setFrameFromDiagonal |
Sets the diagonal of the framing rectangle of this Shape based on two specified Point2D objects. |
Methods declared in class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods declared in interface java.awt.Shape
contains, contains, getBounds2D, getPathIterator, intersects
Constructor Details
RectangularShape
protected RectangularShape()
- Since:
- 1.2
- See Also:
Method Details
getX
public abstract double getX()
double precision.- Returns:
- the X coordinate of the upper-left corner of the framing rectangle.
- Since:
- 1.2
getY
public abstract double getY()
double precision.- Returns:
- the Y coordinate of the upper-left corner of the framing rectangle.
- Since:
- 1.2
getWidth
public abstract double getWidth()
double precision.- Returns:
- the width of the framing rectangle.
- Since:
- 1.2
getHeight
public abstract double getHeight()
double precision.- Returns:
- the height of the framing rectangle.
- Since:
- 1.2
getMinX
public double getMinX()
Shape in double precision.- Returns:
- the smallest X coordinate of the framing rectangle of the
Shape. - Since:
- 1.2
getMinY
public double getMinY()
Shape in double precision.- Returns:
- the smallest Y coordinate of the framing rectangle of the
Shape. - Since:
- 1.2
getMaxX
public double getMaxX()
Shape in double precision.- Returns:
- the largest X coordinate of the framing rectangle of the
Shape. - Since:
- 1.2
getMaxY
public double getMaxY()
Shape in double precision.- Returns:
- the largest Y coordinate of the framing rectangle of the
Shape. - Since:
- 1.2
getCenterX
public double getCenterX()
Shape in double precision.- Returns:
- the X coordinate of the center of the framing rectangle of the
Shape. - Since:
- 1.2
getCenterY
public double getCenterY()
Shape in double precision.- Returns:
- the Y coordinate of the center of the framing rectangle of the
Shape. - Since:
- 1.2
getFrame
public Rectangle2D getFrame()
Rectangle2D that defines the overall shape of this object.- Returns:
- a
Rectangle2D, specified indoublecoordinates. - Since:
- 1.2
- See Also:
isEmpty
public abstract boolean isEmpty()
RectangularShape is empty. When the RectangularShape is empty, it encloses no area.- Returns:
-
trueif theRectangularShapeis empty;falseotherwise. - Since:
- 1.2
setFrame
public abstract void setFrame(double x, double y, double w, double h)
Shape to the specified rectangular values.- Parameters:
-
x- the X coordinate of the upper-left corner of the specified rectangular shape -
y- the Y coordinate of the upper-left corner of the specified rectangular shape -
w- the width of the specified rectangular shape -
h- the height of the specified rectangular shape - Since:
- 1.2
- See Also:
setFrame
public void setFrame(Point2D loc, Dimension2D size)
Shape to the specified Point2D and Dimension2D, respectively. The framing rectangle is used by the subclasses of RectangularShape to define their geometry.- Parameters:
-
loc- the specifiedPoint2D -
size- the specifiedDimension2D - Since:
- 1.2
- See Also:
setFrame
public void setFrame(Rectangle2D r)
Shape to be the specified Rectangle2D. The framing rectangle is used by the subclasses of RectangularShape to define their geometry.- Parameters:
-
r- the specifiedRectangle2D - Since:
- 1.2
- See Also:
setFrameFromDiagonal
public void setFrameFromDiagonal(double x1, double y1, double x2, double y2)
Shape based on the two specified coordinates. The framing rectangle is used by the subclasses of RectangularShape to define their geometry.- Parameters:
-
x1- the X coordinate of the start point of the specified diagonal -
y1- the Y coordinate of the start point of the specified diagonal -
x2- the X coordinate of the end point of the specified diagonal -
y2- the Y coordinate of the end point of the specified diagonal - Since:
- 1.2
setFrameFromDiagonal
public void setFrameFromDiagonal(Point2D p1, Point2D p2)
Shape based on two specified Point2D objects. The framing rectangle is used by the subclasses of RectangularShape to define their geometry.- Parameters:
-
p1- the startPoint2Dof the specified diagonal -
p2- the endPoint2Dof the specified diagonal - Since:
- 1.2
setFrameFromCenter
public void setFrameFromCenter(double centerX, double centerY, double cornerX, double cornerY)
Shape based on the specified center point coordinates and corner point coordinates. The framing rectangle is used by the subclasses of RectangularShape to define their geometry.- Parameters:
-
centerX- the X coordinate of the specified center point -
centerY- the Y coordinate of the specified center point -
cornerX- the X coordinate of the specified corner point -
cornerY- the Y coordinate of the specified corner point - Since:
- 1.2
setFrameFromCenter
public void setFrameFromCenter(Point2D center, Point2D corner)
Shape based on a specified center Point2D and corner Point2D. The framing rectangle is used by the subclasses of RectangularShape to define their geometry.- Parameters:
-
center- the specified centerPoint2D -
corner- the specified cornerPoint2D - Since:
- 1.2
contains
public boolean contains(Point2D p)
Point2D is inside the boundary of the Shape, as described by the definition of insideness.intersects
public boolean intersects(Rectangle2D r)
Shape intersects the interior of a specified Rectangle2D. The Shape.intersects() method allows a Shape implementation to conservatively return true when: - there is a high probability that the
Rectangle2Dand theShapeintersect, but - the calculations to accurately determine this intersection are prohibitively expensive.
Shapes this method might return true even though the Rectangle2D does not intersect the Shape. The Area class performs more accurate computations of geometric intersection than most Shape objects and therefore can be used if a more precise answer is required.- Specified by:
-
intersectsin interfaceShape - Parameters:
-
r- the specifiedRectangle2D - Returns:
-
trueif the interior of theShapeand the interior of the specifiedRectangle2Dintersect, or are both highly likely to intersect and intersection calculations would be too expensive to perform;falseotherwise. - Since:
- 1.2
- See Also:
contains
public boolean contains(Rectangle2D r)
Shape entirely contains the specified Rectangle2D. The Shape.contains() method allows a Shape implementation to conservatively return false when: - the
intersectmethod returnstrueand - the calculations to determine whether or not the
Shapeentirely contains theRectangle2Dare prohibitively expensive.
Shapes this method might return false even though the Shape contains the Rectangle2D. The Area class performs more accurate geometric computations than most Shape objects and therefore can be used if a more precise answer is required.- Specified by:
-
containsin interfaceShape - Parameters:
-
r- The specifiedRectangle2D - Returns:
-
trueif the interior of theShapeentirely contains theRectangle2D;falseotherwise or, if theShapecontains theRectangle2Dand theintersectsmethod returnstrueand the containment calculations would be too expensive to perform. - Since:
- 1.2
- See Also:
getBounds
public Rectangle getBounds()
Rectangle that completely encloses the Shape. Note that there is no guarantee that the returned Rectangle is the smallest bounding box that encloses the Shape, only that the Shape lies entirely within the indicated Rectangle. The returned Rectangle might also fail to completely enclose the Shape if the Shape overflows the limited range of the integer data type. The getBounds2D method generally returns a tighter bounding box due to its greater flexibility in representation. Note that the definition of insideness can lead to situations where points on the defining outline of the shape may not be considered contained in the returned bounds object, but only in cases where those points are also not considered contained in the original shape.
If a point is inside the shape according to the contains(point) method, then it must be inside the returned Rectangle bounds object according to the contains(point) method of the bounds. Specifically:
shape.contains(x,y) requires bounds.contains(x,y)
If a point is not inside the shape, then it might still be contained in the bounds object:
bounds.contains(x,y) does not imply shape.contains(x,y)
getPathIterator
public PathIterator getPathIterator(AffineTransform at, double flatness)
Shape object's boundary and provides access to a flattened view of the outline of the Shape object's geometry. Only SEG_MOVETO, SEG_LINETO, and SEG_CLOSE point types will be returned by the iterator.
The amount of subdivision of the curved segments is controlled by the flatness parameter, which specifies the maximum distance that any point on the unflattened transformed curve can deviate from the returned flattened path segments. An optional AffineTransform can be specified so that the coordinates returned in the iteration are transformed accordingly.
- Specified by:
-
getPathIteratorin interfaceShape - Parameters:
-
at- an optionalAffineTransformto be applied to the coordinates as they are returned in the iteration, ornullif 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 - Returns:
- a
PathIteratorobject that provides access to theShapeobject's flattened geometry. - Since:
- 1.2
clone
public Object clone()
- Overrides:
-
clonein classObject - Returns:
- a clone of this instance.
- Throws:
-
OutOfMemoryError- if there is not enough memory. - Since:
- 1.2
- See Also:
© 1993, 2021, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/17/docs/api/java.desktop/java/awt/geom/RectangularShape.html