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, Path has no verbs, no points, and no weights. the fillType is set to .winding

    Declaration

    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 Path is empty. Empty Path may have FillType but has no Point, Path.verb, or conic weight. Path() constructs empty Path; reset() and rewind() make Path empty.

    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 Path contains one or more verbs of that type. Returns zero if Path contains no lines, or curves: quads, conics, or cubics. egmentMasks returns a cached result; it is very fast.

    Declaration

    Swift

    public var segmentMasks: SegmentMask { get }
  • Returns Point at index in Point array. Valid range for index is 0 to countPoints() - 1. Returns (0, 0) if index is out of range.

    Declaration

    Swift

    public subscript(index: Int32) -> Point { get }

    Parameters

    index

    Point array element selector

    Return Value

    Point array value or (0, 0)

  • Undocumented

    Declaration

    Swift

    public var lastPoint: Point { get }
  • Returns minimum and maximum axes values of Point array. 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. Rect returned includes all Point added to Path, including Point associated with .move that define empty contours.

    Declaration

    Swift

    public var bounds: Rect { get }

    Return Value

    bounds of all Point in Point array

  • 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. Includes Point associated with .move that define empty contours. Behaves identically to bounds when Path contains only lines. If Path contains curves, computed bounds includes the maximum extent of the quad, conic, or cubic; is slower than bounds and unlike bounds, 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

    Declaration

    Swift

    public func getRect() -> (rect: Rect, isClosed: Bool, direction: Direction)
  • 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) -> Bool

    Parameters

    x

    x-axis value of containment test

    y

    y-axis value of containment test

    Return Value

    true if Point is in Path

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

    Declaration

    Swift

    public func contains(point: Point) -> Bool

    Parameters

    point

    point of containment test

    Return Value

    true if Point is in Path

  • 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
  • Adds quad from last point towards p1, to p2 If Path is empty, or last Path.verb is .close, last point is set to (0, 0) before adding quad. Appends .move verb to verb array and (0, 0) to Point array, if needed; then appends .quad to verb array; and Point p1, p2 to Point array.

    Declaration

    Swift

    @discardableResult
    public func quadCurve(to: Point, controlPoint: Point) -> Path

    Parameters

    p1

    control Point of added quad

    p2

    end Point of added quad

    Return Value

    the path

  • Undocumented

    Declaration

    Swift

    @discardableResult
    public func rcurve(to: Point, controlPoint: Point) -> Path
  • Undocumented

    Declaration

    Swift

    @discardableResult
    public func conic(to: Point, and: Point, weightedBy: Float) -> Path
  • Undocumented

    Declaration

    Swift

    @discardableResult
    public func rconic(to: Point, and: Point, weightedBy: Float) -> Path
  • Undocumented

    Declaration

    Swift

    @discardableResult
    public func cubic(to: Point, controlPoint1: Point, controlPoint2: Point) -> Path
  • Undocumented

    Declaration

    Swift

    @discardableResult
    public func cubicTo(_ x0: Float, _ y0: Float, _ x1: Float, _ y1: Float, _ x2: Float, _ y2: Float) -> Path
  • Undocumented

    Declaration

    Swift

    @discardableResult
    public func rcubic(to: Point, controlPoint1: Point, controlPoint2: Point) -> Path
  • 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 last Path Point to (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 last Path Point equals (x, y). arcTo() scales radii (rx, ry) to fit last Path Point and (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

    Swift

    @discardableResult
    public func arcTo(radius: Point, xAxisRotate: Float, largeArc: Size, sweep: Direction, end: Point) -> Path

    Parameters

    radius

    radius on x-axis and y-aix before x-axis, y-axis rotation

    xAxisRotate

    x-axis rotation in degrees; positive values are clockwise

    largeArc

    chooses smaller or larger arc

    sweep

    chooses clockwise or counterclockwise arc

    end

    end of arc

  • 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). Arc sweep is always less than 360 degrees. arcTo() appends line to end Point if either radii are zero, or if last Path Point equals end Point. arcTo() scales radii (rx, ry) to fit last Path Point and end Point if 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 SVG sweep-flag value is opposite the integer value of sweep; SVG sweep-flag uses 1 for clockwise, while .direction cast to int is zero.

    Declaration

    Swift

    @discardableResult
    public func rarcTo(radius: Point, xAxisRotate: Float, largeArc: Size, sweep: Direction, offset: Point) -> Path

    Parameters

    radius

    radius before the rotation

    xAxisRotate

    x-axis rotation in degrees; positive values are clockwise

    largeArc

    chooses smaller or larger arc

    sweep

    chooses clockwise or counterclockwise arc

    offset

    offset end of arc from last Path Point

  • 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 connecting Path last Point to initial arc Point if forceMoveTo is false and Path is 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) -> Path

    Parameters

    oval

    bounds of ellipse containing arc

    startAngle

    starting angle of arc in degrees

    sweepAngle

    sweep, in degrees. Positive is clockwise; treated modulo 360

    forceMoveTo

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

    Parameters

    x1

    x-axis value common to pair of tangents

    y1

    y-axis value common to pair of tangents

    x2

    x-axis value end of second tangent

    y2

    y-axis value end of second tangent

    radius

    distance from arc to circle center

  • Appends .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 Paint.Fill. With Paint.Stroke, open contour draws Paint.Cap at contour start and end; closed contour draws Paint.Join::Join at contour start and end. close() has no effect if Path is empty or last Path .close

    Declaration

    Swift

    public func close()
  • Sets Path to its initial state, preserving internal storage. Removes verb array, Point array, and weights, and sets FillType to kWinding_FillType. Internal storage associated with Path is retained. Use rewind() instead of reset() if Path storage will be reused and performance is critical.

    Declaration

    Swift

    public func rewind()
  • Sets Path to its initial state. Removes verb array, Point array, and weights, and sets FillType to kWinding_FillType. Internal storage associated with Path is 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

    Swift

    @discardableResult
    public func addRect(_ rect: Rect, direction: Direction = .clockwise) -> Path

    Parameters

    rect

    Rect to add as a closed contour

    dir

    Direction 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

    Swift

    @discardableResult
    public func addRect(_ rect: Rect, direction: Direction = .clockwise, start: UInt32) -> Path

    Parameters

    rect

    Rect to add as a closed contour

    dir

    Direction to wind added contour

    start

    index 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

    Swift

    @discardableResult
    public func addRoundedRect(_ roundedRect: RoundRect, direction: Direction = .clockwise) -> Path

    Parameters

    roundedRect

    bounds 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

    Swift

    @discardableResult
    public func addRoundedRect(_ roundedRect: RoundRect, direction: Direction = .clockwise, start: UInt32) -> Path

    Parameters

    roundedRect

    bounds of the rectangle

    start

    index of initial point of RRect

  • Adds oval to path, appending kMove_Verb, four kConic_Verb, and kClose_Verb. Oval is upright ellipse bounded by Rect oval 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

    Swift

    @discardableResult
    public func addOval(_ rect: Rect, direction: Direction = .clockwise) -> Path

    Parameters

    rect

    bounds of ellipse added

    direction

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

    Parameters

    oval

    bounds of ellipse containing arc

    startAngle

    starting 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 more

    Declaration

    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 more

    Declaration

    Swift

    public enum Size : UInt32
  • FillType selects the rule used to fill Path. Path set to .winding fills if the sum of contour edges is not zero, where clockwise edges add one, and counterclockwise edges subtract one. Path set to .evenOdd fills if the number of contour edges is odd. Each FillType has an inverse variant that reverses the rule: .inverseWinding fills where the sum of contour edges is zero; .inverseEvenOdd fills where the number of contour edges is even.

    See more

    Declaration

    Swift

    public enum FillType : UInt32
  • Path is convex if it contains one contour and contour loops no more than 360 degrees, and contour angles all have same Direction. Convex Path may have better performance and require fewer resources on GPU surface.

    Path is 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 Path Convexity is kUnknown_Convexity. Path Convexity is computed f needed by destination Surface.

    See more

    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 .line bit is set.

    See more

    Declaration

    Swift

    public enum SegmentMask : UInt32
  • PathDirection describes whether contour is clockwise or counterclockwise. When Path contains multiple overlapping contours, PathDirection together with FillType determines whether overlaps are filled or form holes.

    PathDirection also determines how contour is measured. For instance, dashing measures along Path to determine where to start and stop stroke; PathDirection will change dashed results as it steps clockwise or counterclockwise.

    Closed contours like Rect, RRect, circle, and oval added with .clockwise travel clockwise; the same added with .counterclockwise travel counterclockwise.

    See more

    Declaration

    Swift

    public enum Direction : UInt32
  • Op

    The logical operations that can be performed when combining two paths

    See more

    Declaration

    Swift

    public enum Op : UInt32