rough-stuff / rough

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

Clone default settings before using it in generator #128

Closed GasimGasimzada closed 4 years ago

GasimGasimzada commented 4 years ago

There are some parts in the renderer where the options object is being mutated by some functions (e.g _line function in renderer). If you are using custom parameters, because default parameters and the custom parameters are merged, the resulting object is a cloned object that we can work on. However, if custom parameters are not passed to these functions, the original value of the default parameters will be used. As a result, any custom object that doesn't specify a value will be overridden by the changing default value.

By cloning default options we can always preserve the original default values, which will stop bleeding of parameters between rendered elements.

pshihn commented 4 years ago

You're right that roughnessGain is being modified, but it should not really have any effects in subsequent renders, as it is calculated every time. I don't see any other instance where any other property is being modified. Maybe I missed something.
So, I'm not sure this will fix your problem. Can you elaborate more what exact issue you're running into?

pshihn commented 4 years ago

Not needed anymore. roughnessGain has been removed from options and is not mutated