Skip to content

Instantly share code, notes, and snippets.

@doughamlin
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save doughamlin/7a31a2034bb4cff1dfe7 to your computer and use it in GitHub Desktop.
Save doughamlin/7a31a2034bb4cff1dfe7 to your computer and use it in GitHub Desktop.
Converts a list of SVG polygon points to fractions/bounding box units
/**
* 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