Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(41)

Unified Diff: third_party/WebKit/LayoutTests/imported/wpt/web-animations/testcommon.js

Issue 2610243002: Import wpt@5e1a3b80cea8d36774d2afd78b29a74792e9f15a (Closed)
Patch Set: Update code that deals with manifest. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/imported/wpt/web-animations/testcommon.js
diff --git a/third_party/WebKit/LayoutTests/imported/wpt/web-animations/testcommon.js b/third_party/WebKit/LayoutTests/imported/wpt/web-animations/testcommon.js
index 31ebdfaf279deca00ef5384fd7d347e1cf00e8e1..348af6e5c1738227d0e5475158b241039fe3cfb0 100644
--- a/third_party/WebKit/LayoutTests/imported/wpt/web-animations/testcommon.js
+++ b/third_party/WebKit/LayoutTests/imported/wpt/web-animations/testcommon.js
@@ -174,3 +174,68 @@ function waitForAnimationFramesWithDelay(minDelay) {
}());
});
}
+
+// Returns 'matrix()' or 'matrix3d()' function string generated from an array.
+function createMatrixFromArray(array) {
+ return (array.length == 16 ? 'matrix3d' : 'matrix') +
+ '(' + array.join() + ')';
+}
+
+// Returns 'matrix3d()' function string equivalent to
+// 'rotate3d(x, y, z, radian)'.
+function rotate3dToMatrix3d(x, y, z, radian) {
+ return createMatrixFromArray(rotate3dToMatrix(x, y, z, radian));
+}
+
+// Returns an array of the 4x4 matrix equivalent to 'rotate3d(x, y, z, radian)'.
+// https://www.w3.org/TR/css-transforms-1/#Rotate3dDefined
+function rotate3dToMatrix(x, y, z, radian) {
+ var sc = Math.sin(radian / 2) * Math.cos(radian / 2);
+ var sq = Math.sin(radian / 2) * Math.sin(radian / 2);
+
+ // Normalize the vector.
+ var length = Math.sqrt(x*x + y*y + z*z);
+ x /= length;
+ y /= length;
+ z /= length;
+
+ return [
+ 1 - 2 * (y*y + z*z) * sq,
+ 2 * (x * y * sq + z * sc),
+ 2 * (x * z * sq - y * sc),
+ 0,
+ 2 * (x * y * sq - z * sc),
+ 1 - 2 * (x*x + z*z) * sq,
+ 2 * (y * z * sq + x * sc),
+ 0,
+ 2 * (x * z * sq + y * sc),
+ 2 * (y * z * sq - x * sc),
+ 1 - 2 * (x*x + y*y) * sq,
+ 0,
+ 0,
+ 0,
+ 0,
+ 1
+ ];
+}
+
+// Compare matrix string like 'matrix(1, 0, 0, 1, 100, 0)' with tolerances.
+function assert_matrix_equals(actual, expected, description) {
+ var matrixRegExp = /^matrix(?:3d)*\((.+)\)/;
+ assert_regexp_match(actual, matrixRegExp,
+ 'Actual value is not a matrix')
+ assert_regexp_match(expected, matrixRegExp,
+ 'Expected value is not a matrix');
+
+ var actualMatrixArray =
+ actual.match(matrixRegExp)[1].split(',').map(Number);
+ var expectedMatrixArray =
+ expected.match(matrixRegExp)[1].split(',').map(Number);
+
+ assert_equals(actualMatrixArray.length, expectedMatrixArray.length,
+ 'dimension of the matrix: ' + description);
+ for (var i = 0; i < actualMatrixArray.length; i++) {
+ assert_approx_equals(actualMatrixArray[i], expectedMatrixArray[i], 0.0001,
+ 'expecetd ' + expected + ' but got ' + actual + ": " + description);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698