Path

public class Path: Equatable

A Path is a sequence of geometric segments which can be straight lines or curves.

  • Initializes an empty Path.

    Declaration

    Swift

    public init()
  • Initializes a new Path from an existing CGPathRef.

    Declaration

    Swift

    public init(path: CGPathRef)

    Parameters

    path

    a previously initialized CGPathRef

  • Determine if the path is empty - returns: A boolean, false if the path contains no points, otherwise true

    Declaration

    Swift

    public func isEmpty() -> Bool

    Return Value

    A boolean, false if the path contains no points, otherwise true

  • Return the path bounding box. The path bounding box is the smallest rectangle completely enclosing all points in the path, not including control points for Bézier cubic and quadratic curves. If the path is empty, then return CGRectNull. - returns: A rectangle that represents the path bounding box of the specified path

    Declaration

    Swift

    public func boundingBox() -> Rect

    Return Value

    A rectangle that represents the path bounding box of the specified path

  • Return true if point is contained in path; false otherwise. A point is contained in a path if it is inside the painted region when the path is filled; if fillRule is EvenOdd, then the even-odd fill rule is used to evaluate the painted region of the path, otherwise, the winding-number fill rule is used.

    Declaration

    Swift

    public func containsPoint(point: Point, fillRule: FillRule = .NonZero) -> Bool

    Parameters

    point

    The point to test.

    fillRule

    The fill rule to use when testing for containment.

    Return Value

    true if point is inside the path, false otherwise.

  • Create a copy of the path - returns: A new copy of the specified path.

    Declaration

    Swift

    public func copy() -> Path

    Return Value

    A new copy of the specified path.

  • A CGPathRef representation of the receiver’s path.

    Declaration

    Swift

    public var CGPath: CGPathRef
  • Return the current point of the current subpath.

    Declaration

    Swift

    public var currentPoint: Point
  • Move the current point of the current subpath. - parameter point: A Point

    Declaration

    Swift

    public func moveToPoint(point: Point)

    Parameters

    point

    A Point

  • Append a straight-line segment fron the current point to point and move the current point to point. - parameter point: A Point

    Declaration

    Swift

    public func addLineToPoint(point: Point)

    Parameters

    point

    A Point

  • Append a quadratic curve from the current point to point with control point control and move the current point to point. - parameter control: A Point used to shape the curve - parameter point: A Point

    Declaration

    Swift

    public func addQuadCurveToPoint(point: Point, control: Point)

    Parameters

    control

    A Point used to shape the curve

    point

    A Point

  • Append a cubic Bézier curve from the current point to point with control points control1 and control2 and move the current point to point. - parameter control1: A Point used to shape the curve - parameter control2: A Point used to shape the curve - parameter point: A Point

    Declaration

    Swift

    public func addCurveToPoint(point: Point, control1: Point, control2: Point)

    Parameters

    control1

    A Point used to shape the curve

    control2

    A Point used to shape the curve

    point

    A Point

  • Append a line from the current point to the starting point of the current subpath and end the subpath.

    Declaration

    Swift

    public func closeSubpath()
  • Add a rectangle to the path. - parameter rect: a Rect to add to the path

    Declaration

    Swift

    public func addRect(rect: Rect)

    Parameters

    rect

    a Rect to add to the path

  • Add a rounded rectangle to the path. The rounded rectangle coincides with the edges of rect. Each corner consists of one-quarter of an ellipse with axes equal to cornerWidth and cornerHeight. The rounded rectangle forms a complete subpath of the path — that is, it begins with a move to and ends with a close subpath — oriented in the clockwise direction. - parameter rect: a Rect to add to the path - parameter cornerWidth: the width of the shape’s rounded corners - parameter cornerHeight: the width of the shape’s rounded corners

    Declaration

    Swift

    public func addRoundedRect(rect: Rect, cornerWidth: Double, cornerHeight: Double)

    Parameters

    rect

    a Rect to add to the path

    cornerWidth

    the width of the shape’s rounded corners

    cornerHeight

    the width of the shape’s rounded corners

  • Add an ellipse (an oval) inside rect. The ellipse is approximated by a sequence of Bézier curves. The center of the ellipse is the midpoint of rect. If rect is square, then the ellipse will be circular with radius equal to one-half the width (equivalently, one-half the height) of rect. If rect is rectangular, then the major- and minor-axes will be the width and height of rect. The ellipse forms a complete subpath — that is, it begins with a move to and ends with a close subpath — oriented in the clockwise direction. - parameter rect: a Rect into which an ellipse will be created and added to the path

    Declaration

    Swift

    public func addEllipse(rect: Rect)

    Parameters

    rect

    a Rect into which an ellipse will be created and added to the path

  • Add an arc of a circle, possibly preceded by a straight line segment. The arc is approximated by a sequence of Bézier curves.

    Declaration

    Swift

    public func addRelativeArc(center: Point, radius: Double, startAngle: Double, delta: Double)

    Parameters

    center

    The center of the arc.

    radius

    The radius of the arc.

    startAngle

    The angle in radians to the first endpoint of the arc, measured counter-clockwise from the positive x-axis.

    delta

    The angle between startAngle and the second endpoint of the arc, in radians. If `delta’ is positive, then the arc is drawn counter-clockwise; if negative, clockwise.

  • Add an arc of a circle, possibly preceded by a straight line segment. The arc is approximated by a sequence of Bézier curves.

    Note that using values very near 2π can be problematic. For example, setting startAngle to 0, endAngle to 2π, and clockwise to true will draw nothing. (It’s easy to see this by considering, instead of 0 and 2π, the values ε and 2π - ε, where ε is very small.) Due to round-off error, however, it’s possible that passing the value 2 * M_PI to approximate 2π will numerically equal to 2π + δ, for some small δ; this will cause a full circle to be drawn.

    If you want a full circle to be drawn clockwise, you should set startAngle to 2π, endAngle to 0, and clockwise to true. This avoids the instability problems discussed above.

    Declaration

    Swift

    public func addArc(center: Point, radius: Double, startAngle: Double, endAngle: Double, clockwise: Bool)

    Parameters

    center

    The center of the arc.

    radius

    The radius of the arc.

    startAngle

    The angle to the first endpoint of the arc in radians.

    endAngle

    The angle to the second endpoint of the arc.

    clockwise

    If true the arc is drawn clockwise.

  • Add an arc of a circle, possibly preceded by a straight line segment. The arc is approximated by a sequence of Bézier curves. The resulting arc is tangent to the line from the current point to point1, and the line from point1 to point2. - parameter point1: the begin point of the arc - parameter point2: the end point of the arc - parameter radius: the radius of the arc

    Declaration

    Swift

    public func addArcToPoint(point1: Point, point2: Point, radius: Double)

    Parameters

    point1

    the begin point of the arc

    point2

    the end point of the arc

    radius

    the radius of the arc

  • Append a path.

    Declaration

    Swift

    public func addPath(path: Path)

    Parameters

    path

    A new Path that is added to the end of the receiver.

  • Transform a path.

    Declaration

    Swift

    public func transform(transform: Transform)

    Parameters

    transform

    A Transform to be applied to the receiver.