@@ -23,7 +23,7 @@ class PathTests: XCTestCase {
23
23
24
24
func testInitCGPathEmpty( ) {
25
25
// trivial test of an empty path
26
- let path = Path ( CGMutablePath ( ) )
26
+ let path = Path ( cgPath : CGMutablePath ( ) )
27
27
XCTAssert ( path. subpaths. isEmpty)
28
28
}
29
29
@@ -32,7 +32,7 @@ class PathTests: XCTestCase {
32
32
// simple test of a rectangle (note that this CGPath uses a moveTo())
33
33
let rect = CGRect ( origin: CGPoint ( x: 0 , y: 0 ) , size: CGSize ( width: 1 , height: 2 ) )
34
34
let cgPath1 = CGPath ( rect: rect, transform: nil )
35
- let path1 = Path ( cgPath1)
35
+ let path1 = Path ( cgPath : cgPath1)
36
36
37
37
let p1 = CGPoint ( x: 0.0 , y: 0.0 )
38
38
let p2 = CGPoint ( x: 1.0 , y: 0.0 )
@@ -50,7 +50,7 @@ class PathTests: XCTestCase {
50
50
// test of a ellipse (4 cubic curves)
51
51
let rect = CGRect ( origin: CGPoint ( x: 0 , y: 0 ) , size: CGSize ( width: 1 , height: 2 ) )
52
52
let cgPath2 = CGPath ( ellipseIn: rect, transform: nil )
53
- let path2 = Path ( cgPath2)
53
+ let path2 = Path ( cgPath : cgPath2)
54
54
55
55
let p1 = CGPoint ( x: 1.0 , y: 1.0 )
56
56
let p2 = CGPoint ( x: 0.5 , y: 2.0 )
@@ -87,7 +87,7 @@ class PathTests: XCTestCase {
87
87
cgPath3. addQuadCurve ( to: p1, control: p6)
88
88
cgPath3. closeSubpath ( )
89
89
90
- let path3 = Path ( cgPath3)
90
+ let path3 = Path ( cgPath : cgPath3)
91
91
XCTAssertEqual ( path3. subpaths. count, 1 )
92
92
XCTAssertEqual ( path3. subpaths [ 0 ] . curves. count, 4 )
93
93
XCTAssertEqual ( path3. subpaths [ 0 ] . curves [ 1 ] as! QuadraticBezierCurve , QuadraticBezierCurve ( p0: p2, p1: p3, p2: p4) )
@@ -107,7 +107,7 @@ class PathTests: XCTestCase {
107
107
cgPath4. move ( to: p3)
108
108
cgPath4. addLine ( to: p4)
109
109
110
- let path4 = Path ( cgPath4)
110
+ let path4 = Path ( cgPath : cgPath4)
111
111
XCTAssertEqual ( path4. subpaths. count, 2 )
112
112
XCTAssertEqual ( path4. subpaths [ 0 ] . curves. count, 1 )
113
113
XCTAssertEqual ( path4. subpaths [ 1 ] . curves. count, 1 )
@@ -121,12 +121,12 @@ class PathTests: XCTestCase {
121
121
let circleCGPath = CGMutablePath ( )
122
122
circleCGPath. addEllipse ( in: CGRect ( origin: CGPoint ( x: 2.0 , y: 3.0 ) , size: CGSize ( width: 2.0 , height: 2.0 ) ) )
123
123
124
- let circlePath = Path ( circleCGPath) // a circle centered at (3, 4) with radius 2
124
+ let circlePath = Path ( cgPath : circleCGPath) // a circle centered at (3, 4) with radius 2
125
125
126
126
let rectangleCGPath = CGMutablePath ( )
127
127
rectangleCGPath. addRect ( CGRect ( origin: CGPoint ( x: 3.0 , y: 4.0 ) , size: CGSize ( width: 2.0 , height: 2.0 ) ) )
128
128
129
- let rectanglePath = Path ( rectangleCGPath)
129
+ let rectanglePath = Path ( cgPath : rectangleCGPath)
130
130
131
131
let intersections = rectanglePath. intersects ( path: circlePath)
132
132
@@ -139,7 +139,7 @@ class PathTests: XCTestCase {
139
139
let circleCGPath = CGMutablePath ( )
140
140
circleCGPath. addEllipse ( in: CGRect ( origin: CGPoint ( x: - 1.0 , y: - 1.0 ) , size: CGSize ( width: 2.0 , height: 2.0 ) ) )
141
141
142
- let circlePath = Path ( circleCGPath) // a circle centered at origin with radius 1
142
+ let circlePath = Path ( cgPath : circleCGPath) // a circle centered at origin with radius 1
143
143
144
144
let d = CGFloat ( 0.1 )
145
145
let p1 = CGPoint ( x: - 3.0 , y: 0.0 )
@@ -155,4 +155,34 @@ class PathTests: XCTestCase {
155
155
156
156
}
157
157
158
+ func testEquatable( ) {
159
+ let rect = CGRect ( origin: CGPoint ( x: - 1 , y: - 1 ) , size: CGSize ( width: 2 , height: 2 ) )
160
+ let path1 = Path ( cgPath: CGPath ( rect: rect, transform: nil ) )
161
+ let path2 = Path ( cgPath: CGPath ( ellipseIn: rect, transform: nil ) )
162
+ let path3 = Path ( cgPath: CGPath ( rect: rect, transform: nil ) )
163
+ XCTAssertNotEqual ( path1, path2)
164
+ XCTAssertEqual ( path1, path3)
165
+ }
166
+
167
+ func testIsEqual( ) {
168
+ let rect = CGRect ( origin: CGPoint ( x: - 1 , y: - 1 ) , size: CGSize ( width: 2 , height: 2 ) )
169
+ let path1 = Path ( cgPath: CGPath ( rect: rect, transform: nil ) )
170
+ let path2 = Path ( cgPath: CGPath ( ellipseIn: rect, transform: nil ) )
171
+ let path3 = Path ( cgPath: CGPath ( rect: rect, transform: nil ) )
172
+
173
+ let string = " hello " as NSString
174
+
175
+ XCTAssertFalse ( path1. isEqual ( nil ) )
176
+ XCTAssertFalse ( path1. isEqual ( string) )
177
+ XCTAssertFalse ( path1. isEqual ( path2) )
178
+ XCTAssertTrue ( path1. isEqual ( path3) )
179
+ }
180
+
181
+ func testEncodeDecode( ) {
182
+ let rect = CGRect ( origin: CGPoint ( x: - 1 , y: - 1 ) , size: CGSize ( width: 2 , height: 2 ) )
183
+ let path = Path ( cgPath: CGPath ( rect: rect, transform: nil ) )
184
+ let data = NSKeyedArchiver . archivedData ( withRootObject: path)
185
+ let decodedPath = NSKeyedUnarchiver . unarchiveObject ( with: data) as! Path
186
+ XCTAssertEqual ( decodedPath, path)
187
+ }
158
188
}
0 commit comments