Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-3941] AffineTransform.rotate(byRadians:) can be wrong #4105

Closed
swift-ci opened this issue Feb 13, 2017 · 6 comments
Closed

[SR-3941] AffineTransform.rotate(byRadians:) can be wrong #4105

swift-ci opened this issue Feb 13, 2017 · 6 comments
Assignees

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-3941
Radar None
Original Reporter ten (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

macOS

Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug
Assignee @filip-sakel
Priority Medium

md5: e970db366b17d050e3e21a3f0cbd7b11

Issue Description:

var affine = AffineTransform(scale: 2)
affine.rotate(byRadians: .pi / 4)
print(affine)

Prints: {m11:0.707106781186548, m12:0.707106781186547, m21:-0.707106781186547, m22:0.707106781186548, tX:0.0, tY:0.0}
Expected Result: {m11:1.4142135623731, m12:1.41421356237309, m21:-1.41421356237309, m22:1.4142135623731, tX:0.0, tY:0.0}

I'll tell you what

public mutating func rotate(byRadians angle: CGFloat) {
    prepend(AffineTransform(rotationByRadians: angle))
}
@swift-ci
Copy link
Contributor Author

Comment by Matt Rajca (JIRA)

swiftlang/swift#9481

@swift-ci
Copy link
Contributor Author

Comment by Matt Rajca (JIRA)

Merged: swiftlang/swift#9481

@swift-ci
Copy link
Contributor Author

Comment by Takafumi Akutagawa (JIRA)

let point = NSPoint(x: CGFloat(10), y: CGFloat(10))
let tx: CGFloat = 20
let ty: CGFloat = -30
let radian: CGFloat = .pi / 2

var translateThenRotate = AffineTransform(translationByX: tx, byY: ty)
translateThenRotate.rotate(byRadians: radian)
print(translateThenRotate.transform(point))// output: (20.0, 30.0)

var translateThenRotate2 = NSAffineTransform()
translateThenRotate2.translateX(by: tx, yBy: ty)
translateThenRotate2.rotate(byRadians: radian)
print(translateThenRotate2.transform(point))// output: (10.0, -20.0)

Should be same

Test Code

var translateThenRotate = AffineTransform(translationByX: 20, byY: -30)
translateThenRotate.rotate(byRadians: .pi / 2)
checkPointTransformation(translateThenRotate, point: point, expectedPoint: NSPoint(x: CGFloat(10), y: CGFloat(-20)))

@swift-ci
Copy link
Contributor Author

Comment by Matt Rajca (JIRA)

Looks fixed in both the core libs (I added a test for this case 00562542e5a7fe6e403dba5dbbfee17a0b51673d) as well as Swift 4.0.1 on macOS.

@filip-sakel
Copy link
Contributor

Foundation's AffineTransform seems to have the same issue.

@filip-sakel
Copy link
Contributor

Resolved here.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from swiftlang/swift May 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants