Skip to content

Commit

Permalink
Add 3d transform tests to offscreen canvas
Browse files Browse the repository at this point in the history
Bug: 1140535
Change-Id: I62d979b9786ccc38232c862f82441521904abbcf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2898320
Commit-Queue: Aaron Krajeski <[email protected]>
Reviewed-by: Yi Xu <[email protected]>
Cr-Commit-Position: refs/heads/master@{#884001}
NOKEYCHECK=True
GitOrigin-RevId: 78c5db488044fdd8c671fa951847c6af5a01c061
  • Loading branch information
mysteryDate authored and copybara-github committed May 18, 2021
1 parent 91d357f commit c1683b1
Show file tree
Hide file tree
Showing 25 changed files with 846 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<!DOCTYPE html>
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<title>Canvas test: 2d.transformation.rotate3d.X</title>
<title>Canvas test: 2d.transformation.rotate3d.x</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/html/canvas/resources/canvas-tests.js"></script>
<link rel="stylesheet" href="/html/canvas/resources/canvas-tests.css">
<body class="show_output">

<h1>2d.transformation.rotate3d.X</h1>
<h1>2d.transformation.rotate3d.x</h1>
<p class="desc">rotate3d() around the x axis results in the correct transformation matrix</p>


Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<!DOCTYPE html>
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<title>Canvas test: 2d.transformation.rotate3d.Y</title>
<title>Canvas test: 2d.transformation.rotate3d.y</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/html/canvas/resources/canvas-tests.js"></script>
<link rel="stylesheet" href="/html/canvas/resources/canvas-tests.css">
<body class="show_output">

<h1>2d.transformation.rotate3d.Y</h1>
<h1>2d.transformation.rotate3d.y</h1>
<p class="desc">rotate3d() around the y axis results in the correct transformation matrix</p>


Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<!DOCTYPE html>
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<title>Canvas test: 2d.transformation.rotate3d.Z</title>
<title>Canvas test: 2d.transformation.rotate3d.z</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/html/canvas/resources/canvas-tests.js"></script>
<link rel="stylesheet" href="/html/canvas/resources/canvas-tests.css">
<body class="show_output">

<h1>2d.transformation.rotate3d.Z</h1>
<h1>2d.transformation.rotate3d.z</h1>
<p class="desc">rotate3d() around the z axis results in the correct transformation matrix</p>


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!DOCTYPE html>
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<title>OffscreenCanvas test: 2d.transformation.perspective</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/html/canvas/resources/canvas-tests.js"></script>

<h1>2d.transformation.perspective</h1>
<p class="desc">perspective() results in the correct transformation matrix</p>


<script>
var t = async_test("perspective() results in the correct transformation matrix");
var t_pass = t.done.bind(t);
var t_fail = t.step_func(function(reason) {
throw reason;
});
t.step(function() {

var offscreenCanvas = new OffscreenCanvas(100, 50);
var ctx = offscreenCanvas.getContext('2d');

const length = 100;
ctx.perspective(length);
const domMatrix = new DOMMatrix();
domMatrix.m34 = -1/length;
_assertMatricesApproxEqual(domMatrix, ctx.getTransform());
ctx.rotateAxis(1, 2, 3, 4);
domMatrix.rotateAxisAngleSelf(1, 2, 3, rad2deg(4));
_assertMatricesApproxEqual(domMatrix, ctx.getTransform());
t.done();

});
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py.
// OffscreenCanvas test in a worker:2d.transformation.perspective
// Description:perspective() results in the correct transformation matrix
// Note:

importScripts("/resources/testharness.js");
importScripts("/html/canvas/resources/canvas-tests.js");

var t = async_test("perspective() results in the correct transformation matrix");
var t_pass = t.done.bind(t);
var t_fail = t.step_func(function(reason) {
throw reason;
});
t.step(function() {

var offscreenCanvas = new OffscreenCanvas(100, 50);
var ctx = offscreenCanvas.getContext('2d');

const length = 100;
ctx.perspective(length);
const domMatrix = new DOMMatrix();
domMatrix.m34 = -1/length;
_assertMatricesApproxEqual(domMatrix, ctx.getTransform());
ctx.rotateAxis(1, 2, 3, 4);
domMatrix.rotateAxisAngleSelf(1, 2, 3, rad2deg(4));
_assertMatricesApproxEqual(domMatrix, ctx.getTransform());
t.done();

});
done();
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!DOCTYPE html>
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<title>OffscreenCanvas test: 2d.transformation.rotate3d</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/html/canvas/resources/canvas-tests.js"></script>

<h1>2d.transformation.rotate3d</h1>
<p class="desc">rotate3d() results in the correct transformation matrix</p>


<script>
var t = async_test("rotate3d() results in the correct transformation matrix");
var t_pass = t.done.bind(t);
var t_fail = t.step_func(function(reason) {
throw reason;
});
t.step(function() {

var offscreenCanvas = new OffscreenCanvas(100, 50);
var ctx = offscreenCanvas.getContext('2d');

// angles are in radians, test something that is not a multiple of pi
const angleX = 2;
const angleY = 3;
const angleZ = 4;
const domMatrix = new DOMMatrix();
ctx.rotate3d(angleX, angleY, angleZ);
domMatrix.rotateSelf(rad2deg(angleX), rad2deg(angleY), rad2deg(angleZ));
_assertMatricesApproxEqual(domMatrix, ctx.getTransform());
ctx.rotate3d(angleX, angleY, angleZ);
domMatrix.rotateSelf(rad2deg(angleX), rad2deg(angleY), rad2deg(angleZ));
_assertMatricesApproxEqual(domMatrix, ctx.getTransform());
t.done();

});
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py.
// OffscreenCanvas test in a worker:2d.transformation.rotate3d
// Description:rotate3d() results in the correct transformation matrix
// Note:

importScripts("/resources/testharness.js");
importScripts("/html/canvas/resources/canvas-tests.js");

var t = async_test("rotate3d() results in the correct transformation matrix");
var t_pass = t.done.bind(t);
var t_fail = t.step_func(function(reason) {
throw reason;
});
t.step(function() {

var offscreenCanvas = new OffscreenCanvas(100, 50);
var ctx = offscreenCanvas.getContext('2d');

// angles are in radians, test something that is not a multiple of pi
const angleX = 2;
const angleY = 3;
const angleZ = 4;
const domMatrix = new DOMMatrix();
ctx.rotate3d(angleX, angleY, angleZ);
domMatrix.rotateSelf(rad2deg(angleX), rad2deg(angleY), rad2deg(angleZ));
_assertMatricesApproxEqual(domMatrix, ctx.getTransform());
ctx.rotate3d(angleX, angleY, angleZ);
domMatrix.rotateSelf(rad2deg(angleX), rad2deg(angleY), rad2deg(angleZ));
_assertMatricesApproxEqual(domMatrix, ctx.getTransform());
t.done();

});
done();
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<title>OffscreenCanvas test: 2d.transformation.rotate3d.x</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/html/canvas/resources/canvas-tests.js"></script>

<h1>2d.transformation.rotate3d.x</h1>
<p class="desc">rotate3d() around the x axis results in the correct transformation matrix</p>


<script>
var t = async_test("rotate3d() around the x axis results in the correct transformation matrix");
var t_pass = t.done.bind(t);
var t_fail = t.step_func(function(reason) {
throw reason;
});
t.step(function() {

var offscreenCanvas = new OffscreenCanvas(100, 50);
var ctx = offscreenCanvas.getContext('2d');

// angles are in radians, test something that is not a multiple of pi
const angle = 2;
const domMatrix = new DOMMatrix();
ctx.rotate3d(angle, 0, 0);
domMatrix.rotateAxisAngleSelf(1, 0, 0, rad2deg(angle));
_assertMatricesApproxEqual(domMatrix, ctx.getTransform())
ctx.rotate3d(angle, 0, 0);
domMatrix.rotateAxisAngleSelf(1, 0, 0, rad2deg(angle));
_assertMatricesApproxEqual(domMatrix, ctx.getTransform())
t.done();

});
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py.
// OffscreenCanvas test in a worker:2d.transformation.rotate3d.x
// Description:rotate3d() around the x axis results in the correct transformation matrix
// Note:

importScripts("/resources/testharness.js");
importScripts("/html/canvas/resources/canvas-tests.js");

var t = async_test("rotate3d() around the x axis results in the correct transformation matrix");
var t_pass = t.done.bind(t);
var t_fail = t.step_func(function(reason) {
throw reason;
});
t.step(function() {

var offscreenCanvas = new OffscreenCanvas(100, 50);
var ctx = offscreenCanvas.getContext('2d');

// angles are in radians, test something that is not a multiple of pi
const angle = 2;
const domMatrix = new DOMMatrix();
ctx.rotate3d(angle, 0, 0);
domMatrix.rotateAxisAngleSelf(1, 0, 0, rad2deg(angle));
_assertMatricesApproxEqual(domMatrix, ctx.getTransform())
ctx.rotate3d(angle, 0, 0);
domMatrix.rotateAxisAngleSelf(1, 0, 0, rad2deg(angle));
_assertMatricesApproxEqual(domMatrix, ctx.getTransform())
t.done();

});
done();
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<title>OffscreenCanvas test: 2d.transformation.rotate3d.y</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/html/canvas/resources/canvas-tests.js"></script>

<h1>2d.transformation.rotate3d.y</h1>
<p class="desc">rotate3d() around the y axis results in the correct transformation matrix</p>


<script>
var t = async_test("rotate3d() around the y axis results in the correct transformation matrix");
var t_pass = t.done.bind(t);
var t_fail = t.step_func(function(reason) {
throw reason;
});
t.step(function() {

var offscreenCanvas = new OffscreenCanvas(100, 50);
var ctx = offscreenCanvas.getContext('2d');

// angles are in radians, test something that is not a multiple of pi
const angle = 2;
const domMatrix = new DOMMatrix();
ctx.rotate3d(0, angle, 0);
domMatrix.rotateAxisAngleSelf(0, 1, 0, rad2deg(angle));
_assertMatricesApproxEqual(domMatrix, ctx.getTransform())
ctx.rotate3d(0, angle, 0);
domMatrix.rotateAxisAngleSelf(0, 1, 0, rad2deg(angle));
_assertMatricesApproxEqual(domMatrix, ctx.getTransform())
t.done();

});
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py.
// OffscreenCanvas test in a worker:2d.transformation.rotate3d.y
// Description:rotate3d() around the y axis results in the correct transformation matrix
// Note:

importScripts("/resources/testharness.js");
importScripts("/html/canvas/resources/canvas-tests.js");

var t = async_test("rotate3d() around the y axis results in the correct transformation matrix");
var t_pass = t.done.bind(t);
var t_fail = t.step_func(function(reason) {
throw reason;
});
t.step(function() {

var offscreenCanvas = new OffscreenCanvas(100, 50);
var ctx = offscreenCanvas.getContext('2d');

// angles are in radians, test something that is not a multiple of pi
const angle = 2;
const domMatrix = new DOMMatrix();
ctx.rotate3d(0, angle, 0);
domMatrix.rotateAxisAngleSelf(0, 1, 0, rad2deg(angle));
_assertMatricesApproxEqual(domMatrix, ctx.getTransform())
ctx.rotate3d(0, angle, 0);
domMatrix.rotateAxisAngleSelf(0, 1, 0, rad2deg(angle));
_assertMatricesApproxEqual(domMatrix, ctx.getTransform())
t.done();

});
done();
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<title>OffscreenCanvas test: 2d.transformation.rotate3d.z</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/html/canvas/resources/canvas-tests.js"></script>

<h1>2d.transformation.rotate3d.z</h1>
<p class="desc">rotate3d() around the z axis results in the correct transformation matrix</p>


<script>
var t = async_test("rotate3d() around the z axis results in the correct transformation matrix");
var t_pass = t.done.bind(t);
var t_fail = t.step_func(function(reason) {
throw reason;
});
t.step(function() {

var offscreenCanvas = new OffscreenCanvas(100, 50);
var ctx = offscreenCanvas.getContext('2d');

// angles are in radians, test something that is not a multiple of pi
const angle = 2;
const domMatrix = new DOMMatrix();
ctx.rotate3d(0, 0, angle);
domMatrix.rotateAxisAngleSelf(0, 0, 1, rad2deg(angle));
_assertMatricesApproxEqual(domMatrix, ctx.getTransform())
ctx.rotate3d(0, 0, angle);
domMatrix.rotateAxisAngleSelf(0, 0, 1, rad2deg(angle));
_assertMatricesApproxEqual(domMatrix, ctx.getTransform())
t.done();

});
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py.
// OffscreenCanvas test in a worker:2d.transformation.rotate3d.z
// Description:rotate3d() around the z axis results in the correct transformation matrix
// Note:

importScripts("/resources/testharness.js");
importScripts("/html/canvas/resources/canvas-tests.js");

var t = async_test("rotate3d() around the z axis results in the correct transformation matrix");
var t_pass = t.done.bind(t);
var t_fail = t.step_func(function(reason) {
throw reason;
});
t.step(function() {

var offscreenCanvas = new OffscreenCanvas(100, 50);
var ctx = offscreenCanvas.getContext('2d');

// angles are in radians, test something that is not a multiple of pi
const angle = 2;
const domMatrix = new DOMMatrix();
ctx.rotate3d(0, 0, angle);
domMatrix.rotateAxisAngleSelf(0, 0, 1, rad2deg(angle));
_assertMatricesApproxEqual(domMatrix, ctx.getTransform())
ctx.rotate3d(0, 0, angle);
domMatrix.rotateAxisAngleSelf(0, 0, 1, rad2deg(angle));
_assertMatricesApproxEqual(domMatrix, ctx.getTransform())
t.done();

});
done();
Loading

0 comments on commit c1683b1

Please sign in to comment.