1 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
2 * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 * Utilities for testing SVG matrices
11 function createMatrix(a, b, c, d, e, f) {
12 var svg = document.getElementsByTagName("svg")[0];
13 var m = svg.createSVGMatrix();
23 // Lightweight dummy Matrix class for representing arrays that get passed in
24 function MatrixFromArray(a) {
33 function cmpMatrix(a, b, msg) {
34 if (a.constructor === Array) {
35 a = new MatrixFromArray(a);
37 if (b.constructor === Array) {
38 b = new MatrixFromArray(b);
48 msg + " - got " + formatMatrix(a) + ", expected " + formatMatrix(b)
52 function roughCmpMatrix(a, b, msg) {
53 if (a.constructor === Array) {
54 a = new MatrixFromArray(a);
56 if (b.constructor === Array) {
57 b = new MatrixFromArray(b);
60 const tolerance = 1 / 65535;
62 Math.abs(b.a - a.a) < tolerance &&
63 Math.abs(b.b - a.b) < tolerance &&
64 Math.abs(b.c - a.c) < tolerance &&
65 Math.abs(b.d - a.d) < tolerance &&
66 Math.abs(b.e - a.e) < tolerance &&
67 Math.abs(b.f - a.f) < tolerance,
68 msg + " - got " + formatMatrix(a) + ", expected " + formatMatrix(b)
72 function formatMatrix(m) {
73 if (m.constructor != Array) {
74 return "(" + [m.a, m.b, m.c, m.d, m.e, m.f].join(", ") + ")";
77 return "(" + m.join(", ") + ")";