Last active
April 4, 2020 22:40
-
-
Save iSapozhnik/d1bc70f44c7c04c6fe89908926b23e03 to your computer and use it in GitHub Desktop.
Converting NSBezierPath to CGPAth
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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