diff options
author | dotnetCarpenter <jon.ronnenberg@gmail.com> | 2016-10-12 11:26:35 -0200 |
---|---|---|
committer | dotnetCarpenter <jon.ronnenberg@gmail.com> | 2016-10-12 12:53:24 -0200 |
commit | 4f8edd919ab159f51d0324b0f0051472055e5da6 (patch) | |
tree | 8572062fd7da0f7a402608b4414e022978748a9f /src/pointarray.js | |
parent | eed96bcf59c00584527ac87902ba48669cb8cb6e (diff) | |
download | svg.js-4f8edd919ab159f51d0324b0f0051472055e5da6.tar.gz svg.js-4f8edd919ab159f51d0324b0f0051472055e5da6.zip |
changing implementation according to review by @Fuzzyma
Diffstat (limited to 'src/pointarray.js')
-rw-r--r-- | src/pointarray.js | 22 |
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) { |