@@ -5,9 +5,11 @@ import XCTest
5
5
6
6
import SwiftWin32
7
7
8
+ private typealias AffineTransform = SwiftWin32 . AffineTransform
9
+
8
10
final class CoreGraphicsTests : XCTestCase {
9
11
func testAffineTransformIdentity( ) {
10
- let identity : SwiftWin32 . AffineTransform = . identity
12
+ let identity : AffineTransform = . identity
11
13
XCTAssertEqual ( identity. a, 1.0 )
12
14
XCTAssertEqual ( identity. b, 0.0 )
13
15
XCTAssertEqual ( identity. c, 0.0 )
@@ -17,15 +19,16 @@ final class CoreGraphicsTests: XCTestCase {
17
19
}
18
20
19
21
func testAffineTransformIdentityIsIdentity( ) {
20
- let transform : SwiftWin32 . AffineTransform =
21
- SwiftWin32 . AffineTransform ( a: 1.0 , b: 0.0 ,
22
- c: 0.0 , d: 1.0 ,
23
- tx: 0.0 , ty: 0.0 )
24
-
25
- XCTAssertTrue ( SwiftWin32 . AffineTransform. identity. isIdentity)
22
+ let transform : AffineTransform = AffineTransform ( a: 1.0 , b: 0.0 ,
23
+ c: 0.0 , d: 1.0 ,
24
+ tx: 0.0 , ty: 0.0 )
26
25
XCTAssertTrue ( transform. isIdentity)
27
26
28
- XCTAssertFalse ( SwiftWin32 . AffineTransform ( ) . isIdentity)
27
+ XCTAssertTrue ( AffineTransform . identity. isIdentity)
28
+ }
29
+
30
+ func testAffineTransformDefaultConstructor( ) {
31
+ XCTAssertFalse ( AffineTransform ( ) . isIdentity)
29
32
}
30
33
31
34
func testRectComputedProperties( ) {
@@ -54,45 +57,38 @@ final class CoreGraphicsTests: XCTestCase {
54
57
XCTAssertEqual ( nonStandardizedOblong. applying ( AffineTransform ( rotationAngle: . pi / 2 ) ) ,
55
58
Rect ( x: 7.999999999999998 , y: - 32 , width: 8 , height: 16 ) )
56
59
57
- var rect : Rect =
58
- Rect ( origin: Point ( x: - 6 , y: - 7 ) ,
59
- size: Size ( width: 12 , height: 14 ) )
60
- . applying ( AffineTransform ( rotationAngle: Double . pi/ 2 ) )
61
-
62
- XCTAssertEqual ( rect. origin. x, - 7 )
63
- XCTAssertEqual ( rect. origin. y, - 6 )
64
- XCTAssertEqual ( rect. size. width, 14 )
65
- XCTAssertEqual ( rect. size. height, 12 )
66
-
67
-
68
- rect =
69
- Rect ( origin: Point ( x: 45 , y: 115 ) ,
70
- size: Size ( width: 13 , height: 14 ) )
71
- . applying ( AffineTransform ( rotationAngle: 42 ) )
72
-
73
- // Test data comes from the UIKit implementation, running on an iPhone,
74
- // and so deviation is expected.
75
- var accuracy = 1e-13
76
-
77
- XCTAssertEqual ( rect. origin. x, 82.20082974097352 , accuracy: accuracy)
78
- XCTAssertEqual ( rect. origin. y, - 104.75635541260408 , accuracy: accuracy)
79
- XCTAssertEqual ( rect. size. width, 18.031110765667435 , accuracy: accuracy)
80
- XCTAssertEqual ( rect. size. height, 17.514574532740156 , accuracy: accuracy)
81
-
82
- // Deviation increases with more operations
83
- accuracy = 1e-12
84
-
85
- rect =
86
- Rect ( origin: Point ( x: 45 , y: 115 ) ,
87
- size: Size ( width: 13 , height: 14 ) )
88
- . applying ( AffineTransform ( rotationAngle: - 104 ) )
89
- . applying ( AffineTransform ( translationX: - 26 , y: 22 ) )
90
- . applying ( AffineTransform ( scaleX: 7 , y: 5 ) )
91
-
92
- XCTAssertEqual ( rect. origin. x, - 856.8534424207578 , accuracy: accuracy)
93
- XCTAssertEqual ( rect. origin. y, - 428.36482622296273 , accuracy: accuracy)
94
- XCTAssertEqual ( rect. size. width, 117.68398448828839 , accuracy: accuracy)
95
- XCTAssertEqual ( rect. size. height, 87.18621695814943 , accuracy: accuracy)
60
+ var rect : Rect
61
+
62
+ rect = Rect ( origin: Point ( x: - 6 , y: - 7 ) ,
63
+ size: Size ( width: 12 , height: 14 ) )
64
+ . applying ( AffineTransform ( rotationAngle: . pi / 2 ) )
65
+ XCTAssertEqual ( rect, Rect ( x: - 7 , y: - 6 , width: 14 , height: 12 ) )
66
+
67
+ rect = Rect ( origin: Point ( x: 45 , y: 115 ) ,
68
+ size: Size ( width: 13 , height: 14 ) )
69
+ . applying ( AffineTransform ( rotationAngle: 42 ) )
70
+ XCTAssertEqual ( rect. origin. x, 82.20082974097352 ,
71
+ accuracy: . ulpOfOne. squareRoot ( ) )
72
+ XCTAssertEqual ( rect. origin. y, - 104.75635541260408 ,
73
+ accuracy: . ulpOfOne. squareRoot ( ) )
74
+ XCTAssertEqual ( rect. size. width, 18.031110765667435 ,
75
+ accuracy: . ulpOfOne. squareRoot ( ) )
76
+ XCTAssertEqual ( rect. size. height, 17.514574532740156 ,
77
+ accuracy: . ulpOfOne. squareRoot ( ) )
78
+
79
+ rect = Rect ( origin: Point ( x: 45 , y: 115 ) ,
80
+ size: Size ( width: 13 , height: 14 ) )
81
+ . applying ( AffineTransform ( rotationAngle: - 104 ) )
82
+ . applying ( AffineTransform ( translationX: - 26 , y: 22 ) )
83
+ . applying ( AffineTransform ( scaleX: 7 , y: 5 ) )
84
+ XCTAssertEqual ( rect. origin. x, - 856.8534424207578 ,
85
+ accuracy: . ulpOfOne. squareRoot ( ) )
86
+ XCTAssertEqual ( rect. origin. y, - 428.36482622296273 ,
87
+ accuracy: . ulpOfOne. squareRoot ( ) )
88
+ XCTAssertEqual ( rect. size. width, 117.68398448828839 ,
89
+ accuracy: . ulpOfOne. squareRoot ( ) )
90
+ XCTAssertEqual ( rect. size. height, 87.18621695814943 ,
91
+ accuracy: . ulpOfOne. squareRoot ( ) )
96
92
}
97
93
98
94
func testRectOffsetByNullRect( ) {
@@ -166,6 +162,7 @@ final class CoreGraphicsTests: XCTestCase {
166
162
static var allTests = [
167
163
( " testAffineTransformIdentity " , testAffineTransformIdentity) ,
168
164
( " testAffineTransformIdentityIsIdentity " , testAffineTransformIdentityIsIdentity) ,
165
+ ( " testAffineTransformDefaultConstructor " , testAffineTransformDefaultConstructor) ,
169
166
( " testRectComputedProperties " , testRectComputedProperties) ,
170
167
( " testRectApplyAffineTransform " , testRectApplyAffineTransform) ,
171
168
( " testRectOffsetByNullRect " , testRectOffsetByNullRect) ,
0 commit comments