rough-stuff / rough

Create graphics with a hand-drawn, sketchy, appearance
http://roughjs.com
MIT License
19.94k stars 617 forks source link

Added precision option to tune the number of digits (precision) the generated SVG paths #80

Closed frakie-com closed 4 years ago

frakie-com commented 6 years ago

When using "dots" for filling with rough.js in SVG, the generated SVG paths have unbounded decimal precission, thus generating very (too) long SVG path definitions, for example:

<path d="M30.539315825403072 38.8454317562159 C31.883007943372455 38.55777292462577, 37.10578534198741 39.022739438608504, 37.7268100198641

This is usually innecessary, because with 2 or 3 decimal digits would be more than enough, AND this reduces the generated SVG size 3-fold or more.

It's easy as adding a "round" function before outputting the numbers, which I have done in src/generator.ts.

Also added a "Precision" option, with default=3 (could be 2).

You can play a bit with our updated version in our On-line digital art gallery