5 // Created by Hori,Masaki on 2017/03/01.
6 // Copyright © 2017年 Hori,Masaki. All rights reserved.
11 extension NSBezierPath {
13 convenience init(start point: NSPoint) {
20 func polygon(_ point: () -> [NSPoint]) -> NSBezierPath? {
22 return polygon(points: point())
25 func polygon(points: [NSPoint]) -> NSBezierPath? {
27 guard points.count > 2 else { return nil }
29 let path = polyline(points: points)
35 func polyline(_ point: () -> [NSPoint]) -> NSBezierPath? {
37 return polyline(points: point())
40 func polyline(points: [NSPoint]) -> NSBezierPath? {
42 guard points.count > 1 else { return nil }
44 return points.dropFirst().reduce(NSBezierPath(start: points[0]), lineToPoint)
47 func lineToPoint(path: NSBezierPath, point: NSPoint) -> NSBezierPath {
53 func multiline(_ lines: () -> [(NSPoint, NSPoint)]) -> NSBezierPath {
55 return multiline(lines: lines())
58 func multiline(lines: [(NSPoint, NSPoint)]) -> NSBezierPath {
60 return lines.reduce(NSBezierPath(), line)
63 func line(_ path: NSBezierPath, _ points: (NSPoint, NSPoint)) -> NSBezierPath {
65 path.move(to: points.0)
66 path.line(to: points.1)