Last active
August 29, 2015 14:11
-
-
Save doughamlin/7a31a2034bb4cff1dfe7 to your computer and use it in GitHub Desktop.
Converts a list of SVG polygon points to fractions/bounding box units
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Converts a list of SVG polygon points to fractions/bounding box units | |
* | |
* @param {string} points Space separated list of points from Illustrator/Sketch/etc. export (each point is a comma separated X,Y pair) | |
* @param {number} width Bounding box width | |
* @param {number} height Bouding box height | |
*/ | |
function convertSVGPoints(points, width, height) { | |
var convertedPoints = []; | |
points = points.split(' '); | |
for (var i = 0; i < points.length; i++) { | |
var point = points[i].split(','); | |
var x = point[0] / width; | |
var y = point[1] / height; | |
convertedPoints.push([x,y]); | |
} | |
console.log(convertedPoints.join(' ')); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment