Path

Path contain geometry. 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 beziers, conics, and cubic beziers. 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.

Internally, Path lazily computes metrics likes bounds and convexity. Call .updateBoundsCache to make Path thread safe.

Constructors

Link copied to clipboard
constructor()

Constructs an empty Path. By default, Path has no verbs, no Point, and no weights. FillMode is set to PathFillMode.WINDING.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

Returns the approximate byte size of the Path in memory.

Link copied to clipboard

Returns array of two points if Path contains only one line; Verb array has two entries: PathVerb.MOVE, PathVerb.LINE. Returns null if Path is not one line.

Link copied to clipboard

Returns minimum and maximum axes values of Point array.

Link copied to clipboard
Link copied to clipboard

Returns a non-zero, globally unique value. A different value is returned if verb array, Point array, or conic weight changes.

Link copied to clipboard
expect open val isClosed: Boolean

Check if underlying resource is closed.

Link copied to clipboard

Returns true if the path is convex. If necessary, it will first compute the convexity.

Link copied to clipboard

Returns if Path is empty.

Link copied to clipboard

Returns true for finite Point array values between negative Float.MIN_VALUE and positive Float.MAX_VALUE. Returns false for any Point array value of Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY, or Float.NaN.

Link copied to clipboard

Returns if contour is closed.

Link copied to clipboard
val isOval: Rect?

Returns oval bounds if this path is recognized as an oval or circle.

Link copied to clipboard
val isRect: Rect?

Returns Rect if Path is equivalent to Rect when filled.

Link copied to clipboard

Returns RRect if this path is recognized as an oval, circle or RRect.

Link copied to clipboard

Returns if Path data is consistent. Corrupt Path data is detected if internal values are out of range or internal storage does not match array dimensions.

Link copied to clipboard

Specifies whether Path is volatile; whether it will be altered or discarded by the caller after it is drawn. Path by default have volatile set false, allowing SkBaseDevice to attach a cache of data which speeds repeated drawing.

Link copied to clipboard

Returns last point on Path in lastPt. Returns null if Point array is empty.

Link copied to clipboard

Returns all points in Path.

Link copied to clipboard

Returns the number of points in Path. Point count is initially zero.

Link copied to clipboard

Returns a mask, where each set bit corresponds to a SegmentMask constant if Path contains one or more verbs of that type.

Link copied to clipboard
Link copied to clipboard

Returns the number of verbs: PathVerb.MOVE, PathVerb.LINE, PathVerb.QUAD, PathVerb.CONIC, PathVerb.CUBIC, and PathVerb.CLOSE; added to Path.

Functions

Link copied to clipboard
fun addArc(oval: Rect, startAngle: Float, sweepAngle: Float): Path

Appends arc to Path, as the start of new contour. Arc added is part of ellipse bounded by oval, from startAngle through sweepAngle. Both startAngle and sweepAngle are measured in degrees, where zero degrees is aligned with the positive x-axis, and positive sweeps extends arc clockwise.

Link copied to clipboard
fun addCircle(x: Float, y: Float, radius: Float, dir: PathDirection = PathDirection.CLOCKWISE): Path

Adds circle centered at (x, y) of size radius to Path, appending PathVerb.MOVE, four PathVerb.CONIC, and PathVerb.CLOSE. Circle begins at: (x + radius, y)

Link copied to clipboard
fun addOval(oval: Rect, dir: PathDirection = PathDirection.CLOCKWISE, start: Int = 1): Path

Adds oval to path, appending PathVerb.MOVE, four PathVerb.CONIC, and PathVerb.CLOSE.

Link copied to clipboard
fun addPath(src: Path?, extend: Boolean = false): Path

Appends src to Path.

fun addPath(src: Path?, matrix: Matrix33, extend: Boolean = false): Path

Appends src to Path, transformed by matrix. Transformed curves may have different verbs, Point, and conic weights.

fun addPath(src: Path?, dx: Float, dy: Float, extend: Boolean = false): Path

Appends src to Path, offset by (dx, dy).

Link copied to clipboard
fun addPoly(pts: Array<Point>, close: Boolean): Path

Adds contour created from line array, adding (pts.length - 1) line segments. Contour added starts at pts0, then adds a line for every additional Point in pts array. If close is true, appends PathVerb.CLOSE to Path, connecting ptspts.length - 1 and pts0.

fun addPoly(pts: FloatArray, close: Boolean): Path

Adds contour created from line array, adding (pts.length / 2 - 1) line segments. Contour added starts at (pts0, pts1), then adds a line for every additional pair of floats in pts array. If close is true, appends PathVerb.CLOSE to Path, connecting (ptscount - 2, ptscount - 1) and (pts0, pts1).

Link copied to clipboard
fun addRect(rect: Rect, dir: PathDirection = PathDirection.CLOCKWISE, start: Int = 0): Path

Adds Rect to Path, appending PathVerb.MOVE, three PathVerb.LINE, and PathVerb.CLOSE, starting with top-left corner of Rect; followed by top-right, bottom-right, and bottom-left if dir is PathDirection.CLOCKWISE; or followed by bottom-left, bottom-right, and top-right if dir is PathDirection.COUNTER_CLOCKWISE.

Link copied to clipboard
fun addRRect(rrect: RRect, dir: PathDirection = PathDirection.CLOCKWISE, start: Int = 6): Path

Adds rrect to Path, creating a new closed contour. RRect starts at top-left of the lower-left corner and winds clockwise.

Link copied to clipboard
fun arcTo(oval: Rect, startAngle: Float, sweepAngle: Float, forceMoveTo: Boolean): Path

Appends arc to Path. Arc added is part of ellipse bounded by oval, from startAngle through sweepAngle. Both startAngle and sweepAngle are measured in degrees, where zero degrees is aligned with the positive x-axis, and positive sweeps extends arc clockwise.

Link copied to clipboard
expect open fun close()

Free underlying native resource, peer is useless afterwards.

Link copied to clipboard

Appends PathVerb.CLOSE to Path. A closed contour connects the first and last Point with line, forming a continuous loop. Open and closed contour draw the same with PaintMode.FILL. With PaintMode.STROKE, open contour draws PaintStrokeCap at contour start and end; closed contour draws PaintStrokeJoin at contour start and end.

Link copied to clipboard

Returns minimum and maximum axes values of the lines and curves in Path. Returns (0, 0, 0, 0) if Path contains no points. Returned bounds width and height may be larger or smaller than area affected when Path is drawn.

Link copied to clipboard
fun conicTo(p1: Point, p2: Point, w: Float): Path

Adds conic from last point towards Point p1, to Point p2, weighted by w.

fun conicTo(x1: Float, y1: Float, x2: Float, y2: Float, w: Float): Path

Adds conic from last point towards (x1, y1), to (x2, y2), weighted by w.

Link copied to clipboard

Returns true if rect is contained by Path. May return false when rect is contained by Path.

Link copied to clipboard
operator fun contains(p: Point): Boolean

Returns true if the point is contained by Path, taking into account PathFillMode.

Returns true if the point (x, y) is contained by Path, taking into account PathFillMode.

Link copied to clipboard
fun cubicTo(p1: Point, p2: Point, p3: Point): Path

Adds cubic from last point towards Point p1, then towards Point p2, ending at Point p3. If Path is empty, or last PathVerb is PathVerb.CLOSE, last point is set to (0, 0) before adding cubic.

fun cubicTo(x1: Float, y1: Float, x2: Float, y2: Float, x3: Float, y3: Float): Path

Adds cubic from last point towards (x1, y1), then towards (x2, y2), ending at (x3, y3). If Path is empty, or last PathVerb is PathVerb.CLOSE, last point is set to (0, 0) before adding cubic.

Link copied to clipboard
fun dump(): Path

Writes text representation of Path to standard output. The representation may be directly compiled as C++ code. Floating point values are written with limited precision; it may not be possible to reconstruct original Path from output.

Link copied to clipboard
fun dumpHex(): Path

Writes text representation of Path to standard output. The representation may be directly compiled as C++ code. Floating point values are written in hexadecimal to preserve their exact bit pattern. The output reconstructs the original Path.

Link copied to clipboard
fun ellipticalArcTo(r: Point, xAxisRotate: Float, arc: PathEllipseArc, direction: PathDirection, xy: Point): Path

Appends arc to Path. Arc is implemented by one or more conic weighted to describe part of oval with radii (r.fX, r.fY) rotated by xAxisRotate degrees. Arc curves from last Path Point to (xy.fX, xy.fY), choosing one of four possible routes: clockwise or counterclockwise, and smaller or larger.

fun ellipticalArcTo(rx: Float, ry: Float, xAxisRotate: Float, arc: PathEllipseArc, direction: PathDirection, x: Float, y: Float): Path

Appends arc to Path. Arc is implemented by one or more conics weighted to describe part of oval with radii (rx, ry) rotated by xAxisRotate degrees. Arc curves from last Path Point to (x, y), choosing one of four possible routes: clockwise or counterclockwise, and smaller or larger.

Link copied to clipboard
fun getPoint(index: Int): Point

Returns Point at index in Point array. Valid range for index is 0 to countPoints() - 1.

Link copied to clipboard
fun getPoints(points: Array<Point?>?, max: Int): Int

Returns number of points in Path. Up to max points are copied.

Link copied to clipboard
fun getVerbs(verbs: Array<PathVerb?>?, max: Int): Int

Returns the number of verbs in the path. Up to max verbs are copied.

Link copied to clipboard
fun incReserve(extraPtCount: Int): Path

Grows Path verb array and Point array to contain extraPtCount additional Point. May improve performance and use less memory by reducing the number and size of allocations when creating Path.

Link copied to clipboard
fun isInterpolatable(compare: Path?): Boolean

Returns true if Path contain equal verbs and equal weights. If Path contain one or more conics, the weights must match.

Link copied to clipboard
open operator override fun iterator(): PathSegmentIterator
Link copied to clipboard
fun lineTo(p: Point): Path

Adds line from last point to Point p. If Path is empty, or last PathVerb is PathVerb.CLOSE, last point is set to (0, 0) before adding line.

fun lineTo(x: Float, y: Float): Path

Adds line from last point to (x, y). If Path is empty, or last Verb is PathVerb.CLOSE, last point is set to (0, 0) before adding line.

Link copied to clipboard
fun makeLerp(ending: Path?, weight: Float): Path

Interpolates between Path with Point array of equal size. Copy verb array and weights to out, and set out Point array to a weighted average of this Point array and ending Point array, using the formula:

Link copied to clipboard
fun moveTo(p: Point): Path

Adds beginning of contour at Point p.

fun moveTo(x: Float, y: Float): Path

Adds beginning of contour at Point (x, y).

Link copied to clipboard
fun offset(dx: Float, dy: Float, dst: Path? = null): Path

Offsets Point array by (dx, dy). Path is replaced by offset data.

Link copied to clipboard
fun quadTo(p1: Point, p2: Point): Path

Adds quad from last point towards Point p1, to Point p2.

fun quadTo(x1: Float, y1: Float, x2: Float, y2: Float): Path

Adds quad from last point towards (x1, y1), to (x2, y2). If Path is empty, or last PathVerb is PathVerb.CLOSE, last point is set to (0, 0) before adding quad.

Link copied to clipboard
fun rConicTo(dx1: Float, dy1: Float, dx2: Float, dy2: Float, w: Float): Path

Adds conic from last point towards vector (dx1, dy1), to vector (dx2, dy2), weighted by w. If Path is empty, or last PathVerb is PathVerb.CLOSE, last point is set to (0, 0) before adding conic.

Link copied to clipboard
fun rCubicTo(dx1: Float, dy1: Float, dx2: Float, dy2: Float, dx3: Float, dy3: Float): Path

Adds cubic from last point towards vector (dx1, dy1), then towards vector (dx2, dy2), to vector (dx3, dy3). If Path is empty, or last PathVerb is PathVerb.CLOSE, last point is set to (0, 0) before adding cubic.

Link copied to clipboard
fun rEllipticalArcTo(rx: Float, ry: Float, xAxisRotate: Float, arc: PathEllipseArc, direction: PathDirection, dx: Float, dy: Float): Path

Appends arc to Path, relative to last Path Point. Arc is implemented by one or more conic, weighted to describe part of oval with radii (rx, ry) rotated by xAxisRotate degrees. Arc curves from last Path Point to relative end Point: (dx, dy), choosing one of four possible routes: clockwise or counterclockwise, and smaller or larger. If Path is empty, the start arc Point is (0, 0).

Link copied to clipboard
fun reset(): Path

Sets Path to its initial state.

Link copied to clipboard

Appends src to Path, from back to front. Reversed src always appends a new contour to Path.

Link copied to clipboard
fun rewind(): Path

Sets Path to its initial state, preserving internal storage. Removes verb array, Point array, and weights, and sets FillMode to kWinding. Internal storage associated with Path is retained.

Link copied to clipboard
fun rLineTo(dx: Float, dy: Float): Path

Adds line from last point to vector (dx, dy). If Path is empty, or last PathVerb is PathVerb.CLOSE, last point is set to (0, 0) before adding line.

Link copied to clipboard
fun rMoveTo(dx: Float, dy: Float): Path

Adds beginning of contour relative to last point.

Link copied to clipboard
fun rQuadTo(dx1: Float, dy1: Float, dx2: Float, dy2: Float): Path

Adds quad from last point towards vector (dx1, dy1), to vector (dx2, dy2). If Path is empty, or last PathVerb is PathVerb.CLOSE, last point is set to (0, 0) before adding quad.

Link copied to clipboard

Writes Path to byte buffer.

Link copied to clipboard
fun setLastPt(x: Float, y: Float): Path

Sets last point to (x, y). If Point array is empty, append PathVerb.MOVE to verb array and append (x, y) to Point array.

Link copied to clipboard
fun setVolatile(isVolatile: Boolean): Path

Specifies whether Path is volatile; whether it will be altered or discarded by the caller after it is drawn. Path by default have volatile set false, allowing SkBaseDevice to attach a cache of data which speeds repeated drawing.

Link copied to clipboard
fun swap(other: Path?): Path

Exchanges the verb array, Point array, weights, and FillMode with other. Cached state is also exchanged. swap() internally exchanges pointers, so it is lightweight and does not allocate memory.

Link copied to clipboard
fun tangentArcTo(p1: Point, p2: Point, radius: Float): Path

Appends arc to Path, after appending line if needed. Arc is implemented by conic weighted to describe part of circle. Arc is contained by tangent from last Path point to p1, and tangent from p1 to p2. Arc is part of circle sized to radius, positioned so it touches both tangent lines.

fun tangentArcTo(x1: Float, y1: Float, x2: Float, y2: Float, radius: Float): Path

Appends arc to Path, after appending line if needed. Arc is implemented by conic weighted to describe part of circle. Arc is contained by tangent from last Path point to (x1, y1), and tangent from (x1, y1) to (x2, y2). Arc is part of circle sized to radius, positioned so it touches both tangent lines.

Link copied to clipboard
expect open override fun toString(): String
Link copied to clipboard
fun transform(matrix: Matrix33, applyPerspectiveClip: Boolean): Path

Transforms verb array, Point array, and weight by matrix. transform may change verbs and increase their number. Path is replaced by transformed data.

fun transform(matrix: Matrix33, dst: Path? = null, applyPerspectiveClip: Boolean = true): Path

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.

Link copied to clipboard

Updates internal bounds so that subsequent calls to .getBounds are instantaneous. Unaltered copies of Path may also access cached bounds through .getBounds.