From 50a994a54a8709efd0b9cd8d4077a12172a6620e Mon Sep 17 00:00:00 2001 From: Dark-detsixE Date: Sun, 31 Aug 2025 03:19:37 +0800 Subject: [PATCH 1/3] Fix CGAffineTransform on non-Darwin platform --- .../OpenCoreGraphics/CGAffineTransform.swift | 8 ++-- .../CGAffineTransformTests.swift | 37 +++++++++++++++++++ 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/Sources/OpenCoreGraphics/CGAffineTransform.swift b/Sources/OpenCoreGraphics/CGAffineTransform.swift index 876706b..95b767f 100644 --- a/Sources/OpenCoreGraphics/CGAffineTransform.swift +++ b/Sources/OpenCoreGraphics/CGAffineTransform.swift @@ -52,17 +52,15 @@ extension CGAffineTransform { } public func translatedBy(x tx: CGFloat, y ty: CGFloat) -> CGAffineTransform { - let t = CGAffineTransform(a: 1, b: 0, c: 0, d: 1, tx: Double(tx), ty: Double(ty)) - return concatenating(t) + CGAffineTransform(a: 1, b: 0, c: 0, d: 1, tx: Double(tx), ty: Double(ty)).concatenating(self) } public func scaledBy(x sx: CGFloat, y sy: CGFloat) -> CGAffineTransform { - let s = CGAffineTransform(a: Double(sx), b: 0, c: 0, d: Double(sy), tx: 0, ty: 0) - return concatenating(s) + CGAffineTransform(a: Double(sx), b: 0, c: 0, d: Double(sy), tx: 0, ty: 0).concatenating(self) } public func rotated(by angle: CGFloat) -> CGAffineTransform { - return concatenating(CGAffineTransform(rotationAngle: angle)) + CGAffineTransform(rotationAngle: angle).concatenating(self) } public func inverted() -> CGAffineTransform { diff --git a/Tests/OpenCoreGraphicsShimsTests/CGAffineTransformTests.swift b/Tests/OpenCoreGraphicsShimsTests/CGAffineTransformTests.swift index 029fc89..980275e 100644 --- a/Tests/OpenCoreGraphicsShimsTests/CGAffineTransformTests.swift +++ b/Tests/OpenCoreGraphicsShimsTests/CGAffineTransformTests.swift @@ -92,4 +92,41 @@ struct CGAffineTransformTests { #expect(inv.tx.isApproximatelyEqual(to: singular.tx)) #expect(inv.ty.isApproximatelyEqual(to: singular.ty)) } + + // MARK: - TranslateBy + @Test + func translatedBy() { + let t1 = CGAffineTransform(a: 1, b: 2, c: 3, d: 4, tx: 5, ty: 6) + let t2 = t1.translatedBy(x: 7, y: 8) + #expect(t2.a.isApproximatelyEqual(to: 1.0)) + #expect(t2.b.isApproximatelyEqual(to: 2.0)) + #expect(t2.c.isApproximatelyEqual(to: 3.0)) + #expect(t2.d.isApproximatelyEqual(to: 4.0)) + #expect(t2.tx.isApproximatelyEqual(to: 36.0)) + #expect(t2.ty.isApproximatelyEqual(to: 52.0)) + } + + @Test + func scaledBy() { + let t1 = CGAffineTransform(a: 1, b: 2, c: 3, d: 4, tx: 5, ty: 6) + let t2 = t1.scaledBy(x: 7, y: 8) + #expect(t2.a.isApproximatelyEqual(to: 7.0)) + #expect(t2.b.isApproximatelyEqual(to: 14.0)) + #expect(t2.c.isApproximatelyEqual(to: 24.0)) + #expect(t2.d.isApproximatelyEqual(to: 32.0)) + #expect(t2.tx.isApproximatelyEqual(to: 5.0)) + #expect(t2.ty.isApproximatelyEqual(to: 6.0)) + } + + @Test + func rotated() { + let t1 = CGAffineTransform(a: 1, b: 2, c: 3, d: 4, tx: 5, ty: 6) + let t2 = t1.rotated(by: .pi / 2) + #expect(t2.a.isApproximatelyEqual(to: 3.0)) + #expect(t2.b.isApproximatelyEqual(to: 4.0)) + #expect(t2.c.isApproximatelyEqual(to: -1.0)) + #expect(t2.d.isApproximatelyEqual(to: -2.0)) + #expect(t2.tx.isApproximatelyEqual(to: 5.0)) + #expect(t2.ty.isApproximatelyEqual(to: 6.0)) + } } From ba2cde3687caed2309739d470bef649279ca774d Mon Sep 17 00:00:00 2001 From: Dark-detsixE Date: Sun, 12 Oct 2025 02:04:00 +0800 Subject: [PATCH 2/3] Fix CGAffineTransformTests for compatibility test suite --- .../CGAffineTransformTests.swift | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Tests/OpenCoreGraphicsShimsTests/CGAffineTransformTests.swift b/Tests/OpenCoreGraphicsShimsTests/CGAffineTransformTests.swift index 980275e..0ca82a7 100644 --- a/Tests/OpenCoreGraphicsShimsTests/CGAffineTransformTests.swift +++ b/Tests/OpenCoreGraphicsShimsTests/CGAffineTransformTests.swift @@ -93,10 +93,15 @@ struct CGAffineTransformTests { #expect(inv.ty.isApproximatelyEqual(to: singular.ty)) } - // MARK: - TranslateBy + // MARK: - TranslateBy + @Test func translatedBy() { + #if OPENCOREGRAPHICS_COREGRAPHICS let t1 = CGAffineTransform(a: 1, b: 2, c: 3, d: 4, tx: 5, ty: 6) + #else + let t1 = OpenCoreGraphics.CGAffineTransform(a: 1, b: 2, c: 3, d: 4, tx: 5, ty: 6) + #endif let t2 = t1.translatedBy(x: 7, y: 8) #expect(t2.a.isApproximatelyEqual(to: 1.0)) #expect(t2.b.isApproximatelyEqual(to: 2.0)) @@ -106,9 +111,15 @@ struct CGAffineTransformTests { #expect(t2.ty.isApproximatelyEqual(to: 52.0)) } + // MARK: - ScaledBy + @Test func scaledBy() { + #if OPENCOREGRAPHICS_COREGRAPHICS let t1 = CGAffineTransform(a: 1, b: 2, c: 3, d: 4, tx: 5, ty: 6) + #else + let t1 = OpenCoreGraphics.CGAffineTransform(a: 1, b: 2, c: 3, d: 4, tx: 5, ty: 6) + #endif let t2 = t1.scaledBy(x: 7, y: 8) #expect(t2.a.isApproximatelyEqual(to: 7.0)) #expect(t2.b.isApproximatelyEqual(to: 14.0)) @@ -118,9 +129,15 @@ struct CGAffineTransformTests { #expect(t2.ty.isApproximatelyEqual(to: 6.0)) } + // MARK: - Rotated + @Test func rotated() { + #if OPENCOREGRAPHICS_COREGRAPHICS let t1 = CGAffineTransform(a: 1, b: 2, c: 3, d: 4, tx: 5, ty: 6) + #else + let t1 = OpenCoreGraphics.CGAffineTransform(a: 1, b: 2, c: 3, d: 4, tx: 5, ty: 6) + #endif let t2 = t1.rotated(by: .pi / 2) #expect(t2.a.isApproximatelyEqual(to: 3.0)) #expect(t2.b.isApproximatelyEqual(to: 4.0)) From ad60aa3390a8292200c4977e3826c53cf3e43276 Mon Sep 17 00:00:00 2001 From: Kyle Date: Mon, 20 Oct 2025 02:07:26 +0800 Subject: [PATCH 3/3] Fix CGAffineTransform.init issue --- .../CGAffineTransformTests.swift | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/Tests/OpenCoreGraphicsShimsTests/CGAffineTransformTests.swift b/Tests/OpenCoreGraphicsShimsTests/CGAffineTransformTests.swift index 0ca82a7..c66c57e 100644 --- a/Tests/OpenCoreGraphicsShimsTests/CGAffineTransformTests.swift +++ b/Tests/OpenCoreGraphicsShimsTests/CGAffineTransformTests.swift @@ -5,6 +5,11 @@ import Testing import OpenCoreGraphicsShims import Numerics +#if OPENCOREGRAPHICS_COREGRAPHICS +import struct CoreGraphics.CGAffineTransform +#else +import struct OpenCoreGraphics.CGAffineTransform +#endif @Suite struct CGAffineTransformTests { @@ -97,11 +102,7 @@ struct CGAffineTransformTests { @Test func translatedBy() { - #if OPENCOREGRAPHICS_COREGRAPHICS let t1 = CGAffineTransform(a: 1, b: 2, c: 3, d: 4, tx: 5, ty: 6) - #else - let t1 = OpenCoreGraphics.CGAffineTransform(a: 1, b: 2, c: 3, d: 4, tx: 5, ty: 6) - #endif let t2 = t1.translatedBy(x: 7, y: 8) #expect(t2.a.isApproximatelyEqual(to: 1.0)) #expect(t2.b.isApproximatelyEqual(to: 2.0)) @@ -115,11 +116,7 @@ struct CGAffineTransformTests { @Test func scaledBy() { - #if OPENCOREGRAPHICS_COREGRAPHICS let t1 = CGAffineTransform(a: 1, b: 2, c: 3, d: 4, tx: 5, ty: 6) - #else - let t1 = OpenCoreGraphics.CGAffineTransform(a: 1, b: 2, c: 3, d: 4, tx: 5, ty: 6) - #endif let t2 = t1.scaledBy(x: 7, y: 8) #expect(t2.a.isApproximatelyEqual(to: 7.0)) #expect(t2.b.isApproximatelyEqual(to: 14.0)) @@ -133,11 +130,7 @@ struct CGAffineTransformTests { @Test func rotated() { - #if OPENCOREGRAPHICS_COREGRAPHICS let t1 = CGAffineTransform(a: 1, b: 2, c: 3, d: 4, tx: 5, ty: 6) - #else - let t1 = OpenCoreGraphics.CGAffineTransform(a: 1, b: 2, c: 3, d: 4, tx: 5, ty: 6) - #endif let t2 = t1.rotated(by: .pi / 2) #expect(t2.a.isApproximatelyEqual(to: 3.0)) #expect(t2.b.isApproximatelyEqual(to: 4.0))