summaryrefslogtreecommitdiffstats
path: root/src/helpers.js
diff options
context:
space:
mode:
authorwout <wout@impinc.co.uk>2014-07-26 21:58:56 +0200
committerwout <wout@impinc.co.uk>2014-07-26 21:58:56 +0200
commit80521a95f894c37d6db2e0480454c1afc3d8f6a5 (patch)
tree762ec2c50953bc7871fbe03770bc985abaeaa351 /src/helpers.js
parent9842187d84e71e736ada6a2e9444bab592945600 (diff)
downloadsvg.js-80521a95f894c37d6db2e0480454c1afc3d8f6a5.tar.gz
svg.js-80521a95f894c37d6db2e0480454c1afc3d8f6a5.zip
Installed Jasmin 2.0.1
Diffstat (limited to 'src/helpers.js')
-rw-r--r--src/helpers.js32
1 files changed, 28 insertions, 4 deletions
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
}