New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
simplify behaves weirdly with fairly simple shapes #920
Comments
Also note that changing the parameter to |
Digging into source, I think it's just not suitable to use |
No, that's not really what it's doing. The algorithm was originally developed to fit bezier curves to large datasets of points connected by straight lines, the way you would get them from a pointing device, e.g. the mouse. So it takes these points and tries to create similar lines by fitting as few curves through them as possible. The parameter controls the allowed error. It is very similar to what Adobe Illustrator is doing in the Pencil Tool when you release the mouse button. In your example, the curve information (the handles / control points) is actually ignored, only the points that the curves pass through (the anchor points) are taken, and passed through the algorithm. And since there are so few and they are wide apart, you get unpredictable results. You could try to use |
So I don't think this is a bug... But perhaps the issue here is that the documentation is not clear about this? |
Thanks that's what we basically concluded once we started looking into it. How do you normally document this kind of thing? Is there some kind of jsdoc on the actual simplify call in the correct js file? I could send a PR when I get a chance (and maybe also update the part of the tutorial that demonstrates simplify.) |
Yes the reference is built out of JSDoc comments, which are translated into this by a customized version of JSDoc 2 that we're using. You can find the source to the The current description is indeed very vague. We're always happy to accept PRs with improvements, of course! |
It's not clear when one should use
simplify
to be honest, but it does some pretty surprising things. Take this example sketch.Screenshot as well:
The top is the original display of
CompoundPath
objects creating from svg path data. The bottom is applyingsimplify
to a copy each child path of the original (re-positioned down obviously).Now obviously
simplify
is more useful on complicated curvy paths, but if you're processing arbitrary inputs you don't know in advance if it would make sense to simplify. In our code we do guard this by checking for the number of child paths and count of segments in those child paths, but it seems weird to just arbitrarily threshold.The text was updated successfully, but these errors were encountered: