Skip to content

Commit 3c7cb5d

Browse files
committed
CGSize extended initializers implemented
1 parent 6940c1c commit 3c7cb5d

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

Foundation/NSGeometry.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,20 @@ public struct CGSize {
117117
}
118118
}
119119

120+
extension CGSize {
121+
public static var zero: CGSize {
122+
return CGSize(width: CGFloat(0), height: CGFloat(0))
123+
}
124+
125+
public init(width: Int, height: Int) {
126+
self.init(width: CGFloat(width), height: CGFloat(height))
127+
}
128+
129+
public init(width: Double, height: Double) {
130+
self.init(width: CGFloat(width), height: CGFloat(height))
131+
}
132+
}
133+
120134
extension CGSize: Equatable {
121135
public static func ==(lhs: CGSize, rhs: CGSize) -> Bool {
122136
return lhs.width == rhs.width && lhs.height == rhs.height

TestFoundation/TestNSGeometry.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class TestNSGeometry : XCTestCase {
2929
("test_CGPoint_BasicConstruction", test_CGPoint_BasicConstruction),
3030
("test_CGPoint_ExtendedConstruction", test_CGPoint_ExtendedConstruction),
3131
("test_CGSize_BasicConstruction", test_CGSize_BasicConstruction),
32+
("test_CGSize_ExtendedConstruction", test_CGSize_ExtendedConstruction),
3233
("test_CGRect_BasicConstruction", test_CGRect_BasicConstruction),
3334
("test_NSEdgeInsets_BasicConstruction", test_NSEdgeInsets_BasicConstruction),
3435
("test_NSEdgeInsetsEqual", test_NSEdgeInsetsEqual),
@@ -137,6 +138,20 @@ class TestNSGeometry : XCTestCase {
137138
XCTAssertEqual(s2.width, CGFloat(3.6))
138139
XCTAssertEqual(s2.height, CGFloat(4.5))
139140
}
141+
142+
func test_CGSize_ExtendedConstruction() {
143+
let s1 = CGSize.zero
144+
XCTAssertEqual(s1.width, CGFloat(0))
145+
XCTAssertEqual(s1.height, CGFloat(0))
146+
147+
let s2 = CGSize(width: Int(3), height: Int(4))
148+
XCTAssertEqual(s2.width, CGFloat(3))
149+
XCTAssertEqual(s2.height, CGFloat(4))
150+
151+
let s3 = CGSize(width: Double(3.6), height: Double(4.5))
152+
XCTAssertEqual(s3.width, CGFloat(3.6))
153+
XCTAssertEqual(s3.height, CGFloat(4.5))
154+
}
140155

141156
func test_CGRect_BasicConstruction() {
142157
let r1 = CGRect()

0 commit comments

Comments
 (0)