Skip to content

Instantly share code, notes, and snippets.

@iSapozhnik
Last active April 4, 2020 22:40
Show Gist options
  • Save iSapozhnik/d1bc70f44c7c04c6fe89908926b23e03 to your computer and use it in GitHub Desktop.
Save iSapozhnik/d1bc70f44c7c04c6fe89908926b23e03 to your computer and use it in GitHub Desktop.
Converting NSBezierPath to CGPAth
extension NSBezierPath {
var cgPath: CGPath {
let path = CGMutablePath()
var points = [CGPoint](repeating: .zero, count: 3)
for i in 0 ..< self.elementCount {
let type = self.element(at: i, associatedPoints: &points)
switch type {
case .moveTo:
path.move(to: points[0])
case .lineTo:
path.addLine(to: points[0])
case .curveTo:
path.addCurve(to: points[2], control1: points[0], control2: points[1])
case .closePath:
path.closeSubpath()
@unknown default:
break
}
}
return path
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment