Skip to content
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

Paths won't merge #2040

Open
MichaelHinrichs opened this issue Jun 21, 2024 · 3 comments
Open

Paths won't merge #2040

MichaelHinrichs opened this issue Jun 21, 2024 · 3 comments
Labels

Comments

@MichaelHinrichs
Copy link

Describe the bug
When I try to use SVGOMG to merge the paths in the attached SVG, two paths remain unmerged.
3DCommerce_Black_Aug20

To Reproduce

  1. Go to https://jakearchibald.github.io/svgomg/
  2. Open the attached SVG.
  3. Make sure the "Merge Paths' switch is on.
  4. Click "Markup" tab.

Expected behavior
All paths merge, leaving only one.

Screenshots
twopaths

Desktop (please complete the following information):

  • SVGO v3.0.0
  • Unknown NodeJs Version. Whatever SVGOMG is using.
  • OS: Windows 10

Additional context
I'm able to merge the paths with a text editor with no issue. The SVG looks exactly the same, so I'm not sure what's preventing SVGO from doing it. The original file comes from here, as well as others that may replicate the same problem.

@GreLI
Copy link
Member

GreLI commented Jun 27, 2024

It's not a bug. It's a desirable behavior. Unfortunately, it's not easy to implement. Merging paths can lead to issues like excluding sections. To avoid them one need to check for intersections or even path directions. Currently there is quick and dirty check for convex hulls intersections (by GJK algorithm). If you know a library that can do such a check for paths better than with O(n²) complexity, please let me know.

@adamdiestelkamp
Copy link

Running into this too. Sometimes when I export a flattened SVG from Figma I get three paths. These paths don't intersect, but I'd like them to merge into one path (our design system library expects this) but svgo leaves them as 3 paths.

<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="...pathdata" fill="black"/>
<path d="...pathdata" fill="black"/>
<path d="...pathdata" fill="black"/>
</svg>

Is that expected that it won't merge paths that don't touch?

@GreLI
Copy link
Member

GreLI commented Sep 24, 2024

Yes, if their convex hulls touch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants