Class Path
- All Implemented Interfaces:
PathConsumer
,PathIterable
- Direct Known Subclasses:
Path
Path
object contains mutable path elements.
Path may be empty, or contain one or more verbs that outline a figure. Path always starts with a move verb to a Cartesian coordinate, and may be followed by additional verbs that add lines or curves. Adding a close verb makes the geometry into a continuous loop, a closed contour. Path may contain any number of contours, each beginning with a move verb.
Path contours may contain only a move verb, or may also contain lines, quadratic Béziers, and cubic Béziers. Path contours may be open or closed.
When used to draw a filled area, Path describes whether the fill is inside or outside the geometry. Path also describes the winding rule used to fill overlapping contours.
Note: Path lazily computes metrics likes bounds and convexity. Call
updateBoundsCache()
to make path thread safe.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic @interface
class
Low-level access to path elements.static @interface
Segment constants correspond to each drawing verb type in path; for instance, if path contains only lines, only the Line bit is set. -
Field Summary
Modifier and TypeFieldDescriptionstatic final int
static final int
static final int
Counter-clockwise direction for adding closed contours, assumes the origin is top left, y-down.static final int
Clockwise direction for adding closed contours, assumes the origin is top left, y-down.static final int
The fill rule constant for specifying an even-odd rule for determining the interior of a path.
The even-odd rule specifies that a point lies inside the path if a ray drawn in any direction from that point to infinity is crossed by path segments an odd number of times.static final int
The fill rule constant for specifying a non-zero rule for determining the interior of a path.
The non-zero rule specifies that a point lies inside the path if a ray drawn in any direction from that point to infinity is crossed by path segments a different number of times in the counter-clockwise direction than the clockwise direction.static final int
static final int
static final int
static final byte
Primitive commands of path segments.static final byte
Primitive commands of path segments.static final byte
Primitive commands of path segments.static final byte
Primitive commands of path segments.static final byte
Primitive commands of path segments. -
Constructor Summary
ConstructorDescriptionPath()
Creates an empty Path with a default fill rule ofFILL_NON_ZERO
.Creates a copy of an existing Path object. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Resets the path to its initial state, clears points and verbs and sets fill rule toFILL_NON_ZERO
.void
close()
Closes the current contour by drawing a straight line back to the point of the lastmoveTo(float, float)
.int
Returns the number of points (x,y pairs) in path.int
Returns the number of verbs added to path.void
cubicTo
(float x1, float y1, float x2, float y2, float x3, float y3) Adds a curved segment, defined by three new points, to the path by drawing a cubic Bézier curve that intersects both the current point and the specified point(x3,y3)
, using the specified points(x1,y1)
and(x2,y2)
as cubic control points.void
cubicToRel
(float dx1, float dy1, float dx2, float dy2, float dx3, float dy3) Relative version of "cubic to".void
done()
Called after the last segment of the last sub-path when the iteration of the path segments is completely done.boolean
long
Returns the estimated byte size of path object in memory.void
forEach
(PathConsumer action) Iterates the Path and feeds the given consumer.Returns minimum and maximum axes values of coordinates.void
Helper method togetBounds()
, stores the result to dst.int
Returns the rule used to fill path.int
Returns a mask, where each set bit corresponds to a Segment constant if path contains one or more verbs of that type.int
hashCode()
boolean
isEmpty()
Returns true if path has no point and verb.boolean
isFinite()
Returns false for any coordinate value of infinity or NaN.void
lineTo
(float x, float y) Adds a point to the path by drawing a straight line from the current point to the new specified point(x,y)
.void
lineToRel
(float dx, float dy) Relative version of "line to".void
Moves contents from other path into this path.void
moveTo
(float x, float y) Adds a point to the path by moving to the specified point(x,y)
.void
moveToRel
(float dx, float dy) Relative version of "move to".void
quadTo
(float x1, float y1, float x2, float y2) Adds a curved segment, defined by two new points, to the path by drawing a quadratic Bézier curve that intersects both the current point and the specified point(x2,y2)
, using the specified point(x1,y1)
as a quadratic control point.void
quadToRel
(float dx1, float dy1, float dx2, float dy2) Relative version of "quad to".void
recycle()
Resets the path to its initial state, clears points and verbs and sets fill rule toFILL_NON_ZERO
.void
reset()
Resets the path to its initial state, clears points and verbs and sets fill rule toFILL_NON_ZERO
.void
Creates a copy of an existing Path object.void
setFillRule
(int rule) Sets the rule used to fill path.void
Transforms verb array, Point array, and weight by matrix.void
Transforms verb array, point array, and weight by matrix.void
Trims the internal storage to the current size.void
Updates internal bounds so that subsequent calls togetBounds()
are instantaneous.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface icyllis.arc3d.core.PathConsumer
cubicTo, quadTo
-
Field Details
-
FILL_NON_ZERO
public static final int FILL_NON_ZEROThe fill rule constant for specifying a non-zero rule for determining the interior of a path.
The non-zero rule specifies that a point lies inside the path if a ray drawn in any direction from that point to infinity is crossed by path segments a different number of times in the counter-clockwise direction than the clockwise direction.- See Also:
-
FILL_EVEN_ODD
public static final int FILL_EVEN_ODDThe fill rule constant for specifying an even-odd rule for determining the interior of a path.
The even-odd rule specifies that a point lies inside the path if a ray drawn in any direction from that point to infinity is crossed by path segments an odd number of times.- See Also:
-
VERB_MOVE
public static final byte VERB_MOVEPrimitive commands of path segments.- See Also:
-
VERB_LINE
public static final byte VERB_LINEPrimitive commands of path segments.- See Also:
-
VERB_QUAD
public static final byte VERB_QUADPrimitive commands of path segments.- See Also:
-
VERB_CUBIC
public static final byte VERB_CUBICPrimitive commands of path segments.- See Also:
-
VERB_CLOSE
public static final byte VERB_CLOSEPrimitive commands of path segments.- See Also:
-
DIRECTION_CW
public static final int DIRECTION_CWClockwise direction for adding closed contours, assumes the origin is top left, y-down.- See Also:
-
DIRECTION_CCW
public static final int DIRECTION_CCWCounter-clockwise direction for adding closed contours, assumes the origin is top left, y-down.- See Also:
-
SEGMENT_LINE
public static final int SEGMENT_LINE- See Also:
-
SEGMENT_QUAD
public static final int SEGMENT_QUAD- See Also:
-
SEGMENT_CUBIC
public static final int SEGMENT_CUBIC- See Also:
-
APPROXIMATE_ARC_WITH_CUBICS
public static final int APPROXIMATE_ARC_WITH_CUBICS- See Also:
-
APPROXIMATE_CONIC_WITH_QUADS
public static final int APPROXIMATE_CONIC_WITH_QUADS- See Also:
-
-
Constructor Details
-
Path
public Path()Creates an empty Path with a default fill rule ofFILL_NON_ZERO
. -
Path
Creates a copy of an existing Path object.Internally, the two paths share reference values. The underlying verb array, coordinate array and weights are copied when modified.
-
-
Method Details
-
getFillRule
public int getFillRule()Returns the rule used to fill path.- Specified by:
getFillRule
in interfacePathIterable
- Returns:
- current fill rule
- See Also:
-
setFillRule
public void setFillRule(int rule) Sets the rule used to fill path. rule is eitherFILL_NON_ZERO
orFILL_EVEN_ODD
. -
set
Creates a copy of an existing Path object.Internally, the two paths share reference values. The underlying verb array, coordinate array and weights are copied when modified.
-
move
Moves contents from other path into this path. This is equivalent to callthis.set(other)
and thenother.recycle()
. -
reset
public void reset()Resets the path to its initial state, clears points and verbs and sets fill rule toFILL_NON_ZERO
.Preserves internal storage if it's unique, otherwise discards.
-
clear
public void clear()Resets the path to its initial state, clears points and verbs and sets fill rule toFILL_NON_ZERO
.Preserves internal storage if it's unique, otherwise allocates new storage with the same size.
-
recycle
public void recycle()Resets the path to its initial state, clears points and verbs and sets fill rule toFILL_NON_ZERO
.This explicitly discards the internal storage, it is recommended to call when the path object will be no longer used.
-
trimToSize
public void trimToSize()Trims the internal storage to the current size. This operation can minimize memory usage, seeestimatedByteSize()
. -
isEmpty
public boolean isEmpty()- Returns:
- true if the path contains no verb
-
isFinite
public boolean isFinite()Returns false for any coordinate value of infinity or NaN.- Returns:
- true if all point coordinates are finite
-
moveTo
public void moveTo(float x, float y) Adds a point to the path by moving to the specified point(x,y)
. A new contour begins at(x,y)
.- Specified by:
moveTo
in interfacePathConsumer
- Parameters:
x
- the specified X coordinatey
- the specified Y coordinate
-
moveToRel
public void moveToRel(float dx, float dy) Relative version of "move to".- Parameters:
dx
- offset from last point to contour start on x-axisdy
- offset from last point to contour start on y-axis- Throws:
IllegalStateException
- Path is empty
-
lineTo
public void lineTo(float x, float y) Adds a point to the path by drawing a straight line from the current point to the new specified point(x,y)
.- Specified by:
lineTo
in interfacePathConsumer
- Parameters:
x
- the specified X coordinatey
- the specified Y coordinate- Throws:
IllegalStateException
- No contour
-
lineToRel
public void lineToRel(float dx, float dy) Relative version of "line to".Adds a line from the last point to the specified vector (dx, dy).
- Parameters:
dx
- the offset from last point to line end on x-axisdy
- the offset from last point to line end on y-axis
-
quadTo
public void quadTo(float x1, float y1, float x2, float y2) Adds a curved segment, defined by two new points, to the path by drawing a quadratic Bézier curve that intersects both the current point and the specified point(x2,y2)
, using the specified point(x1,y1)
as a quadratic control point.- Specified by:
quadTo
in interfacePathConsumer
- Parameters:
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 point
-
quadToRel
public void quadToRel(float dx1, float dy1, float dx2, float dy2) Relative version of "quad to".Adds quad from last point towards vector (dx1, dy1), to vector (dx2, dy2).
- Parameters:
dx1
- offset from last point to quad control on x-axisdy1
- offset from last point to quad control on y-axisdx2
- offset from last point to quad end on x-axisdy2
- offset from last point to quad end on y-axis
-
cubicTo
public void cubicTo(float x1, float y1, float x2, float y2, float x3, float y3) Adds a curved segment, defined by three new points, to the path by drawing a cubic Bézier curve that intersects both the current point and the specified point(x3,y3)
, using the specified points(x1,y1)
and(x2,y2)
as cubic control points.- Specified by:
cubicTo
in interfacePathConsumer
- Parameters:
x1
- the X coordinate of the first cubic control pointy1
- the Y coordinate of the first cubic control pointx2
- the X coordinate of the second cubic control pointy2
- the Y coordinate of the second cubic control pointx3
- the X coordinate of the final end pointy3
- the Y coordinate of the final end point
-
cubicToRel
public void cubicToRel(float dx1, float dy1, float dx2, float dy2, float dx3, float dy3) Relative version of "cubic to".Adds cubic from last point towards vector (dx1, dy1), vector (dx2, dy2), to vector (dx3, dy3).
- Parameters:
dx1
- offset from last point to first cubic control on x-axisdy1
- offset from last point to first cubic control on y-axisdx2
- offset from last point to second cubic control on x-axisdy2
- offset from last point to second cubic control on y-axisdx3
- offset from last point to cubic end on x-axisdy3
- offset from last point to cubic end on y-axis
-
close
public void close()Closes the current contour by drawing a straight line back to the point of the lastmoveTo(float, float)
. If the path is already closed then this method has no effect.- Specified by:
close
in interfacePathConsumer
-
done
public void done()Description copied from interface:PathConsumer
Called after the last segment of the last sub-path when the iteration of the path segments is completely done.- Specified by:
done
in interfacePathConsumer
-
transform
Transforms verb array, Point array, and weight by matrix. transform may change verbs and increase their number. Path is replaced by transformed data.- Parameters:
matrix
- Matrix to apply to Path
-
transform
Transforms verb array, point array, and weight by matrix. transform may change verbs and increase their number. Transformed Path replaces dst; if dst is null, original data is replaced.- Parameters:
matrix
- Matrix to apply to Pathdst
- overwritten, transformed copy of Path; may be null
-
countVerbs
public int countVerbs()Returns the number of verbs added to path.- Returns:
- size of verb list
-
countPoints
public int countPoints()Returns the number of points (x,y pairs) in path.- Returns:
- size of point list
-
getBounds
Returns minimum and maximum axes values of coordinates. Returns empty if path contains no points or is not finite.Returned bounds includes all points added to path, including points associated with MOVE that define empty contours.
This method returns a cached result; it is recalculated only after this path is altered.
- Returns:
- bounds of all points, read-only
- See Also:
-
getBounds
Helper method togetBounds()
, stores the result to dst. -
updateBoundsCache
public void updateBoundsCache()Updates internal bounds so that subsequent calls togetBounds()
are instantaneous. Unaltered copies of path may also access cached bounds throughgetBounds()
.For now, identical to calling
getBounds()
and ignoring the returned value.Call to prepare path subsequently drawn from multiple threads, to avoid a race condition where each draw separately computes the bounds.
-
getSegmentMask
public int getSegmentMask()Returns a mask, where each set bit corresponds to a Segment constant if path contains one or more verbs of that type.This method returns a cached result; it is very fast.
- Returns:
- Segment bits or zero
-
getPathIterator
- Specified by:
getPathIterator
in interfacePathIterable
-
forEach
Iterates the Path and feeds the given consumer.- Specified by:
forEach
in interfacePathIterable
-
estimatedByteSize
public long estimatedByteSize()Returns the estimated byte size of path object in memory. This method does not take into account whether internal storage is shared or not. -
hashCode
public int hashCode() -
equals
-