From 80521a95f894c37d6db2e0480454c1afc3d8f6a5 Mon Sep 17 00:00:00 2001 From: wout Date: Sat, 26 Jul 2014 21:58:56 +0200 Subject: Installed Jasmin 2.0.1 --- src/helpers.js | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'src/helpers.js') diff --git a/src/helpers.js b/src/helpers.js index bf417b7..8b11a00 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -52,16 +52,40 @@ function arrayToMatrix(a) { return { a: a[0], b: a[1], c: a[2], d: a[3], e: a[4], f: a[5] } } +// Parse matrix if required +function parseMatrix(matrix) { + if (!(matrix instanceof SVG.Matrix)) + matrix = new SVG.Matrix(matrix) + + return matrix +} + +// Convert string to matrix +function stringToMatrix(source) { + // remove matrix wrapper and split to individual numbers + source = source + .replace(SVG.regex.whitespace, '') + .replace(SVG.regex.matrix, '') + .split(',') + + // convert string values to floats and convert to a matrix-formatted object + return arrayToMatrix( + SVG.utils.map(source, function(n) { + return parseFloat(n) + }) + ) +} + // Calculate position according to from and to function at(o, pos) { - /* number recalculation (don't bother converting to SVG.Number for performance reasons) */ + // number recalculation (don't bother converting to SVG.Number for performance reasons) return typeof o.from == 'number' ? o.from + (o.to - o.from) * pos : - /* instance recalculation */ - o instanceof SVG.Color || o instanceof SVG.Number ? o.at(pos) : + // instance recalculation + o instanceof SVG.Color || o instanceof SVG.Number || o instanceof SVG.Matrix ? o.at(pos) : - /* for all other values wait until pos has reached 1 to return the final value */ + // for all other values wait until pos has reached 1 to return the final value pos < 1 ? o.from : o.to } -- cgit v1.2.3