Class Path
- All Implemented Interfaces:
PathConsumer,Shape,Shape
- 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.
Note: Path also implements AWT Shape for convenience, but only a few methods are actually implemented.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassLow-level access to path elements.static @interfaceSegment constants correspond to each drawing verb type in path; for instance, if path contains only lines, only the Line bit is set. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intCounter-clockwise direction for adding closed contours, assumes the origin is top left, y-down.static final intClockwise direction for adding closed contours, assumes the origin is top left, y-down.static final intstatic final intstatic final intstatic final bytePrimitive commands of path segments.static final bytePrimitive commands of path segments.static final bytestatic final bytePrimitive commands of path segments.static final bytePrimitive commands of path segments.static final bytePrimitive commands of path segments.static final intThe 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 intThe 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. -
Constructor Summary
ConstructorsConstructorDescriptionPath()Creates an empty Path with a default fill rule ofWIND_NON_ZERO.Creates a copy of an existing Path object. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Resets the path to its initial state, clears points and verbs and sets fill rule toWIND_NON_ZERO.voidclose()Closes the current contour by drawing a straight line back to the point of the lastmoveTo(float, float).booleancontains(double x, double y) booleancontains(double x, double y, double w, double h) booleanbooleanintReturns the number of points (x,y pairs) in path.intReturns the number of verbs added to path.voidcubicTo(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.voidcubicToRel(float dx1, float dy1, float dx2, float dy2, float dx3, float dy3) Relative version of "cubic to".voiddone()Called after the last segment of the last sub-path when the iteration of the path segments is completely done.booleanlongReturns the estimated byte size of path object in memory.voidforEach(@NonNull PathConsumer action) Iterates the Path and feeds the given consumer.@NonNull RectanglevoidHelper method togetBounds(), stores the result to dst.@NonNull Rectangle2DReturns minimum and maximum axes values of coordinates.@NonNull PathIterator@NonNull PathIteratorgetPathIterator(@Nullable AffineTransform at) @NonNull PathIteratorgetPathIterator(@Nullable AffineTransform at, double flatness) intReturns a mask, where each set bit corresponds to a Segment constant if path contains one or more verbs of that type.intReturns the rule used to fill path.inthashCode()booleanintersects(double x, double y, double w, double h) booleanbooleanisEmpty()Returns true if path has no point and verb.booleanisFinite()Returns false for any coordinate value of infinity or NaN.voidlineTo(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).voidlineToRel(float dx, float dy) Relative version of "line to".voidMoves contents from other path into this path.voidmoveTo(float x, float y) Adds a point to the path by moving to the specified point(x,y).voidmoveToRel(float dx, float dy) Relative version of "move to".voidquadTo(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.voidquadToRel(float dx1, float dy1, float dx2, float dy2) Relative version of "quad to".voidrelease()Resets the path to its initial state, clears points and verbs and sets fill rule toWIND_NON_ZERO.voidreset()Resets the path to its initial state, clears points and verbs and sets fill rule toWIND_NON_ZERO.voidCreates a copy of an existing Path object.voidsetWindingRule(int rule) Sets the rule used to fill path.voidTransforms verb array, Point array, and weight by matrix.voidTransforms verb array, point array, and weight by matrix.voidTrims the internal storage to the current size.voidUpdates internal bounds so that subsequent calls togetBounds()are instantaneous.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface icyllis.arc3d.sketch.PathConsumer
cubicTo, quadTo
-
Field Details
-
WIND_EVEN_ODD
public static final int WIND_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:
-
WIND_NON_ZERO
public static final int WIND_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:
-
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:
-
VERB_DONE
@Internal public static final byte VERB_DONE- 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 ofWIND_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
-
getWindingRule
public int getWindingRule()Returns the rule used to fill path.- Specified by:
getWindingRulein interfaceShape- Returns:
- current fill rule
- See Also:
-
setWindingRule
public void setWindingRule(int rule) Sets the rule used to fill path. rule is eitherWIND_NON_ZEROorWIND_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 toWIND_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 toWIND_NON_ZERO.Preserves internal storage if it's unique, otherwise allocates new storage with the same size.
-
release
public void release()Resets the path to its initial state, clears points and verbs and sets fill rule toWIND_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:
moveToin 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:
lineToin 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:
quadToin 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:
cubicToin 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:
closein interfacePathConsumer
-
done
public void done()Description copied from interface:PathConsumerCalled after the last segment of the last sub-path when the iteration of the path segments is completely done.- Specified by:
donein 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
-
getBounds2D
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.
- Specified by:
getBounds2Din interfaceShape- Returns:
- bounds of all points
- See Also:
-
getBounds
Helper method togetBounds(), stores the result to dst. -
contains
public boolean contains(double x, double y) -
contains
-
contains
public boolean contains(double x, double y, double w, double h) -
contains
-
intersects
public boolean intersects(double x, double y, double w, double h) - Specified by:
intersectsin interfaceShape
-
intersects
- Specified by:
intersectsin interfaceShape
-
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:
getPathIteratorin interfaceShape
-
getPathIterator
- Specified by:
getPathIteratorin interfaceShape
-
getPathIterator
- Specified by:
getPathIteratorin interfaceShape
-
forEach
Iterates the Path and feeds the given consumer. -
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
-