Skip to content

Commit 27e24d7

Browse files
committed
Merge branch 'master' of https://github.com/mattrajca/swift-corelibs-foundation into mattrajca-master
2 parents 5961557 + aee746d commit 27e24d7

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

Foundation/NSAffineTransform.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,9 @@ public class NSAffineTransform : NSObject, NSCopying, NSSecureCoding {
8585

8686
// Scaling
8787
public func scaleBy(scale: CGFloat) {
88-
let scale = NSAffineTransformStruct.scale(sX: scale, sY: scale)
89-
90-
transformStruct = transformStruct.concat(scale)
88+
scaleXBy(scale, yBy: scale)
9189
}
90+
9291
public func scaleXBy(scaleX: CGFloat, yBy scaleY: CGFloat) {
9392
let scale = NSAffineTransformStruct.scale(sX: scaleX, sY: scaleY)
9493

TestFoundation/TestNSAffineTransform.swift

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ class TestNSAffineTransform : XCTestCase {
3131
("test_BasicConstruction", test_BasicConstruction),
3232
("test_IdentityTransformation", test_IdentityTransformation),
3333
("test_Scale", test_Scale),
34+
("test_Scaling", test_Scaling),
35+
("test_TranslationScaling", test_TranslationScaling),
36+
("test_ScalingTranslation", test_ScalingTranslation),
3437
("test_Rotation_Degrees", test_Rotation_Degrees),
3538
("test_Rotation_Radians", test_Rotation_Radians),
3639
("test_Inversion", test_Inversion),
@@ -208,5 +211,37 @@ class TestNSAffineTransform : XCTestCase {
208211
checkPointTransformation(xyPlus5, point: NSMakePoint(CGFloat(-2.0), CGFloat(-3.0)),
209212
expectedPoint: NSMakePoint(CGFloat(3.0), CGFloat(2.0)))
210213
}
214+
215+
func test_Scaling() {
216+
let xyTimes5 = NSAffineTransform()
217+
xyTimes5.scaleBy(CGFloat(5.0))
218+
219+
checkPointTransformation(xyTimes5, point: NSMakePoint(CGFloat(-2.0), CGFloat(3.0)),
220+
expectedPoint: NSMakePoint(CGFloat(-10.0), CGFloat(15.0)))
221+
222+
let xTimes2YTimes3 = NSAffineTransform()
223+
xTimes2YTimes3.scaleXBy(CGFloat(2.0), yBy: CGFloat(-3.0))
224+
225+
checkPointTransformation(xTimes2YTimes3, point: NSMakePoint(CGFloat(-1.0), CGFloat(3.5)),
226+
expectedPoint: NSMakePoint(CGFloat(-2.0), CGFloat(-10.5)))
227+
}
228+
229+
func test_TranslationScaling() {
230+
let xPlus2XYTimes5 = NSAffineTransform()
231+
xPlus2XYTimes5.translateXBy(CGFloat(2.0), yBy: CGFloat())
232+
xPlus2XYTimes5.scaleXBy(CGFloat(5.0), yBy: CGFloat(-5.0))
233+
234+
checkPointTransformation(xPlus2XYTimes5, point: NSMakePoint(CGFloat(1.0), CGFloat(2.0)),
235+
expectedPoint: NSMakePoint(CGFloat(7.0), CGFloat(-10.0)))
236+
}
237+
238+
func test_ScalingTranslation() {
239+
let xyTimes5XPlus3 = NSAffineTransform()
240+
xyTimes5XPlus3.scaleBy(CGFloat(5.0))
241+
xyTimes5XPlus3.translateXBy(CGFloat(3.0), yBy: CGFloat())
242+
243+
checkPointTransformation(xyTimes5XPlus3, point: NSMakePoint(CGFloat(1.0), CGFloat(2.0)),
244+
expectedPoint: NSMakePoint(CGFloat(20.0), CGFloat(10.0)))
245+
}
211246
}
212247

0 commit comments

Comments
 (0)