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

MergePaths causes warping when paths overlap #88

Closed
jzbrooks opened this issue Sep 30, 2024 · 4 comments · Fixed by #109
Closed

MergePaths causes warping when paths overlap #88

jzbrooks opened this issue Sep 30, 2024 · 4 comments · Fixed by #109
Labels
bug Something isn't working

Comments

@jzbrooks
Copy link
Owner

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Shrinking this vector drawable results in the image being hollowed out.

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="19dp"
    android:height="30dp"
    android:viewportWidth="19"
    android:viewportHeight="30">
  <path
      android:pathData="M18.4271,7.7715C17.7591,2.6885 14.5931,0.0015 9.2721,0.0005C3.9521,0.0015 0.7861,2.6885 0.1171,7.7715C-0.1029,9.4425 -0.0129,11.2385 0.3831,13.1085C2.3331,22.3275 7.0441,27.8595 8.4421,29.3365C8.6571,29.5625 8.9601,29.6925 9.2721,29.6935C9.5851,29.6925 9.8871,29.5625 10.1031,29.3365C11.5001,27.8595 16.2121,22.3275 18.1621,13.1085C18.5581,11.2385 18.6471,9.4425 18.4271,7.7715"
      android:fillColor="#253993"
      android:fillType="nonZero"
      />
  <path
      android:pathData="M16.5721,12.7755C14.8421,20.9505 10.7491,26.1695 9.2721,27.8385C7.7961,26.1695 3.7031,20.9505 1.9731,12.7755C1.6141,11.0815 1.5321,9.4685 1.7281,7.9825C2.2841,3.7615 4.8221,1.6215 9.2721,1.6205C13.7221,1.6215 16.2601,3.7615 16.8161,7.9825C17.0121,9.4685 16.9301,11.0815 16.5721,12.7755"
      android:fillColor="#253993"
      android:fillType="nonZero"
      />
</vector>

Expected behavior
The image to visually identical

Screenshots
Screenshot 2024-09-30 at 3 54 48 PM

@jzbrooks jzbrooks added the bug Something isn't working label Sep 30, 2024
@jzbrooks
Copy link
Owner Author

jzbrooks commented Oct 1, 2024

svgo had a similar bug: svg/svgo@e1060df
The ultimate solution is probably to revert #59 and implement intersection checking.

@jzbrooks jzbrooks changed the title MergePaths warps some images MergePaths causes warping when paths overlap Oct 1, 2024
@jzbrooks
Copy link
Owner Author

jzbrooks commented Oct 1, 2024

https://computerwebsite.net/writing/gjk seems like a useful summary of the algorithm they use

@jzbrooks
Copy link
Owner Author

It just occurred to me that GJK isn't absolutely necessary. A good first step would be to use an axis-aligned bounding box check for intersection detection. svgo does this as an optimization but it's really all that's required to avoid this bug because it will over signal intersections. GJK would make the intersection detection more precise and result in more path merging, but it could be done in a follow up.

@jzbrooks
Copy link
Owner Author

jzbrooks commented Nov 14, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant