forked from kaunteya/ProgressKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgressUtils.swift
More file actions
55 lines (45 loc) · 1.33 KB
/
ProgressUtils.swift
File metadata and controls
55 lines (45 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//
// ProgressUtils.swift
// ProgressKit
//
// Created by Kauntey Suryawanshi on 09/07/15.
// Copyright (c) 2015 Kauntey Suryawanshi. All rights reserved.
//
import AppKit
extension NSRect {
var mid: CGPoint {
return CGPoint(x: self.midX, y: self.midY)
}
}
extension NSBezierPath {
/// Converts NSBezierPath to CGPath
var CGPath: CGPath {
let path = CGMutablePath()
let points = UnsafeMutablePointer<NSPoint>.allocate(capacity: 3)
let numElements = self.elementCount
for index in 0..<numElements {
let pathType = self.element(at: index, associatedPoints: points)
switch pathType {
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()
}
}
points.deallocate()
return path
}
}
func degreeToRadian(_ degree: Int) -> Double {
return Double(degree) * (Double.pi / 180)
}
func radianToDegree(_ radian: Double) -> Int {
return Int(radian * (180 / Double.pi))
}
func + (p1: CGPoint, p2: CGPoint) -> CGPoint {
return CGPoint(x: p1.x + p2.x, y: p1.y + p2.y)
}