Skip to content

Commit 492c2e6

Browse files
committed
Merge pull request #37 from mattrajca/master
2 parents 15beaf9 + 98862b4 commit 492c2e6

File tree

5 files changed

+66
-2
lines changed

5 files changed

+66
-2
lines changed

Foundation.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@
196196
5BF7AEBF1BCD51F9008F214A /* NSURL.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BDC3F4A1BCC5DCB00ED97BB /* NSURL.swift */; };
197197
5BF7AEC01BCD51F9008F214A /* NSUUID.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BDC3F4B1BCC5DCB00ED97BB /* NSUUID.swift */; };
198198
5BF7AEC11BCD51F9008F214A /* NSValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BDC3F4C1BCC5DCB00ED97BB /* NSValue.swift */; };
199+
C93559291C12C49F009FD6A9 /* TestNSAffineTransform.swift in Sources */ = {isa = PBXBuildFile; fileRef = C93559281C12C49F009FD6A9 /* TestNSAffineTransform.swift */; };
199200
E876A73E1C1180E000F279EC /* TestNSRange.swift in Sources */ = {isa = PBXBuildFile; fileRef = E876A73D1C1180E000F279EC /* TestNSRange.swift */; };
200201
EA66F6361BEED03E00136161 /* TargetConditionals.h in Headers */ = {isa = PBXBuildFile; fileRef = EA66F6351BEED03E00136161 /* TargetConditionals.h */; settings = {ATTRIBUTES = (Public, ); }; };
201202
EA66F6441BF1619600136161 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA66F6381BF1619600136161 /* main.swift */; };
@@ -518,6 +519,7 @@
518519
5BDC3FCF1BCF17E600ED97BB /* NSCFSet.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSCFSet.swift; sourceTree = "<group>"; };
519520
5BDC405C1BD6D83B00ED97BB /* TestFoundation.app */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = TestFoundation.app; sourceTree = BUILT_PRODUCTS_DIR; };
520521
5BF7AEC21BCD568D008F214A /* ForSwiftFoundationOnly.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ForSwiftFoundationOnly.h; sourceTree = "<group>"; };
522+
C93559281C12C49F009FD6A9 /* TestNSAffineTransform.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNSAffineTransform.swift; sourceTree = "<group>"; };
521523
E876A73D1C1180E000F279EC /* TestNSRange.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNSRange.swift; sourceTree = "<group>"; };
522524
EA313DFC1BE7F2E90060A403 /* CFURLComponents_Internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CFURLComponents_Internal.h; sourceTree = "<group>"; };
523525
EA313DFD1BE7F2E90060A403 /* CFURLComponents_URIParser.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = CFURLComponents_URIParser.c; sourceTree = "<group>"; };
@@ -1006,6 +1008,7 @@
10061008
EA66F65A1BF1976100136161 /* Tests */ = {
10071009
isa = PBXGroup;
10081010
children = (
1011+
C93559281C12C49F009FD6A9 /* TestNSAffineTransform.swift */,
10091012
EA66F63C1BF1619600136161 /* TestNSArray.swift */,
10101013
52829AD61C160D64003BC4EF /* TestNSCalendar.swift */,
10111014
EA66F63D1BF1619600136161 /* TestNSDictionary.swift */,
@@ -1709,6 +1712,7 @@
17091712
EA66F6521BF1619600136161 /* TestNSPropertyList.swift in Sources */,
17101713
4DC1D0801C12EEEF00B5948A /* TestNSPipe.swift in Sources */,
17111714
52829AD71C160D64003BC4EF /* TestNSCalendar.swift in Sources */,
1715+
C93559291C12C49F009FD6A9 /* TestNSAffineTransform.swift in Sources */,
17121716
EA66F64E1BF1619600136161 /* TestNSIndexSet.swift in Sources */,
17131717
22B9C1E11C165D7A00DECFF9 /* TestNSDate.swift in Sources */,
17141718
EA66F6541BF1619600136161 /* TestNSSet.swift in Sources */,

Foundation/NSAffineTransform.swift

+7-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ public struct NSAffineTransformStruct {
1616
public var tX: CGFloat
1717
public var tY: CGFloat
1818
public init() { NSUnimplemented() }
19-
public init(m11: CGFloat, m12: CGFloat, m21: CGFloat, m22: CGFloat, tX: CGFloat, tY: CGFloat) { NSUnimplemented() }
19+
public init(m11: CGFloat, m12: CGFloat, m21: CGFloat, m22: CGFloat, tX: CGFloat, tY: CGFloat) {
20+
(self.m11, self.m12, self.m21, self.m22) = (m11, m12, m21, m22)
21+
(self.tX, self.tY) = (tX, tY)
22+
}
2023
}
2124

2225
public class NSAffineTransform : NSObject, NSCopying, NSSecureCoding {
@@ -36,7 +39,9 @@ public class NSAffineTransform : NSObject, NSCopying, NSSecureCoding {
3639

3740
// Initialization
3841
public convenience init(transform: NSAffineTransform) { NSUnimplemented() }
39-
public override init() { NSUnimplemented() }
42+
public override init() {
43+
transformStruct = NSAffineTransformStruct(m11: CGFloat(1.0), m12: CGFloat(), m21: CGFloat(), m22: CGFloat(1.0), tX: CGFloat(), tY: CGFloat())
44+
}
4045

4146
// Translating
4247
public func translateXBy(deltaX: CGFloat, yBy deltaY: CGFloat) { NSUnimplemented() }

Foundation/NSGeometry.swift

+6
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ public func <(lhs: CGFloat, rhs: CGFloat) -> Bool {
3737
return lhs.native < rhs.native
3838
}
3939

40+
@_transparent extension Double {
41+
public init(_ value: CGFloat) {
42+
self = Double(value.native)
43+
}
44+
}
45+
4046
public struct CGPoint {
4147
public var x: CGFloat
4248
public var y: CGFloat
+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// This source file is part of the Swift.org open source project
2+
//
3+
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
4+
// Licensed under Apache License v2.0 with Runtime Library Exception
5+
//
6+
// See http://swift.org/LICENSE.txt for license information
7+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
8+
//
9+
10+
11+
12+
#if DEPLOYMENT_RUNTIME_OBJC || os(Linux)
13+
import Foundation
14+
import XCTest
15+
#else
16+
import SwiftFoundation
17+
import SwiftXCTest
18+
#endif
19+
20+
#if os(OSX) || os(iOS)
21+
import Darwin
22+
#elseif os(Linux)
23+
import Glibc
24+
#endif
25+
26+
class TestNSAffineTransform : XCTestCase {
27+
28+
var allTests : [(String, () -> ())] {
29+
return [
30+
("test_BasicConstruction", test_BasicConstruction)
31+
]
32+
}
33+
34+
func test_BasicConstruction() {
35+
let identityTransform = NSAffineTransform()
36+
let transformStruct = identityTransform.transformStruct
37+
38+
// The diagonal entries (1,1) and (2,2) of the identity matrix are ones. The other entries are zeros.
39+
// 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+
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)
47+
}
48+
}

TestFoundation/main.swift

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ internal func testBundle() -> NSBundle {
2222
// For the Swift version of the Foundation tests, we must manually list all test cases here.
2323
XCTMain([
2424
TestNSString(),
25+
TestNSAffineTransform(),
2526
TestNSArray(),
2627
TestNSCalendar(),
2728
TestNSDictionary(),

0 commit comments

Comments
 (0)