24
24
#endif
25
25
26
26
class TestNSAffineTransform : XCTestCase {
27
+ private let accuracyThreshold = 0.001
27
28
28
29
var allTests : [ ( String , ( ) -> ( ) ) ] {
29
30
return [
30
- ( " test_BasicConstruction " , test_BasicConstruction)
31
+ ( " test_BasicConstruction " , test_BasicConstruction) ,
32
+ ( " test_IdentityTransformation " , test_IdentityTransformation)
31
33
]
32
34
}
33
35
@@ -37,12 +39,36 @@ class TestNSAffineTransform : XCTestCase {
37
39
38
40
// The diagonal entries (1,1) and (2,2) of the identity matrix are ones. The other entries are zeros.
39
41
// TODO: These should use DBL_MAX but it's not available as part of Glibc on Linux
40
- XCTAssertEqualWithAccuracy ( Double ( transformStruct. m11) , Double ( 1 ) , accuracy: 0.001 )
41
- XCTAssertEqualWithAccuracy ( Double ( transformStruct. m22) , Double ( 1 ) , accuracy: 0.001 )
42
+ XCTAssertEqualWithAccuracy ( Double ( transformStruct. m11) , Double ( 1 ) , accuracy: accuracyThreshold )
43
+ XCTAssertEqualWithAccuracy ( Double ( transformStruct. m22) , Double ( 1 ) , accuracy: accuracyThreshold )
42
44
43
- XCTAssertEqualWithAccuracy ( Double ( transformStruct. m12) , Double ( 0 ) , accuracy: 0.001 )
44
- XCTAssertEqualWithAccuracy ( Double ( transformStruct. m21) , Double ( 0 ) , accuracy: 0.001 )
45
- XCTAssertEqualWithAccuracy ( Double ( transformStruct. tX) , Double ( 0 ) , accuracy: 0.001 )
46
- XCTAssertEqualWithAccuracy ( Double ( transformStruct. tY) , Double ( 0 ) , accuracy: 0.001 )
45
+ XCTAssertEqualWithAccuracy ( Double ( transformStruct. m12) , Double ( 0 ) , accuracy: accuracyThreshold)
46
+ XCTAssertEqualWithAccuracy ( Double ( transformStruct. m21) , Double ( 0 ) , accuracy: accuracyThreshold)
47
+ XCTAssertEqualWithAccuracy ( Double ( transformStruct. tX) , Double ( 0 ) , accuracy: accuracyThreshold)
48
+ XCTAssertEqualWithAccuracy ( Double ( transformStruct. tY) , Double ( 0 ) , accuracy: accuracyThreshold)
49
+ }
50
+
51
+ func test_IdentityTransformation( ) {
52
+ let identityTransform = NSAffineTransform ( )
53
+
54
+ func checkIdentityPointTransformation( point: NSPoint ) {
55
+ let newPoint = identityTransform. transformPoint ( point)
56
+ XCTAssertEqualWithAccuracy ( Double ( newPoint. x) , Double ( point. x) , accuracy: accuracyThreshold)
57
+ XCTAssertEqualWithAccuracy ( Double ( newPoint. y) , Double ( point. y) , accuracy: accuracyThreshold)
58
+ }
59
+
60
+ checkIdentityPointTransformation ( NSPoint ( ) )
61
+ checkIdentityPointTransformation ( NSMakePoint ( CGFloat ( 24.5 ) , CGFloat ( 10.0 ) ) )
62
+ checkIdentityPointTransformation ( NSMakePoint ( CGFloat ( - 7.5 ) , CGFloat ( 2.0 ) ) )
63
+
64
+ func checkIdentitySizeTransformation( size: NSSize ) {
65
+ let newSize = identityTransform. transformSize ( size)
66
+ XCTAssertEqualWithAccuracy ( Double ( newSize. width) , Double ( size. width) , accuracy: accuracyThreshold)
67
+ XCTAssertEqualWithAccuracy ( Double ( newSize. height) , Double ( size. height) , accuracy: accuracyThreshold)
68
+ }
69
+
70
+ checkIdentitySizeTransformation ( NSSize ( ) )
71
+ checkIdentitySizeTransformation ( NSMakeSize ( CGFloat ( 13.0 ) , CGFloat ( 12.5 ) ) )
72
+ checkIdentitySizeTransformation ( NSMakeSize ( CGFloat ( 100.0 ) , CGFloat ( - 100.0 ) ) )
47
73
}
48
74
}
0 commit comments