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
30 let path = polyline(points: points)
36 func polyline(_ point: () -> [NSPoint]) -> NSBezierPath? {
38 return polyline(points: point())
41 func polyline(points: [NSPoint]) -> NSBezierPath? {
43 guard points.count > 1
46 return points.dropFirst().reduce(NSBezierPath(start: points[0]), lineToPoint)
49 func lineToPoint(path: NSBezierPath, point: NSPoint) -> NSBezierPath {
55 func multiline(_ lines: () -> [(NSPoint, NSPoint)]) -> NSBezierPath {
57 return multiline(lines: lines())
60 func multiline(lines: [(NSPoint, NSPoint)]) -> NSBezierPath {
62 return lines.reduce(NSBezierPath(), line)
65 func line(_ path: NSBezierPath, _ points: (NSPoint, NSPoint)) -> NSBezierPath {
67 path.move(to: points.0)
68 path.line(to: points.1)