public class CompoundShape extends Object implements Shape
Details:
A CompoundShape
aggregates multiple Shape
s into a single Shape
.
To build a CompoundShape
, create a new instance using the default constructor, and then add each individual subshape using add(Shape)
.
Constructor and Description |
---|
CompoundShape()
Initializes empty compound.
|
Modifier and Type | Method and Description |
---|---|
void |
add(Shape iShape)
Adds shape to compound.
|
boolean |
contains(double iX,
double iY)
Determines whether point is contained in compound.
|
boolean |
contains(double iX,
double iY,
double iW,
double iH)
Determines whether rectangle is contained in compound.
|
boolean |
contains(Point2D iP)
Determines whether point is contained in compound.
|
boolean |
contains(Rectangle2D iR)
Determines whether rectangle is contained in compound.
|
Rectangle |
getBounds()
Computes bounds of entire compound.
|
Rectangle2D |
getBounds2D()
Computes bounds of entire compound.
|
PathIterator |
getPathIterator(AffineTransform iTrans)
Iterates path of entire shape.
|
PathIterator |
getPathIterator(AffineTransform iTrans,
double iFlatness)
Iterates path of entire shape.
|
boolean |
intersects(double iX,
double iY,
double iW,
double iH)
Determines whether rectangle intersects compound.
|
boolean |
intersects(Rectangle2D iR)
Determines whether rectangle intersects compound.
|
void |
remove(Shape iShape)
Removes subshape.
|
public CompoundShape()
Details:
This default constructor initializes an empty compound with the default winding rule, which is PathIterator.WIND_EVEN_ODD
.
After creating a new instance, you should add the subshapes using add(Shape)
.
public void add(Shape iShape)
Details:
add
adds the given subshape to this compound.
iShape
- the subshape to addpublic void remove(Shape iShape)
Details:
remove
removes the given subshape from this compound.
If the shape to remove is not a part of this compound, no action is taken and no harm is done.
iShape
- the subshape to removepublic Rectangle getBounds()
Details:
getBounds
returns a rectangle that totally every subshape in this compound.
public Rectangle2D getBounds2D()
Details:
getBounds
returns a rectangle that totally every subshape in this compound.
getBounds2D
in interface Shape
public boolean contains(double iX, double iY)
Details:
contains
returns true
if the given point lies within this compound shape, false
otherwise.
Containment is determined by testing the point for containment in each individual subshape.
If any of the subshapes' contains
methods reports that the subshape contains the point, then the entire compound is reported to contain the point.
public boolean contains(Point2D iP)
Details:
contains
returns true
if the given point lies within this compound shape, false
otherwise.
Containment is determined by testing the point for containment in each individual subshape.
If any of the subshapes' contains
methods reports that the subshape contains the point, then the entire compound is reported to contain the point.
public boolean intersects(double iX, double iY, double iW, double iH)
Details:
intersects
returns true
if the given rectangle intersects this compound shape, false
otherwise.
Intersection is determined by testing the rectangle for intersection with each individual subshape.
If any of the subshapes' intersects
methods reports that the subshape intersects with the rectangle, then the entire compound is reported to intersect with the rectangle.
intersects
in interface Shape
iX
- rectangle origin, x coordinateiY
- rectangle origin, y coordinateiW
- rectangle widthiH
- rectangle heightpublic boolean intersects(Rectangle2D iR)
Details:
intersects
returns true
if the given rectangle intersects this compound shape, false
otherwise.
Intersection is determined by testing the rectangle for intersection with each individual subshape.
If any of the subshapes' intersects
methods reports that the subshape intersects with the rectangle, then the entire compound is reported to intersect with the rectangle.
intersects
in interface Shape
iR
- the rectanglepublic boolean contains(double iX, double iY, double iW, double iH)
Details:
contains
returns true
if the given rectangle lies entirely within this compound shape, false
otherwise.
Containment is determined by testing the rectangle for complete containment in each individual subshape.
If any of the subshapes' contains
methods reports that the subshape contains the point, then the entire compound is reported to contain the point.
Note that this implementation is not entirely perfect. For example, if a portion of the rectangle is enclosed in one subshape, and the remaining portion is covered by another subshape, this implementation may still report that the entire rectangle is not contained in the composite, if there is no single subshape that completely encloses it.
public boolean contains(Rectangle2D iR)
Details:
contains
returns true
if the given rectangle lies entirely within this compound shape, false
otherwise.
Containment is determined by testing the rectangle for complete containment in each individual subshape.
If any of the subshapes' contains
methods reports that the subshape contains the point, then the entire compound is reported to contain the point.
Note that this implementation is not entirely perfect. For example, if a portion of the rectangle is enclosed in one subshape, and the remaining portion is covered by another subshape, this implementation may still report that the entire rectangle is not contained in the composite, if there is no single subshape that completely encloses it.
public PathIterator getPathIterator(AffineTransform iTrans)
Details:
getPathIterator
returns a single path iterator for this entire compound shape, in compliance with the Shape.getPathIterator(AffineTransform)
specification.
getPathIterator
in interface Shape
iTrans
- transformation for pathpublic PathIterator getPathIterator(AffineTransform iTrans, double iFlatness)
Details:
getPathIterator
returns a single path iterator for this entire compound shape, in compliance with the Shape.getPathIterator(AffineTransform, double)
specification.
getPathIterator
in interface Shape
iTrans
- transformation for pathiFlatness
- the flatness valueCopyright © 2013. All Rights Reserved.