aboutsummaryrefslogtreecommitdiffstats
path: root/src/pointarray.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/pointarray.js')
-rw-r--r--src/pointarray.js22
1 files changed, 7 insertions, 15 deletions
diff --git a/src/pointarray.js b/src/pointarray.js
index b935cb5..2911cd1 100644
--- a/src/pointarray.js
+++ b/src/pointarray.js
@@ -40,33 +40,25 @@ SVG.extend(SVG.PointArray, {
}
// Parse point string
, parse: function(array) {
+ var points = []
+
array = array.valueOf()
// if already is an array, no need to parse it
if (Array.isArray(array)) return array
-
// parse points
- var points = array.split(/\s|,/)
+ array = array.split(/\s|,/)
// validate points - https://svgwg.org/svg2-draft/shapes.html#DataTypePoints
// Odd number of coordinates is an error. In such cases, drop the last odd coordinate.
- if (points.length % 2 !== 0) points.pop()
-
- // parse points as floats
- points = points.map(function(x) { return parseFloat(x) })
+ if (array.length % 2 !== 0) array.pop()
- // wrap points in two-tuples
- points = points.map(wrapPoints()).filter(function(x) { return x })
+ // wrap points in two-tuples and parse points as floats
+ for(var i = 0, len = points.length; i < len; i + 2)
+ point.push([ parseFloat(points[i]), parseFloat(points[i+1]) ])
return points
-
- function wrapPoints() {
- var a
- return function(b, i) {
- return i % 2 === 0 ? (a = b, null) : [a,b]
- }
- }
}
// Move point string
, move: function(x, y) {