Skip to content

Commit

Permalink
fixed a crash if you tried to initialize a Path object from a cgPath …
Browse files Browse the repository at this point in the history
…that starts a new component without using move(to:)
  • Loading branch information
hfutrell committed May 3, 2019
1 parent 8a31c5c commit 0df8811
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions BezierKit/Library/Path.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ internal func windingCountImpliesContainment(_ count: Int, using rule: PathFillR
currentComponentPoints = []
currentComponentOrders = []
}
func appendCurrentPointIfEmpty() {
if currentComponentPoints.isEmpty {
currentComponentPoints = [self.currentPoint!]
}
}
func finishUp() {
self.completeComponentIfNeededAndClearPointsAndOrders()
}
Expand Down Expand Up @@ -141,15 +146,18 @@ internal func windingCountImpliesContainment(_ count: Int, using rule: PathFillR
context.currentComponentPoints = [points[0]]
context.currentPoint = points[0]
case .addLineToPoint:
context.appendCurrentPointIfEmpty()
context.currentComponentOrders.append(1)
context.currentComponentPoints.append(points[0])
context.currentPoint = points[0]
case .addQuadCurveToPoint:
context.appendCurrentPointIfEmpty()
context.currentComponentOrders.append(2)
context.currentComponentPoints.append(points[0])
context.currentComponentPoints.append(points[1])
context.currentPoint = points[1]
case .addCurveToPoint:
context.appendCurrentPointIfEmpty()
context.currentComponentOrders.append(3)
context.currentComponentPoints.append(points[0])
context.currentComponentPoints.append(points[1])
Expand Down

0 comments on commit 0df8811

Please sign in to comment.