Open DarkContact opened 3 years ago
This must be related to miter limit which isn't supported in vg-renderer (see Readme)
Inkscape (and all proper vector graphics renderers) support miter limit which will convert thin long miters into bevel joints. vg-renderer doesn't support miter limit in order to simplify stroke calculations. It was a decision I made very early and never got back into fixing it. I don't really know how much such calculations will affect runtime performance.
Unfortunately, I cannot think of an easy way to fix this, other than rewriting all stroker functions in a way to include this kind of checks and convert the problematic stoke corners into bevels.
EDIT: Added link to stroke-miterlimit SVG attribute.
Not supporting miter limit in vg-renderer is the same as setting the limit to a large value in all other renderers. You can check this by altering stroke-miterlimit in your SVG file and viewing it in your browser. See example in the linked MDN page.
Thanks for the answer. But it seems to me that the problem is not only miter limit. I have attached some images for a better understanding of the problem. In the turquoise rectangles, I have highlighted the problem areas. As the kMaxExtrusionScale ratio increases, there are fewer errors. However, on smaller scales, kMaxExtrusionScale has to be done more in order to achieve acceptable quality. It seems that kMaxExtrusionScale should not be constant. What do you think on this?
Even path fills suffer from the same problem as strokes without a miter limit when using AA. This is because the same algorithm is used for calculating AA fringes. Fringes as half-width strokes around a filled path. See https://github.com/jdryg/vg-renderer/blob/master/src/stroker.cpp#L867
kMaxExtrusionScale is a hack to limit the amount of extrusion of those problematic cases. The correct way to handle it is to dynamically limit the extrusion and convert those corners into bevels, even for the AA fringes. Problem with dynamically produced bevels is that the amount of vertices isn't known beforehand so extra allocations are necessary inside the inner loop as well as extra checks.
Hope that makes sense. You can check this is due to AA if you disable AA in all the problematic cases you shown above. A polygon fill without AA doesn't introduce any more vertices than those produced by the path tesselation. AA on the other hand produces extra vertices around the polygon with an alpha value of 0 in order to smoothly fade the edges.
I tried to make a minimal example to demonstrate the problem.
Let's take a bezier curve made in inkscape:
If I try render with vg I see what:
![image](https://user-images.githubusercontent.com/2587074/130455423-22685d1c-eb74-4661-9564-889cdc60b911.png)
Code:
Also the problem is easy to reproduce it to output svg on a small scale (0.1f or less) with AA enabled:
![image](https://user-images.githubusercontent.com/2587074/130456699-a64dfc6a-ac35-4c43-a67e-69015599e064.png)
In an imperial way, I tried to change the kMaxExtrusionScale parameter here:https://github.com/jdryg/vg-renderer/blob/4f1bfa7e57561728fc5fa36476cf550bac885663/src/stroker.cpp#L45 and there are fewer chaotic lines. But there are small inaccuracies elsewhere. Any ideas on how to fix this?