Expanded my old shape code when porting to 3.0. Sample images here. Note that there’s a separate extension that allows UIKit Bezier calls on NSBezierPaths.
Expanded my old shape code when porting to 3.0. Sample images here. Note that there’s a separate extension that allows UIKit Bezier calls on NSBezierPaths.
4 Comments
You’ve got to be kidding me. I have something somewhat similar, which is more about layering regular polygons though: https://github.com/marcusrossel/geometry-view
Under Swift 3 the open funcs have an error: “Expected Declaration”
Commenting out the opens gets the MacOS version to work.
In the IOS version there is an error: “Value of type UIBezierPath has no member ‘line’
I’m fairly sure you are using the wrong conversion from a quadratic to a cubic.
open func addQuadCurve(to point: CGPoint, controlPoint: CGPoint) {
self.curve(to: point, controlPoint1: controlPoint, controlPoint2: controlPoint)
}
I think you have to use the 2/3rds formula like the following snippet:
case .addQuadCurveToPoint: // As NSBezierPath has no native quad curve element, convert to cubic.
let ⅔ = CGFloat(2.0/3.0)
let quadControlPoint = points.pointee
let nextPoint = points.advanced(by: 1).pointee
let startPoint = myself.currentPoint ?? NSPoint(x: 0, y: 0)
let control1X = startPoint.x + ⅔*(quadControlPoint.x-startPoint.x)
let control1Y = startPoint.y + ⅔*(quadControlPoint.y-startPoint.y)
let controlPoint1 = NSPoint(x: control1X, y: control1Y)
let control2X = nextPoint.x + ⅔*(quadControlPoint.x-nextPoint.x)
let control2Y = nextPoint.y + ⅔*(quadControlPoint.y-nextPoint.y)
let controlPoint2 = NSPoint(x: control2X, y: control2Y)
myself.curve(to: nextPoint, controlPoint1: controlPoint1, controlPoint2: controlPoint2)
https://github.com/GenerallyHelpfulSoftware/Scalar2D/blob/master/GraphicPath/Source/NSBezierPath%2BSVG.swift