{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

AndroidPath

public final class AndroidPath implements Path


Summary

Public constructors

AndroidPath(@NonNull Path internalPath)

Public methods

void
addArc(
    @NonNull Rect oval,
    float startAngleDegrees,
    float sweepAngleDegrees
)

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.

void
addArcRad(
    @NonNull Rect oval,
    float startAngleRadians,
    float sweepAngleRadians
)

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.

void

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

void
addPath(@NonNull Path path, @NonNull Offset offset)

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

void

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

void

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

void
arcTo(
    @NonNull Rect rect,
    float startAngleDegrees,
    float sweepAngleDegrees,
    boolean forceMoveTo
)

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

void

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

void
cubicTo(float x1, float y1, float x2, float y2, float x3, float y3)

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).

@NonNull Rect

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

@NonNull PathFillType

Determines how the interior of this path is calculated.

final @NonNull Path
boolean

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

boolean

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

void
lineTo(float x, float y)

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

void
moveTo(float x, float y)

Starts a new subpath at the given coordinate

boolean
op(@NonNull Path path1, @NonNull Path path2, @NonNull PathOperation operation)

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

void
quadraticBezierTo(float x1, float y1, float x2, float y2)

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

void
relativeCubicTo(
    float dx1,
    float dy1,
    float dx2,
    float dy2,
    float dx3,
    float dy3
)

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.

void
relativeLineTo(float dx, float dy)

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

void
relativeMoveTo(float dx, float dy)

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

void
relativeQuadraticBezierTo(float dx1, float dy1, float dx2, float dy2)

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.

void

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

void

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

void

Determines how the interior of this path is calculated.

void

Transform the points in this path by the provided matrix

void

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

Inherited methods

From androidx.compose.ui.graphics.Path
void
arcToRad(
    @NonNull Rect rect,
    float startAngleRadians,
    float sweepAngleRadians,
    boolean forceMoveTo
)

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

Public constructors

AndroidPath

public AndroidPath(@NonNull Path internalPath)

Public methods

addArc

public void addArc(
    @NonNull Rect oval,
    float startAngleDegrees,
    float sweepAngleDegrees
)

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

public void addArcRad(
    @NonNull Rect oval,
    float startAngleRadians,
    float sweepAngleRadians
)

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

public void addOval(@NonNull Rect oval)

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.

addPath

public void addPath(@NonNull Path path, @NonNull Offset offset)

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

addRect

public void addRect(@NonNull Rect rect)

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

addRoundRect

public void addRoundRect(@NonNull RoundRect roundRect)

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

arcTo

public void arcTo(
    @NonNull Rect rect,
    float startAngleDegrees,
    float sweepAngleDegrees,
    boolean forceMoveTo
)

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.

close

public void close()

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

cubicTo

public void cubicTo(float x1, float y1, float x2, float y2, float x3, float y3)

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

public @NonNull Rect getBounds()

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)

getFillType

public @NonNull PathFillType getFillType()

Determines how the interior of this path is calculated.

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

getInternalPath

public final @NonNull Path getInternalPath()

isConvex

public boolean isConvex()

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

public boolean isEmpty()

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)

lineTo

public void lineTo(float x, float y)

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

moveTo

public void moveTo(float x, float y)

Starts a new subpath at the given coordinate

op

public boolean op(@NonNull Path path1, @NonNull Path path2, @NonNull PathOperation operation)

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
@NonNull Path path1

The first operand (for difference, the minuend)

@NonNull Path path2

The second operand (for difference, the subtrahend)

Returns
boolean

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

quadraticBezierTo

public void quadraticBezierTo(float x1, float y1, float x2, float y2)

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

relativeCubicTo

public void relativeCubicTo(
    float dx1,
    float dy1,
    float dx2,
    float dy2,
    float dx3,
    float dy3
)

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

public void relativeLineTo(float dx, float dy)

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

relativeMoveTo

public void relativeMoveTo(float dx, float dy)

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

relativeQuadraticBezierTo

public void relativeQuadraticBezierTo(float dx1, float dy1, float dx2, float dy2)

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

public void reset()

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

public void rewind()

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

setFillType

public void setFillType(@NonNull PathFillType fillType)

Determines how the interior of this path is calculated.

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

transform

public void transform(@NonNull Matrix matrix)

Transform the points in this path by the provided matrix

translate

public void translate(@NonNull Offset offset)

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