Bug 40414 - Fetching inline style gives different matrix for rotate(90deg) than getComputedStyle
Summary: Fetching inline style gives different matrix for rotate(90deg) than getComput...
Status: REOPENED
Alias: None
Product: WebKit
Classification: Unclassified
Component: CSS (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC OS X 10.5
: P2 Normal
Assignee: Nobody
URL:
Keywords: BrowserCompat, InRadar
Depends on:
Blocks:
 
Reported: 2010-06-10 03:26 PDT by Dirk Schulze
Modified: 2023-11-09 16:13 PST (History)
9 users (show)

See Also:


Attachments
Test case (417 bytes, text/html)
2010-06-10 03:26 PDT, Dirk Schulze
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Dirk Schulze 2010-06-10 03:26:23 PDT
Created attachment 58354 [details]
Test case

CSS Transforms rotate(90deg) make's responing matrix uninvertvible. See alert on attached text. Matrix is 0,1,-1,0,0,0
Comment 1 Simon Fraser (smfr) 2010-06-10 07:04:15 PDT
I don't see a test for the matrix being uninvertible.
Comment 2 Dirk Schulze 2010-06-10 07:17:48 PDT
(In reply to comment #1)
> I don't see a test for the matrix being uninvertible.

I get (0,1,-1,0,0,0). That means a = d = 0. Do you get somthing different?
Comment 3 Dirk Schulze 2010-06-10 07:45:02 PDT
But I get correct values with getComputedStyle.
Comment 4 Dirk Schulze 2010-06-10 07:58:37 PDT
The calculation was correct, sorry. A rotation of 90deg means that 'a' gets cos(90/180*pi) and cos(pi/2) is 0.
Comment 5 Simon Fraser (smfr) 2010-06-10 09:25:10 PDT
I don't know why getComputedStyle would return a different value in this case. Reopening this bug to figure out why fetching inline style gives a different answer.
Comment 6 Dirk Schulze 2010-06-10 09:37:33 PDT
(In reply to comment #5)
> I don't know why getComputedStyle would return a different value in this case. Reopening this bug to figure out why fetching inline style gives a different answer.

The difference is not quite big matrix(1,77321e-16, 1, -1, 1,77321e-16, 0, 0) to matrix(0,000000, 1,000000, -1,000000, 0,000000, 0,000000, 0,000000). With different code paths:

getComputedStyle:
var parent = document.getElementById('parent');
var matrix = window.getComputedStyle(parent).webkitTransform;
alert(matrix);

inline style:
var firstMatrix = new WebKitCSSMatrix(document.getElementById('parent').style.webkitTransform);
alert(firstMatrix);
Comment 7 Chris Marrin 2010-06-11 08:28:36 PDT
Those two matrices are, for all intents and purposes, identical. The only difference is rounding.

The source of the rounding error may be one of the several places we use single precision floating point numbers in TransformationMatrix::rotate3d(). All the use of single precision in this file is a holdover from when the matrix itself was single precision. None of the uses of single precision here seem dangerous. I think they will all up-convert before being used. And the numbers are all 1.0f or 2.0f, which I believe are exactly represented in single precision. But there may be places where single precision math is being performed.

It could also be just general precision loss. We need to convert to radians, which is inherently lossy. But this seems like greater loss than that.

Finally, there could be places outside the TransformationMatrix code where the values could be getting shortened. But that seems unlikely for 90 degrees, since we store rotation values in degrees directly in the style declaration. So there's no conversion there.

At any rate, all the use of single precision in TransformationMatrix should be removed.
Comment 8 Ahmad Saleem 2022-07-23 05:48:55 PDT
Based on attached test cases - I get following values across browsers:


Safari 15.6 - transform: matrix(6.123233995736766e-17, 1, -1, 6.123233995736766e-17, 0, 0)

Chrome Canary 106 - transform: matrix(6.123233995736766e-17, 1, -1, 6.123233995736766e-17, 0, 0)

Firefox Nightly 104 - transform: matrix(2.220446049250313e-16, 1, -1, 2.220446049250313e-16, 0, 0)

Safari and Firefox match each other but differ from Firefox Nightly slightly. Just wanted to share updated results as of today. Thanks!
Comment 9 Brent Fulgham 2022-07-23 16:11:58 PDT
Seems like this warrants some investigation. Thank you for testing!
Comment 10 Radar WebKit Bug Importer 2022-07-23 16:12:08 PDT
<rdar://problem/97496245>