@@ -132,9 +132,9 @@ private extension NSAffineTransformStruct {
132
132
Creates an affine transformation matrix from translation values.
133
133
The matrix takes the following form:
134
134
135
- [ 1 0 tX ]
136
- [ 0 1 tY ]
137
- [ 0 0 1 ]
135
+ [ 1 0 tX ]
136
+ [ 0 1 tY ]
137
+ [ 0 0 1 ]
138
138
*/
139
139
static func translation( tX tX: CGFloat , tY: CGFloat ) -> NSAffineTransformStruct {
140
140
return NSAffineTransformStruct (
@@ -148,9 +148,9 @@ private extension NSAffineTransformStruct {
148
148
Creates an affine transformation matrix from scaling values.
149
149
The matrix takes the following form:
150
150
151
- [ sX 0 0 ]
152
- [ 0 sY 0 ]
153
- [ 0 0 1 ]
151
+ [ sX 0 0 ]
152
+ [ 0 sY 0 ]
153
+ [ 0 0 1 ]
154
154
*/
155
155
static func scale( sX sX: CGFloat , sY: CGFloat ) -> NSAffineTransformStruct {
156
156
return NSAffineTransformStruct (
@@ -164,9 +164,9 @@ private extension NSAffineTransformStruct {
164
164
Creates an affine transformation matrix from rotation value (angle in radians).
165
165
The matrix takes the following form:
166
166
167
- [ cos α -sin α 0 ]
168
- [ sin α cos α 0 ]
169
- [ 0 0 1 ]
167
+ [ cos α -sin α 0 ]
168
+ [ sin α cos α 0 ]
169
+ [ 0 0 1 ]
170
170
*/
171
171
static func rotation( radians angle: CGFloat ) -> NSAffineTransformStruct {
172
172
let α = Double ( angle)
@@ -182,9 +182,9 @@ private extension NSAffineTransformStruct {
182
182
Creates an affine transformation matrix from a rotation value (angle in degrees).
183
183
The matrix takes the following form:
184
184
185
- [ cos α -sin α 0 ]
186
- [ sin α cos α 0 ]
187
- [ 0 0 1 ]
185
+ [ cos α -sin α 0 ]
186
+ [ sin α cos α 0 ]
187
+ [ 0 0 1 ]
188
188
*/
189
189
static func rotation( degrees angle: CGFloat ) -> NSAffineTransformStruct {
190
190
let α = Double ( angle) * M_PI / 180.0
@@ -198,13 +198,13 @@ private extension NSAffineTransformStruct {
198
198
the `transformStruct`'s affine transformation matrix.
199
199
The resulting matrix takes the following form:
200
200
201
- [ m11_T m12_T tX_T ] [ m11_M m12_M tX_M ]
202
- T * M = [ m21_T m22_T tY_T ] [ m21_M m22_M tY_M ]
203
- [ 0 0 1 ] [ 0 0 1 ]
201
+ [ m11_T m12_T tX_T ] [ m11_M m12_M tX_M ]
202
+ T * M = [ m21_T m22_T tY_T ] [ m21_M m22_M tY_M ]
203
+ [ 0 0 1 ] [ 0 0 1 ]
204
204
205
- [ (m11_T*m11_M + m12_T*m21_M) (m11_T*m12_M + m12_T*m22_M) (m11_T*tX_M + m12_T*tY_M + tX_T) ]
206
- = [ (m21_T*m11_M + m22_T*m21_M) (m21_T*m12_M + m22_T*m22_M) (m21_T*tX_M + m22_T*tY_M + tY_T) ]
207
- [ 0 0 1 ]
205
+ [ (m11_T*m11_M + m12_T*m21_M) (m11_T*m12_M + m12_T*m22_M) (m11_T*tX_M + m12_T*tY_M + tX_T) ]
206
+ = [ (m21_T*m11_M + m22_T*m21_M) (m21_T*m12_M + m22_T*m22_M) (m21_T*tX_M + m22_T*tY_M + tY_T) ]
207
+ [ 0 0 1 ]
208
208
*/
209
209
func concat( transformStruct: NSAffineTransformStruct ) -> NSAffineTransformStruct {
210
210
let ( t, m) = ( self , transformStruct)
@@ -221,9 +221,9 @@ private extension NSAffineTransformStruct {
221
221
Applies the affine transformation to `toPoint` and returns the result.
222
222
The resulting point takes the following form:
223
223
224
- [ x' ] [ x ] [ m11 m12 tX ] [ x ] [ m11*x + m12*y + tX ]
225
- [ y' ] = T [ y ] = [ m21 m22 tY ] [ y ] = [ m21*x + m22*y + tY ]
226
- [ 1 ] [ 1 ] [ 0 0 1 ] [ 1 ] [ 1 ]
224
+ [ x' ] [ x ] [ m11 m12 tX ] [ x ] [ m11*x + m12*y + tX ]
225
+ [ y' ] = T [ y ] = [ m21 m22 tY ] [ y ] = [ m21*x + m22*y + tY ]
226
+ [ 1 ] [ 1 ] [ 0 0 1 ] [ 1 ] [ 1 ]
227
227
*/
228
228
func applied( toPoint p: NSPoint ) -> NSPoint {
229
229
let x = ( m11 * p. x) + ( m12 * p. y) + tX
@@ -235,10 +235,10 @@ private extension NSAffineTransformStruct {
235
235
/**
236
236
Applies the affine transformation to `toSize` and returns the result.
237
237
The resulting size takes the following form:
238
-
239
- [ w' ] [ w ] [ m11 m12 tX ] [ w ] [ m11*w + m12*h ]
240
- [ h' ] = T [ h ] = [ m21 m22 tY ] [ h ] = [ m21*w + m22*h ]
241
- [ 0 ] [ 0 ] [ 0 0 1 ] [ 1 ] [ 0 ]
238
+
239
+ [ w' ] [ w ] [ m11 m12 tX ] [ w ] [ m11*w + m12*h ]
240
+ [ h' ] = T [ h ] = [ m21 m22 tY ] [ h ] = [ m21*w + m22*h ]
241
+ [ 0 ] [ 0 ] [ 0 0 1 ] [ 1 ] [ 0 ]
242
242
243
243
Note: Translation has no effect on the size.
244
244
*/
@@ -253,13 +253,17 @@ private extension NSAffineTransformStruct {
253
253
/**
254
254
Returns the inverse affine transformation matrix or `nil` if it has no inverse.
255
255
The receiver's affine transformation matrix can be divided into matrix sub-block as
256
- [ M t ]
257
- [ 0 1 ]
256
+
257
+ [ M t ]
258
+ [ 0 1 ]
259
+
258
260
where `M` represents the linear map and `t` the translation vector.
259
261
260
262
The inversion can then be calculated as
261
- [ inv(M) -inv(M) * t ]
262
- [ 0 1 ]
263
+
264
+ [ inv(M) -inv(M) * t ]
265
+ [ 0 1 ]
266
+
263
267
if `M` is invertible.
264
268
*/
265
269
var inverse : NSAffineTransformStruct ? {
0 commit comments