Class: java.awt.geom.Area
Area object stores and manipulates a
resolution-independent description of an enclosed area of
2-dimensional space.
Area objects can be transformed and can perform
various Constructive Area Geometry (CAG) operations when combined
with other Area objects.
The CAG operations include area
addition, subtraction,
intersection, and exclusive or.
See the linked method documentation for examples of the various
operations.
The Area class implements the Shape
interface and provides full support for all of its hit-testing
and path iteration facilities, but an Area is more
specific than a generalized path in a number of ways:
- Only closed paths and sub-paths are stored.
Areaobjects constructed from unclosed paths are implicitly closed during construction as if those paths had been filled by theGraphics2D.fillmethod. - The interiors of the individual stored sub-paths are all non-empty and non-overlapping. Paths are decomposed during construction into separate component non-overlapping parts, empty pieces of the path are discarded, and then these non-empty and non-overlapping properties are maintained through all subsequent CAG operations. Outlines of different component sub-paths may touch each other, as long as they do not cross so that their enclosed areas overlap.
- The geometry of the path describing the outline of the
Arearesembles the path from which it was constructed only in that it describes the same enclosed 2-dimensional area, but may use entirely different types and ordering of the path segments to do so.
Area include:
- Creating an
Areafrom an unclosed (open)Shaperesults in a closed outline in theAreaobject. - Creating an
Areafrom aShapewhich encloses no area (even when "closed") produces an emptyArea. A common example of this issue is that producing anAreafrom a line will be empty since the line encloses no area. An emptyAreawill iterate no geometry in itsPathIteratorobjects. - A self-intersecting
Shapemay be split into two (or more) sub-paths each enclosing one of the non-intersecting portions of the original path. - An
Areamay take more path segments to describe the same geometry even when the original outline is simple and obvious. The analysis that theAreaclass must perform on the path may not reflect the same concepts of "simple and obvious" as a human being perceives.
Methods
-
Areatop
public Area()Default constructor which creates an empty area. -
Areatop
public Area(Shape s)TheAreaclass creates an area geometry from the specified java.awt.Shape object. The geometry is explicitly closed, if theShapeis not already closed. The fill rule (even-odd or winding) specified by the geometry of theShapeis used to determine the resulting enclosed area. -
addtop
public void add(Area rhs)Adds the shape of the specifiedAreato the shape of thisArea. The resulting shape of thisAreawill include the union of both shapes, or all areas that were contained in either this or the specifiedArea.// Example: Area a1 = new Area([triangle 0,0 => 8,0 => 0,8]); Area a2 = new Area([triangle 0,0 => 8,0 => 8,8]); a1.add(a2); a1(before) + a2 = a1(after) ################ ################ ################ ############## ############## ################ ############ ############ ################ ########## ########## ################ ######## ######## ################ ###### ###### ###### ###### #### #### #### #### ## ## ## ## -
clonetop
public Object clone()Returns an exact copy of thisAreaobject. -
containstop
public boolean contains(double x, double y)Tests if the specified coordinates are inside the boundary of theShape. -
containstop
public 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 rectanglar area to be considered contained within theShape.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 the rectangular area are prohibitively expensive.
-
the
-
containstop
public boolean contains(Point2D p)Tests if a specified java.awt.geom.Point2D is inside the boundary of theShape. -
containstop
public boolean contains(Rectangle2D r)Tests if the interior of theShapeentirely contains the specifiedRectangle2D. 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.
-
the
-
createTransformedAreatop
public Area createTransformedArea(AffineTransform t)Creates a newAreaobject that contains the same geometry as thisAreatransformed by the specifiedAffineTransform. ThisAreaobject is unchanged. -
equalstop
public boolean equals(Area other)Tests whether the geometries of the twoAreaobjects are equal. This method will return false if the argument is null. -
exclusiveOrtop
public void exclusiveOr(Area rhs)Sets the shape of thisAreato be the combined area of its current shape and the shape of the specifiedArea, minus their intersection. The resulting shape of thisAreawill include only areas that were contained in either thisAreaor in the specifiedArea, but not in both.// Example: Area a1 = new Area([triangle 0,0 => 8,0 => 0,8]); Area a2 = new Area([triangle 0,0 => 8,0 => 8,8]); a1.exclusiveOr(a2); a1(before) xor a2 = a1(after) ################ ################ ############## ############## ## ## ############ ############ #### #### ########## ########## ###### ###### ######## ######## ################ ###### ###### ###### ###### #### #### #### #### ## ## ## ## -
getBoundstop
public Rectangle getBounds()Returns a bounding java.awt.Rectangle that completely encloses thisArea.The Area class will attempt to return the tightest bounding box possible for the Shape. The bounding box will not be padded to include the control points of curves in the outline of the Shape, but should tightly fit the actual geometry of the outline itself. Since the returned object represents the bounding box with integers, the bounding box can only be as tight as the nearest integer coordinates that encompass the geometry of the Shape.
-
getBounds2Dtop
public Rectangle2D getBounds2D()Returns a high precision bounding java.awt.geom.Rectangle2D that completely encloses thisArea.The Area class will attempt to return the tightest bounding box possible for the Shape. The bounding box will not be padded to include the control points of curves in the outline of the Shape, but should tightly fit the actual geometry of the outline itself.
- Specified by:
- getBounds2D from Shape
-
getCachedBoundstop
private Rectangle2D getCachedBounds() -
getPathIteratortop
public PathIterator getPathIterator(AffineTransform at)Creates a java.awt.geom.PathIterator for the outline of thisAreaobject. ThisAreaobject is unchanged.- Specified by:
- getPathIterator from Shape
-
getPathIteratortop
public PathIterator getPathIterator(AffineTransform at, double flatness)Creates aPathIteratorfor the flattened outline of thisAreaobject. Only uncurved path segments represented by the SEG_MOVETO, SEG_LINETO, and SEG_CLOSE point types are returned by the iterator. ThisAreaobject is unchanged.- Specified by:
- getPathIterator from Shape
-
intersecttop
public void intersect(Area rhs)Sets the shape of thisAreato the intersection of its current shape and the shape of the specifiedArea. The resulting shape of thisAreawill include only areas that were contained in both thisAreaand also in the specifiedArea.// Example: Area a1 = new Area([triangle 0,0 => 8,0 => 0,8]); Area a2 = new Area([triangle 0,0 => 8,0 => 8,8]); a1.intersect(a2); a1(before) intersect a2 = a1(after) ################ ################ ################ ############## ############## ############ ############ ############ ######## ########## ########## #### ######## ######## ###### ###### #### #### ## ## -
intersectstop
public 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 a Shape implementation to conservatively return true when:
-
there is a high probability that the rectangular area and the
Shapeintersect, but - the calculations to accurately determine this intersection are prohibitively expensive.
- Specified by:
- intersects from Shape
-
there is a high probability that the rectangular area and the
-
intersectstop
public boolean intersects(Rectangle2D r)Tests if the interior of theShapeintersects the interior of a specifiedRectangle2D. 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.
- Specified by:
- intersects from Shape
-
there is a high probability that the
-
invalidateBoundstop
private void invalidateBounds() -
isEmptytop
public boolean isEmpty()Tests whether thisAreaobject encloses any area. -
isPolygonaltop
public boolean isPolygonal()Tests whether thisAreaconsists entirely of straight edged polygonal geometry. -
isRectangulartop
public boolean isRectangular()Tests whether thisAreais rectangular in shape. -
isSingulartop
public boolean isSingular()Tests whether thisAreais comprised of a single closed subpath. This method returnstrueif the path contains 0 or 1 subpaths, orfalseif the path contains more than 1 subpath. The subpaths are counted by the number of SEG_MOVETO segments that appear in the path. -
pathToCurvestop
static private Vector pathToCurves(PathIterator pi) -
resettop
public void reset()Removes all of the geometry from thisAreaand restores it to an empty area. -
subtracttop
public void subtract(Area rhs)Subtracts the shape of the specifiedAreafrom the shape of thisArea. The resulting shape of thisAreawill include areas that were contained only in thisAreaand not in the specifiedArea.// Example: Area a1 = new Area([triangle 0,0 => 8,0 => 0,8]); Area a2 = new Area([triangle 0,0 => 8,0 => 8,8]); a1.subtract(a2); a1(before) - a2 = a1(after) ################ ################ ############## ############## ## ############ ############ #### ########## ########## ###### ######## ######## ######## ###### ###### ###### #### #### #### ## ## ## -
transformtop
public void transform(AffineTransform t)Transforms the geometry of thisAreausing the specified java.awt.geom.AffineTransform. The geometry is transformed in place, which permanently changes the enclosed area defined by this object.
Fields
-
EmptyCurves
static private Vector EmptyCurves -
cachedBounds
private Rectangle2D cachedBounds -
curves
private Vector curves
