Reputation: 5128
I can draw the quad curve using UIBezierPath's
method addQuadCurveToPoint
in iOS, but unable to find the same method in NSBezierPath.
I can see only below methods in NSBezierPath class,
- moveToPoint:(NSPoint)point;
- lineToPoint:(NSPoint)point;
- curveToPoint:(NSPoint)endPoint
controlPoint1:(NSPoint)controlPoint1
controlPoint2:(NSPoint)controlPoint2;
- closePath;
Is there a way to draw the quad curve in OS X environment?
Upvotes: 3
Views: 488
Reputation: 2699
call path.addQuadCurve(to: endPoint, controlPoint: controlPoint)
,
with code below
extension NSBezierPath{
func addQuadCurve(to endPoint: CGPoint, controlPoint: CGPoint){
let startPoint = self.currentPoint
let controlPoint1 = CGPoint(x: (startPoint.x + (controlPoint.x - startPoint.x) * 2.0/3.0), y: (startPoint.y + (controlPoint.y - startPoint.y) * 2.0/3.0))
let controlPoint2 = CGPoint(x: (endPoint.x + (controlPoint.x - endPoint.x) * 2.0/3.0), y: (endPoint.y + (controlPoint.y - endPoint.y) * 2.0/3.0))
curve(to: endPoint, controlPoint1: controlPoint1, controlPoint2: controlPoint2)
}
}
Thanks to Rhythmic Fistman
Upvotes: 6