@@ -40,6 +40,20 @@ final class CoreGraphicsTests: XCTestCase {
40
40
}
41
41
42
42
func testRectApplyAffineTransform( ) {
43
+ let null : Rect = . null
44
+ XCTAssertEqual ( null. applying ( AffineTransform ( rotationAngle: . pi) ) ,
45
+ Rect . null)
46
+
47
+ let nonStandardized : Rect =
48
+ Rect ( origin: . zero, size: Size ( width: - 32 , height: - 32 ) )
49
+ XCTAssertEqual ( nonStandardized. applying ( . identity) ,
50
+ Rect ( x: - 32.0 , y: - 32.0 , width: 32.0 , height: 32.0 ) )
51
+
52
+ let nonStandardizedOblong : Rect =
53
+ Rect ( origin: Point ( x: - 16 , y: - 8 ) , size: Size ( width: - 16 , height: - 8 ) )
54
+ XCTAssertEqual ( nonStandardizedOblong. applying ( AffineTransform ( rotationAngle: . pi / 2 ) ) ,
55
+ Rect ( x: 7.999999999999998 , y: - 32 , width: 8 , height: 16 ) )
56
+
43
57
var rect : Rect =
44
58
Rect ( origin: Point ( x: - 6 , y: - 7 ) ,
45
59
size: Size ( width: 12 , height: 14 ) )
@@ -95,6 +109,58 @@ final class CoreGraphicsTests: XCTestCase {
95
109
. offsetBy ( dx: 4.0 , dy: 4.0 )
96
110
XCTAssertEqual ( r2. origin, Point ( x: 8.0 , y: 8.0 ) )
97
111
XCTAssertEqual ( r2. size, Size ( width: 4.0 , height: 4.0 ) )
112
+
113
+ let nonStandardized : Rect =
114
+ Rect ( origin: . zero, size: Size ( width: - 32 , height: - 32 ) )
115
+ XCTAssertEqual ( nonStandardized. offsetBy ( dx: 16.0 , dy: 16.0 ) ,
116
+ Rect ( x: - 16.0 , y: - 16.0 , width: 32.0 , height: 32.0 ) )
117
+ }
118
+
119
+ func testRectStandardizing( ) {
120
+ let null : Rect = . null
121
+ XCTAssertEqual ( null. standardized, Rect . null)
122
+
123
+ let normal : Rect = Rect ( x: 0 , y: 0 , width: 32 , height: 32 )
124
+ XCTAssertEqual ( normal. standardized, normal)
125
+
126
+ let negativeHeight : Rect = Rect ( x: 0 , y: 0 , width: - 32 , height: 32 )
127
+ XCTAssertEqual ( negativeHeight. standardized,
128
+ Rect ( x: - 32 , y: 0 , width: 32 , height: 32 ) )
129
+
130
+ let negativeWidth : Rect = Rect ( x: 0 , y: 0 , width: 32 , height: - 32 )
131
+ XCTAssertEqual ( negativeWidth. standardized,
132
+ Rect ( x: 0 , y: - 32 , width: 32 , height: 32 ) )
133
+
134
+ let negativeHeightAndWidth : Rect = Rect ( x: 0 , y: 0 , width: - 32 , height: - 32 )
135
+ XCTAssertEqual ( negativeHeightAndWidth. standardized,
136
+ Rect ( x: - 32 , y: - 32 , width: 32 , height: 32 ) )
137
+
138
+ let positiveOrigin : Rect = Rect ( x: 32 , y: 32 , width: - 32 , height: - 32 )
139
+ XCTAssertEqual ( positiveOrigin. standardized,
140
+ Rect ( origin: . zero, size: Size ( width: 32 , height: 32 ) ) )
141
+
142
+ let negativeOrigin : Rect = Rect ( x: - 32 , y: - 32 , width: - 32 , height: - 32 )
143
+ XCTAssertEqual ( negativeOrigin. standardized,
144
+ Rect ( x: - 64 , y: - 64 , width: 32 , height: 32 ) )
145
+ }
146
+
147
+ func testRectIntegral( ) {
148
+ let null : Rect = . null
149
+ XCTAssertEqual ( null. integral, Rect . null)
150
+ }
151
+
152
+ func testRectInsetBy( ) {
153
+ let null : Rect = . null
154
+ XCTAssertEqual ( null. insetBy ( dx: 0.0 , dy: 0.0 ) , Rect . null)
155
+
156
+ let normal : Rect = Rect ( x: 4.0 , y: 4.0 , width: 16.0 , height: 8.0 )
157
+ XCTAssertEqual ( normal. insetBy ( dx: 2.0 , dy: 2.0 ) ,
158
+ Rect ( x: 6.0 , y: 6.0 , width: 12.0 , height: 4.0 ) )
159
+
160
+ let nonStandardized : Rect =
161
+ Rect ( origin: . zero, size: Size ( width: - 32 , height: - 32 ) )
162
+ XCTAssertEqual ( nonStandardized. insetBy ( dx: 4.0 , dy: 4.0 ) ,
163
+ Rect ( x: - 28.0 , y: - 28.0 , width: 24.0 , height: 24.0 ) )
98
164
}
99
165
100
166
static var allTests = [
@@ -104,5 +170,8 @@ final class CoreGraphicsTests: XCTestCase {
104
170
( " testRectApplyAffineTransform " , testRectApplyAffineTransform) ,
105
171
( " testRectOffsetByNullRect " , testRectOffsetByNullRect) ,
106
172
( " testRectOffsetBy " , testRectOffsetBy) ,
173
+ ( " testRectStandardizing " , testRectStandardizing) ,
174
+ ( " testRectIntegral " , testRectIntegral) ,
175
+ ( " testRectInsetBy " , testRectInsetBy) ,
107
176
]
108
177
}
0 commit comments