Bug 1392722: Allow zero in rotateFromVector r=bzbarsky

Aligns to the spec. Try: https://treeherder.mozilla.org/#/jobs?repo=try&revision=f7c12c831fb8a6ce0d5ec6b31fcf1f708464deaf

Differential Revision: https://phabricator.services.mozilla.com/D36748

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Kagami Sascha Rosylight 2019-07-04 07:39:45 +00:00
parent c9de23aa09
commit 95687d2f8d
3 changed files with 21 additions and 7 deletions

View File

@ -848,11 +848,7 @@ DOMMatrix* DOMMatrix::Scale3dSelf(double aScale, double aOriginX,
} }
DOMMatrix* DOMMatrix::RotateFromVectorSelf(double aX, double aY) { DOMMatrix* DOMMatrix::RotateFromVectorSelf(double aX, double aY) {
if (aX == 0.0 || aY == 0.0) { const double angle = (aX == 0.0 && aY == 0.0) ? 0 : atan2(aY, aX);
return this;
}
const double angle = atan2(aY, aX);
if (fmod(angle, 2 * M_PI) == 0) { if (fmod(angle, 2 * M_PI) == 0) {
return this; return this;

View File

@ -99,8 +99,8 @@ interface DOMMatrixReadOnly {
LegacyWindowAlias=WebKitCSSMatrix] LegacyWindowAlias=WebKitCSSMatrix]
interface DOMMatrix : DOMMatrixReadOnly { interface DOMMatrix : DOMMatrixReadOnly {
[NewObject, Throws] static DOMMatrix fromMatrix(optional DOMMatrixInit other = {}); [NewObject, Throws] static DOMMatrix fromMatrix(optional DOMMatrixInit other = {});
[NewObject, Throws] static DOMMatrixReadOnly fromFloat32Array(Float32Array array32); [NewObject, Throws] static DOMMatrix fromFloat32Array(Float32Array array32);
[NewObject, Throws] static DOMMatrixReadOnly fromFloat64Array(Float64Array array64); [NewObject, Throws] static DOMMatrix fromFloat64Array(Float64Array array64);
// These attributes are simple aliases for certain elements of the 4x4 matrix // These attributes are simple aliases for certain elements of the 4x4 matrix

View File

@ -203,6 +203,24 @@
checkDOMMatrix(result, expected); checkDOMMatrix(result, expected);
},"test rotateFromVector()"); },"test rotateFromVector()");
test(function() {
var result = initialDOMMatrix().rotateFromVector(0, 1);
var expected = initialDOMMatrix().rotate(90);
checkDOMMatrix(result, expected);
},"test rotateFromVector() with x being zero");
test(function() {
var result = initialDOMMatrix().rotateFromVector(1, 0);
var expected = initialDOMMatrix()
checkDOMMatrix(result, expected);
},"test rotateFromVector() with y being zero");
test(function() {
var result = initialDOMMatrix().rotateFromVector(0, 0);
var expected = initialDOMMatrix()
checkDOMMatrix(result, expected);
},"test rotateFromVector() with two zeros");
test(function() { test(function() {
var result = initialDOMMatrix().rotateAxisAngle(3, 3, 3, 120); var result = initialDOMMatrix().rotateAxisAngle(3, 3, 3, 120);
var expected = initialDOMMatrix().multiply(getRotationMatrix(3, 3, 3, 120)); var expected = initialDOMMatrix().multiply(getRotationMatrix(3, 3, 3, 120));