rough-stuff / rough

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

Feature Request: Allow to provide path data as array of segments #170

Open aleksey-shmatov opened 4 years ago

aleksey-shmatov commented 4 years ago

Currently path method accepts data as a string. In the internals it is being parse twice once in pointsOnPath and another time in svgPath. In my case I want to do some preprocessing to the path data before applying roughness. Currently I am basically forced to:

  1. Parse string to segments.
  2. Apply my own transformations to path data.
  3. Convert transformed data back to string.
  4. This string will be parsed twice inside RoughJS library.
pshihn commented 3 years ago

Sorry for the late response. But if you are still interested in this, can you give a bit more details and context. Maybe some example of what you are trying to achieve? thanks!

aleksey-shmatov commented 3 years ago

I want to implement real-time resizing of the shapes. I can't just use scaling because the way RoughJS works is based on the absolute distance values. So for example if you apply roughness to 10px line and then scale it 10x result will not be same as applying roughness to the 100px line. In second case there would be more "roughness" and result looks more natural. So what I am doing is adjusting shape/path data according to a new size and then pass down adjusted data to the RoughJS library. The problem is that RoughJS accepts only a string. This basically results in 3 path data parsing operations. One is my own because I need to adjust data to a new size and another two inside RoughJS(not sure why it happens twice pretty sure this can be optimised to single one). All these additional parsing slows down things quite a bit and for more complex shapes I am seeing performance issues during resize.