Skip to content

Commit

Permalink
Bug 1392722: Allow zero in rotateFromVector r=bzbarsky
Browse files Browse the repository at this point in the history
  • Loading branch information
saschanaz committed Jul 4, 2019
1 parent c9de23a commit 95687d2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
6 changes: 1 addition & 5 deletions dom/base/DOMMatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -848,11 +848,7 @@ DOMMatrix* DOMMatrix::Scale3dSelf(double aScale, double aOriginX,
}

DOMMatrix* DOMMatrix::RotateFromVectorSelf(double aX, double aY) {
if (aX == 0.0 || aY == 0.0) {
return this;
}

const double angle = atan2(aY, aX);
const double angle = (aX == 0.0 && aY == 0.0) ? 0 : atan2(aY, aX);

if (fmod(angle, 2 * M_PI) == 0) {
return this;
Expand Down
4 changes: 2 additions & 2 deletions dom/webidl/DOMMatrix.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ interface DOMMatrixReadOnly {
LegacyWindowAlias=WebKitCSSMatrix]
interface DOMMatrix : DOMMatrixReadOnly {
[NewObject, Throws] static DOMMatrix fromMatrix(optional DOMMatrixInit other = {});
[NewObject, Throws] static DOMMatrixReadOnly fromFloat32Array(Float32Array array32);
[NewObject, Throws] static DOMMatrixReadOnly fromFloat64Array(Float64Array array64);
[NewObject, Throws] static DOMMatrix fromFloat32Array(Float32Array array32);
[NewObject, Throws] static DOMMatrix fromFloat64Array(Float64Array array64);


// These attributes are simple aliases for certain elements of the 4x4 matrix
Expand Down
18 changes: 18 additions & 0 deletions testing/web-platform/tests/css/geometry/DOMMatrix-003.html
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,24 @@
checkDOMMatrix(result, expected);
},"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() {
var result = initialDOMMatrix().rotateAxisAngle(3, 3, 3, 120);
var expected = initialDOMMatrix().multiply(getRotationMatrix(3, 3, 3, 120));
Expand Down

0 comments on commit 95687d2

Please sign in to comment.