blob: 38556ec524ecc1e9365d073899947477c317a0c5 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<title>Geometry Interfaces: DOMMatrix conversion to and from typed arrays</title>
<link href="mailto:cdumez@apple.com" rel="author" title="Chris Dumez">
<link href="https://drafts.fxtf.org/geometry/#dommatrixreadonly" rel="help">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>
for (let matrix of ["DOMMatrixReadOnly", "DOMMatrix"]) {
test(function() {
assert_throws_js(TypeError, () => { window[matrix].fromFloat32Array() }, "No parameter");
assert_throws_js(TypeError, () => { window[matrix].fromFloat32Array(null) }, "Passing null");
assert_throws_js(TypeError, () => { window[matrix].fromFloat32Array(new Float64Array()) }, "Bad parameter");
assert_throws_js(TypeError, () => { window[matrix].fromFloat32Array(new Float32Array()) }, "Empty Float32Array");
assert_throws_js(TypeError, () => { window[matrix].fromFloat32Array(new Float32Array([1, 2])) }, "Float32Array with too few items");
assert_throws_js(TypeError, () => { window[matrix].fromFloat32Array(new Float32Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17])) }, "Float32Array with too many items");
}, matrix + ".fromFloat32Array (error cases)");
test(function() {
let matrix2d = window[matrix].fromFloat32Array(new Float32Array([1.5, 2.5, 3.5, 4.5, 5.5, 6.5]));
assert_equals(matrix2d.__proto__, window[matrix].prototype);
assert_equals(matrix2d.toString(), "matrix(1.5, 2.5, 3.5, 4.5, 5.5, 6.5)");
let matrix3d = window[matrix].fromFloat32Array(new Float32Array([1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5, 16.5]));
assert_equals(matrix3d.__proto__, window[matrix].prototype);
assert_equals(matrix3d.toString(), "matrix3d(1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5, 16.5)");
}, matrix + ".fromFloat32Array");
test(function() {
assert_throws_js(TypeError, () => { window[matrix].fromFloat64Array() }, "No parameter");
assert_throws_js(TypeError, () => { window[matrix].fromFloat64Array(null) }, "Passing null");
assert_throws_js(TypeError, () => { window[matrix].fromFloat64Array(new Float32Array()) }, "Bad parameter");
assert_throws_js(TypeError, () => { window[matrix].fromFloat64Array(new Float64Array()) }, "Empty Float64Array");
assert_throws_js(TypeError, () => { window[matrix].fromFloat64Array(new Float64Array([1, 2])) }, "Float64Array with too few items");
assert_throws_js(TypeError, () => { window[matrix].fromFloat64Array(new Float64Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17])) }, "Float64Array with too many items");
}, matrix + ".fromFloat64Array (error cases)");
test(function() {
let matrix2d = window[matrix].fromFloat64Array(new Float64Array([1.5, 2.5, 3.5, 4.5, 5.5, 6.5]));
assert_equals(matrix2d.__proto__, window[matrix].prototype);
assert_equals(matrix2d.toString(), "matrix(1.5, 2.5, 3.5, 4.5, 5.5, 6.5)");
let matrix3d = window[matrix].fromFloat64Array(new Float64Array([1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5, 16.5]));
assert_equals(matrix3d.__proto__, window[matrix].prototype);
assert_equals(matrix3d.toString(), "matrix3d(1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5, 16.5)");
}, matrix + ".fromFloat64Array");
}
test(function() {
let matrix2d = new DOMMatrixReadOnly([1.5, 2.5, 3.5, 4.5, 5.5, 6.5]);
let array32 = matrix2d.toFloat32Array();
assert_equals(array32.__proto__, Float32Array.prototype);
assert_equals(array32.length, 16);
assert_equals(array32.toString(), "1.5,2.5,0,0,3.5,4.5,0,0,0,0,1,0,5.5,6.5,0,1");
let matrix3d = new DOMMatrixReadOnly([1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5, 16.5]);
array32 = matrix3d.toFloat32Array();
assert_equals(array32.__proto__, Float32Array.prototype);
assert_equals(array32.length, 16);
assert_equals(array32.toString(), "1.5,2.5,3.5,4.5,5.5,6.5,7.5,8.5,9.5,10.5,11.5,12.5,13.5,14.5,15.5,16.5");
assert_equals(matrix3d.toString(), DOMMatrixReadOnly.fromFloat32Array(array32).toString());
}, "DOMMatrixReadonly.toFloat32Array");
test(function() {
let matrix2d = new DOMMatrixReadOnly([1.5, 2.5, 3.5, 4.5, 5.5, 6.5]);
let array64 = matrix2d.toFloat64Array();
assert_equals(array64.__proto__, Float64Array.prototype);
assert_equals(array64.length, 16);
assert_equals(array64.toString(), "1.5,2.5,0,0,3.5,4.5,0,0,0,0,1,0,5.5,6.5,0,1");
let matrix3d = new DOMMatrixReadOnly([1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5, 16.5]);
array64 = matrix3d.toFloat64Array();
assert_equals(array64.__proto__, Float64Array.prototype);
assert_equals(array64.length, 16);
assert_equals(array64.toString(), "1.5,2.5,3.5,4.5,5.5,6.5,7.5,8.5,9.5,10.5,11.5,12.5,13.5,14.5,15.5,16.5");
assert_equals(matrix3d.toString(), DOMMatrixReadOnly.fromFloat64Array(array64).toString());
}, "DOMMatrixReadonly.toFloat64Array");
</script>
</body>
</html>