Skip to content

Commit f9d441a

Browse files
committed
Bug 1975174 - Fix rotateAxisAngleSelf not to always call Ensure3DMatrix r=smaug
I wonder it's worth keeping the current implementation deviation that we don't have is2D check but instead have mMatrix2D/3D. Seems that only complicates the implementation without a clear win. Differential Revision: https://phabricator.services.mozilla.com/D256115
1 parent cfcd733 commit f9d441a

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

dom/base/DOMMatrix.cpp

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -949,19 +949,42 @@ DOMMatrix* DOMMatrix::RotateSelf(double aRotX, const Optional<double>& aRotY,
949949
return this;
950950
}
951951

952+
// https://drafts.fxtf.org/geometry/#dom-dommatrix-rotateaxisangleself
952953
DOMMatrix* DOMMatrix::RotateAxisAngleSelf(double aX, double aY, double aZ,
953954
double aAngle) {
955+
// (Unspecified but rather obvious optimization)
954956
if (fmod(aAngle, 360) == 0) {
955957
return this;
956958
}
957959

958960
aAngle *= radPerDegree;
959961

960-
Ensure3DMatrix();
962+
// Step 1: Post-multiply a rotation transformation on the current matrix
963+
// around the specified vector x, y, z by the specified rotation angle in
964+
// degrees.
965+
// (But actual multiplication happens below with step 2)
961966
gfx::Matrix4x4Double m;
962967
m.SetRotateAxisAngle(aX, aY, aZ, aAngle);
963968

964-
*mMatrix3D = m * *mMatrix3D;
969+
// Step 2: If x or y are not 0 or -0, set is 2D of the current matrix to
970+
// false.
971+
// (But we don't have "is 2D" flag and need to multiply either 2D or 3D
972+
// matrix)
973+
if (mMatrix3D || aX != 0 || aY != 0) {
974+
Ensure3DMatrix();
975+
*mMatrix3D = m * *mMatrix3D;
976+
return this;
977+
}
978+
979+
gfx::Matrix4x4Double result = m * gfx::Matrix4x4Double::From2D(*mMatrix2D);
980+
mMatrix2D->_11 = result._11;
981+
mMatrix2D->_12 = result._12;
982+
mMatrix2D->_21 = result._21;
983+
mMatrix2D->_22 = result._22;
984+
985+
// Different field names, see ::From2D implementation
986+
mMatrix2D->_31 = result._41;
987+
mMatrix2D->_32 = result._42;
965988

966989
return this;
967990
}

testing/web-platform/tests/css/geometry/DOMMatrix-003.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,12 @@
227227
checkDOMMatrix(result, expected);
228228
},"test rotateAxisAngle() ");
229229

230+
test(function() {
231+
var result = new DOMMatrix([1, 1, 1, 1, 1, 1]).rotateAxisAngle(0, 0, 3, 90);
232+
var expected = new DOMMatrix([1, 1, -1, -1, 1, 1]);
233+
checkDOMMatrix(result, expected);
234+
},"test rotateAxisAngle() on 2D matrix with 2D rotation");
235+
230236
test(function() {
231237
var angleDeg = 75;
232238
var result = initialDOMMatrix().skewX(angleDeg);

0 commit comments

Comments
 (0)