Path2D (Java Platform SE 6) (original) (raw)
java.awt.geom
Class Path2D
java.lang.Object
java.awt.geom.Path2D
All Implemented Interfaces:
Direct Known Subclasses:
public abstract class Path2D
extends Object
The Path2D
class provides a simple, yet flexible shape which represents an arbitrary geometric path. It can fully represent any path which can be iterated by thePathIterator interface including all of its segment types and winding rules and it implements all of the basic hit testing methods of the Shape interface.
Use Path2D.Float when dealing with data that can be represented and used with floating point precision. Use Path2D.Double for data that requires the accuracy or range of double precision.
Path2D
provides exactly those facilities required for basic construction and management of a geometric path and implementation of the above interfaces with little added interpretation. If it is useful to manipulate the interiors of closed geometric shapes beyond simple hit testing then theArea class provides additional capabilities specifically targeted at closed figures. While both classes nominally implement the Shape
interface, they differ in purpose and together they provide two useful views of a geometric shape where Path2D
deals primarily with a trajectory formed by path segments and Area
deals more with interpretation and manipulation of enclosed regions of 2D geometric space.
The PathIterator interface has more detailed descriptions of the types of segments that make up a path and the winding rules that control how to determine which regions are inside or outside the path.
Since:
1.6
Nested Class Summary | |
---|---|
static class | Path2D.Double The Double class defines a geometric path with coordinates stored in double precision floating point. |
static class | Path2D.Float The Float class defines a geometric path with coordinates stored in single precision floating point. |
Field Summary | |
---|---|
static int | WIND_EVEN_ODD An even-odd winding rule for determining the interior of a path. |
static int | WIND_NON_ZERO A non-zero winding rule for determining the interior of a path. |
Method Summary | |
---|---|
abstract void | [append](../../../java/awt/geom/Path2D.html#append%28java.awt.geom.PathIterator, boolean%29)(PathIterator pi, boolean connect) Appends the geometry of the specifiedPathIterator object to the path, possibly connecting the new geometry to the existing path segments with a line segment. |
void | [append](../../../java/awt/geom/Path2D.html#append%28java.awt.Shape, boolean%29)(Shape s, boolean connect) Appends the geometry of the specified Shape object to the path, possibly connecting the new geometry to the existing path segments with a line segment. |
abstract Object | clone() Creates a new object of the same class as this object. |
void | closePath() Closes the current subpath by drawing a straight line back to the coordinates of the last moveTo. |
boolean | [contains](../../../java/awt/geom/Path2D.html#contains%28double, double%29)(double x, double y) Tests if the specified coordinates are inside the boundary of the Shape. |
boolean | [contains](../../../java/awt/geom/Path2D.html#contains%28double, double, double, double%29)(double x, double y, double w, double h) Tests if the interior of the Shape entirely contains the specified rectangular area. |
static boolean | [contains](../../../java/awt/geom/Path2D.html#contains%28java.awt.geom.PathIterator, double, double%29)(PathIterator pi, double x, double y) Tests if the specified coordinates are inside the closed boundary of the specified PathIterator. |
static boolean | [contains](../../../java/awt/geom/Path2D.html#contains%28java.awt.geom.PathIterator, double, double, double, double%29)(PathIterator pi, double x, double y, double w, double h) Tests if the specified rectangular area is entirely inside the closed boundary of the specified PathIterator. |
static boolean | [contains](../../../java/awt/geom/Path2D.html#contains%28java.awt.geom.PathIterator, java.awt.geom.Point2D%29)(PathIterator pi,Point2D p) Tests if the specified Point2D is inside the closed boundary of the specified PathIterator. |
static boolean | [contains](../../../java/awt/geom/Path2D.html#contains%28java.awt.geom.PathIterator, java.awt.geom.Rectangle2D%29)(PathIterator pi,Rectangle2D r) Tests if the specified Rectangle2D is entirely inside the closed boundary of the specified PathIterator. |
boolean | contains(Point2D p) Tests if a specified Point2D is inside the boundary of the Shape. |
boolean | contains(Rectangle2D r) Tests if the interior of the Shape entirely contains the specified Rectangle2D. |
Shape | createTransformedShape(AffineTransform at) Returns a new Shape representing a transformed version of this Path2D. |
abstract void | [curveTo](../../../java/awt/geom/Path2D.html#curveTo%28double, double, double, double, double, double%29)(double x1, double y1, double x2, double y2, double x3, double y3) Adds a curved segment, defined by three new points, to the path by drawing a Bézier curve that intersects both the current coordinates and the specified coordinates (x3,y3), using the specified points (x1,y1) and (x2,y2) as Bézier control points. |
Rectangle | getBounds() Returns an integer Rectangle that completely encloses theShape. |
Point2D | getCurrentPoint() Returns the coordinates most recently added to the end of the path as a Point2D object. |
PathIterator | [getPathIterator](../../../java/awt/geom/Path2D.html#getPathIterator%28java.awt.geom.AffineTransform, double%29)(AffineTransform at, double flatness) Returns an iterator object that iterates along the Shape boundary and provides access to a flattened view of theShape outline geometry. |
int | getWindingRule() Returns the fill style winding rule. |
boolean | [intersects](../../../java/awt/geom/Path2D.html#intersects%28double, double, double, double%29)(double x, double y, double w, double h) Tests if the interior of the Shape intersects the interior of a specified rectangular area. |
static boolean | [intersects](../../../java/awt/geom/Path2D.html#intersects%28java.awt.geom.PathIterator, double, double, double, double%29)(PathIterator pi, double x, double y, double w, double h) Tests if the interior of the specified PathIterator intersects the interior of a specified set of rectangular coordinates. |
static boolean | [intersects](../../../java/awt/geom/Path2D.html#intersects%28java.awt.geom.PathIterator, java.awt.geom.Rectangle2D%29)(PathIterator pi,Rectangle2D r) Tests if the interior of the specified PathIterator intersects the interior of a specified Rectangle2D. |
boolean | intersects(Rectangle2D r) Tests if the interior of the Shape intersects the interior of a specified Rectangle2D. |
abstract void | [lineTo](../../../java/awt/geom/Path2D.html#lineTo%28double, double%29)(double x, double y) Adds a point to the path by drawing a straight line from the current coordinates to the new specified coordinates specified in double precision. |
abstract void | [moveTo](../../../java/awt/geom/Path2D.html#moveTo%28double, double%29)(double x, double y) Adds a point to the path by moving to the specified coordinates specified in double precision. |
abstract void | [quadTo](../../../java/awt/geom/Path2D.html#quadTo%28double, double, double, double%29)(double x1, double y1, double x2, double y2) Adds a curved segment, defined by two new points, to the path by drawing a Quadratic curve that intersects both the current coordinates and the specified coordinates (x2,y2), using the specified point (x1,y1) as a quadratic parametric control point. |
void | reset() Resets the path to empty. |
void | setWindingRule(int rule) Sets the winding rule for this path to the specified value. |
abstract void | transform(AffineTransform at) Transforms the geometry of this path using the specified AffineTransform. |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, [wait](../../../java/lang/Object.html#wait%28long, int%29) |
Methods inherited from interface java.awt.Shape |
---|
getBounds2D, getPathIterator |
Field Detail |
---|
WIND_EVEN_ODD
public static final int WIND_EVEN_ODD
An even-odd winding rule for determining the interior of a path.
Since:
1.6
See Also:
PathIterator.WIND_EVEN_ODD, Constant Field Values
WIND_NON_ZERO
public static final int WIND_NON_ZERO
A non-zero winding rule for determining the interior of a path.
Since:
1.6
See Also:
PathIterator.WIND_NON_ZERO, Constant Field Values
Method Detail |
---|
moveTo
public abstract void moveTo(double x, double y)
Adds a point to the path by moving to the specified coordinates specified in double precision.
Parameters:
x
- the specified X coordinate
y
- the specified Y coordinate
Since:
1.6
lineTo
public abstract void lineTo(double x, double y)
Adds a point to the path by drawing a straight line from the current coordinates to the new specified coordinates specified in double precision.
Parameters:
x
- the specified X coordinate
y
- the specified Y coordinate
Since:
1.6
quadTo
public abstract void quadTo(double x1, double y1, double x2, double y2)
Adds a curved segment, defined by two new points, to the path by drawing a Quadratic curve that intersects both the current coordinates and the specified coordinates (x2,y2)
, using the specified point (x1,y1)
as a quadratic parametric control point. All coordinates are specified in double precision.
Parameters:
x1
- the X coordinate of the quadratic control point
y1
- the Y coordinate of the quadratic control point
x2
- the X coordinate of the final end point
y2
- the Y coordinate of the final end point
Since:
1.6
curveTo
public abstract void curveTo(double x1, double y1, double x2, double y2, double x3, double y3)
Adds a curved segment, defined by three new points, to the path by drawing a Bézier curve that intersects both the current coordinates and the specified coordinates (x3,y3)
, using the specified points (x1,y1)
and (x2,y2)
as Bézier control points. All coordinates are specified in double precision.
Parameters:
x1
- the X coordinate of the first Bézier control point
y1
- the Y coordinate of the first Bézier control point
x2
- the X coordinate of the second Bézier control point
y2
- the Y coordinate of the second Bézier control point
x3
- the X coordinate of the final end point
y3
- the Y coordinate of the final end point
Since:
1.6
closePath
public final void closePath()
Closes the current subpath by drawing a straight line back to the coordinates of the last moveTo
. If the path is already closed then this method has no effect.
Since:
1.6
append
public final void append(Shape s, boolean connect)
Appends the geometry of the specified Shape
object to the path, possibly connecting the new geometry to the existing path segments with a line segment. If the connect
parameter is true
and the path is not empty then any initial moveTo
in the geometry of the appended Shape
is turned into a lineTo
segment. If the destination coordinates of such a connecting lineTo
segment match the ending coordinates of a currently open subpath then the segment is omitted as superfluous. The winding rule of the specified Shape
is ignored and the appended geometry is governed by the winding rule specified for this path.
Parameters:
s
- the Shape
whose geometry is appended to this path
connect
- a boolean to control whether or not to turn an initialmoveTo
segment into a lineTo
segment to connect the new geometry to the existing path
Since:
1.6
append
public abstract void append(PathIterator pi, boolean connect)
Appends the geometry of the specifiedPathIterator object to the path, possibly connecting the new geometry to the existing path segments with a line segment. If the connect
parameter is true
and the path is not empty then any initial moveTo
in the geometry of the appended Shape
is turned into alineTo
segment. If the destination coordinates of such a connecting lineTo
segment match the ending coordinates of a currently open subpath then the segment is omitted as superfluous. The winding rule of the specified Shape
is ignored and the appended geometry is governed by the winding rule specified for this path.
Parameters:
pi
- the PathIterator
whose geometry is appended to this path
connect
- a boolean to control whether or not to turn an initialmoveTo
segment into a lineTo
segment to connect the new geometry to the existing path
Since:
1.6
getWindingRule
public final int getWindingRule()
Returns the fill style winding rule.
Returns:
an integer representing the current winding rule.
Since:
1.6
See Also:
WIND_EVEN_ODD, WIND_NON_ZERO, setWindingRule(int)
setWindingRule
public final void setWindingRule(int rule)
Sets the winding rule for this path to the specified value.
Parameters:
rule
- an integer representing the specified winding rule
Throws:
[IllegalArgumentException](../../../java/lang/IllegalArgumentException.html "class in java.lang")
- if rule
is not either WIND_EVEN_ODD orWIND_NON_ZERO
Since:
1.6
See Also:
getCurrentPoint
public final Point2D getCurrentPoint()
Returns the coordinates most recently added to the end of the path as a Point2D object.
Returns:
a Point2D
object containing the ending coordinates of the path or null
if there are no points in the path.
Since:
1.6
reset
public final void reset()
Resets the path to empty. The append position is set back to the beginning of the path and all coordinates and point types are forgotten.
Since:
1.6
transform
public abstract void transform(AffineTransform at)
Transforms the geometry of this path using the specified AffineTransform. The geometry is transformed in place, which permanently changes the boundary defined by this object.
Parameters:
at
- the AffineTransform
used to transform the area
Since:
1.6
createTransformedShape
public final Shape createTransformedShape(AffineTransform at)
Returns a new Shape
representing a transformed version of this Path2D
. Note that the exact type and coordinate precision of the return value is not specified for this method. The method will return a Shape that contains no less precision for the transformed geometry than this Path2D
currently maintains, but it may contain no more precision either. If the tradeoff of precision vs. storage size in the result is important then the convenience constructors in the[Path2D.Float](../../../java/awt/geom/Path2D.Float.html#Path2D.Float%28java.awt.Shape, java.awt.geom.AffineTransform%29) and[Path2D.Double](../../../java/awt/geom/Path2D.Double.html#Path2D.Double%28java.awt.Shape, java.awt.geom.AffineTransform%29) subclasses should be used to make the choice explicit.
Parameters:
at
- the AffineTransform
used to transform a new Shape
.
Returns:
a new Shape
, transformed with the specified AffineTransform
.
Since:
1.6
getBounds
public final Rectangle getBounds()
Returns an integer Rectangle that completely encloses theShape
. 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.
Specified by:
[getBounds](../../../java/awt/Shape.html#getBounds%28%29)
in interface [Shape](../../../java/awt/Shape.html "interface in java.awt")
Returns:
an integer Rectangle
that completely encloses the Shape
.
Since:
1.6
See Also:
contains
public static boolean contains(PathIterator pi, double x, double y)
Tests if the specified coordinates are inside the closed boundary of the specified PathIterator.
This method provides a basic facility for implementors of the Shape interface to implement support for the[Shape.contains(double, double)](../../../java/awt/Shape.html#contains%28double, double%29) method.
Parameters:
pi
- the specified PathIterator
x
- the specified X coordinate
y
- the specified Y coordinate
Returns:
true
if the specified coordinates are inside the specified PathIterator
; false
otherwise
Since:
1.6
contains
public static boolean contains(PathIterator pi, Point2D p)
Tests if the specified Point2D is inside the closed boundary of the specified PathIterator.
This method provides a basic facility for implementors of the Shape interface to implement support for theShape.contains(Point2D) method.
Parameters:
pi
- the specified PathIterator
p
- the specified Point2D
Returns:
true
if the specified coordinates are inside the specified PathIterator
; false
otherwise
Since:
1.6
contains
public final boolean contains(double x, double y)
Tests if the specified coordinates are inside the boundary of the Shape
.
Specified by:
[contains](../../../java/awt/Shape.html#contains%28double, double%29)
in interface [Shape](../../../java/awt/Shape.html "interface in java.awt")
Parameters:
x
- the specified X coordinate to be tested
y
- the specified Y coordinate to be tested
Returns:
true
if the specified coordinates are inside the Shape
boundary; false
otherwise.
Since:
1.6
contains
public final boolean contains(Point2D p)
Tests if a specified Point2D is inside the boundary of the Shape
.
Specified by:
[contains](../../../java/awt/Shape.html#contains%28java.awt.geom.Point2D%29)
in interface [Shape](../../../java/awt/Shape.html "interface in java.awt")
Parameters:
p
- the specified Point2D
to be tested
Returns:
true
if the specified Point2D
is inside the boundary of the Shape
;false
otherwise.
Since:
1.6
contains
public static boolean contains(PathIterator pi, double x, double y, double w, double h)
Tests if the specified rectangular area is entirely inside the closed boundary of the specified PathIterator.
This method provides a basic facility for implementors of the Shape interface to implement support for the[Shape.contains(double, double, double, double)](../../../java/awt/Shape.html#contains%28double, double, double, double%29) method.
This method object may conservatively return false in cases where the specified rectangular area intersects a segment of the path, but that segment does not represent a boundary between the interior and exterior of the path. Such segments could lie entirely within the interior of the path if they are part of a path with a WIND_NON_ZERO winding rule or if the segments are retraced in the reverse direction such that the two sets of segments cancel each other out without any exterior area falling between them. To determine whether segments represent true boundaries of the interior of the path would require extensive calculations involving all of the segments of the path and the winding rule and are thus beyond the scope of this implementation.
Parameters:
pi
- the specified PathIterator
x
- the specified X coordinate
y
- the specified Y coordinate
w
- the width of the specified rectangular area
h
- the height of the specified rectangular area
Returns:
true
if the specified PathIterator
contains the specified rectangluar area; false
otherwise.
Since:
1.6
contains
public static boolean contains(PathIterator pi, Rectangle2D r)
Tests if the specified Rectangle2D is entirely inside the closed boundary of the specified PathIterator.
This method provides a basic facility for implementors of the Shape interface to implement support for theShape.contains(Rectangle2D) method.
This method object may conservatively return false in cases where the specified rectangular area intersects a segment of the path, but that segment does not represent a boundary between the interior and exterior of the path. Such segments could lie entirely within the interior of the path if they are part of a path with a WIND_NON_ZERO winding rule or if the segments are retraced in the reverse direction such that the two sets of segments cancel each other out without any exterior area falling between them. To determine whether segments represent true boundaries of the interior of the path would require extensive calculations involving all of the segments of the path and the winding rule and are thus beyond the scope of this implementation.
Parameters:
pi
- the specified PathIterator
r
- a specified Rectangle2D
Returns:
true
if the specified PathIterator
contains the specified Rectangle2D
; false
otherwise.
Since:
1.6
contains
public final boolean contains(double x, double y, double w, double h)
Tests if the interior of the Shape
entirely contains the specified rectangular area. All coordinates that lie inside the rectangular area must lie within the Shape
for the entire rectanglar area to be considered contained within the Shape
.
The Shape.contains()
method allows a Shape
implementation to conservatively return false
when:
- the
intersect
method returnstrue
and - the calculations to determine whether or not the
Shape
entirely contains the rectangular area are prohibitively expensive. This means that for someShapes
this method might returnfalse
even though theShape
contains the rectangular area. The Area class performs more accurate geometric computations than mostShape
objects and therefore can be used if a more precise answer is required.
This method object may conservatively return false in cases where the specified rectangular area intersects a segment of the path, but that segment does not represent a boundary between the interior and exterior of the path. Such segments could lie entirely within the interior of the path if they are part of a path with a WIND_NON_ZERO winding rule or if the segments are retraced in the reverse direction such that the two sets of segments cancel each other out without any exterior area falling between them. To determine whether segments represent true boundaries of the interior of the path would require extensive calculations involving all of the segments of the path and the winding rule and are thus beyond the scope of this implementation.
Specified by:
[contains](../../../java/awt/Shape.html#contains%28double, double, double, double%29)
in interface [Shape](../../../java/awt/Shape.html "interface in java.awt")
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:
true
if the interior of the Shape
entirely contains the specified rectangular area;false
otherwise or, if the Shape
contains the rectangular area and the intersects
method returns true
and the containment calculations would be too expensive to perform.
Since:
1.6
See Also:
Area, [Shape.intersects(double, double, double, double)](../../../java/awt/Shape.html#intersects%28double, double, double, double%29)
contains
public final boolean contains(Rectangle2D r)
Tests if the interior of the Shape
entirely contains the specified Rectangle2D
. The Shape.contains()
method allows a Shape
implementation to conservatively return false
when:
- the
intersect
method returnstrue
and - the calculations to determine whether or not the
Shape
entirely contains theRectangle2D
are prohibitively expensive. This means that for someShapes
this method might returnfalse
even though theShape
contains theRectangle2D
. The Area class performs more accurate geometric computations than mostShape
objects and therefore can be used if a more precise answer is required.
This method object may conservatively return false in cases where the specified rectangular area intersects a segment of the path, but that segment does not represent a boundary between the interior and exterior of the path. Such segments could lie entirely within the interior of the path if they are part of a path with a WIND_NON_ZERO winding rule or if the segments are retraced in the reverse direction such that the two sets of segments cancel each other out without any exterior area falling between them. To determine whether segments represent true boundaries of the interior of the path would require extensive calculations involving all of the segments of the path and the winding rule and are thus beyond the scope of this implementation.
Specified by:
[contains](../../../java/awt/Shape.html#contains%28java.awt.geom.Rectangle2D%29)
in interface [Shape](../../../java/awt/Shape.html "interface in java.awt")
Parameters:
r
- The specified Rectangle2D
Returns:
true
if the interior of the Shape
entirely contains the Rectangle2D
;false
otherwise or, if the Shape
contains the Rectangle2D
and theintersects
method returns true
and the containment calculations would be too expensive to perform.
Since:
1.6
See Also:
[Shape.contains(double, double, double, double)](../../../java/awt/Shape.html#contains%28double, double, double, double%29)
intersects
public static boolean intersects(PathIterator pi, double x, double y, double w, double h)
Tests if the interior of the specified PathIterator intersects the interior of a specified set of rectangular coordinates.
This method provides a basic facility for implementors of the Shape interface to implement support for the[Shape.intersects(double, double, double, double)](../../../java/awt/Shape.html#intersects%28double, double, double, double%29) method.
This method object may conservatively return true in cases where the specified rectangular area intersects a segment of the path, but that segment does not represent a boundary between the interior and exterior of the path. Such a case may occur if some set of segments of the path are retraced in the reverse direction such that the two sets of segments cancel each other out without any interior area between them. To determine whether segments represent true boundaries of the interior of the path would require extensive calculations involving all of the segments of the path and the winding rule and are thus beyond the scope of this implementation.
Parameters:
pi
- the specified PathIterator
x
- the specified X coordinate
y
- the specified Y coordinate
w
- the width of the specified rectangular coordinates
h
- the height of the specified rectangular coordinates
Returns:
true
if the specified PathIterator
and the interior of the specified set of rectangular coordinates intersect each other; false
otherwise.
Since:
1.6
intersects
public static boolean intersects(PathIterator pi, Rectangle2D r)
Tests if the interior of the specified PathIterator intersects the interior of a specified Rectangle2D.
This method provides a basic facility for implementors of the Shape interface to implement support for theShape.intersects(Rectangle2D) method.
This method object may conservatively return true in cases where the specified rectangular area intersects a segment of the path, but that segment does not represent a boundary between the interior and exterior of the path. Such a case may occur if some set of segments of the path are retraced in the reverse direction such that the two sets of segments cancel each other out without any interior area between them. To determine whether segments represent true boundaries of the interior of the path would require extensive calculations involving all of the segments of the path and the winding rule and are thus beyond the scope of this implementation.
Parameters:
pi
- the specified PathIterator
r
- the specified Rectangle2D
Returns:
true
if the specified PathIterator
and the interior of the specified Rectangle2D
intersect each other; false
otherwise.
Since:
1.6
intersects
public final boolean intersects(double x, double y, double w, double h)
Tests if the interior of the Shape
intersects the interior of a specified rectangular area. The rectangular area is considered to intersect the Shape
if any point is contained in both the interior of the Shape
and 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
Shape
intersect, but - the calculations to accurately determine this intersection are prohibitively expensive.
This means that for some
Shapes
this method might returntrue
even though the rectangular area does not intersect theShape
. The Area class performs more accurate computations of geometric intersection than mostShape
objects and therefore can be used if a more precise answer is required.
This method object may conservatively return true in cases where the specified rectangular area intersects a segment of the path, but that segment does not represent a boundary between the interior and exterior of the path. Such a case may occur if some set of segments of the path are retraced in the reverse direction such that the two sets of segments cancel each other out without any interior area between them. To determine whether segments represent true boundaries of the interior of the path would require extensive calculations involving all of the segments of the path and the winding rule and are thus beyond the scope of this implementation.
Specified by:
[intersects](../../../java/awt/Shape.html#intersects%28double, double, double, double%29)
in interface [Shape](../../../java/awt/Shape.html "interface in java.awt")
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:
true
if the interior of the Shape
and the interior of the rectangular area intersect, or are both highly likely to intersect and intersection calculations would be too expensive to perform; false
otherwise.
Since:
1.6
See Also:
intersects
public final boolean intersects(Rectangle2D r)
Tests if the interior of the 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
Rectangle2D
and theShape
intersect, but - the calculations to accurately determine this intersection are prohibitively expensive.
This means that for some
Shapes
this method might returntrue
even though theRectangle2D
does not intersect theShape
. The Area class performs more accurate computations of geometric intersection than mostShape
objects and therefore can be used if a more precise answer is required.
This method object may conservatively return true in cases where the specified rectangular area intersects a segment of the path, but that segment does not represent a boundary between the interior and exterior of the path. Such a case may occur if some set of segments of the path are retraced in the reverse direction such that the two sets of segments cancel each other out without any interior area between them. To determine whether segments represent true boundaries of the interior of the path would require extensive calculations involving all of the segments of the path and the winding rule and are thus beyond the scope of this implementation.
Specified by:
[intersects](../../../java/awt/Shape.html#intersects%28java.awt.geom.Rectangle2D%29)
in interface [Shape](../../../java/awt/Shape.html "interface in java.awt")
Parameters:
r
- the specified Rectangle2D
Returns:
true
if the interior of the Shape
and the interior of the specified Rectangle2D
intersect, or are both highly likely to intersect and intersection calculations would be too expensive to perform; false
otherwise.
Since:
1.6
See Also:
[Shape.intersects(double, double, double, double)](../../../java/awt/Shape.html#intersects%28double, double, double, double%29)
getPathIterator
public PathIterator getPathIterator(AffineTransform at, double flatness)
Returns an iterator object that iterates along the Shape
boundary and provides access to a flattened view of theShape
outline geometry.
Only SEG_MOVETO, SEG_LINETO, and SEG_CLOSE point types are returned by the iterator.
If an optional AffineTransform
is specified, the coordinates returned in the iteration are transformed accordingly.
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. Note that a limit on the accuracy of the flattened path might be silently imposed, causing very small flattening parameters to be treated as larger values. This limit, if there is one, is defined by the particular implementation that is used.
Each call to this method returns a fresh PathIterator
object that traverses the Shape
object geometry independently from any other PathIterator
objects in use at the same time.
It is recommended, but not guaranteed, that objects implementing the Shape
interface isolate iterations that are in process from any changes that might occur to the original object's geometry during such iterations.
The iterator for this class is not multi-threaded safe, which means that this Path2D
class does not guarantee that modifications to the geometry of thisPath2D
object do not affect any iterations of that geometry that are already in process.
Specified by:
[getPathIterator](../../../java/awt/Shape.html#getPathIterator%28java.awt.geom.AffineTransform, double%29)
in interface [Shape](../../../java/awt/Shape.html "interface in java.awt")
Parameters:
at
- an optional AffineTransform
to be applied to the coordinates as they are returned in the iteration, or null
if 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 new PathIterator
that independently traverses a flattened view of the geometry of the Shape
.
Since:
1.6
clone
public abstract Object clone()
Creates a new object of the same class as this object.
Overrides:
[clone](../../../java/lang/Object.html#clone%28%29)
in class [Object](../../../java/lang/Object.html "class in java.lang")
Returns:
a clone of this instance.
Throws:
[OutOfMemoryError](../../../java/lang/OutOfMemoryError.html "class in java.lang")
- if there is not enough memory.
Since:
1.6
See Also:
Submit a bug or feature
For further API reference and developer documentation, see Java SE Developer Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2015, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
Scripting on this page tracks web page traffic, but does not change the content in any way.