svg / svgo

⚙️ Node.js tool for optimizing SVG files
https://svgo.dev/
MIT License
20.83k stars 1.38k forks source link

fill-rule removal for non-self-intersecting paths #975

Open akx opened 6 years ago

akx commented 6 years ago

It would be useful to be able to remove fill-rule stanzas from paths that certifiably do not self-intersect.

The implementation might be a little tricky though, as it would involve parsing the path string and rasterizing it or otherwise analyzing it for self-intersection.

GreLI commented 6 years ago

The tricky part is how to know about self-intersection. Do you know an algorithm with complexity less then O(n²)? Rasterization isn't reliable since SVG is really scalable and you can never tell how it'll be used, also I believe it's needs a lot of computation.

akx commented 6 years ago

This would be a "lossy" transformation for sure, something that's not enabled by default.

Re complexity: Good question. Google suggests the Bentley–Ottmann algorithm, which is O((n+k) / log n), but still, the path, which is not necessarily just line segments, would need to be flattened to line segments first. (Or the transformation could just give up on non-line-segment shapes.)

yisibl commented 5 years ago

@akx Do you have the idea of achieving it?

mahnunchik commented 3 years ago

+1