Last active
August 29, 2015 14:02
-
-
Save wout/a92ceb50716586a6e62f to your computer and use it in GitHub Desktop.
Round path directives to a given amount of decimals
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
// svg.compress.js 0.0.1 - Copyright (c) 2014 Wout Fierens - Licensed under the MIT license | |
SVG.extend(SVG.Path, { | |
// Round path directives to a given amount of decimals | |
compress: function(decimals) { | |
decimals = eval('1e' + decimals) | |
for (var n, i = this.array.value.length - 1; i >= 0; i--) | |
for (n = this.array.value[i].length - 1; n >= 1; n--) | |
this.array.value[i][n] = ~~(this.array.value[i][n] * decimals) / decimals | |
return this | |
} | |
}) | |
// Usage: path.compress(3) | |
// Warning: this feature works desctructive and will reduce the resolution of your path |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment