Path
public final class 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.
The various commands that add to the path provide a fluid interface, meaning that calling the methods return the instance on which it was invoked, easily allowing the drawing operations to be concatenated.
-
Constructs an empty
Path. By default,Pathhas no verbs, no points, and no weights. thefillTypeis set to.windingDeclaration
Swift
public init() -
Returns FillType, the rule used to fill Path. FillType of a new Path is .winding
Declaration
Swift
public var fillType: FillType { get set } -
Undocumented
Declaration
Swift
public var convexity: Convexity { get set } -
Returns the number of elements on the verb array containing the draw operations
Declaration
Swift
public var verbCount: Int32 { get } -
Undocumented
Declaration
Swift
public var isConvex: Bool { get } -
Undocumented
Declaration
Swift
public var isConcave: Bool { get } -
Returns if
Pathis empty. EmptyPathmay have FillType but has noPoint,Path.verb, or conic weight.Path() constructs emptyPath; reset() and rewind() makePathempty.Declaration
Swift
public var isEmpty: Bool { get } -
Undocumented
Declaration
Swift
public var isOval: Bool { get } -
Undocumented
Declaration
Swift
public var isRoundedRect: Bool { get } -
Undocumented
Declaration
Swift
public var isLine: Bool { get } -
Undocumented
Declaration
Swift
public var isRect: Bool { get } -
Returns the number of points in SkPath. the count is initially zero.
Declaration
Swift
public var pointCount: Int32 { get } -
Returns a mask, where each set bit corresponds to a SegmentMask constant if
Pathcontains one or more verbs of that type. Returns zero ifPathcontains no lines, or curves: quads, conics, or cubics.egmentMasksreturns a cached result; it is very fast.Declaration
Swift
public var segmentMasks: SegmentMask { get } -
Undocumented
Declaration
Swift
public var lastPoint: Point { get } -
Returns minimum and maximum axes values of
Pointarray. Returns (0, 0, 0, 0) ifPathcontains no points. Returned bounds width and height may be larger or smaller than area affected whenPathis drawn.Rectreturned includes allPointadded toPath, includingPointassociated with.movethat define empty contours.Declaration
Swift
public var bounds: Rect { get } -
Returns minimum and maximum axes values of the lines and curves in
Path. Returns (0, 0, 0, 0) ifPathcontains no points. Returned bounds width and height may be larger or smaller than area affected whenPathis drawn. IncludesPointassociated with.movethat define empty contours. Behaves identically toboundswhenPathcontains only lines. IfPathcontains curves, computed bounds includes the maximum extent of the quad, conic, or cubic; is slower thanboundsand unlikebounds, does not cache the result.Declaration
Swift
public var tightBounds: Rect { get }Return Value
tight bounds of curves in
Path -
Undocumented
Declaration
Swift
public func getTightBounds() -> Rect? -
Undocumented
Declaration
Swift
public func getOvalBounds() -> Rect? -
Undocumented
Declaration
Swift
public func getRoundRect() -> RoundRect? -
Undocumented
Declaration
Swift
public func getLine() -> [Point]? -
Undocumented
-
Returns the point stored at the specified index, if this is out of bounds, it returns a point(0,0)
Declaration
Swift
public func getPoint(index: Int32) -> Point -
Undocumented
Declaration
Swift
public func getPoints(maxPoints: Int32 = -1) -> [Point] -
Returns true if the point (x, y) is contained by
Path, taking into account FillType.Declaration
Swift
public func contains(x: Float, y: Float) -> BoolParameters
xx-axis value of containment test
yy-axis value of containment test
Return Value
true if
Pointis inPath -
Undocumented
Declaration
Swift
public func offset(_ pt: Point) -
Undocumented
Declaration
Swift
public func offset(x: Float, y: Float) -
Undocumented
Declaration
Swift
@discardableResult public func move(to: Point) -> Path -
Undocumented
Declaration
Swift
@discardableResult public func moveTo(_ x: Float, _ y: Float) -> Path -
Undocumented
Declaration
Swift
@discardableResult public func rmove(to: Point) -> Path -
Undocumented
Declaration
Swift
@discardableResult public func rmoveTo(_ x: Float, _ y: Float) -> Path -
Undocumented
Declaration
Swift
@discardableResult public func line(to: Point) -> Path -
Undocumented
Declaration
Swift
@discardableResult public func lineTo(_ x: Float, _ y: Float) -> Path -
Undocumented
Declaration
Swift
@discardableResult public func rline(to: Point) -> Path -
Undocumented
Declaration
Swift
@discardableResult public func rlineTo(_ x: Float, _ y: Float) -> Path -
Undocumented
-
Undocumented
Declaration
-
Undocumented
Declaration
-
Undocumented
Declaration
-
Undocumented
Declaration
Swift
@discardableResult public func cubicTo(_ x0: Float, _ y0: Float, _ x1: Float, _ y1: Float, _ x2: Float, _ y2: Float) -> Path -
Undocumented
Declaration
-
Undocumented
Declaration
Swift
@discardableResult public func rcubicTo(_ x0: Float, _ y0: Float, _ x1: Float, _ y1: Float, _ x2: Float, _ y2: 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 lastPathPointto (x, y), choosing one of four possible routes: clockwise or counterclockwise, and smaller or larger. Arc sweep is always less than 360 degrees. arcTo() appends line to (x, y) if either radii are zero, or if lastPathPointequals (x, y). arcTo() scales radii (rx, ry) to fit lastPathPointand (x, y) if both are greater than zero but too small. arcTo() appends up to four conic curves. arcTo() implements the functionality of SVG arc, although SVG sweep-flag value is opposite the integer value of sweep; SVG sweep-flag uses 1 for clockwise, while kCW_Direction cast to int is zero.Declaration
Parameters
radiusradius on x-axis and y-aix before x-axis, y-axis rotation
xAxisRotatex-axis rotation in degrees; positive values are clockwise
largeArcchooses smaller or larger arc
sweepchooses clockwise or counterclockwise arc
endend of arc
-
Appends arc to
Path, relative to lastPathPoint. 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 lastPathPointto relative endPoint: (dx, dy), choosing one of four possible routes: clockwise or counterclockwise, and smaller or larger. IfPathis empty, the start arcPointis (0, 0). Arc sweep is always less than 360 degrees. arcTo() appends line to endPointif either radii are zero, or if lastPathPointequals endPoint. arcTo() scales radii (rx, ry) to fit lastPathPointand endPointif both are greater than zero but too small to describe an arc. arcTo() appends up to four conic curves. arcTo() implements the functionality of svg arc, although SVGsweep-flag
value is opposite the integer value of sweep; SVGsweep-flag
uses 1 for clockwise, while.directioncast to int is zero.Declaration
Parameters
radiusradius before the rotation
xAxisRotatex-axis rotation in degrees; positive values are clockwise
largeArcchooses smaller or larger arc
sweepchooses clockwise or counterclockwise arc
offsetoffset end of arc from last
PathPoint -
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. arcTo() adds line connectingPathlastPointto initial arcPointif forceMoveTo is false andPathis not empty. Otherwise, added contour begins with first point of arc. Angles greater than -360 and less than 360 are treated modulo 360.Declaration
Swift
@discardableResult public func arcTo(oval: Rect, startAngle: Float, sweepAngle: Float, forceMoveTo: Bool) -> PathParameters
ovalbounds of ellipse containing arc
startAnglestarting angle of arc in degrees
sweepAnglesweep, in degrees. Positive is clockwise; treated modulo 360
forceMoveTotrue to start a new contour with arc
-
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 lastPathpoint 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. If last Path Point does not start Arc, arcTo appends connecting Line to Path. The length of Vector from (x1, y1) to (x2, y2) does not affect Arc. Arc sweep is always less than 180 degrees. If radius is zero, or if tangents are nearly parallel, arcTo appends Line from last Path Point to (x1, y1). arcTo appends at most one Line and one conic. arcTo implements the functionality of PostScript arct and HTML Canvas arcTo.Declaration
Swift
@discardableResult public func arcTo(x1: Float, y1: Float, x2: Float, y2: Float, radius: Float) -> PathParameters
x1x-axis value common to pair of tangents
y1y-axis value common to pair of tangents
x2x-axis value end of second tangent
y2y-axis value end of second tangent
radiusdistance from arc to circle center
-
Appends
.closetoPath. A closed contour connects the first and lastPointwith line, forming a continuous loop. Open and closed contour draw the same withPaint.Fill. WithPaint.Stroke, open contour drawsPaint.Capat contour start and end; closed contour drawsPaint.Join::Join at contour start and end. close() has no effect ifPathis empty or lastPath.closeDeclaration
Swift
public func close() -
Sets
Pathto its initial state, preserving internal storage. Removes verb array,Pointarray, and weights, and sets FillType to kWinding_FillType. Internal storage associated withPathis retained. Use rewind() instead of reset() ifPathstorage will be reused and performance is critical.Declaration
Swift
public func rewind() -
Sets
Pathto its initial state. Removes verb array,Pointarray, and weights, and sets FillType to kWinding_FillType. Internal storage associated withPathis released.Declaration
Swift
public func reset() -
Add Rect to the path, appending kMove_Verb, three kLine_Verb, and kClose_Verb, starting with top-left corner of Rect; followed by top-right, bottom-right, and bottom-left if dir is .clockwise direction; or followed by bottom-left, bottom-right, and top-right if dir is .counterClockwise direction
Declaration
Parameters
rectRect to add as a closed contour
dirDirection to wind added contour
-
Add Rect to the path, appending kMove_Verb, three kLine_Verb, and kClose_Verb, starting with top-left corner of Rect; followed by top-right, bottom-right, and bottom-left if dir is .clockwise direction; or followed by bottom-left, bottom-right, and top-right if dir is .counterClockwise direction
Declaration
Parameters
rectRect to add as a closed contour
dirDirection to wind added contour
startindex of initial point of Rect
-
Append RoundedRect to the path, creating a new closed contour. RRect has bounds equal to rect; each corner is 90 degrees of an ellipse with radii (rx, ry). If dir is .clockwise, RRect starts at top-left of the lower-left corner and winds clockwise. If dir is .counterClockwise, RRect starts at the bottom-left of the upper-left corner and winds counterclockwise.
If either rx or ry is too large, rx and ry are scaled uniformly until the corners fit. If rx or ry is less than or equal to zero, the method appends the Rect rect to the path. After appending, Path may be empty, or may contain: Rect, Oval, or RoundRect.
Declaration
Parameters
roundedRectbounds of the rectangle
-
Append RoundedRect to the path, creating a new closed contour. RRect has bounds equal to rect; each corner is 90 degrees of an ellipse with radii (rx, ry). If dir is .clockwise, RRect starts at top-left of the lower-left corner and winds clockwise. If dir is .counterClockwise, RRect starts at the bottom-left of the upper-left corner and winds counterclockwise.
If either rx or ry is too large, rx and ry are scaled uniformly until the corners fit. If rx or ry is less than or equal to zero, the method appends the Rect rect to the path. After appending, Path may be empty, or may contain: Rect, Oval, or RoundRect.
Declaration
Parameters
roundedRectbounds of the rectangle
startindex of initial point of RRect
-
Adds oval to path, appending kMove_Verb, four kConic_Verb, and kClose_Verb. Oval is upright ellipse bounded by
Rectoval with radii equal to half oval width and half oval height. Oval begins at (oval.fRight, oval.centerY()) and continues clockwise if dir is kCW_Direction, counterclockwise if dir is kCCW_Direction.Declaration
Parameters
rectbounds of ellipse added
directionPath::Direction to wind ellipse -
Append arc to the 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.
If sweepAngle is less than -360, or sweepAngle is larger than 360; and startAngle modulo 90 is nearly zero, append oval instead of arc. Otherwise, sweepAngle values are treated modulo 360, and arc may or may not draw depending on numeric rounding.
Declaration
Swift
@discardableResult public func addArc(_ rect: Rect, startAngle: Float, sweepAngle: Float) -> PathParameters
ovalbounds of ellipse containing arc
startAnglestarting angle of arc in degrees
-
Transform verb array, Point array, and weight by matrix. transform may change verbs and increase their number. Path is replaced by transformed data.
Declaration
Swift
public func transform(matrix: Matrix) -
Undocumented
See moreDeclaration
Swift
public enum PathAddMode -
Undocumented
Declaration
Swift
@discardableResult public func addPath(_ other: Path, dx: Float, dy: Float, mode: PathAddMode = .append) -> Path -
Undocumented
Declaration
Swift
@discardableResult public func addPath(_ other: Path, mode: PathAddMode = .append) -> Path -
Undocumented
Declaration
Swift
@discardableResult public func addPath(_ other: Path, matrix: Matrix, mode: PathAddMode = .append) -> Path -
Undocumented
Declaration
Swift
@discardableResult public func addPathReverse(_ other: Path) -> Path -
Undocumented
Declaration
Swift
@discardableResult public func addCircle(x: Float, y: Float, radius: Float, direction: Direction = .clockwise) -> Path -
Undocumented
Declaration
Swift
@discardableResult public func addPoly(points: [Point], close: Bool = true) -> Path -
Undocumented
Declaration
Swift
public func op(other: Path, op: Op, result: Path) -> Bool -
Undocumented
Declaration
Swift
public func op(other: Path, op localop: Op) -> Path? -
Undocumented
Declaration
Swift
public func simplify(result: Path) -
Undocumented
Declaration
Swift
public func simplify() -> Path -
Undocumented
Declaration
Swift
public func toSvgPathData() -> String -
Undocumented
Declaration
Swift
public static func parseSvgPathData(svgPath: String) -> Path? -
Four oval parts with radii (rx, ry) start at last SkPath SkPoint and ends at (x, y). Size and Direction select one of the four oval parts.
See moreDeclaration
Swift
public enum Size : UInt32 -
FillType selects the rule used to fill
See morePath.Pathset to.windingfills if the sum of contour edges is not zero, where clockwise edges add one, and counterclockwise edges subtract one.Pathset to.evenOddfills if the number of contour edges is odd. Each FillType has an inverse variant that reverses the rule:.inverseWindingfills where the sum of contour edges is zero;.inverseEvenOddfills where the number of contour edges is even.Declaration
Swift
public enum FillType : UInt32 -
Pathis convex if it contains one contour and contour loops no more than 360 degrees, and contour angles all have same Direction. ConvexPathmay have better performance and require fewer resources on GPU surface.Pathis concave when either at least one Direction change is clockwise and another is counterclockwise, or the sum of the changes in Direction is not 360 degrees.Initially
See morePathConvexity is kUnknown_Convexity.PathConvexity is computed f needed by destinationSurface.Declaration
Swift
public enum Convexity : UInt32 -
SegmentMask constants correspond to each drawing Verb type in Path; for instance, if Path only contains lines, only the
See more.linebit is set.Declaration
Swift
public enum SegmentMask : UInt32 -
PathDirectiondescribes whether contour is clockwise or counterclockwise. WhenPathcontains multiple overlapping contours,PathDirectiontogether withFillTypedetermines whether overlaps are filled or form holes.PathDirectionalso determines how contour is measured. For instance, dashing measures alongPathto determine where to start and stop stroke;PathDirectionwill change dashed results as it steps clockwise or counterclockwise.Closed contours like
See moreRect,RRect, circle, and oval added with.clockwisetravel clockwise; the same added with.counterclockwisetravel counterclockwise.Declaration
Swift
public enum Direction : UInt32 -
The logical operations that can be performed when combining two paths
See moreDeclaration
Swift
public enum Op : UInt32
View on GitHub
Install in Dash
Path Class Reference