public class Path2D extends Shape implements PathConsumer2D
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 the
PathIterator
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
when dealing with data that can be represented
and used with floating point 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 the
Area
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.
Modifier and Type | Class and Description |
---|---|
(package private) static class |
Path2D.CopyIterator |
static class |
Path2D.CornerPrefix |
(package private) static class |
Path2D.Iterator |
(package private) static class |
Path2D.SVGParser |
(package private) static class |
Path2D.TxIterator |
Modifier and Type | Field and Description |
---|---|
(package private) float |
currX |
(package private) float |
currY |
(package private) static int[] |
curvecoords |
(package private) static int |
EXPAND_MAX |
(package private) float[] |
floatCoords |
(package private) static int |
INIT_SIZE |
(package private) float |
moveX |
(package private) float |
moveY |
(package private) int |
numCoords |
(package private) int |
numTypes |
(package private) byte[] |
pointTypes |
(package private) float |
prevX |
(package private) float |
prevY |
private static byte |
SEG_CLOSE |
private static byte |
SEG_CUBICTO |
private static byte |
SEG_LINETO |
private static byte |
SEG_MOVETO |
private static byte |
SEG_QUADTO |
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.
|
(package private) int |
windingRule |
OUT_BOTTOM, OUT_LEFT, OUT_RIGHT, OUT_TOP, RECT_INTERSECTS
Constructor and Description |
---|
Path2D()
Constructs a new empty single precision
Path2D object
with a default winding rule of WIND_NON_ZERO . |
Path2D(int rule)
Constructs a new empty single precision
Path2D object
with the specified winding rule to control operations that
require the interior of the path to be defined. |
Path2D(int windingRule,
byte[] pointTypes,
int numTypes,
float[] pointCoords,
int numCoords)
Construct a Path2D from pre-composed data.
|
Path2D(int rule,
int initialCapacity)
Constructs a new empty single precision
Path2D object
with the specified winding rule and the specified initial
capacity to store path segments. |
Path2D(Shape s)
Constructs a new single precision
Path2D object
from an arbitrary Shape object. |
Path2D(Shape s,
BaseTransform tx)
Constructs a new single precision
Path2D object
from an arbitrary Shape object, transformed by an
BaseTransform object. |
Modifier and Type | Method and Description |
---|---|
void |
append(PathIterator pi,
boolean connect) |
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. |
void |
appendOvalQuadrant(float sx,
float sy,
float cx,
float cy,
float ex,
float ey,
float tfrom,
float tto,
Path2D.CornerPrefix prefix)
Append a section of a quadrant of an oval to the current path.
|
void |
appendSVGPath(java.lang.String svgpath)
Appends the geometry of the path in the specified
String
argument in the format of an SVG path. |
void |
arcTo(float radiusx,
float radiusy,
float xAxisRotation,
boolean largeArcFlag,
boolean sweepFlag,
float x,
float y)
Append a portion of an ellipse to the path.
|
void |
arcToRel(float radiusx,
float radiusy,
float xAxisRotation,
boolean largeArcFlag,
boolean sweepFlag,
float relx,
float rely)
Append a portion of an ellipse to the path using relative coordinates.
|
boolean |
checkAndGetIntRect(Rectangle retrect,
float tolerance)
Check and return if the fillable interior of the path is a simple
rectangle on nearly integer bounds and initialize the indicated
Rectangle with the integer representation of the rectangle
if it is. |
private boolean |
close(int ix,
float fx,
float tolerance) |
void |
closePath()
Closes the current subpath by drawing a straight line back to
the coordinates of the last
moveTo . |
boolean |
contains(float x,
float y)
Tests if the specified coordinates are inside the boundary of the
Shape . |
boolean |
contains(float x,
float y,
float w,
float h)
Tests if the interior of the
Shape entirely contains
the specified rectangular area. |
static boolean |
contains(PathIterator pi,
float x,
float y)
Tests if the specified coordinates are inside the closed
boundary of the specified
PathIterator . |
static boolean |
contains(PathIterator pi,
float x,
float y,
float w,
float h)
Tests if the specified rectangular area is entirely inside the
closed boundary of the specified
PathIterator . |
static boolean |
contains(PathIterator pi,
Point2D p)
Tests if the specified
Point2D is inside the closed
boundary of the specified PathIterator . |
boolean |
contains(Point2D p)
Tests if a specified
Point2D is inside the boundary
of the Shape . |
Path2D |
copy()
Returns a new copy of this
Shape instance. |
(package private) static byte[] |
copyOf(byte[] original,
int newLength) |
(package private) static float[] |
copyOf(float[] original,
int newLength) |
Shape |
createTransformedShape(BaseTransform tx)
Returns a new
Shape representing a transformed version
of this Path2D . |
void |
curveTo(float x1,
float y1,
float x2,
float y2,
float x3,
float y3)
Adds a curved segment to the path, defined by three new points, 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. |
void |
curveToRel(float relx1,
float rely1,
float relx2,
float rely2,
float relx3,
float rely3)
Adds a curved segment to the path, defined by three new points
relative to the current point, 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. |
void |
curveToSmooth(float x2,
float y2,
float x3,
float y3)
Adds a curved segment to the path, defined by two new points and
a third point inferred from the previous curve, by
drawing a Bézier curve that intersects both the current
coordinates and the specified coordinates
(x3,y3) ,
using the specified point (x2,y2) as the second
Bézier control point and a first Bézier control
point that is positioned
symmetrically across the current point from the previous curve
control point. |
void |
curveToSmoothRel(float relx2,
float rely2,
float relx3,
float rely3)
Adds a curved segment to the path, defined by two new points relative
to the current point and
a third point inferred from the previous curve, by
drawing a Bézier curve that intersects both the current
coordinates and the specified relative coordinates
(rx3,ry3) ,
using the specified relative point (rx2,ry2) as the second
Bézier control point and a first Bézier control
point that is positioned
symmetrically across the current point from the previous curve
control point. |
boolean |
equals(java.lang.Object obj)
Note that this method may return false when the geometry of the
given
Path2D is identical to the geometry of this object
but is expressed in a different way. |
RectBounds |
getBounds()
Note that there is no guarantee that the returned
RectBounds is the smallest bounding box that encloses
the Shape , only that the Shape lies
entirely within the indicated RectBounds . |
byte[] |
getCommandsNoClone() |
Point2D |
getCurrentPoint()
Returns the coordinates most recently added to the end of the path
as a
Point2D object. |
float |
getCurrentX() |
float |
getCurrentY() |
float[] |
getFloatCoordsNoClone() |
int |
getNumCommands() |
PathIterator |
getPathIterator(BaseTransform tx)
Returns an iterator object that iterates along the
Shape boundary and provides access to the geometry of the
Shape outline. |
PathIterator |
getPathIterator(BaseTransform tx,
float flatness)
Returns an iterator object that iterates along the
Shape
boundary and provides access to a flattened view of the
Shape outline geometry. |
(package private) Point2D |
getPoint(int coordindex) |
int |
getWindingRule()
Returns the fill style winding rule.
|
int |
hashCode() |
boolean |
intersects(float x,
float y,
float w,
float h)
Tests if the interior of the
Shape intersects the
interior of a specified rectangular area. |
static boolean |
intersects(PathIterator pi,
float x,
float y,
float w,
float h)
Tests if the interior of the specified
PathIterator
intersects the interior of a specified set of rectangular
coordinates. |
void |
lineTo(float x,
float y)
Adds a point to the path by drawing a straight line from the
current coordinates to the new coordinates.
|
void |
lineToRel(float relx,
float rely)
Adds a point to the path by drawing a straight line from the
current coordinates to the new coordinates relative to the
current point.
|
void |
moveTo(float x,
float y)
Adds a point to the path by moving to the specified
coordinates specified in float precision.
|
void |
moveToRel(float relx,
float rely)
Adds a point to the path by moving to the specified coordinates
relative to the current point, specified in float precision.
|
(package private) void |
needRoom(boolean needMove,
int newCoords) |
void |
ovalQuadrantTo(float cx,
float cy,
float ex,
float ey,
float tfrom,
float tto)
Append a section of a quadrant of an oval to the current path,
relative to the current point.
|
void |
pathDone() |
(package private) int |
pointCrossings(float px,
float py) |
void |
quadTo(float x1,
float y1,
float x2,
float y2)
Adds a curved segment to the path, defined by two new points, 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 |
quadToRel(float relx1,
float rely1,
float relx2,
float rely2)
Adds a curved segment to the path, defined by two new points
relative to the current point, by
drawing a Quadratic curve that intersects both the current
coordinates and the specified relative coordinates
(rx2,ry2) ,
using the specified relative point (rx1,ry1) as a quadratic
parametric control point. |
void |
quadToSmooth(float x2,
float y2)
Adds a curved segment to the path, defined by a new point, by
drawing a Quadratic curve that intersects both the current
coordinates and the specified coordinates
(x,y) ,
using a quadratic parametric control point that is positioned
symmetrically across the current point from the previous curve
control point. |
void |
quadToSmoothRel(float relx2,
float rely2)
Adds a curved segment to the path, defined by a new point
relative to the current point, by
drawing a Quadratic curve that intersects both the current
coordinates and the specified relative coordinates
(x,y) ,
using a quadratic parametric control point that is positioned
symmetrically across the current point from the previous curve
control point. |
(package private) int |
rectCrossings(float rxmin,
float rymin,
float rxmax,
float rymax) |
void |
reset()
Resets the path to empty.
|
void |
setTo(Path2D otherPath) |
void |
setWindingRule(int rule)
Sets the winding rule for this path to the specified value.
|
void |
transform(BaseTransform tx) |
accumulate, accumulateCubic, accumulateCubic, accumulateQuad, contains, intersects, intersectsLine, outcode, pointCrossingsForCubic, pointCrossingsForLine, pointCrossingsForPath, pointCrossingsForQuad, rectCrossingsForCubic, rectCrossingsForLine, rectCrossingsForPath, rectCrossingsForQuad
static final int[] curvecoords
public static final int WIND_EVEN_ODD
PathIterator.WIND_EVEN_ODD
,
Constant Field Valuespublic static final int WIND_NON_ZERO
PathIterator.WIND_NON_ZERO
,
Constant Field Valuesprivate static final byte SEG_MOVETO
private static final byte SEG_LINETO
private static final byte SEG_QUADTO
private static final byte SEG_CUBICTO
private static final byte SEG_CLOSE
byte[] pointTypes
int numTypes
int numCoords
int windingRule
static final int INIT_SIZE
static final int EXPAND_MAX
float[] floatCoords
float moveX
float moveY
float prevX
float prevY
float currX
float currY
public Path2D()
Path2D
object
with a default winding rule of WIND_NON_ZERO
.public Path2D(int rule)
Path2D
object
with the specified winding rule to control operations that
require the interior of the path to be defined.rule
- the winding ruleWIND_EVEN_ODD
,
WIND_NON_ZERO
public Path2D(int rule, int initialCapacity)
Path2D
object
with the specified winding rule and the specified initial
capacity to store path segments.
This number is an initial guess as to how many path segments
will be added to the path, but the storage is expanded as
needed to store whatever path segments are added.rule
- the winding ruleinitialCapacity
- the estimate for the number of path segments
in the pathWIND_EVEN_ODD
,
WIND_NON_ZERO
public Path2D(Shape s)
Path2D
object
from an arbitrary Shape
object.
All of the initial geometry and the winding rule for this path are
taken from the specified Shape
object.s
- the specified Shape
objectpublic Path2D(Shape s, BaseTransform tx)
Path2D
object
from an arbitrary Shape
object, transformed by an
BaseTransform
object.
All of the initial geometry and the winding rule for this path are
taken from the specified Shape
object and transformed
by the specified BaseTransform
object.s
- the specified Shape
objecttx
- the specified BaseTransform
objectpublic Path2D(int windingRule, byte[] pointTypes, int numTypes, float[] pointCoords, int numCoords)
Point2D getPoint(int coordindex)
private boolean close(int ix, float fx, float tolerance)
public boolean checkAndGetIntRect(Rectangle retrect, float tolerance)
Rectangle
with the integer representation of the rectangle
if it is.
The method will return false if the path is not rectangular, or if
the horizontal and linear segments are not within the indicated
tolerance of an integer coordinate, or if the resulting rectangle
cannot be safely represented by the integer attributes of the
Rectangle
object.retrect
- the Rectangle
to return the rectangular area,
or nulltolerance
- the maximum difference from an integer allowed
for any edge of the rectanglevoid needRoom(boolean needMove, int newCoords)
public final void moveTo(float x, float y)
moveTo
in interface PathConsumer2D
x
- the specified X coordinatey
- the specified Y coordinatepublic final void moveToRel(float relx, float rely)
relx
- the specified relative X coordinaterely
- the specified relative Y coordinatemoveTo(float, float)
public final void lineTo(float x, float y)
lineTo
in interface PathConsumer2D
x
- the specified X coordinatey
- the specified Y coordinatepublic final void lineToRel(float relx, float rely)
relx
- the specified relative X coordinaterely
- the specified relative Y coordinatelineTo(float, float)
public final void quadTo(float x1, float y1, float x2, float y2)
(x2,y2)
,
using the specified point (x1,y1)
as a quadratic
parametric control point.quadTo
in interface PathConsumer2D
x1
- the X coordinate of the quadratic control pointy1
- the Y coordinate of the quadratic control pointx2
- the X coordinate of the final end pointy2
- the Y coordinate of the final end pointpublic final void quadToRel(float relx1, float rely1, float relx2, float rely2)
(rx2,ry2)
,
using the specified relative point (rx1,ry1)
as a quadratic
parametric control point.
This is equivalent to:
quadTo(getCurrentX() + rx1, getCurrentY() + ry1, getCurrentX() + rx2, getCurrentY() + ry2);
relx1
- the relative X coordinate of the quadratic control pointrely1
- the relative Y coordinate of the quadratic control pointrelx2
- the relative X coordinate of the final end pointrely2
- the relative Y coordinate of the final end pointquadTo(float, float, float, float)
public final void quadToSmooth(float x2, float y2)
(x,y)
,
using a quadratic parametric control point that is positioned
symmetrically across the current point from the previous curve
control point.
If the previous path segment is not a curve, then the control
point will be positioned at the current point. This is
equivalent to:
quadTo(getCurrentX() * 2 -, getCurrentY() * 2 - , x, y);
x2
- the X coordinate of the final end pointy2
- the Y coordinate of the final end pointquadTo(float, float, float, float)
public final void quadToSmoothRel(float relx2, float rely2)
(x,y)
,
using a quadratic parametric control point that is positioned
symmetrically across the current point from the previous curve
control point.
If the previous path segment is not a curve, then the control
point will be positioned at the current point. This is
equivalent to:
quadTo(getCurrentX() * 2 -, getCurrentY() * 2 - , getCurrentX() + x, getCurrentY() + y);
relx2
- the relative X coordinate of the final end pointrely2
- the relative Y coordinate of the final end pointquadTo(float, float, float, float)
public final void curveTo(float x1, float y1, float x2, float y2, float x3, float y3)
(x3,y3)
,
using the specified points (x1,y1)
and (x2,y2)
as
Bézier control points.curveTo
in interface PathConsumer2D
x1
- the X coordinate of the first Bézier control pointy1
- the Y coordinate of the first Bézier control pointx2
- the X coordinate of the second Bézier control pointy2
- the Y coordinate of the second Bézier control pointx3
- the X coordinate of the final end pointy3
- the Y coordinate of the final end pointcurveTo(float, float, float, float, float, float)
public final void curveToRel(float relx1, float rely1, float relx2, float rely2, float relx3, float rely3)
(x3,y3)
,
using the specified points (x1,y1)
and (x2,y2)
as
Bézier control points.
This is equivalent to:
curveTo(getCurrentX() + rx1, getCurrentY() + ry1, getCurrentX() + rx2, getCurrentY() + ry2, getCurrentX() + rx3, getCurrentY() + ry3)
relx1
- the relative X coordinate of the first Bézier control pointrely1
- the relative Y coordinate of the first Bézier control pointrelx2
- the relative X coordinate of the second Bézier control pointrely2
- the relative Y coordinate of the second Bézier control pointrelx3
- the relative X coordinate of the final end pointrely3
- the relative Y coordinate of the final end pointcurveTo(float, float, float, float, float, float)
public final void curveToSmooth(float x2, float y2, float x3, float y3)
(x3,y3)
,
using the specified point (x2,y2)
as the second
Bézier control point and a first Bézier control
point that is positioned
symmetrically across the current point from the previous curve
control point.
This is equivalent to:
curveTo(getCurrentX() * 2.0f -, getCurrentY() * 2.0f - , x2, y2, x3, y3);
x2
- the X coordinate of the second Bézier control pointy2
- the Y coordinate of the second Bézier control pointx3
- the X coordinate of the final end pointy3
- the Y coordinate of the final end pointcurveTo(float, float, float, float, float, float)
public final void curveToSmoothRel(float relx2, float rely2, float relx3, float rely3)
(rx3,ry3)
,
using the specified relative point (rx2,ry2)
as the second
Bézier control point and a first Bézier control
point that is positioned
symmetrically across the current point from the previous curve
control point.
This is equivalent to:
curveTo(getCurrentX() * 2.0f -, getCurrentY() * 2.0f - , getCurrentX() + x2, getCurrentY() + y2, getCurrentX() + x3, getCurrentY() + y3);
relx2
- the relative X coordinate of the second Bézier control pointrely2
- the relative Y coordinate of the second Bézier control pointrelx3
- the relative X coordinate of the final end pointrely3
- the relative Y coordinate of the final end pointcurveTo(float, float, float, float, float, float)
public final void ovalQuadrantTo(float cx, float cy, float ex, float ey, float tfrom, float tto)
appendOvalQuadrant
for a precise definition of the
path segments to be added, considering that this method uses the
current point of the path as the first pair of coordinates and
a hard-coded prefix of CORNER_ONLY
.
This method is equivalent to (and only slightly faster than):
appendOvalQuadrant(getCurrentX(), getCurrentY(), cx, cy, ex, ey, tfrom, tto, CornerPrefix.CORNER_ONLY);Note that you could define a circle inscribed in the rectangular bounding box from
(x0, y0)
to (x1, y1)
with the
following 4 calls to this method:
Path2D path = new Path2D(); float cx = (x0 + x1) * 0.5f; // center X coordinate of top and bottom float cy = (y0 + y1) * 0.5f; // center Y coordinate of left and right path.moveTo(cx, y0); path.ovalQuadrantTo(x1, y0, x1, cy, 0f, 1f); path.ovalQuadrantTo(x1, y1, cx, y1, 0f, 1f); path.ovalQuadrantTo(x0, y1, x0, cy, 0f, 1f); path.ovalQuadrantTo(x0, y0, cx, y0, 0f, 1f); path.closePath();You could also define a rounded rectangle inscribed in the rectangular bounding box from
(x0, y0)
to (x1, y1)
with a corner
arc radius r
less than half the width and the height with the
following 4 calls to this method:
Path2D path = new Path2D(); float lx = x0 + r; float rx = x1 - r; float ty = y0 + r; float by = y1 - r; path.moveTo(rx, y0); path.ovalQuadrantTo(x1, y0, x1, ty, 0f, 1f); path.lineTo(x1, by); path.ovalQuadrantTo(x1, y1, rx, y1, 0f, 1f); path.lineTo(lx, y1); path.ovalQuadrantTo(x0, y1, x0, by, 0f, 1f); path.lineTo(x0, by); path.ovalQuadrantTo(x0, y0, lx, y0, 0f, 1f); path.closePath();
cx
- the X coordinate of the cornercy
- the Y coordinate of the cornerex
- the X coordinate of the midpoint of the trailing edge
interpolated by the ovaley
- the Y coordinate of the midpoint of the trailing edge
interpolated by the ovaltfrom
- the fraction of the oval section where the curve should starttto
- the fraction of the oval section where the curve should endIllegalPathStateException
- if there is no current point in the pathjava.lang.IllegalArgumentException
- if the tfrom
and tto
values do not satisfy the
required relationship {@code (0 <= tfrom <= tto <= 1).public final void appendOvalQuadrant(float sx, float sy, float cx, float cy, float ex, float ey, float tfrom, float tto, Path2D.CornerPrefix prefix)
(sx, sy)
which is considered to be the midpoint of the edge
leading into the corner of the oval where the oval grazes it,
(cx, cy)
which is considered to be the location of the
corner of the parallelogram in which the oval is inscribed,
and (ex, ey)
which is considered to be the midpoint of the
edge leading away from the corner of the oval where the oval grazes it.
A typical case involves the two segments being equal in length and
at right angles to each other in which case the oval is a quarter of
a circle.
Only the portion of the oval from tfrom
to tto
will be included where 0f
represents the point where the
oval grazes the leading edge, 1f
represents the point where
the oval grazes the trailing edge, and 0.5f
represents the
point on the oval closest to the corner (i.e. the "45 degree" point).
The two values must satisfy the relation
(0 <= tfrom <= tto <= 1)
.
If tfrom
is not 0f
then the caller would most likely
want to use one of the prefix
values that inserts a segment
leading to the initial point (see below).
An initial moveTo
or lineTo
can be added to direct
the path to the starting point of the oval section if
MOVE_THEN_CORNER
or
LINE_THEN_CORNER
are
specified by the prefix argument.
The lineTo
path segment will only be added if the current point
is not already at the indicated location to avoid spurious empty line
segments.
The prefix can be specified as
CORNER_ONLY
if the current point
on the path is known to be at the starting point of the oval section,
but could otherwise produce odd results if the current point is not
appropriate.
Note that you could define a circle inscribed in the rectangular
bounding box from (x0, y0)
to (x1, y1)
with the
following 4 calls to this method:
Path2D path = new Path2D(); float cx = (x0 + x1) * 0.5f; // center X coordinate of top and bottom float cy = (y0 + y1) * 0.5f; // center Y coordinate of left and right path.appendOvalQuadrant(cx, y0, x1, y0, x1, cy, 0f, 1f, MOVE_THEN_CORNER); path.appendOvalQuadrant(x1, cy, x1, y1, cx, y1, 0f, 1f, CORNER_ONLY); path.appendOvalQuadrant(cx, y1, x0, y1, x0, cy, 0f, 1f, CORNER_ONLY); path.appendOvalQuadrant(x0, cy, x0, y0, cx, y0, 0f, 1f, CORNER_ONLY); path.closePath();You could also define a rounded rectangle inscribed in the rectangular bounding box from
(x0, y0)
to (x1, y1)
with a corner
arc radius r
less than half the width and the height with the
following 4 calls to this method:
Path2D path = new Path2D(); float lx = x0 + r; float rx = x1 - r; float ty = y0 + r; float by = y1 - r; path.appendOvalQuadrant(rx, y0, x1, y0, x1, ty, 0f, 1f, MOVE_THEN_CORNER); path.appendOvalQuadrant(x1, by, x1, y1, rx, y1, 0f, 1f, LINE_THEN_CORNER); path.appendOvalQuadrant(lx, y1, x0, y1, x0, by, 0f, 1f, LINE_THEN_CORNER); path.appendOvalQuadrant(x0, by, x0, y0, lx, y0, 0f, 1f, LINE_THEN_CORNER); path.closePath();
sx
- the X coordinate of the midpoint of the leading edge
interpolated by the ovalsy
- the Y coordinate of the midpoint of the leading edge
interpolated by the ovalcx
- the X coordinate of the cornercy
- the Y coordinate of the cornerex
- the X coordinate of the midpoint of the trailing edge
interpolated by the ovaley
- the Y coordinate of the midpoint of the trailing edge
interpolated by the ovaltfrom
- the fraction of the oval section where the curve should starttto
- the fraction of the oval section where the curve should endprefix
- the specification of what additional path segments should
be appended to lead the current path to the starting pointIllegalPathStateException
- if there is no current point in the path and the prefix is
not CornerPrevix.MOVE_THEN_CORNER MOVE_THEN_CORNER
.java.lang.IllegalArgumentException
- if the tfrom
and tto
values do not satisfy the
required relationship {@code (0 <= tfrom <= tto <= 1).public void arcTo(float radiusx, float radiusy, float xAxisRotation, boolean largeArcFlag, boolean sweepFlag, float x, float y)
xAxisRotation
specified in radians.
radiusx
and radiusy
unless that ellipse is too small to bridge the gap from the current
point to the specified destination point in which case a larger
ellipse with the same ratio of dimensions will be substituted instead.
largeArcFlag
is true, then the ellipse will sweep
the longer way around the ellipse that meets these criteria.
sweepFlag
is true, then the ellipse will sweep
clockwise around the ellipse that meets these criteria.
Note: This method adheres to the definition of an elliptical arc path segment from the SVG spec:
http://www.w3.org/TR/SVG/paths.html#PathDataEllipticalArcCommands
radiusx
- the X radius of the tilted ellipseradiusy
- the Y radius of the tilted ellipsexAxisRotation
- the angle of tilt of the ellipselargeArcFlag
- true iff the path will sweep the long way around
the ellipsesweepFlag
- true iff the path will sweep clockwise around
the ellipsex
- the destination X coordinatey
- the destination Y coordinateIllegalPathStateException
- if there is no current point in the pathpublic void arcToRel(float radiusx, float radiusy, float xAxisRotation, boolean largeArcFlag, boolean sweepFlag, float relx, float rely)
arcTo(radiusX, radiusY, xAxisRotation, largeArcFlag, sweepFlag, getCurrentX() + rx, getCurrentY() + ry);
radiusx
- the X radius of the tilted ellipseradiusy
- the Y radius of the tilted ellipsexAxisRotation
- the angle of tilt of the ellipselargeArcFlag
- true iff the path will sweep the long way around
the ellipsesweepFlag
- true iff the path will sweep clockwise around
the ellipserelx
- the relative destination relative X coordinaterely
- the relative destination relative Y coordinateIllegalPathStateException
- if there is no current point in the patharcTo(float, float, float, boolean, boolean, float, float)
int pointCrossings(float px, float py)
int rectCrossings(float rxmin, float rymin, float rxmax, float rymax)
public final void append(PathIterator pi, boolean connect)
public final void transform(BaseTransform tx)
public final RectBounds getBounds()
RectBounds
is the smallest bounding box that encloses
the Shape
, only that the Shape
lies
entirely within the indicated RectBounds
.public final int getNumCommands()
public final byte[] getCommandsNoClone()
public final float[] getFloatCoordsNoClone()
public PathIterator getPathIterator(BaseTransform tx)
Shape
boundary and provides access to the geometry of the
Shape
outline. If an optional BaseTransform
is specified, the coordinates returned in the iteration are
transformed accordingly.
Each call to this method returns a fresh PathIterator
object that traverses the geometry of the Shape
object
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 the Path2D
class does not
guarantee that modifications to the geometry of this
Path2D
object do not affect any iterations of
that geometry that are already in process.
getPathIterator
in class Shape
tx
- an optional BaseTransform
to be applied to the
coordinates as they are returned in the iteration, or
null
if untransformed coordinates are desiredPathIterator
object, which independently
traverses the geometry of the Shape
.public final void closePath()
moveTo
. If the path is already
closed then this method has no effect.closePath
in interface PathConsumer2D
public void pathDone()
pathDone
in interface PathConsumer2D
public final void append(Shape s, boolean connect)
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.s
- the Shape
whose geometry is appended
to this pathconnect
- a boolean to control whether or not to turn an initial
moveTo
segment into a lineTo
segment
to connect the new geometry to the existing pathpublic final void appendSVGPath(java.lang.String svgpath)
String
argument in the format of an SVG path.
The specification of the grammar of the language for an SVG path
is specified on the W3C web page:
http://www.w3.org/TR/SVG/paths.html#PathDataBNFand the interpretation of the various elements in the format is specified on the W3C web page:
http://www.w3.org/TR/SVG/paths.html#PathData
svgpath
- the String
object containing the SVG style
definition of the geometry to be apppendedjava.lang.IllegalArgumentException
- if svgpath
does not match the indicated SVG path grammarIllegalPathStateException
- if there is no current point in the pathpublic final int getWindingRule()
WIND_EVEN_ODD
,
WIND_NON_ZERO
,
setWindingRule(int)
public final void setWindingRule(int rule)
rule
- an integer representing the specified
winding rulejava.lang.IllegalArgumentException
- if
rule
is not either
WIND_EVEN_ODD
or
WIND_NON_ZERO
getWindingRule()
public final Point2D getCurrentPoint()
Point2D
object.Point2D
object containing the ending coordinates of
the path or null
if there are no points in the path.public final float getCurrentX()
public final float getCurrentY()
public final void reset()
public final Shape createTransformedShape(BaseTransform tx)
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
tx
- the BaseTransform
used to transform a
new Shape
.Shape
, transformed with the specified
BaseTransform
.public Path2D copy()
Shape
Shape
instance.public boolean equals(java.lang.Object obj)
Path2D
is identical to the geometry of this object
but is expressed in a different way. This method will only return
true when the internal representation of this object is exactly the
same as that of the given object.equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public static boolean contains(PathIterator pi, float x, float y)
PathIterator
.
This method provides a basic facility for implementors of
the Shape
interface to implement support for the
Shape#contains(double, double)
method.
pi
- the specified PathIterator
x
- the specified X coordinatey
- the specified Y coordinatetrue
if the specified coordinates are inside the
specified PathIterator
; false
otherwisepublic static boolean contains(PathIterator pi, Point2D p)
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 the
Shape.contains(Point2D)
method.
pi
- the specified PathIterator
p
- the specified Point2D
true
if the specified coordinates are inside the
specified PathIterator
; false
otherwisepublic final boolean contains(float x, float y)
Shape
.public final boolean contains(Point2D p)
Point2D
is inside the boundary
of the Shape
.public static boolean contains(PathIterator pi, float x, float y, float w, float h)
PathIterator
.
This method provides a basic facility for implementors of
the Shape
interface to implement support for the
Shape#contains(double, double, double, double)
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.
pi
- the specified PathIterator
x
- the specified X coordinatey
- the specified Y coordinatew
- the width of the specified rectangular areah
- the height of the specified rectangular areatrue
if the specified PathIterator
contains
the specified rectangluar area; false
otherwise.public final boolean contains(float x, float y, float w, float h)
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:
intersect
method returns true
and
Shape
entirely contains the rectangular area are
prohibitively expensive.
Shapes
this method might
return false
even though the Shape
contains
the rectangular area.
The Area
class performs
more accurate geometric computations than most
Shape
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.
contains
in class Shape
x
- the X coordinate of the upper-left corner
of the specified rectangular areay
- the Y coordinate of the upper-left corner
of the specified rectangular areaw
- the width of the specified rectangular areah
- the height of the specified rectangular areatrue
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.Shape.intersects(float, float, float, float)
public static boolean intersects(PathIterator pi, float x, float y, float w, float h)
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)
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.
pi
- the specified PathIterator
x
- the specified X coordinatey
- the specified Y coordinatew
- the width of the specified rectangular coordinatesh
- the height of the specified rectangular coordinatestrue
if the specified PathIterator
and
the interior of the specified set of rectangular
coordinates intersect each other; false
otherwise.public final boolean intersects(float x, float y, float w, float h)
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:
Shape
intersect, but
Shapes
this method might
return true
even though the rectangular area 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.
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.
intersects
in class Shape
x
- the X coordinate of the upper-left corner
of the specified rectangular areay
- the Y coordinate of the upper-left corner
of the specified rectangular areaw
- the width of the specified rectangular areah
- the height of the specified rectangular areatrue
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.public PathIterator getPathIterator(BaseTransform tx, float flatness)
Shape
boundary and provides access to a flattened view of the
Shape
outline geometry.
Only SEG_MOVETO, SEG_LINETO, and SEG_CLOSE point types are returned by the iterator.
If an optional BaseTransform
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 this
Path2D
object do not affect any iterations of
that geometry that are already in process.
getPathIterator
in class Shape
tx
- an optional BaseTransform
to be applied to the
coordinates as they are returned in the iteration, or
null
if untransformed coordinates are desiredflatness
- the maximum distance that the line segments used to
approximate the curved segments are allowed to deviate
from any point on the original curvePathIterator
that independently traverses
a flattened view of the geometry of the Shape
.static byte[] copyOf(byte[] original, int newLength)
static float[] copyOf(float[] original, int newLength)
public void setTo(Path2D otherPath)