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

Implementation of CGAffineTransform #428

Open
filip-sakel opened this issue Jul 16, 2021 · 6 comments
Open

Implementation of CGAffineTransform #428

filip-sakel opened this issue Jul 16, 2021 · 6 comments

Comments

@filip-sakel
Copy link
Contributor

Is the implementation of the non-apple CGAffineTransform correct?

Several things seem "off". For one, the implementation of inverted() simply negates the matrix's components. On other implementations, however, such as the Foundation and SwiftWin32 ones, it's much more complex — calculating a determinant, examining if inversion is possible, etc. Furthermore, rotated(by:) — despite claiming to rotate an existing transformation — ignores the translation components of the matrix (tx and ty) and existing scaling and rotation adjustments.

Perhaps, the current return value of rotated(by:) was intended to be appended to self before being returned.

If this is indeed incorrect, I'd be happy to submit a PR to fix it and add a test coverage — although tests in Tokamak seem to cover higher-level rendering behavior.

@carson-katri
Copy link
Member

Could we just add a typealias CGAffineTransform = Foundation.AffineTransform?

@MaxDesiatov
Copy link
Collaborator

I don't see why not? Ideally we want some tests that prove it would help though.

@MaxDesiatov
Copy link
Collaborator

And tests that cover both low level stuff (the canonical meaning of "unit tests") and high level stuff are great. More tests on both sides is better 👍

@MaxDesiatov
Copy link
Collaborator

To fully clarify, just making sure that CGAffineTransform and Foundation.AffineTransform are equivalent on all platforms both from API perspective (this would be confirmed by the plain build not failing on any platform) and functionally (some basic unit tests) should be enough.

High level snapshot tests would only be needed for transform modifiers, if we expect them to be impacted by this change.

@filip-sakel
Copy link
Contributor Author

It looks like Foundation.AffineTransform has a pretty different API compared to CGAffineTransform. So, I ended up using the same implementation but packaged in the CGAffineTransform API. Here's the PR.

Note: I suspect Foundation's implementation of inverted() is incorrect. So, the actual implementation is similar to Draw2d's Inverse() function.

@MaxDesiatov
Copy link
Collaborator

Is there anything available on bugs.swift.org or a radar for inverted() incorrectness? Maybe we should also submit a PR to upstream Foundation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants