|
45 | 45 | // everything to two decimal places, which isn't OK for the matrices |
46 | 46 | // that result from large perspective values. |
47 | 47 | const compareWithPerspective = (actual, expected) => { |
48 | | - const matrixRegExp = /^matrix3d\(((?:(?:[-0-9.]+), ){15}(?:[-0-9.]+))\)$/; |
49 | | - const actualArray = actual.match(matrixRegExp)[1].split(", ").map(Number); |
50 | | - const expectedArray = expected.match(matrixRegExp)[1].split(", ").map(Number); |
| 48 | + // TODO: This RegExp should be more precise to capture only what is a |
| 49 | + // valid float, and this code should be merged with other code doing |
| 50 | + // the same thing, e.g., RoundMatrix in |
| 51 | + // web-animations/animation-model/animation-types/property-list.js . |
| 52 | + const matrixRegExp = /^matrix3d\(((?:(?:[-0-9.e]+), ){15}(?:[-0-9.]+))\)$/; |
| 53 | + const actualMatch = actual.match(matrixRegExp); |
| 54 | + const expectedMatch = expected.match(matrixRegExp); |
| 55 | + assert_not_equals(actualMatch, null, `${actual} should be a matrix`); |
| 56 | + assert_not_equals(expectedMatch, null, `${expected} should be a matrix`); |
| 57 | + if (actualMatch === null || expectedMatch === null) { |
| 58 | + return; |
| 59 | + } |
| 60 | + const actualArray = actualMatch[1].split(", ").map(Number); |
| 61 | + const expectedArray = expectedMatch[1].split(", ").map(Number); |
51 | 62 | assert_equals(actualArray.length, 16); |
52 | 63 | assert_equals(expectedArray.length, 16); |
53 | 64 |
|
| 65 | + if (actualArray.length != expectedArray.length) { |
| 66 | + return; |
| 67 | + } |
| 68 | + |
54 | 69 | for (let i in actualArray) { |
55 | 70 | const error = Math.abs((actualArray[i] - expectedArray[i])) / |
56 | 71 | Math.max(1e-6, |
|
0 commit comments