Skip to content

Commit

Permalink
Updated Path API
Browse files Browse the repository at this point in the history
to match CGPath
  • Loading branch information
colemancda committed Oct 5, 2016
1 parent 351fc9c commit 816933b
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions Sources/Silica/Path.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ public enum PathElement {
case closeSubpath
}

// MARK: - Extensions
// MARK: - Constructing a Path

public extension Path {

mutating func add(rect: Rect) {
mutating func addRect(_ rect: Rect) {

let newElements: [Element] = [.moveToPoint(Point(x: rect.minX, y: rect.minY)),
.addLineToPoint(Point(x: rect.maxX, y: rect.minY)),
Expand All @@ -60,7 +60,7 @@ public extension Path {
elements.append(contentsOf: newElements)
}

mutating func add(ellipseIn rect: Rect) {
mutating func addEllipse(in rect: Rect) {

var p = Point()
var p1 = Point()
Expand Down Expand Up @@ -92,6 +92,31 @@ public extension Path {
p2 = Point(x: rect.origin.x + rect.size.width / 2 + hdiff, y: rect.origin.y + rect.size.height)
elements.append(.addCurveToPoint(p1, p2, p))
}

mutating func move(to point: Point) {

elements.append(.moveToPoint(point))
}

mutating func addLine(to point: Point) {

elements.append(.addLineToPoint(point))
}

mutating func addCurve(to endPoint: Point, control1: Point, control2: Point) {

elements.append(.addCurveToPoint(control1, control2, endPoint))
}

mutating func addQuadCurve(to endPoint: Point, control: Point) {

elements.append(.addQuadCurveToPoint(control, endPoint))
}

mutating func closeSubpath() {

elements.append(.closeSubpath)
}
}

// This magic number is 4 *(sqrt(2) -1)/3
Expand Down

0 comments on commit 816933b

Please sign in to comment.