Skip to content

Commit f886620

Browse files
ianpartridgephausler
authored andcommitted
AffineTransform: implement hashValue and improve tests (#1212)
* NSAffineTransform: implement hashValue and enable tests * AffineTransform: add rotation test
1 parent 7bf00de commit f886620

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

Foundation/AffineTransform.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,10 @@ open class NSAffineTransform : NSObject, NSCopying, NSSecureCoding {
338338
return other === self
339339
|| (other.transformStruct == self.transformStruct)
340340
}
341+
342+
open override var hashValue: Int {
343+
return transformStruct.hashValue
344+
}
341345

342346
public static var supportsSecureCoding: Bool {
343347
return true

TestFoundation/TestAffineTransform.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ class TestAffineTransform : XCTestCase {
3838
("test_AppendTransform", test_AppendTransform),
3939
("test_PrependTransform", test_PrependTransform),
4040
("test_TransformComposition", test_TransformComposition),
41+
("test_hashing_identity", test_hashing_identity),
42+
("test_hashing_values", test_hashing_values),
43+
("test_rotation_compose", test_rotation_compose),
4144
("test_Equal", test_Equal),
4245
("test_NSCoding", test_NSCoding),
4346
]
@@ -345,6 +348,16 @@ class TestAffineTransform : XCTestCase {
345348
XCTAssertEqual(ref.hashValue, val.hashValue)
346349
}
347350
}
351+
352+
func test_rotation_compose() {
353+
var t = AffineTransform.identity
354+
t.translate(x: 1.0, y: 1.0)
355+
t.rotate(byDegrees: 90)
356+
t.translate(x: -1.0, y: -1.0)
357+
let result = t.transform(NSPoint(x: 1.0, y: 2.0))
358+
XCTAssertEqual(0.0, Double(result.x), accuracy: accuracyThreshold)
359+
XCTAssertEqual(1.0, Double(result.y), accuracy: accuracyThreshold)
360+
}
348361

349362
func test_Equal() {
350363
let transform = NSAffineTransform()

0 commit comments

Comments
 (0)