Known direct subclasses

Summary

Nested types

Specifies how closed shapes (e.g. rectangles, ovals) are wound (oriented) when they are added to a path.

Public companion functions

Path
combine(operation: PathOperation, path1: Path, path2: Path)

Combines the two paths according to the manner specified by the given operation.

Cmn

Public functions

Unit
addArc(oval: Rect, startAngleDegrees: Float, sweepAngleDegrees: Float)

Adds a new subpath with one arc segment that consists of the arc that follows the edge of the oval bounded by the given rectangle, from startAngle degrees around the oval up to startAngle + sweepAngle degrees around the oval, with zero degrees being the point on the right hand side of the oval that crosses the horizontal line that intersects the center of the rectangle and with positive angles going clockwise around the oval.

Cmn
Unit
addArcRad(oval: Rect, startAngleRadians: Float, sweepAngleRadians: Float)

Adds a new subpath with one arc segment that consists of the arc that follows the edge of the oval bounded by the given rectangle, from startAngle radians around the oval up to startAngle + sweepAngle radians around the oval, with zero radians being the point on the right hand side of the oval that crosses the horizontal line that intersects the center of the rectangle and with positive angles going clockwise around the oval.

Cmn
Unit
addOval(oval: Rect, direction: Path.Direction)

Adds a new subpath that consists of a curve that forms the ellipse that fills the given rectangle.

Cmn
Unit
addPath(path: Path, offset: Offset)

Adds a new subpath that consists of the given path offset by the given offset.

Cmn
Unit
addRect(rect: Rect, direction: Path.Direction)

Adds a new subpath that consists of four lines that outline the given rectangle.

Cmn
Unit
addRoundRect(roundRect: RoundRect, direction: Path.Direction)

Add a round rectangle shape to the path from the given RoundRect.

Cmn
open infix Path
and(path: Path)

Returns the intersection of two paths as a new Path.

Cmn
Unit
arcTo(
    rect: Rect,
    startAngleDegrees: Float,
    sweepAngleDegrees: Float,
    forceMoveTo: Boolean
)

If the forceMoveTo argument is false, adds a straight line segment and an arc segment.

Cmn
open Unit
arcToRad(
    rect: Rect,
    startAngleRadians: Float,
    sweepAngleRadians: Float,
    forceMoveTo: Boolean
)

If the forceMoveTo argument is false, adds a straight line segment and an arc segment.

Cmn
Unit

Closes the last subpath, as if a straight line had been drawn from the current point to the first point of the subpath.

Cmn
Unit
cubicTo(x1: Float, y1: Float, x2: Float, y2: Float, x3: Float, y3: Float)

Adds a cubic bezier segment that curves from the current point to the given point (x3, y3), using the control points (x1, y1) and (x2, y2).

Cmn
Rect

Compute the bounds of the control points of the path, and write the answer into bounds.

Cmn
open operator PathIterator

Creates a new PathIterator for this Path that evaluates conics as quadratics.

Cmn
open PathIterator
iterator(conicEvaluation: PathIterator.ConicEvaluation, tolerance: Float)

Creates a new PathIterator for this Path.

Cmn
Unit
lineTo(x: Float, y: Float)

Adds a straight line segment from the current point to the given point

Cmn
open operator Path
minus(path: Path)

Returns the difference of two paths as a new Path.

Cmn
Unit
moveTo(x: Float, y: Float)

Starts a new subpath at the given coordinate

Cmn
Boolean
op(path1: Path, path2: Path, operation: PathOperation)

Set this path to the result of applying the Op to the two specified paths.

Cmn
open infix Path
or(path: Path)

Returns the union of two paths as a new Path.

Cmn
open operator Path
plus(path: Path)

Returns the union of two paths as a new Path.

Cmn
Unit
quadraticBezierTo(x1: Float, y1: Float, x2: Float, y2: Float)

This function is deprecated. Use quadraticTo() for consistency with cubicTo()

Cmn
open Unit
quadraticTo(x1: Float, y1: Float, x2: Float, y2: Float)

Adds a quadratic bezier segment that curves from the current point to the given point (x2, y2), using the control point (x1, y1).

Cmn
Unit
relativeCubicTo(
    dx1: Float,
    dy1: Float,
    dx2: Float,
    dy2: Float,
    dx3: Float,
    dy3: Float
)

Adds a cubic bezier segment that curves from the current point to the point at the offset (dx3, dy3) from the current point, using the control points at the offsets (dx1, dy1) and (dx2, dy2) from the current point.

Cmn
Unit

Adds a straight line segment from the current point to the point at the given offset from the current point.

Cmn
Unit

Starts a new subpath at the given offset from the current point

Cmn
Unit
relativeQuadraticBezierTo(dx1: Float, dy1: Float, dx2: Float, dy2: Float)

This function is deprecated. Use relativeQuadraticTo() for consistency with relativeCubicTo()

Cmn
open Unit
relativeQuadraticTo(dx1: Float, dy1: Float, dx2: Float, dy2: Float)

Adds a quadratic bezier segment that curves from the current point to the point at the offset (dx2, dy2) from the current point, using the control point at the offset (dx1, dy1) from the current point.

Cmn
Unit

Clears the Path object of all subpaths, returning it to the same state it had when it was created.

Cmn
open Unit

Rewinds the path: clears any lines and curves from the path but keeps the internal data structure for faster reuse.

Cmn
open Unit
transform(matrix: Matrix)

Transform the points in this path by the provided matrix

Cmn
Unit
translate(offset: Offset)

Translates all the segments of every subpath by the given offset.

Cmn
open infix Path
xor(path: Path)

Returns the union minus the intersection of two paths as a new Path.

Cmn

Public properties

PathFillType

Determines how the interior of this path is calculated.

Cmn
Boolean

Returns the path's convexity, as defined by the content of the path.

Cmn
Boolean

Returns true if the path is empty (contains no lines or curves)

Cmn

Extension functions

inline Path
android
inline Path

This function is deprecated. Use asSkiaPath()

android
Unit

Adds the outline to the Path.

Cmn
Path.Direction

Computes this Path's direction (or winding, or orientation), which can be either Path.Direction.Clockwise or Path.Direction.CounterClockwise.

Cmn
MutableList<Path>

Divides this path into a list of paths.

Cmn
Path
Path.reverse(destination: Path)

Reverses the segments of this path into the specified destination, turning a clockwise path into a counter-clockwise path and vice-versa.

Cmn
Path

Create a new path, copying the contents from the src path.

Cmn
Unit
Path.addSvg(pathData: String)

Adds the specified SVG path data to this Path.

Cmn
String
Path.toSvg(asDocument: Boolean)

Returns an SVG representation of this path.

Cmn
Path

Obtain a reference to the org.jetbrains.skia.Path

android

Public companion functions

combine

fun combine(operation: PathOperation, path1: Path, path2: Path): Path

Combines the two paths according to the manner specified by the given operation.

The resulting path will be constructed from non-overlapping contours. The curve order is reduced where possible so that cubics may be turned into quadratics, and quadratics maybe turned into lines.

Throws IllegalArgumentException if the combining operation fails.

Public functions

addArc

fun addArc(oval: Rect, startAngleDegrees: Float, sweepAngleDegrees: Float): Unit

Adds a new subpath with one arc segment that consists of the arc that follows the edge of the oval bounded by the given rectangle, from startAngle degrees around the oval up to startAngle + sweepAngle degrees around the oval, with zero degrees being the point on the right hand side of the oval that crosses the horizontal line that intersects the center of the rectangle and with positive angles going clockwise around the oval.

addArcRad

fun addArcRad(oval: Rect, startAngleRadians: Float, sweepAngleRadians: Float): Unit

Adds a new subpath with one arc segment that consists of the arc that follows the edge of the oval bounded by the given rectangle, from startAngle radians around the oval up to startAngle + sweepAngle radians around the oval, with zero radians being the point on the right hand side of the oval that crosses the horizontal line that intersects the center of the rectangle and with positive angles going clockwise around the oval.

addOval

fun addOval(oval: Rect, direction: Path.Direction = Direction.CounterClockwise): Unit

Adds a new subpath that consists of a curve that forms the ellipse that fills the given rectangle.

To add a circle, pass an appropriate rectangle as oval. Rect can be used to easily describe the circle's center Offset and radius.

The direction to wind the rectangle's contour is specified by direction.

addPath

fun addPath(path: Path, offset: Offset = Offset.Zero): Unit

Adds a new subpath that consists of the given path offset by the given offset.

addRect

fun addRect(rect: Rect, direction: Path.Direction = Direction.CounterClockwise): Unit

Adds a new subpath that consists of four lines that outline the given rectangle. The direction to wind the rectangle's contour is specified by direction.

addRoundRect

fun addRoundRect(
    roundRect: RoundRect,
    direction: Path.Direction = Direction.CounterClockwise
): Unit

Add a round rectangle shape to the path from the given RoundRect. The direction to wind the rectangle's contour is specified by direction.

and

open infix fun and(path: Path): Path

Returns the intersection of two paths as a new Path. If the paths do not intersect, returns an empty path.

arcTo

fun arcTo(
    rect: Rect,
    startAngleDegrees: Float,
    sweepAngleDegrees: Float,
    forceMoveTo: Boolean
): Unit

If the forceMoveTo argument is false, adds a straight line segment and an arc segment.

If the forceMoveTo argument is true, starts a new subpath consisting of an arc segment.

In either case, the arc segment consists of the arc that follows the edge of the oval bounded by the given rectangle, from startAngle degrees around the oval up to startAngle + sweepAngle degrees around the oval, with zero degrees being the point on the right hand side of the oval that crosses the horizontal line that intersects the center of the rectangle and with positive angles going clockwise around the oval.

The line segment added if forceMoveTo is false starts at the current point and ends at the start of the arc.

arcToRad

open fun arcToRad(
    rect: Rect,
    startAngleRadians: Float,
    sweepAngleRadians: Float,
    forceMoveTo: Boolean
): Unit

If the forceMoveTo argument is false, adds a straight line segment and an arc segment.

If the forceMoveTo argument is true, starts a new subpath consisting of an arc segment.

In either case, the arc segment consists of the arc that follows the edge of the oval bounded by the given rectangle, from startAngle radians around the oval up to startAngle + sweepAngle radians around the oval, with zero radians being the point on the right hand side of the oval that crosses the horizontal line that intersects the center of the rectangle and with positive angles going clockwise around the oval.

The line segment added if forceMoveTo is false starts at the current point and ends at the start of the arc.

close

fun close(): Unit

Closes the last subpath, as if a straight line had been drawn from the current point to the first point of the subpath.

cubicTo

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

Adds a cubic bezier segment that curves from the current point to the given point (x3, y3), using the control points (x1, y1) and (x2, y2).

getBounds

fun getBounds(): Rect

Compute the bounds of the control points of the path, and write the answer into bounds. If the path contains 0 or 1 points, the bounds is set to (0,0,0,0)

iterator

open operator fun iterator(): PathIterator

Creates a new PathIterator for this Path that evaluates conics as quadratics. To preserve conics, use the Path.iterator function that takes a PathIterator.ConicEvaluation parameter.

iterator

open fun iterator(
    conicEvaluation: PathIterator.ConicEvaluation,
    tolerance: Float = 0.25f
): PathIterator

Creates a new PathIterator for this Path. To preserve conics as conics (not convert them to quadratics), set conicEvaluation to PathIterator.ConicEvaluation.AsConic.

Parameters
conicEvaluation: PathIterator.ConicEvaluation

Indicates how to evaluate conic segments

tolerance: Float = 0.25f

When conicEvaluation is set to PathIterator.ConicEvaluation.AsQuadratics defines the maximum distance between the original conic curve and its quadratic approximations

lineTo

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

Adds a straight line segment from the current point to the given point

minus

open operator fun minus(path: Path): Path

Returns the difference of two paths as a new Path.

moveTo

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

Starts a new subpath at the given coordinate

op

fun op(path1: Path, path2: Path, operation: PathOperation): Boolean

Set this path to the result of applying the Op to the two specified paths. The resulting path will be constructed from non-overlapping contours. The curve order is reduced where possible so that cubics may be turned into quadratics, and quadratics maybe turned into lines.

Parameters
path1: Path

The first operand (for difference, the minuend)

path2: Path

The second operand (for difference, the subtrahend)

Returns
Boolean

True if operation succeeded, false otherwise and this path remains unmodified.

or

open infix fun or(path: Path): Path

Returns the union of two paths as a new Path.

plus

open operator fun plus(path: Path): Path

Returns the union of two paths as a new Path.

quadraticBezierTo

fun quadraticBezierTo(x1: Float, y1: Float, x2: Float, y2: Float): Unit

Adds a quadratic bezier segment that curves from the current point to the given point (x2, y2), using the control point (x1, y1).

quadraticTo

open fun quadraticTo(x1: Float, y1: Float, x2: Float, y2: Float): Unit

Adds a quadratic bezier segment that curves from the current point to the given point (x2, y2), using the control point (x1, y1).

relativeCubicTo

fun relativeCubicTo(
    dx1: Float,
    dy1: Float,
    dx2: Float,
    dy2: Float,
    dx3: Float,
    dy3: Float
): Unit

Adds a cubic bezier segment that curves from the current point to the point at the offset (dx3, dy3) from the current point, using the control points at the offsets (dx1, dy1) and (dx2, dy2) from the current point.

relativeLineTo

fun relativeLineTo(dx: Float, dy: Float): Unit

Adds a straight line segment from the current point to the point at the given offset from the current point.

relativeMoveTo

fun relativeMoveTo(dx: Float, dy: Float): Unit

Starts a new subpath at the given offset from the current point

relativeQuadraticBezierTo

fun relativeQuadraticBezierTo(dx1: Float, dy1: Float, dx2: Float, dy2: Float): Unit

Adds a quadratic bezier segment that curves from the current point to the point at the offset (dx2, dy2) from the current point, using the control point at the offset (dx1, dy1) from the current point.

relativeQuadraticTo

open fun relativeQuadraticTo(dx1: Float, dy1: Float, dx2: Float, dy2: Float): Unit

Adds a quadratic bezier segment that curves from the current point to the point at the offset (dx2, dy2) from the current point, using the control point at the offset (dx1, dy1) from the current point.

reset

fun reset(): Unit

Clears the Path object of all subpaths, returning it to the same state it had when it was created. The current point is reset to the origin. This does NOT change the fill-type setting.

rewind

open fun rewind(): Unit

Rewinds the path: clears any lines and curves from the path but keeps the internal data structure for faster reuse.

transform

open fun transform(matrix: Matrix): Unit

Transform the points in this path by the provided matrix

translate

fun translate(offset: Offset): Unit

Translates all the segments of every subpath by the given offset.

xor

open infix fun xor(path: Path): Path

Returns the union minus the intersection of two paths as a new Path.

Public properties

fillType

var fillTypePathFillType

Determines how the interior of this path is calculated.

Defaults to the non-zero winding rule, PathFillType.NonZero.

isConvex

val isConvexBoolean

Returns the path's convexity, as defined by the content of the path.

A path is convex if it has a single contour, and only ever curves in a single direction.

This function will calculate the convexity of the path from its control points, and cache the result.

isEmpty

val isEmptyBoolean

Returns true if the path is empty (contains no lines or curves)

Returns
Boolean

true if the path is empty (contains no lines or curves)

Extension functions

asAndroidPath

inline fun Path.asAndroidPath(): Path
Throws
kotlin.UnsupportedOperationException

if this Path is not backed by an android.graphics.Path.

asDesktopPath

inline fun Path.asDesktopPath(): Path

addOutline

fun Path.addOutline(outline: Outline): Unit

Adds the outline to the Path.

computeDirection

fun Path.computeDirection(): Path.Direction

Computes this Path's direction (or winding, or orientation), which can be either Path.Direction.Clockwise or Path.Direction.CounterClockwise.

If the path is made of multiple contours (the path contains multiple "move" commands), the direction returned by this property is the direction of the first contour.

If the path is empty (contains no lines/curves), the direction is Path.Direction.Clockwise.

If the path has no area (single straight line), the direction is Path.Direction.Clockwise.

Calling this property does not cache the result, the direction is computed Calling this method does not cache the result, the direction is computed every time the method is called.

If you need to query the direction of individual contours, you should divide the path first.

fun Path.divide(contours: MutableList<Path> = mutableListOf()): MutableList<Path>

Divides this path into a list of paths. Each contour inside this path is returned as a separate Path. For instance the following code snippet creates two rectangular contours:

val p = Path()
p.addRect(...)
p.addRect(...)

val contours = p.divide()

The list returned by calling p.divide() will contain two Path instances, each representing one of the two rectangles.

Empty contours (contours with no lines/curves) are omitted from the resulting list.

Parameters
contours: MutableList<Path> = mutableListOf()

An optional mutable list of Path that will hold the result of the division.

Returns
MutableList<Path>

A list of Path representing all the contours in this path. The returned list is either a newly allocated list if the contours parameter was left unspecified, or the contours parameter.

fun Path.reverse(destination: Path = Path()): Path

Reverses the segments of this path into the specified destination, turning a clockwise path into a counter-clockwise path and vice-versa. Each contour in the path is reversed independently, and the contours appear in the destination in reverse order.

This method preserves the general structure of this path as much as possible:

  • Lines become lines

  • Quadratic Bézier curves become quadratic Bézier curves

  • Cubic Bézier curves become cubic Bézier curves

  • Close and move commands remain close and move commands

  • Conic segments become quadratic Bézier curves

Returns
Path

A Path containing the reverse of this Path. The returned path is either a newly allocated Path if the destination parameter was left unspecified, or the destination parameter.

fun Path.copy(): Path

Create a new path, copying the contents from the src path.

fun Path.addSvg(pathData: String): Unit

Adds the specified SVG path data to this Path. The SVG path data encodes a series of instructions that will be applied to this path. For instance, the following path data:

M200,300 Q400,50 600,300 L1000,300

Will generate the following series of instructions for this path:

moveTo(200f, 300f)
quadraticTo(400f, 50f, 600f, 300f)
lineTo(1000f, 300f)

To convert a Path to its SVG path data representation, please refer to Path.toSvg.

Throws
kotlin.IllegalArgumentException

if the path data contains an invalid instruction

See also
toSvg
fun Path.toSvg(asDocument: Boolean = false): String

Returns an SVG representation of this path. The caller can choose whether the returned SVG represents a fully-formed SVG document or only the path data. By default, only the path data is returned which can be used either with Path.addSvg or androidx.compose.ui.graphics.vector.PathParser.

Parameters
asDocument: Boolean = false

When set to true, this function returns a fully-formed SVG document, otherwise returns only the path data.

See also
PathParser
addSvg

asSkiaPath

fun Path.asSkiaPath(): Path

Obtain a reference to the org.jetbrains.skia.Path

Throws
kotlin.UnsupportedOperationException

if this Path is not backed by an org.jetbrains.skia.Path