PathBuilder

PathBuilder is used to create immutable Path objects.

PathBuilder follows the builder pattern - all mutation methods return the builder instance for method chaining. Once path construction is complete, call detach to get an immutable Path object, or snapshot to get a copy while keeping the builder usable.

This class contains all path construction methods that were previously mutation methods on the Path class. Path objects created from PathBuilder are immutable.

Constructors

Link copied to clipboard
constructor()

Constructs an empty PathBuilder with WINDING fill type.

constructor(fillType: PathFillMode)

Constructs a PathBuilder with the specified fill type.

constructor(path: Path)

Constructs a PathBuilder by copying an existing Path.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
expect open val isClosed: Boolean

Check if underlying resource is closed.

Functions

Link copied to clipboard
fun addArc(oval: Rect, startAngle: Float, sweepAngle: Float): PathBuilder
fun addArc(left: Float, top: Float, right: Float, bottom: Float, startAngle: Float, sweepAngle: Float): PathBuilder

Appends arc to path, as the start of new contour.

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

Adds circle centered at (x, y) of size radius to path.

Link copied to clipboard
fun addOval(oval: Rect, dir: PathDirection = PathDirection.CLOCKWISE, start: Int = 1): PathBuilder
fun addOval(left: Float, top: Float, right: Float, bottom: Float, dir: PathDirection = PathDirection.CLOCKWISE, start: Int = 1): PathBuilder

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

Link copied to clipboard
fun addPath(src: Path, mode: PathAddMode = PathAddMode.APPEND): PathBuilder

Appends src path to this builder.

fun addPath(src: Path, matrix: Matrix33, mode: PathAddMode = PathAddMode.APPEND): PathBuilder

Appends src path transformed by matrix.

fun addPath(src: Path, dx: Float, dy: Float, mode: PathAddMode = PathAddMode.APPEND): PathBuilder

Appends src path offset by (dx, dy).

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

Adds contour created from line array.

Link copied to clipboard
fun addRect(rect: Rect, dir: PathDirection = PathDirection.CLOCKWISE, start: Int = 0): PathBuilder
fun addRect(left: Float, top: Float, right: Float, bottom: Float, dir: PathDirection = PathDirection.CLOCKWISE, start: Int = 0): PathBuilder

Adds rectangle to path, appending MOVE, three LINE, and CLOSE verbs.

Link copied to clipboard
fun addRRect(rrect: RRect, dir: PathDirection = PathDirection.CLOCKWISE, start: Int = 6): PathBuilder
fun addRRect(left: Float, top: Float, right: Float, bottom: Float, radii: FloatArray, dir: PathDirection = PathDirection.CLOCKWISE, start: Int = 6): PathBuilder

Adds rounded rectangle to path, creating a new closed contour.

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

Appends arc to path. Arc is part of ellipse bounded by oval, from startAngle through sweepAngle.

fun arcTo(left: Float, top: Float, right: Float, bottom: Float, startAngle: Float, sweepAngle: Float, forceMoveTo: Boolean): PathBuilder

Appends arc to path. Arc is part of ellipse bounded by rectangle.

Link copied to clipboard
expect open fun close()

Free underlying native resource, peer is useless afterwards.

Link copied to clipboard

Appends CLOSE verb to path. A closed contour connects the first and last point with line.

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

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): PathBuilder

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

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

Adds cubic from last point towards point p1, then towards point p2, ending at point p3.

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

Adds cubic from last point towards (x1, y1), then towards (x2, y2), ending at (x3, y3).

Link copied to clipboard
fun detach(): Path

Returns an immutable Path representing the current state of this builder. The builder is reset to empty after this call.

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

Appends arc to path using point parameters.

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

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.

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

Hints to reserve additional space for approximately extraPtCount points and verbs. May improve performance by reducing allocations.

Link copied to clipboard

Adds line from last point to point p.

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

Link copied to clipboard

Adds beginning of contour at point p.

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

Link copied to clipboard
fun offset(dx: Float, dy: Float): PathBuilder

Offsets all points in this builder by (dx, dy).

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

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

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

Adds quad from last point towards (x1, y1), to (x2, y2).

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

Adds conic from last point towards vector (dx1, dy1), to vector (dx2, dy2), weighted by w. Control is last point plus vector (dx1, dy1). End is last point plus vector (dx2, dy2).

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

Adds cubic from last point towards vector (dx1, dy1), then towards (dx2, dy2), to (dx3, dy3).

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

Appends arc to path, relative to last point.

Link copied to clipboard

Resets the builder to empty, removing all verbs, points, and weights. Fill type is reset to WINDING.

Link copied to clipboard

Adds line from last point to vector (dx, dy). If PathBuilder is empty, or last verb is CLOSE, last point is set to (0, 0) before adding line. Line end is last point plus vector (dx, dy).

Link copied to clipboard

Adds beginning of contour relative to last point. If PathBuilder is empty, starts contour at (dx, dy). Otherwise, start contour at last point offset by (dx, dy).

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

Adds quad from last point towards vector (dx1, dy1), to vector (dx2, dy2). Quad control is last point plus vector (dx1, dy1). Quad end is last point plus vector (dx2, dy2).

Link copied to clipboard

Sets the fill type for paths created from this builder.

Link copied to clipboard

Sets last point to (x, y).

Link copied to clipboard
fun snapshot(): Path

Returns an immutable Path representing the current state of this builder. The builder remains valid and can continue to be used.

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

Appends arc to path, after appending line if needed.

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

Appends arc to path, after appending line if needed. Arc is contained by tangent from last point to (x1, y1), and tangent from (x1, y1) to (x2, y2).

Link copied to clipboard
expect open override fun toString(): String
Link copied to clipboard

Transforms this builder by matrix.