杨锴
2024-08-14 909e20941e45f8712c012db602034b47da0bfdb0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
// CATransform3DExtensions.swift - Copyright 2024 SwifterSwift
 
// swiftlint:disable identifier_name
 
#if canImport(QuartzCore)
 
import QuartzCore
 
// MARK: - Equatable
 
extension CATransform3D: Equatable {
    // swiftlint:disable missing_swifterswift_prefix
 
    /// Returns a Boolean value indicating whether two values are equal.
    ///
    /// Equality is the inverse of inequality. For any values `a` and `b`,
    /// `a == b` implies that `a != b` is `false`.
    ///
    /// - Parameters:
    ///   - lhs: A value to compare.
    ///   - rhs: Another value to compare.
    @inlinable
    public static func == (lhs: CATransform3D, rhs: CATransform3D) -> Bool {
        CATransform3DEqualToTransform(lhs, rhs)
    }
 
    // swiftlint:enable missing_swifterswift_prefix
}
 
// MARK: - Static Properties
 
public extension CATransform3D {
    /// SwifterSwift: The identity transform: [1 0 0 0; 0 1 0 0; 0 0 1 0; 0 0 0 1].
    @inlinable
    static var identity: CATransform3D { CATransform3DIdentity }
}
 
// MARK: - Codable
 
extension CATransform3D: Codable {
    // swiftlint:disable missing_swifterswift_prefix
 
    /// Creates a new instance by decoding from the given decoder.
    ///
    /// This initializer throws an error if reading from the decoder fails, or if the data read is corrupted or
    /// otherwise invalid.
    /// - Parameter decoder: The decoder to read data from.
    @inlinable
    public init(from decoder: any Decoder) throws {
        var container = try decoder.unkeyedContainer()
        try self.init(m11: container.decode(CGFloat.self),
                      m12: container.decode(CGFloat.self),
                      m13: container.decode(CGFloat.self),
                      m14: container.decode(CGFloat.self),
                      m21: container.decode(CGFloat.self),
                      m22: container.decode(CGFloat.self),
                      m23: container.decode(CGFloat.self),
                      m24: container.decode(CGFloat.self),
                      m31: container.decode(CGFloat.self),
                      m32: container.decode(CGFloat.self),
                      m33: container.decode(CGFloat.self),
                      m34: container.decode(CGFloat.self),
                      m41: container.decode(CGFloat.self),
                      m42: container.decode(CGFloat.self),
                      m43: container.decode(CGFloat.self),
                      m44: container.decode(CGFloat.self))
    }
 
    /// Encodes this value into the given encoder.
    ///
    /// If the value fails to encode anything, encoder will encode an empty keyed container in its place.
    ///
    /// This function throws an error if any values are invalid for the given encoder’s format.
    /// - Parameter encoder: The encoder to write data to.
    @inlinable
    public func encode(to encoder: any Encoder) throws {
        var container = encoder.unkeyedContainer()
        try container.encode(m11)
        try container.encode(m12)
        try container.encode(m13)
        try container.encode(m14)
        try container.encode(m21)
        try container.encode(m22)
        try container.encode(m23)
        try container.encode(m24)
        try container.encode(m31)
        try container.encode(m32)
        try container.encode(m33)
        try container.encode(m34)
        try container.encode(m41)
        try container.encode(m42)
        try container.encode(m43)
        try container.encode(m44)
    }
 
    // swiftlint:enable missing_swifterswift_prefix
}
 
// MARK: - Initializers
 
public extension CATransform3D {
    /// SwifterSwift: Returns a transform that translates by `(tx, ty, tz)`.
    /// - Parameters:
    ///   - tx: x-axis translation
    ///   - ty: y-axis translation
    ///   - tz: z-axis translation
    @inlinable
    init(translationX tx: CGFloat, y ty: CGFloat, z tz: CGFloat) {
        self = CATransform3DMakeTranslation(tx, ty, tz)
    }
 
    /// SwifterSwift: Returns a transform that scales by `(sx, sy, sz)`.
    /// - Parameters:
    ///   - sx: x-axis scale
    ///   - sy: y-axis scale
    ///   - sz: z-axis scale
    @inlinable
    init(scaleX sx: CGFloat, y sy: CGFloat, z sz: CGFloat) {
        self = CATransform3DMakeScale(sx, sy, sz)
    }
 
    /// SwifterSwift: Returns a transform that rotates by `angle` radians about the vector `(x, y, z)`.
    ///
    /// If the vector has zero length the behavior is undefined.
    /// - Parameters:
    ///   - angle: The angle of rotation
    ///   - x: x position of the vector
    ///   - y: y position of the vector
    ///   - z: z position of the vector
    @inlinable
    init(rotationAngle angle: CGFloat, x: CGFloat, y: CGFloat, z: CGFloat) {
        self = CATransform3DMakeRotation(angle, x, y, z)
    }
}
 
// MARK: - Properties
 
public extension CATransform3D {
    /// SwifterSwift: Returns `true` if the receiver is the identity transform.
    @inlinable
    var isIdentity: Bool { CATransform3DIsIdentity(self) }
}
 
// MARK: - Methods
 
public extension CATransform3D {
    /// SwifterSwift: Translate the receiver by `(tx, ty, tz)`.
    /// - Parameters:
    ///   - tx: x-axis translation
    ///   - ty: y-axis translation
    ///   - tz: z-axis translation
    /// - Returns: The translated matrix.
    @inlinable
    func translatedBy(x tx: CGFloat, y ty: CGFloat,
                      z tz: CGFloat) -> CATransform3D {
        CATransform3DTranslate(self, tx, ty, tz)
    }
 
    /// SwifterSwift: Scale the receiver by `(sx, sy, sz)`.
    /// - Parameters:
    ///   - sx: x-axis scale
    ///   - sy: y-axis scale
    ///   - sz: z-axis scale
    /// - Returns: The scaled matrix.
    @inlinable
    func scaledBy(x sx: CGFloat, y sy: CGFloat,
                  z sz: CGFloat) -> CATransform3D {
        CATransform3DScale(self, sx, sy, sz)
    }
 
    /// SwifterSwift: Rotate the receiver by `angle` radians about the vector `(x, y, z)`.
    ///
    /// If the vector has zero length the behavior is undefined.
    /// - Parameters:
    ///   - angle: The angle of rotation
    ///   - x: x position of the vector
    ///   - y: y position of the vector
    ///   - z: z position of the vector
    /// - Returns: The rotated matrix.
    @inlinable
    func rotated(by angle: CGFloat, x: CGFloat, y: CGFloat, z: CGFloat) -> CATransform3D {
        CATransform3DRotate(self, angle, x, y, z)
    }
 
    /// SwifterSwift: Invert the receiver.
    ///
    /// Returns the original matrix if the receiver has no inverse.
    /// - Returns: The inverted matrix of the receiver.
    @inlinable
    func inverted() -> CATransform3D {
        CATransform3DInvert(self)
    }
 
    /// SwifterSwift: Concatenate `transform` to the receiver.
    /// - Parameter t2: The transform to concatenate on to the receiver
    /// - Returns: The concatenated matrix.
    @inlinable
    func concatenating(_ t2: CATransform3D) -> CATransform3D {
        CATransform3DConcat(self, t2)
    }
 
    /// SwifterSwift: Translate the receiver by `(tx, ty, tz)`.
    /// - Parameters:
    ///   - tx: x-axis translation
    ///   - ty: y-axis translation
    ///   - tz: z-axis translation
    @inlinable
    mutating func translateBy(x tx: CGFloat, y ty: CGFloat, z tz: CGFloat) {
        self = CATransform3DTranslate(self, tx, ty, tz)
    }
 
    /// SwifterSwift: Scale the receiver by `(sx, sy, sz)`.
    /// - Parameters:
    ///   - sx: x-axis scale
    ///   - sy: y-axis scale
    ///   - sz: z-axis scale
    @inlinable
    mutating func scaleBy(x sx: CGFloat, y sy: CGFloat, z sz: CGFloat) {
        self = CATransform3DScale(self, sx, sy, sz)
    }
 
    /// SwifterSwift: Rotate the receiver by `angle` radians about the vector `(x, y, z)`.
    ///
    /// If the vector has zero length the behavior is undefined.
    /// - Parameters:
    ///   - angle: The angle of rotation
    ///   - x: x position of the vector
    ///   - y: y position of the vector
    ///   - z: z position of the vector
    @inlinable
    mutating func rotate(by angle: CGFloat, x: CGFloat, y: CGFloat, z: CGFloat) {
        self = CATransform3DRotate(self, angle, x, y, z)
    }
 
    /// SwifterSwift: Invert the receiver.
    ///
    /// Returns the original matrix if the receiver has no inverse.
    @inlinable
    mutating func invert() {
        self = CATransform3DInvert(self)
    }
 
    /// SwifterSwift: Concatenate `transform` to the receiver.
    /// - Parameter t2: The transform to concatenate on to the receiver
    @inlinable
    mutating func concatenate(_ t2: CATransform3D) {
        self = CATransform3DConcat(self, t2)
    }
}
 
#if canImport(CoreGraphics)
 
import CoreGraphics
 
// MARK: - CGAffineTransform
 
public extension CATransform3D {
    /// SwifterSwift: Returns true if the receiver can be represented exactly by an affine transform.
    @inlinable
    var isAffine: Bool { CATransform3DIsAffine(self) }
 
    /// SwifterSwift: Returns the affine transform represented by the receiver.
    ///
    /// If the receiver can not be represented exactly by an affine transform the returned value is undefined.
    @inlinable
    func affineTransform() -> CGAffineTransform {
        CATransform3DGetAffineTransform(self)
    }
}
 
#endif
 
#endif
 
// swiftlint:enable identifier_name