profile
viewpoint
If you are wondering where the data of this site comes from, please visit https://api.github.com/users/spevans/events. GitMemory does not store any data, but only uses NGINX to cache data for a period of time. The idea behind GitMemory is simply to give users a better reading experience.

apple/swift 57342

The Swift Programming Language

apple/swift-corelibs-foundation 4409

The Foundation Project, providing core utilities, internationalization, and OS independence

apple/swift-corelibs-xctest 931

The XCTest Project, A Swift core library for providing unit test support

spevans/swift-project1 218

A minimal bare metal kernel in Swift

spevans/swift-kstdlib 12

Fork of apple/swift with modifications to the stdlib to use in a bare metal kernel for use with swift-project1

spevans/vmm386 11

Virtual Machine Monitor/386 bare metal hypervisor. Run vm86 mode processes on a 386

spevans/FoundationBenchmarks 5

Various benchmarks for testing swift-corelibs-foundation

spevans/swift-integer128 3

Int128 and UInt128 for Swift

spevans/mach-o-reader 2

Test utility for reading Mach-O files

spevans/qurl-safari-extension 2

Simple Safari extension to queue URLs for later reading

pull request commentapple/swift-corelibs-foundation

[SR-14384][SR-14974] Fix `Decimal.ulp`, `nextUp`, `nextDown`

@swift-ci test

xwu

comment created time in 19 days

PullRequestReviewEvent
PullRequestReviewEvent
PullRequestReviewEvent

Pull request review commentapple/swift-corelibs-foundation

[SR-14384][SR-14974] Fix `Decimal.ulp`, `nextUp`, `nextDown`

 class TestDecimal: XCTestCase {     }          func test_ULP() {-        let x = 0.1 as Decimal+        var x = 0.1 as Decimal         XCTAssertFalse(x.ulp > x)++        x = .nan+        XCTAssertTrue(x.ulp.isNaN)+        XCTAssertTrue(x.nextDown.isNaN)+        XCTAssertTrue(x.nextUp.isNaN)++        x = .greatestFiniteMagnitude+        XCTAssertEqual(x.ulp, Decimal(string: "1e127")!)+        XCTAssertEqual(x.nextDown, x - Decimal(string: "1e127")!)+        XCTAssertTrue(x.nextUp.isNaN)++        x = 1+        XCTAssertEqual(x.ulp, Decimal(string: "1e-38")!)+        XCTAssertEqual(x.nextDown, x - Decimal(string: "1e-38")!)+        XCTAssertEqual(x.nextUp, x + Decimal(string: "1e-38")!)++        x = .leastNonzeroMagnitude+        // XCTAssertEqual(x.ulp, x)        // SR-6671+        // XCTAssertEqual(x.nextDown, 0)   // SR-6671+        // XCTAssertEqual(x.nextUp, x + x) // SR-6671+        XCTAssertNotEqual(x.ulp, 0)+        XCTAssertNotEqual(x.nextDown, x)+        XCTAssertNotEqual(x.nextUp, x)++        x = 0+        XCTAssertEqual(x.ulp, Decimal(string: "1e-128")!)+        XCTAssertEqual(x.nextDown, -Decimal(string: "1e-128")!)+        XCTAssertEqual(x.nextUp, Decimal(string: "1e-128")!)++        x = -1+        XCTAssertEqual(x.ulp, (1 as Decimal).ulp)+        XCTAssertEqual(x.nextDown, -((1 as Decimal).nextUp))+        XCTAssertEqual(x.nextUp, -((1 as Decimal).nextDown))

Could you add a few extra tests for these last 3 to test the result against absolute values eg: XCTAssertEqual(x.ulp, Decimal(string: "1e-38")!) in case there is an equal and opposite bug in both methods.

xwu

comment created time in 23 days

PullRequestReviewEvent

Pull request review commentapple/swift-corelibs-foundation

[SR-14384][SR-14974] Fix `Decimal.ulp`, `nextUp`, `nextDown`

 class TestDecimal: XCTestCase {     }          func test_ULP() {-        let x = 0.1 as Decimal+        var x = 0.1 as Decimal         XCTAssertFalse(x.ulp > x)++        x = .nan+        XCTAssertTrue(x.ulp.isNaN)+        XCTAssertTrue(x.nextDown.isNaN)+        XCTAssertTrue(x.nextUp.isNaN)++        x = .greatestFiniteMagnitude+        XCTAssertEqual(x.ulp, Decimal(string: "1e127")!)+        XCTAssertEqual(x.nextDown, x - Decimal(string: "1e127")!)+        XCTAssertTrue(x.nextUp.isNaN)++        x = 1+        XCTAssertEqual(x.ulp, Decimal(string: "1e-38")!)+        XCTAssertEqual(x.nextDown, x - Decimal(string: "1e-38")!)+        XCTAssertEqual(x.nextUp, x + Decimal(string: "1e-38")!)++        x = .leastNonzeroMagnitude+        // XCTAssertEqual(x.ulp, x)        // SR-6671+        // XCTAssertEqual(x.nextDown, 0)   // SR-6671+        // XCTAssertEqual(x.nextUp, x + x) // SR-6671

These tests can be enabled now that #3067 has been merged.

xwu

comment created time in 23 days

PullRequestReviewEvent
PullRequestReviewEvent

pull request commentapple/swift-corelibs-foundation

Restore previous value of `Decimal.leastFiniteMagnitude` for compatibility and deprecate

Sorry, I meant it would be up to the Foundation team to decide on the API change, so just removing the deprecation change would allow the PR to go through whilst they come to a decision. Personally I think its a reasonable change.

cc @millenomi

xwu

comment created time in 24 days

PullRequestReviewEvent
PullRequestReviewEvent

push eventapple/swift-corelibs-foundation

Xiaodi Wu

commit sha cbf6a73f675ea6d0fee9c7ce45004d5a1fcf2ecf

Fix orthography of 'orthography.'

view details

Simon Evans

commit sha 671cadb15479038ddb88fec657a5dc50c63923c5

Merge pull request #3069 from xwu/orthography Fix orthography of 'orthography'

view details

push time in 25 days

PR merged apple/swift-corelibs-foundation

Reviewers
Fix orthography of 'orthography'

The irony is fun, but particularly in the case of the placeholder API, it only serves its purpose if it's holding the right place.

+11 -11

1 comment

1 changed file

xwu

pr closed time in 25 days

PullRequestReviewEvent

pull request commentapple/swift-corelibs-foundation

[SR-15132] Fix `Decimal` implementation of significand APIs

I agree your fix is correct in that it makes it compatible with the operation of the types conforming to FloatingPoint as documented: https://developer.apple.com/documentation/swift/float/1847179-init however the parameters are listed as being:

sign: The sign to use for the new value.
exponent: The new value’s exponent.
significand: The new value’s significand.

Do you think the documentation is assuming the significand is always positive? From my reading of it, the sign parameter sets the sign of the resulting value.

I wonder if a better fix would be to trap on a negative significand - although that could be considered API breaking. I think the documentation may need to be made a bit clearer as it currently seems to contradict itself.

I'd be interested to hear @stephentyrone thoughts on this.

Also, at some point the documentation for https://developer.apple.com/documentation/foundation/decimal/2143030-init needs to be expanded since its single line summary could be interpreted as the sign parameter does indeed set the value's sign.

xwu

comment created time in a month

Pull request review commentapple/swift-corelibs-foundation

[SR-15132] Fix `Decimal` implementation of significand APIs

 class TestDecimal: XCTestCase {         XCTAssertEqual(zero3.description, "0")     } +    func test_Significand() {+        let x = -42 as Decimal+        XCTAssertEqual(x.significand.sign, .plus)+        let y = Decimal(sign: .plus, exponent: 0, significand: x)+        XCTAssertEqual(y.sign, .minus)

Could you expand the tests to explicitly test all 4 combinations of sign/significand being +/-, and test the result of the initialiser against the full value, thanks. I know its a bit cumbersome but I find with number tests its useful to cover all the cases if possible.

xwu

comment created time in a month

PullRequestReviewEvent

pull request commentapple/swift-corelibs-foundation

Fix `AffineTransform.rotate(byRadians:)` implementation.

I ran the tests against BigSur 11.5's Foundation using the DarwinCompatibilityTests project and there was a few test failures (unless these work in Monterrey)?

filip-sakel

comment created time in a month

PullRequestReviewEvent

Pull request review commentapple/swift-corelibs-foundation

Fix `AffineTransform.rotate(byRadians:)` implementation.

 // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors // -class TestAffineTransform : XCTestCase {+#if NS_FOUNDATION_ALLOWS_TESTABLE_IMPORT+    #if canImport(SwiftFoundation) && !DEPLOYMENT_RUNTIME_OBJC+        @testable import SwiftFoundation+    #else+        @testable import Foundation+    #endif+#endif++// MARK: - Tests++class TestAffineTransform: XCTestCase {     private let accuracyThreshold = 0.001      static var allTests: [(String, (TestAffineTransform) -> () throws -> Void)] {         return [-            ("test_BasicConstruction", test_BasicConstruction),-            ("test_IdentityTransformation", test_IdentityTransformation),-            ("test_Scale", test_Scale),-            ("test_Scaling", test_Scaling),-            ("test_TranslationScaling", test_TranslationScaling),-            ("test_ScalingTranslation", test_ScalingTranslation),-            ("test_Rotation_Degrees", test_Rotation_Degrees),-            ("test_Rotation_Radians", test_Rotation_Radians),-            ("test_Inversion", test_Inversion),-            ("test_IdentityTransformation", test_IdentityTransformation),-            ("test_Translation", test_Translation),-            ("test_TranslationComposed", test_TranslationComposed),-            ("test_AppendTransform", test_AppendTransform),-            ("test_PrependTransform", test_PrependTransform),-            ("test_TransformComposition", test_TransformComposition),-            ("test_hashing", test_hashing),-            ("test_rotation_compose", test_rotation_compose),-            ("test_translation_and_rotation", test_translation_and_rotation),-            ("test_Equal", test_Equal),-            ("test_NSCoding", test_NSCoding),+            ("testConstruction", testConstruction),+            ("testBridging", testBridging),+            ("testEqualityHashing", testEqualityHashing),+            ("testVectorTransformations", testVectorTransformations),+            ("testIdentityConstruction", testIdentityConstruction),+            ("testIdentity", testIdentity),+            ("testTranslationConstruction", testTranslationConstruction),+            ("testTranslation", testTranslation),+            ("testScalingConstruction", testScalingConstruction),+            ("testScaling", testScaling),+            ("testRotationConstruction", testRotationConstruction),+            ("testRotation", testRotation),+            ("testTranslationScaling", testTranslationScaling),+            ("testTranslationRotation", testTranslationRotation),+            ("testScalingRotation", testScalingRotation),+            ("testInversion", testInversion),+            ("testPrependTransform", testPrependTransform),+            ("testAppendTransform", testAppendTransform),+            ("testNSCoding", testNSCoding),         ]     }-    -    func checkPointTransformation(_ transform: NSAffineTransform, point: NSPoint, expectedPoint: NSPoint, _ message: String = "", file: StaticString = #file, line: UInt = #line) {+}+ +// MARK: - Helper++extension TestAffineTransform {+    func assert(+        point: CGPoint,+        transformedBy transform: AffineTransform,+        equals expectedPoint: CGPoint,+        _ message: String = "",+        file: StaticString = #file, line: UInt = #line+    ) {+        let size = CGSize(width: point.x, height: point.y)+                 let newPoint = transform.transform(point)-        XCTAssertEqual(Double(newPoint.x), Double(expectedPoint.x), accuracy: accuracyThreshold,-                       "x (expected: \(expectedPoint.x), was: \(newPoint.x)): \(message)", file: file, line: line)-        XCTAssertEqual(Double(newPoint.y), Double(expectedPoint.y), accuracy: accuracyThreshold,-                       "y (expected: \(expectedPoint.y), was: \(newPoint.y)): \(message)", file: file, line: line)-    }-    -    func checkSizeTransformation(_ transform: NSAffineTransform, size: NSSize, expectedSize: NSSize, _ message: String = "", file: StaticString = #file, line: UInt = #line) {         let newSize = transform.transform(size)-        XCTAssertEqual(Double(newSize.width), Double(expectedSize.width), accuracy: accuracyThreshold,-                       "width (expected: \(expectedSize.width), was: \(newSize.width)): \(message)", file: file, line: line)-        XCTAssertEqual(Double(newSize.height), Double(expectedSize.height), accuracy: accuracyThreshold,-                       "height (expected: \(expectedSize.height), was: \(newSize.height)): \(message)", file: file, line: line)-    }-    -    func checkRectTransformation(_ transform: NSAffineTransform, rect: NSRect, expectedRect: NSRect, _ message: String = "", file: StaticString = #file, line: UInt = #line) {-        let newRect = transform.transformRect(rect)         -        checkPointTransformation(transform, point: newRect.origin, expectedPoint: expectedRect.origin,-                                 "origin (expected: \(expectedRect.origin), was: \(newRect.origin)): \(message)", file: file, line: line)-        checkSizeTransformation(transform, size: newRect.size, expectedSize: expectedRect.size,-                                "size (expected: \(expectedRect.size), was: \(newRect.size)): \(message)", file: file, line: line)+        XCTAssertEqual(+            newPoint.x, newSize.width,+            "Expected point x and size width to match",+            file: file, line: line+        )+        XCTAssertEqual(+            newPoint.y, newSize.height,+            "Expected point y and size height to match",+            file: file, line: line+        )+        +        let nsTransform = transform as NSAffineTransform+        XCTAssertEqual(+            nsTransform.transform(point), newPoint,+            "Expected NSAffineTransform to match AffineTransform's point-accepting transform(_:)",+            file: file, line: line+        )+        XCTAssertEqual(+            nsTransform.transform(size), newSize,+            "Expected NSAffineTransform to match AffineTransform's size-accepting transform(_:)",+            file: file, line: line+        )+        +        XCTAssertEqual(+            newPoint.x, expectedPoint.x,+            accuracy: accuracyThreshold,+            "Invalid x: \(message)",+            file: file, line: line+        )+        +        XCTAssertEqual(+            newPoint.y, expectedPoint.y,+            accuracy: accuracyThreshold,+            "Invalid y: \(message)",+            file: file, line: line+        )     }+} -    func test_BasicConstruction() {-        let identityTransform = NSAffineTransform()-        let transformStruct = identityTransform.transformStruct--        // The diagonal entries (1,1) and (2,2) of the identity matrix are ones. The other entries are zeros.-        // TODO: These should use DBL_MAX but it's not available as part of Glibc on Linux-        XCTAssertEqual(Double(transformStruct.m11), Double(1), accuracy: accuracyThreshold)-        XCTAssertEqual(Double(transformStruct.m22), Double(1), accuracy: accuracyThreshold)--        XCTAssertEqual(Double(transformStruct.m12), Double(0), accuracy: accuracyThreshold)-        XCTAssertEqual(Double(transformStruct.m21), Double(0), accuracy: accuracyThreshold)-        XCTAssertEqual(Double(transformStruct.tX), Double(0), accuracy: accuracyThreshold)-        XCTAssertEqual(Double(transformStruct.tY), Double(0), accuracy: accuracyThreshold)+// MARK: - Construction++extension TestAffineTransform {+    func testConstruction() {+        let transform = AffineTransform(+            m11: 1, m12: 2,+            m21: 3, m22: 4,+             tX: 5,  tY: 6+        )+        +        XCTAssertEqual(transform.m11, 1)+        XCTAssertEqual(transform.m12, 2)+        XCTAssertEqual(transform.m21, 3)+        XCTAssertEqual(transform.m22, 4)+        XCTAssertEqual(transform.tX , 5)+        XCTAssertEqual(transform.tY , 6)     }+} -    func test_IdentityTransformation() {-        let identityTransform = NSAffineTransform()+// MARK: - Bridging -        func checkIdentityPointTransformation(_ point: NSPoint) {-            checkPointTransformation(identityTransform, point: point, expectedPoint: point)-        }+extension TestAffineTransform {+    func testBridging() {+        let transform = AffineTransform(+            m11: 1, m12: 2,+            m21: 3, m22: 4,+             tX: 5,  tY: 6+        )         -        checkIdentityPointTransformation(NSPoint.zero)-        checkIdentityPointTransformation(NSPoint(x: 24.5, y: 10.0))-        checkIdentityPointTransformation(NSPoint(x: -7.5, y: 2.0))+        let nsTransform = NSAffineTransform(transform: transform)+        XCTAssertEqual(transform, nsTransform.affineTransform)+        +        XCTAssertEqual(nsTransform as AffineTransform, transform)+    }+} -        func checkIdentitySizeTransformation(_ size: NSSize) {-            checkSizeTransformation(identityTransform, size: size, expectedSize: size)+// MARK: Equality++extension TestAffineTransform {+    func testEqualityHashing() {+        let samples = [+            AffineTransform(m11: 1.5, m12: 2.0, m21: 3.0, m22: 4.0, tX: 5.0, tY: 6.0),+            AffineTransform(m11: 1.0, m12: 2.5, m21: 3.0, m22: 4.0, tX: 5.0, tY: 6.0),+            AffineTransform(m11: 1.0, m12: 2.0, m21: 3.5, m22: 4.0, tX: 5.0, tY: 6.0),+            AffineTransform(m11: 1.0, m12: 2.0, m21: 3.0, m22: 4.5, tX: 5.0, tY: 6.0),+            AffineTransform(m11: 1.0, m12: 2.0, m21: 3.0, m22: 4.0, tX: 5.5, tY: 6.0),+            AffineTransform(m11: 1.0, m12: 2.0, m21: 3.0, m22: 4.0, tX: 5.0, tY: 6.5),+        ].map(NSAffineTransform.init)+        +        for (index, sample) in samples.enumerated() {+            let otherSamples: [NSAffineTransform] = {+                var samplesCopy = samples+                samplesCopy.remove(at: index)+                return samplesCopy+            }()+            +            XCTAssertEqual(sample, sample)+            XCTAssertEqual(sample.hashValue, sample.hashValue)+            +            for otherSample in otherSamples {+                XCTAssert(sample != otherSample)+                XCTAssert(sample.hashValue != otherSample.hashValue)+            }         }+    }+} -        checkIdentitySizeTransformation(NSSize.zero)-        checkIdentitySizeTransformation(NSSize(width: 13.0, height: 12.5))-        checkIdentitySizeTransformation(NSSize(width: 100.0, height: -100.0))+// MARK: - Vector Transformations++extension TestAffineTransform {+    func testVectorTransformations() {+        +        // To transform a given point with coordinated px and py,+        // we do:+        //+        //   [ x' y' ]+        //+        // = [ px  py ]  *  [ m11  m12 ] + [ tX  tY ]+        //                  [ m21  m22 ]+        //+        // = [ px*m11+py*m21+tX  px*m12+py*m22+tY ]+        +        assert(+            point: CGPoint(x: 10, y: 20),+            transformedBy: AffineTransform(+                m11: 1, m12: 2,+                m21: 3, m22: 4,+                 tX: 5,  tY: 6+            ),+            // [ px*m11+py*m21+tX  px*m12+py*m22+tY ]+            // [   10*1+20*3+5       10*2+20*4+6    ]+            // [       75                106        ]+            equals: CGPoint(x: 75, y: 106)+        )+        +        assert(+            point: CGPoint(x: 5, y: 25),+            transformedBy: AffineTransform(+                m11: 5, m12: 4,+                m21: 3, m22: 2,+                 tX: 1,  tY: 0+            ),+            // [ px*m11+py*m21+tX  px*m12+py*m22+tY ]+            // [    5*5+25*3+1        5*4+25*2+0    ]+            // [       101                70        ]+            equals: CGPoint(x: 101, y: 70)+        )     }-    -    func test_Translation() {-        let point = NSPoint.zero+} -        let noop = NSAffineTransform()-        noop.translateX(by: CGFloat(), yBy: CGFloat())-        checkPointTransformation(noop, point: point, expectedPoint: point)-        -        let translateH = NSAffineTransform()-        translateH.translateX(by: CGFloat(10.0), yBy: CGFloat())-        checkPointTransformation(translateH, point: point, expectedPoint: NSPoint(x: 10.0, y: 0.0))-        -        let translateV = NSAffineTransform()-        translateV.translateX(by: CGFloat(), yBy: CGFloat(20.0))-        checkPointTransformation(translateV, point: point, expectedPoint: NSPoint(x: 0.0, y: 20.0))-        -        let translate = NSAffineTransform()-        translate.translateX(by: CGFloat(-30.0), yBy: CGFloat(40.0))-        checkPointTransformation(translate, point: point, expectedPoint: NSPoint(x: -30.0, y: 40.0))+// MARK: - Identity++extension TestAffineTransform {+    func testIdentityConstruction() {+        // Check that the transform matrix is the identity:+        // [ 1 0 0 ]+        // [ 0 1 0 ]+        // [ 0 0 1 ]+        let identity = AffineTransform(+            m11: 1, m12: 0,+            m21: 0, m22: 1,+             tX: 0,  tY: 0+        )+        +        XCTAssertEqual(AffineTransform(), identity)+        XCTAssertEqual(AffineTransform.identity, identity)+        XCTAssertEqual(NSAffineTransform().affineTransform, identity)     }     -    func test_Scale() {-        let size = NSSize(width: 10.0, height: 10.0)-        -        let noop = NSAffineTransform()-        noop.scale(by: CGFloat(1.0))-        checkSizeTransformation(noop, size: size, expectedSize: size)-        -        let shrink = NSAffineTransform()-        shrink.scale(by: CGFloat(0.5))-        checkSizeTransformation(shrink, size: size, expectedSize: NSSize(width: 5.0, height: 5.0))-        -        let grow = NSAffineTransform()-        grow.scale(by: CGFloat(3.0))-        checkSizeTransformation(grow, size: size, expectedSize: NSSize(width: 30.0, height: 30.0))-        -        let stretch = NSAffineTransform()-        stretch.scaleX(by: CGFloat(2.0), yBy: CGFloat(0.5))-        checkSizeTransformation(stretch, size: size, expectedSize: NSSize(width: 20.0, height: 5.0))+    func testIdentity() {+        assert(+            point: CGPoint(x: 25, y: 10),+            transformedBy: .identity,+            equals: CGPoint(x: 25, y: 10)+        )     }-    -    func test_Rotation_Degrees() {-        let point = NSPoint(x: 10.0, y: 10.0)+} -        let noop = NSAffineTransform()-        noop.rotate(byDegrees: CGFloat())-        checkPointTransformation(noop, point: point, expectedPoint: point)-        -        let tenEighty = NSAffineTransform()-        tenEighty.rotate(byDegrees: CGFloat(1080.0))-        checkPointTransformation(tenEighty, point: point, expectedPoint: point)+// MARK: - Translation++extension TestAffineTransform {+    func testTranslationConstruction() {+        let translatedIdentity: AffineTransform = {+            var transform = AffineTransform.identity+            transform.translate(x: 15, y: 20)+            return transform+        }()         -        let rotateCounterClockwise = NSAffineTransform()-        rotateCounterClockwise.rotate(byDegrees: CGFloat(90.0))-        checkPointTransformation(rotateCounterClockwise, point: point, expectedPoint: NSPoint(x: -10.0, y: 10.0))+        let translation = AffineTransform(+            translationByX: 15, byY: 20+        )         -        let rotateClockwise = NSAffineTransform()-        rotateClockwise.rotate(byDegrees: CGFloat(-90.0))-        checkPointTransformation(rotateClockwise, point: point, expectedPoint: NSPoint(x: 10.0, y: -10.0))+        let nsTranslation: NSAffineTransform = {+            let transform = NSAffineTransform()+            transform.translateX(by: 15, yBy: 20)+            return transform+        }()         -        let reflectAboutOrigin = NSAffineTransform()-        reflectAboutOrigin.rotate(byDegrees: CGFloat(180.0))-        checkPointTransformation(reflectAboutOrigin, point: point, expectedPoint: NSPoint(x: -10.0, y: -10.0))+        XCTAssertEqual(translatedIdentity, translation)+        XCTAssertEqual(nsTranslation.affineTransform, translation)     }     -    func test_Rotation_Radians() {-        let point = NSPoint(x: 10.0, y: 10.0)+    func testTranslation() {+        assert(+            point: CGPoint(x: 10, y: 10),+            transformedBy: AffineTransform(+                translationByX: 0, byY: 0+            ),+            equals: CGPoint(x: 10, y: 10)+        )+        +        assert(+            point: CGPoint(x: 10, y: 10),+            transformedBy: AffineTransform(+                translationByX: 0, byY: 5+            ),+            equals: CGPoint(x: 10, y: 15)+        )+        +        assert(+            point: CGPoint(x: 10, y: 10),+            transformedBy: AffineTransform(+                translationByX: 5, byY: 5+            ),+            equals: CGPoint(x: 15, y: 15)+        )+        +        assert(+            point: CGPoint(x: -2, y: -3),+            // Translate by 5+            transformedBy: {+                var transform = AffineTransform.identity+                +                transform.translate(x: 2, y: 3)+                transform.translate(x: 3, y: 2)+                +                return transform+            }(),+            equals: CGPoint(x: 3, y: 2)+        )+    }+}++// MARK: - Scaling -        let noop = NSAffineTransform()-        noop.rotate(byRadians: CGFloat())-        checkPointTransformation(noop, point: point, expectedPoint: point)+extension TestAffineTransform {+    func testScalingConstruction() {+        // Distinct x/y Components         -        let tenEighty = NSAffineTransform()-        tenEighty.rotate(byRadians: 6 * .pi)-        checkPointTransformation(tenEighty, point: point, expectedPoint: point)+        let scaledIdentity: AffineTransform = {+            var transform = AffineTransform.identity+            transform.scale(x: 15, y: 20)+            return transform+        }()         -        let rotateCounterClockwise = NSAffineTransform()-        rotateCounterClockwise.rotate(byRadians: .pi / 2)-        checkPointTransformation(rotateCounterClockwise, point: point, expectedPoint: NSPoint(x: -10.0, y: 10.0))+        let scaling = AffineTransform(+            scaleByX: 15, byY: 20+        )         -        let rotateClockwise = NSAffineTransform()-        rotateClockwise.rotate(byRadians: -.pi / 2)-        checkPointTransformation(rotateClockwise, point: point, expectedPoint: NSPoint(x: 10.0, y: -10.0))+        let nsScaling: NSAffineTransform = {+            let transform = NSAffineTransform()+            transform.scaleX(by: 15, yBy: 20)+            return transform+        }()         -        let reflectAboutOrigin = NSAffineTransform()-        reflectAboutOrigin.rotate(byRadians: .pi)-        checkPointTransformation(reflectAboutOrigin, point: point, expectedPoint: NSPoint(x: -10.0, y: -10.0))-    }-    -    func test_Inversion() {-        let point = NSPoint(x: 10.0, y: 10.0)--        var translate = AffineTransform()-        translate.translate(x: CGFloat(-30.0), y: CGFloat(40.0))+        XCTAssertEqual(scaledIdentity, scaling)+        XCTAssertEqual(nsScaling.affineTransform, scaling)         -        var rotate = AffineTransform()-        translate.rotate(byDegrees: CGFloat(30.0))+        // Same x/y Components         -        var scale = AffineTransform()-        scale.scale(CGFloat(2.0))+        let differentScaledIdentity = AffineTransform(+            scaleByX: 20, byY: 20+        )         -        let identityTransform = NSAffineTransform()+        let sameScaledIdentity: AffineTransform = {+            var transform = AffineTransform.identity+            transform.scale(20)+            return transform+        }()         -        // append transformations-        identityTransform.append(translate)-        identityTransform.append(rotate)-        identityTransform.append(scale)+        let sameScaling = AffineTransform(+            scale: 20+        )         -        // invert transformations-        scale.invert()-        rotate.invert()-        translate.invert()+        let sameNSScaling: NSAffineTransform = {+            let transform = NSAffineTransform()+            transform.scale(by: 20)+            return transform+        }()         -        // append inverse transformations in reverse order-        identityTransform.append(scale)-        identityTransform.append(rotate)-        identityTransform.append(translate)+        XCTAssertEqual(sameScaling, differentScaledIdentity)         -        checkPointTransformation(identityTransform, point: point, expectedPoint: point)-    }--    func test_TranslationComposed() {-        let xyPlus5 = NSAffineTransform()-        xyPlus5.translateX(by: CGFloat(2.0), yBy: CGFloat(3.0))-        xyPlus5.translateX(by: CGFloat(3.0), yBy: CGFloat(2.0))--        checkPointTransformation(xyPlus5, point: NSPoint(x: -2.0, y: -3.0),-                                  expectedPoint: NSPoint(x: 3.0, y: 2.0))-    }--    func test_Scaling() {-        let xyTimes5 = NSAffineTransform()-        xyTimes5.scale(by: CGFloat(5.0))--        checkPointTransformation(xyTimes5, point: NSPoint(x: -2.0, y: 3.0),-                                   expectedPoint: NSPoint(x: -10.0, y: 15.0))--        let xTimes2YTimes3 = NSAffineTransform()-        xTimes2YTimes3.scaleX(by: CGFloat(2.0), yBy: CGFloat(-3.0))--        checkPointTransformation(xTimes2YTimes3, point: NSPoint(x: -1.0, y: 3.5),-                                         expectedPoint: NSPoint(x: -2.0, y: -10.5))+        XCTAssertEqual(sameScaledIdentity, sameScaling)+        XCTAssertEqual(sameNSScaling.affineTransform, sameScaling)     } -    func test_TranslationScaling() {-        let xPlus2XYTimes5 = NSAffineTransform()-        xPlus2XYTimes5.translateX(by: CGFloat(2.0), yBy: CGFloat())-        xPlus2XYTimes5.scaleX(by: CGFloat(5.0), yBy: CGFloat(-5.0))--        checkPointTransformation(xPlus2XYTimes5, point: NSPoint(x: 1.0, y: 2.0),-                                         expectedPoint: NSPoint(x: 7.0, y: -10.0))+    func testScaling() {+        assert(+            point: CGPoint(x: 10, y: 10),+            transformedBy: AffineTransform(+                scaleByX: 1, byY: 0+            ),+            equals: CGPoint(x: 10, y: 0)+        )+        +        assert(+            point: CGPoint(x: 10, y: 10),+            transformedBy: AffineTransform(+                scaleByX: 0.5, byY: 1+            ),+            equals: CGPoint(x: 5, y: 10)+        )+        +        assert(+            point: CGPoint(x: 10, y: 10),+            transformedBy: AffineTransform(+                scaleByX: 0, byY: 2+            ),+            equals: CGPoint(x: 0, y: 20)+        )+        +        assert(+            point: CGPoint(x: 10, y: 10),+            // Scale by (2, 0)+            transformedBy: {+                var transform = AffineTransform.identity+                +                transform.scale(x: 4, y: 0)+                transform.scale(x: 0.5, y: 1)+                +                return transform+            }(),+            equals: CGPoint(x: 20, y: 0)+        )     }+} -    func test_ScalingTranslation() {-        let xyTimes5XPlus3 = NSAffineTransform()-        xyTimes5XPlus3.scale(by: CGFloat(5.0))-        xyTimes5XPlus3.translateX(by: CGFloat(3.0), yBy: CGFloat())--        checkPointTransformation(xyTimes5XPlus3, point: NSPoint(x: 1.0, y: 2.0),-                                         expectedPoint: NSPoint(x: 20.0, y: 10.0))+// MARK: - Rotation++extension TestAffineTransform {+    func testRotationConstruction() {+        let baseRotation = AffineTransform(+            rotationByRadians: .pi+        )+        +        func assertPiRotation(+            _ rotation: AffineTransform,+            file: StaticString = #file,+            line: UInt = #line+        ) {+            let point = CGPoint(x: 10, y: 15)+            let newPoint = baseRotation.transform(point)+            +            self.assert(+                point: point, transformedBy: rotation,+                equals: newPoint,+                file: file, line: line+            )+        }+        +        // Radians+        +        assertPiRotation({+            var transform = AffineTransform.identity+            transform.rotate(byRadians: .pi)+            return transform+        }())+        +        assertPiRotation({+            let transform = NSAffineTransform()+            transform.rotate(byRadians: .pi)+            return transform+        }() as NSAffineTransform as AffineTransform)+        +        // Degrees+        +        assertPiRotation({+            var transform = AffineTransform.identity+            transform.rotate(byDegrees: 180)+            return transform+        }())+        +        assertPiRotation(AffineTransform(+            rotationByDegrees: 180+        ))+        +        assertPiRotation({+            let transform = NSAffineTransform()+            transform.rotate(byDegrees: 180)+            return transform+        }() as NSAffineTransform as AffineTransform)     }     -    func test_AppendTransform() {-        let point = NSPoint(x: 10.0, y: 10.0)+    func testRotation() {+        assert(+            point: CGPoint(x: 10, y: 15),+            transformedBy: AffineTransform(rotationByDegrees: 0),+            equals: CGPoint(x: 10, y: 15)+        )+        +        assert(+            point: CGPoint(x: 10, y: 15),+            transformedBy: AffineTransform(rotationByDegrees: 1080),+            equals: CGPoint(x: 10, y: 15)+        )+        +        // Counter-clockwise rotation+        assert(+            point: CGPoint(x: 15, y: 10),+            transformedBy: AffineTransform(rotationByRadians: .pi / 2),+            equals: CGPoint(x: -10, y: 15)+        )+        +        // Clockwise rotation+        assert(+            point: CGPoint(x: 15, y: 10),+            transformedBy: AffineTransform(rotationByDegrees: -90),+            equals: CGPoint(x: 10, y: -15)+        )+        +        // Reflect about origin+        assert(+            point: CGPoint(x: 10, y: 15),+            transformedBy: AffineTransform(rotationByRadians: .pi),+            equals: CGPoint(x: -10, y: -15)+        )+        +        // Composed reflection about origin+        assert(+            point: CGPoint(x: 10, y: 15),+            // Rotate by 180º+            transformedBy: {+                var transform = AffineTransform.identity+                +                transform.rotate(byDegrees: 90)+                transform.rotate(byDegrees: 90)+                +                return transform+            }(),+            equals: CGPoint(x: -10, y: -15)+        )+    }+} -        var identityTransform = AffineTransform()-        identityTransform.append(identityTransform)-        checkPointTransformation(NSAffineTransform(transform: identityTransform), point: point, expectedPoint: point)-        -        var translate = AffineTransform()-        translate.translate(x: CGFloat(10.0), y: CGFloat())-        -        var scale = AffineTransform()-        scale.scale(CGFloat(2.0))-        -        let translateThenScale = NSAffineTransform(transform: translate)-        translateThenScale.append(scale)-        checkPointTransformation(translateThenScale, point: point, expectedPoint: NSPoint(x: 40.0, y: 20.0))+// MARK: - Permutations++extension TestAffineTransform {+    func testTranslationScaling() {+        assert(+            point: CGPoint(x: 1, y: 3),+            // Translate by (2, 0) then scale by (5, -5)+            transformedBy: {+                var transform = AffineTransform.identity+                +                transform.append(.init(translationByX: 2, byY: 0))+                transform.append(.init(scaleByX: 5, byY: -5))+                print(">>>>>>>>>>>>>>>>>", transform)+                +                transform = .identity+                transform.translate(x: 2, y: 0)+                transform.scale(x: 5, y: -5)+                print(">>>>>>>>>>>>>>>>>", transform)

These two debug print()s should be removed.

filip-sakel

comment created time in a month

PullRequestReviewEvent

Pull request review commentapple/swift-corelibs-foundation

Fix `AffineTransform.rotate(byRadians:)` implementation.

 // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors // -class TestAffineTransform : XCTestCase {+#if NS_FOUNDATION_ALLOWS_TESTABLE_IMPORT+    #if canImport(SwiftFoundation) && !DEPLOYMENT_RUNTIME_OBJC+        @testable import SwiftFoundation+    #else+        @testable import Foundation+    #endif+#endif++// MARK: - Tests++class TestAffineTransform: XCTestCase {     private let accuracyThreshold = 0.001      static var allTests: [(String, (TestAffineTransform) -> () throws -> Void)] {         return [-            ("test_BasicConstruction", test_BasicConstruction),-            ("test_IdentityTransformation", test_IdentityTransformation),-            ("test_Scale", test_Scale),-            ("test_Scaling", test_Scaling),-            ("test_TranslationScaling", test_TranslationScaling),-            ("test_ScalingTranslation", test_ScalingTranslation),-            ("test_Rotation_Degrees", test_Rotation_Degrees),-            ("test_Rotation_Radians", test_Rotation_Radians),-            ("test_Inversion", test_Inversion),-            ("test_IdentityTransformation", test_IdentityTransformation),-            ("test_Translation", test_Translation),-            ("test_TranslationComposed", test_TranslationComposed),-            ("test_AppendTransform", test_AppendTransform),-            ("test_PrependTransform", test_PrependTransform),-            ("test_TransformComposition", test_TransformComposition),-            ("test_hashing", test_hashing),-            ("test_rotation_compose", test_rotation_compose),-            ("test_translation_and_rotation", test_translation_and_rotation),-            ("test_Equal", test_Equal),-            ("test_NSCoding", test_NSCoding),+            ("testConstruction", testConstruction),+            ("testBridging", testBridging),+            ("testEqualityHashing", testEqualityHashing),+            ("testVectorTransformations", testVectorTransformations),+            ("testIdentityConstruction", testIdentityConstruction),+            ("testIdentity", testIdentity),+            ("testTranslationConstruction", testTranslationConstruction),+            ("testTranslation", testTranslation),+            ("testScalingConstruction", testScalingConstruction),+            ("testScaling", testScaling),+            ("testRotationConstruction", testRotationConstruction),+            ("testRotation", testRotation),+            ("testTranslationScaling", testTranslationScaling),+            ("testTranslationRotation", testTranslationRotation),+            ("testScalingRotation", testScalingRotation),+            ("testInversion", testInversion),+            ("testPrependTransform", testPrependTransform),+            ("testAppendTransform", testAppendTransform),+            ("testNSCoding", testNSCoding),         ]     }-    -    func checkPointTransformation(_ transform: NSAffineTransform, point: NSPoint, expectedPoint: NSPoint, _ message: String = "", file: StaticString = #file, line: UInt = #line) {+}+ +// MARK: - Helper++extension TestAffineTransform {+    func assert(

I would suggest a different name to assert() as that is common global function, maybe just checkValue or so.

filip-sakel

comment created time in a month

Pull request review commentapple/swift-corelibs-foundation

Fix `AffineTransform.rotate(byRadians:)` implementation.

 // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors // -class TestAffineTransform : XCTestCase {+#if NS_FOUNDATION_ALLOWS_TESTABLE_IMPORT+    #if canImport(SwiftFoundation) && !DEPLOYMENT_RUNTIME_OBJC+        @testable import SwiftFoundation+    #else+        @testable import Foundation+    #endif+#endif++// MARK: - Tests++class TestAffineTransform: XCTestCase {     private let accuracyThreshold = 0.001      static var allTests: [(String, (TestAffineTransform) -> () throws -> Void)] {         return [-            ("test_BasicConstruction", test_BasicConstruction),-            ("test_IdentityTransformation", test_IdentityTransformation),-            ("test_Scale", test_Scale),-            ("test_Scaling", test_Scaling),-            ("test_TranslationScaling", test_TranslationScaling),-            ("test_ScalingTranslation", test_ScalingTranslation),-            ("test_Rotation_Degrees", test_Rotation_Degrees),-            ("test_Rotation_Radians", test_Rotation_Radians),-            ("test_Inversion", test_Inversion),-            ("test_IdentityTransformation", test_IdentityTransformation),-            ("test_Translation", test_Translation),-            ("test_TranslationComposed", test_TranslationComposed),-            ("test_AppendTransform", test_AppendTransform),-            ("test_PrependTransform", test_PrependTransform),-            ("test_TransformComposition", test_TransformComposition),-            ("test_hashing", test_hashing),-            ("test_rotation_compose", test_rotation_compose),-            ("test_translation_and_rotation", test_translation_and_rotation),-            ("test_Equal", test_Equal),-            ("test_NSCoding", test_NSCoding),+            ("testConstruction", testConstruction),+            ("testBridging", testBridging),+            ("testEqualityHashing", testEqualityHashing),+            ("testVectorTransformations", testVectorTransformations),+            ("testIdentityConstruction", testIdentityConstruction),+            ("testIdentity", testIdentity),+            ("testTranslationConstruction", testTranslationConstruction),+            ("testTranslation", testTranslation),+            ("testScalingConstruction", testScalingConstruction),+            ("testScaling", testScaling),+            ("testRotationConstruction", testRotationConstruction),+            ("testRotation", testRotation),+            ("testTranslationScaling", testTranslationScaling),+            ("testTranslationRotation", testTranslationRotation),+            ("testScalingRotation", testScalingRotation),+            ("testInversion", testInversion),+            ("testPrependTransform", testPrependTransform),+            ("testAppendTransform", testAppendTransform),+            ("testNSCoding", testNSCoding),         ]     }-    -    func checkPointTransformation(_ transform: NSAffineTransform, point: NSPoint, expectedPoint: NSPoint, _ message: String = "", file: StaticString = #file, line: UInt = #line) {+}+ +// MARK: - Helper++extension TestAffineTransform {+    func assert(+        point: CGPoint,+        transformedBy transform: AffineTransform,+        equals expectedPoint: CGPoint,+        _ message: String = "",+        file: StaticString = #file, line: UInt = #line+    ) {+        let size = CGSize(width: point.x, height: point.y)+                 let newPoint = transform.transform(point)-        XCTAssertEqual(Double(newPoint.x), Double(expectedPoint.x), accuracy: accuracyThreshold,-                       "x (expected: \(expectedPoint.x), was: \(newPoint.x)): \(message)", file: file, line: line)-        XCTAssertEqual(Double(newPoint.y), Double(expectedPoint.y), accuracy: accuracyThreshold,-                       "y (expected: \(expectedPoint.y), was: \(newPoint.y)): \(message)", file: file, line: line)-    }-    -    func checkSizeTransformation(_ transform: NSAffineTransform, size: NSSize, expectedSize: NSSize, _ message: String = "", file: StaticString = #file, line: UInt = #line) {         let newSize = transform.transform(size)-        XCTAssertEqual(Double(newSize.width), Double(expectedSize.width), accuracy: accuracyThreshold,-                       "width (expected: \(expectedSize.width), was: \(newSize.width)): \(message)", file: file, line: line)-        XCTAssertEqual(Double(newSize.height), Double(expectedSize.height), accuracy: accuracyThreshold,-                       "height (expected: \(expectedSize.height), was: \(newSize.height)): \(message)", file: file, line: line)-    }-    -    func checkRectTransformation(_ transform: NSAffineTransform, rect: NSRect, expectedRect: NSRect, _ message: String = "", file: StaticString = #file, line: UInt = #line) {-        let newRect = transform.transformRect(rect)         -        checkPointTransformation(transform, point: newRect.origin, expectedPoint: expectedRect.origin,-                                 "origin (expected: \(expectedRect.origin), was: \(newRect.origin)): \(message)", file: file, line: line)-        checkSizeTransformation(transform, size: newRect.size, expectedSize: expectedRect.size,-                                "size (expected: \(expectedRect.size), was: \(newRect.size)): \(message)", file: file, line: line)+        XCTAssertEqual(+            newPoint.x, newSize.width,+            "Expected point x and size width to match",+            file: file, line: line+        )+        XCTAssertEqual(+            newPoint.y, newSize.height,+            "Expected point y and size height to match",+            file: file, line: line+        )+        +        let nsTransform = transform as NSAffineTransform+        XCTAssertEqual(+            nsTransform.transform(point), newPoint,+            "Expected NSAffineTransform to match AffineTransform's point-accepting transform(_:)",+            file: file, line: line+        )+        XCTAssertEqual(+            nsTransform.transform(size), newSize,+            "Expected NSAffineTransform to match AffineTransform's size-accepting transform(_:)",+            file: file, line: line+        )+        +        XCTAssertEqual(+            newPoint.x, expectedPoint.x,+            accuracy: accuracyThreshold,+            "Invalid x: \(message)",+            file: file, line: line+        )+        +        XCTAssertEqual(+            newPoint.y, expectedPoint.y,+            accuracy: accuracyThreshold,+            "Invalid y: \(message)",+            file: file, line: line+        )     }+} -    func test_BasicConstruction() {-        let identityTransform = NSAffineTransform()-        let transformStruct = identityTransform.transformStruct--        // The diagonal entries (1,1) and (2,2) of the identity matrix are ones. The other entries are zeros.-        // TODO: These should use DBL_MAX but it's not available as part of Glibc on Linux-        XCTAssertEqual(Double(transformStruct.m11), Double(1), accuracy: accuracyThreshold)-        XCTAssertEqual(Double(transformStruct.m22), Double(1), accuracy: accuracyThreshold)--        XCTAssertEqual(Double(transformStruct.m12), Double(0), accuracy: accuracyThreshold)-        XCTAssertEqual(Double(transformStruct.m21), Double(0), accuracy: accuracyThreshold)-        XCTAssertEqual(Double(transformStruct.tX), Double(0), accuracy: accuracyThreshold)-        XCTAssertEqual(Double(transformStruct.tY), Double(0), accuracy: accuracyThreshold)+// MARK: - Construction++extension TestAffineTransform {+    func testConstruction() {+        let transform = AffineTransform(+            m11: 1, m12: 2,+            m21: 3, m22: 4,+             tX: 5,  tY: 6+        )+        +        XCTAssertEqual(transform.m11, 1)+        XCTAssertEqual(transform.m12, 2)+        XCTAssertEqual(transform.m21, 3)+        XCTAssertEqual(transform.m22, 4)+        XCTAssertEqual(transform.tX , 5)+        XCTAssertEqual(transform.tY , 6)     }+} -    func test_IdentityTransformation() {-        let identityTransform = NSAffineTransform()+// MARK: - Bridging -        func checkIdentityPointTransformation(_ point: NSPoint) {-            checkPointTransformation(identityTransform, point: point, expectedPoint: point)-        }+extension TestAffineTransform {+    func testBridging() {+        let transform = AffineTransform(+            m11: 1, m12: 2,+            m21: 3, m22: 4,+             tX: 5,  tY: 6+        )         -        checkIdentityPointTransformation(NSPoint.zero)-        checkIdentityPointTransformation(NSPoint(x: 24.5, y: 10.0))-        checkIdentityPointTransformation(NSPoint(x: -7.5, y: 2.0))+        let nsTransform = NSAffineTransform(transform: transform)+        XCTAssertEqual(transform, nsTransform.affineTransform)+        +        XCTAssertEqual(nsTransform as AffineTransform, transform)+    }+} -        func checkIdentitySizeTransformation(_ size: NSSize) {-            checkSizeTransformation(identityTransform, size: size, expectedSize: size)+// MARK: Equality++extension TestAffineTransform {+    func testEqualityHashing() {+        let samples = [+            AffineTransform(m11: 1.5, m12: 2.0, m21: 3.0, m22: 4.0, tX: 5.0, tY: 6.0),+            AffineTransform(m11: 1.0, m12: 2.5, m21: 3.0, m22: 4.0, tX: 5.0, tY: 6.0),+            AffineTransform(m11: 1.0, m12: 2.0, m21: 3.5, m22: 4.0, tX: 5.0, tY: 6.0),+            AffineTransform(m11: 1.0, m12: 2.0, m21: 3.0, m22: 4.5, tX: 5.0, tY: 6.0),+            AffineTransform(m11: 1.0, m12: 2.0, m21: 3.0, m22: 4.0, tX: 5.5, tY: 6.0),+            AffineTransform(m11: 1.0, m12: 2.0, m21: 3.0, m22: 4.0, tX: 5.0, tY: 6.5),+        ].map(NSAffineTransform.init)+        +        for (index, sample) in samples.enumerated() {+            let otherSamples: [NSAffineTransform] = {+                var samplesCopy = samples+                samplesCopy.remove(at: index)+                return samplesCopy+            }()+            +            XCTAssertEqual(sample, sample)+            XCTAssertEqual(sample.hashValue, sample.hashValue)+            +            for otherSample in otherSamples {+                XCTAssert(sample != otherSample)+                XCTAssert(sample.hashValue != otherSample.hashValue)

Might be better to use XCTAssertNotEqual() insert to XCTAssert as if there is a test failure it will show the incorrect values.

filip-sakel

comment created time in a month

PullRequestReviewEvent

Pull request review commentapple/swift-corelibs-foundation

Fix `AffineTransform.rotate(byRadians:)` implementation.

 // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors // -class TestAffineTransform : XCTestCase {+#if NS_FOUNDATION_ALLOWS_TESTABLE_IMPORT+    #if canImport(SwiftFoundation) && !DEPLOYMENT_RUNTIME_OBJC+        @testable import SwiftFoundation+    #else+        @testable import Foundation+    #endif+#endif++// MARK: - Tests++class TestAffineTransform: XCTestCase {     private let accuracyThreshold = 0.001      static var allTests: [(String, (TestAffineTransform) -> () throws -> Void)] {         return [-            ("test_BasicConstruction", test_BasicConstruction),-            ("test_IdentityTransformation", test_IdentityTransformation),-            ("test_Scale", test_Scale),-            ("test_Scaling", test_Scaling),-            ("test_TranslationScaling", test_TranslationScaling),-            ("test_ScalingTranslation", test_ScalingTranslation),-            ("test_Rotation_Degrees", test_Rotation_Degrees),-            ("test_Rotation_Radians", test_Rotation_Radians),-            ("test_Inversion", test_Inversion),-            ("test_IdentityTransformation", test_IdentityTransformation),-            ("test_Translation", test_Translation),-            ("test_TranslationComposed", test_TranslationComposed),-            ("test_AppendTransform", test_AppendTransform),-            ("test_PrependTransform", test_PrependTransform),-            ("test_TransformComposition", test_TransformComposition),-            ("test_hashing", test_hashing),-            ("test_rotation_compose", test_rotation_compose),-            ("test_translation_and_rotation", test_translation_and_rotation),-            ("test_Equal", test_Equal),-            ("test_NSCoding", test_NSCoding),+            ("testConstruction", testConstruction),+            ("testBridging", testBridging),+            ("testEqualityHashing", testEqualityHashing),+            ("testVectorTransformations", testVectorTransformations),+            ("testIdentityConstruction", testIdentityConstruction),+            ("testIdentity", testIdentity),+            ("testTranslationConstruction", testTranslationConstruction),+            ("testTranslation", testTranslation),+            ("testScalingConstruction", testScalingConstruction),+            ("testScaling", testScaling),+            ("testRotationConstruction", testRotationConstruction),+            ("testRotation", testRotation),+            ("testTranslationScaling", testTranslationScaling),+            ("testTranslationRotation", testTranslationRotation),+            ("testScalingRotation", testScalingRotation),+            ("testInversion", testInversion),+            ("testPrependTransform", testPrependTransform),+            ("testAppendTransform", testAppendTransform),+            ("testNSCoding", testNSCoding),         ]     }-    -    func checkPointTransformation(_ transform: NSAffineTransform, point: NSPoint, expectedPoint: NSPoint, _ message: String = "", file: StaticString = #file, line: UInt = #line) {+}+ +// MARK: - Helper++extension TestAffineTransform {+    func assert(+        point: CGPoint,+        transformedBy transform: AffineTransform,+        equals expectedPoint: CGPoint,+        _ message: String = "",+        file: StaticString = #file, line: UInt = #line+    ) {+        let size = CGSize(width: point.x, height: point.y)+                 let newPoint = transform.transform(point)-        XCTAssertEqual(Double(newPoint.x), Double(expectedPoint.x), accuracy: accuracyThreshold,-                       "x (expected: \(expectedPoint.x), was: \(newPoint.x)): \(message)", file: file, line: line)-        XCTAssertEqual(Double(newPoint.y), Double(expectedPoint.y), accuracy: accuracyThreshold,-                       "y (expected: \(expectedPoint.y), was: \(newPoint.y)): \(message)", file: file, line: line)-    }-    -    func checkSizeTransformation(_ transform: NSAffineTransform, size: NSSize, expectedSize: NSSize, _ message: String = "", file: StaticString = #file, line: UInt = #line) {         let newSize = transform.transform(size)-        XCTAssertEqual(Double(newSize.width), Double(expectedSize.width), accuracy: accuracyThreshold,-                       "width (expected: \(expectedSize.width), was: \(newSize.width)): \(message)", file: file, line: line)-        XCTAssertEqual(Double(newSize.height), Double(expectedSize.height), accuracy: accuracyThreshold,-                       "height (expected: \(expectedSize.height), was: \(newSize.height)): \(message)", file: file, line: line)-    }-    -    func checkRectTransformation(_ transform: NSAffineTransform, rect: NSRect, expectedRect: NSRect, _ message: String = "", file: StaticString = #file, line: UInt = #line) {-        let newRect = transform.transformRect(rect)         -        checkPointTransformation(transform, point: newRect.origin, expectedPoint: expectedRect.origin,-                                 "origin (expected: \(expectedRect.origin), was: \(newRect.origin)): \(message)", file: file, line: line)-        checkSizeTransformation(transform, size: newRect.size, expectedSize: expectedRect.size,-                                "size (expected: \(expectedRect.size), was: \(newRect.size)): \(message)", file: file, line: line)+        XCTAssertEqual(+            newPoint.x, newSize.width,+            "Expected point x and size width to match",+            file: file, line: line+        )+        XCTAssertEqual(+            newPoint.y, newSize.height,+            "Expected point y and size height to match",+            file: file, line: line+        )+        +        let nsTransform = transform as NSAffineTransform+        XCTAssertEqual(+            nsTransform.transform(point), newPoint,+            "Expected NSAffineTransform to match AffineTransform's point-accepting transform(_:)",+            file: file, line: line+        )+        XCTAssertEqual(+            nsTransform.transform(size), newSize,+            "Expected NSAffineTransform to match AffineTransform's size-accepting transform(_:)",+            file: file, line: line+        )+        +        XCTAssertEqual(+            newPoint.x, expectedPoint.x,+            accuracy: accuracyThreshold,+            "Invalid x: \(message)",+            file: file, line: line+        )+        +        XCTAssertEqual(+            newPoint.y, expectedPoint.y,+            accuracy: accuracyThreshold,+            "Invalid y: \(message)",+            file: file, line: line+        )     }+} -    func test_BasicConstruction() {-        let identityTransform = NSAffineTransform()-        let transformStruct = identityTransform.transformStruct--        // The diagonal entries (1,1) and (2,2) of the identity matrix are ones. The other entries are zeros.-        // TODO: These should use DBL_MAX but it's not available as part of Glibc on Linux-        XCTAssertEqual(Double(transformStruct.m11), Double(1), accuracy: accuracyThreshold)-        XCTAssertEqual(Double(transformStruct.m22), Double(1), accuracy: accuracyThreshold)--        XCTAssertEqual(Double(transformStruct.m12), Double(0), accuracy: accuracyThreshold)-        XCTAssertEqual(Double(transformStruct.m21), Double(0), accuracy: accuracyThreshold)-        XCTAssertEqual(Double(transformStruct.tX), Double(0), accuracy: accuracyThreshold)-        XCTAssertEqual(Double(transformStruct.tY), Double(0), accuracy: accuracyThreshold)+// MARK: - Construction++extension TestAffineTransform {+    func testConstruction() {+        let transform = AffineTransform(+            m11: 1, m12: 2,+            m21: 3, m22: 4,+             tX: 5,  tY: 6+        )+        +        XCTAssertEqual(transform.m11, 1)+        XCTAssertEqual(transform.m12, 2)+        XCTAssertEqual(transform.m21, 3)+        XCTAssertEqual(transform.m22, 4)+        XCTAssertEqual(transform.tX , 5)+        XCTAssertEqual(transform.tY , 6)     }+} -    func test_IdentityTransformation() {-        let identityTransform = NSAffineTransform()+// MARK: - Bridging -        func checkIdentityPointTransformation(_ point: NSPoint) {-            checkPointTransformation(identityTransform, point: point, expectedPoint: point)-        }+extension TestAffineTransform {+    func testBridging() {+        let transform = AffineTransform(+            m11: 1, m12: 2,+            m21: 3, m22: 4,+             tX: 5,  tY: 6+        )         -        checkIdentityPointTransformation(NSPoint.zero)-        checkIdentityPointTransformation(NSPoint(x: 24.5, y: 10.0))-        checkIdentityPointTransformation(NSPoint(x: -7.5, y: 2.0))+        let nsTransform = NSAffineTransform(transform: transform)+        XCTAssertEqual(transform, nsTransform.affineTransform)

.affineTransform is an internal property so will need to be gated with NS_FOUNDATION_ALLOWS_TESTABLE_IMPORT - there are a few uses of this which will also require it.

filip-sakel

comment created time in a month

PullRequestReviewEvent

pull request commentapple/swift-corelibs-foundation

Fix `AffineTransform.rotate(byRadians:)` implementation.

@swift-ci test

filip-sakel

comment created time in a month

pull request commentapple/swift-corelibs-foundation

[5.4] SR-14933: Implement `copy()` in `ISO8601DateFormatter`.

@swift-ci test macOS

YOCKOW

comment created time in a month