Package sec.sun.awt.geom
Class Area
java.lang.Object
sec.sun.awt.geom.Area
An
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.
- Since:
- 1.2
-
Constructor Summary
ConstructorsConstructorDescriptionArea()Default constructor which creates an empty area.Area(ShapeObject s) TheAreaclass creates an area geometry from the specifiedShapeobject. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds the shape of the specifiedAreato the shape of thisArea.booleanTests whether the geometries of the twoAreaobjects are equal.voidexclusiveOr(Area rhs) Sets the shape of thisAreato be the combined area of its current shape and the shape of the specifiedArea, minus their intersection.Creates aPathIteratorfor the outline of thisAreaobject.voidSets the shape of thisAreato the intersection of its current shape and the shape of the specifiedArea.booleanisEmpty()Tests whether thisAreaobject encloses any area.booleanTests whether thisAreaconsists entirely of straight edged polygonal geometry.booleanTests whether thisAreais rectangular in shape.booleanTests whether thisAreais comprised of a single closed subpath.voidreset()Removes all of the geometry from thisAreaand restores it to an empty area.voidSubtracts the shape of the specifiedAreafrom the shape of thisArea.
-
Constructor Details
-
Area
public Area()Default constructor which creates an empty area.- Since:
- 1.2
-
Area
TheAreaclass creates an area geometry from the specifiedShapeobject. 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.- Parameters:
s- theShapefrom which the area is constructed- Throws:
NullPointerException- ifsis null- Since:
- 1.2
-
-
Method Details
-
add
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) ################ ################ ################ ############## ############## ################ ############ ############ ################ ########## ########## ################ ######## ######## ################ ###### ###### ###### ###### #### #### #### #### ## ## ## ##- Parameters:
rhs- theAreato be added to the current shape- Throws:
NullPointerException- ifrhsis null- Since:
- 1.2
-
subtract
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) ################ ################ ############## ############## ## ############ ############ #### ########## ########## ###### ######## ######## ######## ###### ###### ###### #### #### #### ## ## ##- Parameters:
rhs- theAreato be subtracted from the current shape- Throws:
NullPointerException- ifrhsis null- Since:
- 1.2
-
intersect
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) ################ ################ ################ ############## ############## ############ ############ ############ ######## ########## ########## #### ######## ######## ###### ###### #### #### ## ##- Parameters:
rhs- theAreato be intersected with thisArea- Throws:
NullPointerException- ifrhsis null- Since:
- 1.2
-
exclusiveOr
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) ################ ################ ############## ############## ## ## ############ ############ #### #### ########## ########## ###### ###### ######## ######## ################ ###### ###### ###### ###### #### #### #### #### ## ## ## ##- Parameters:
rhs- theAreato be exclusive ORed with thisArea.- Throws:
NullPointerException- ifrhsis null- Since:
- 1.2
-
reset
Removes all of the geometry from thisAreaand restores it to an empty area.- Since:
- 1.2
-
isEmpty
Tests whether thisAreaobject encloses any area.- Returns:
trueif thisAreaobject represents an empty area;falseotherwise.- Since:
- 1.2
-
isPolygonal
Tests whether thisAreaconsists entirely of straight edged polygonal geometry.- Returns:
trueif the geometry of thisAreaconsists entirely of line segments;falseotherwise.- Since:
- 1.2
-
isRectangular
Tests whether thisAreais rectangular in shape.- Returns:
trueif the geometry of thisAreais rectangular in shape;falseotherwise.- Since:
- 1.2
-
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 ofSEG_MOVETOsegments that appear in the path.- Returns:
trueif theAreais comprised of a single basic geometry;falseotherwise.- Since:
- 1.2
-
equals
Tests whether the geometries of the twoAreaobjects are equal. This method will return false if the argument is null.- Parameters:
other- theAreato be compared to thisArea- Returns:
trueif the two geometries are equal;falseotherwise.- Since:
- 1.2
-
getPathIterator
- Parameters:
at- an optionalAffineTransformto be applied to the coordinates as they are returned in the iteration, ornullif untransformed coordinates are desired- Returns:
- the
PathIteratorobject that returns the geometry of the outline of thisArea, one segment at a time. - Since:
- 1.2
-