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

Avoid merging intersecting paths #109

Merged
merged 28 commits into from
Nov 28, 2024
Merged

Avoid merging intersecting paths #109

merged 28 commits into from
Nov 28, 2024

Conversation

jzbrooks
Copy link
Owner

@jzbrooks jzbrooks commented Nov 27, 2024

Merging paths that overlap can cause problems with transparency determinations related to fill rules and can negatively impact paths which make use of relative coordinates.

Avoiding merging those paths addresses the issues in #59 also, but in a more robust way—so we can consider merging even odd fill rule paths, so long as they don't intersect.

This intersection test is fairly corse. An axis-aligned bounding box is computed for each path and a simple rectangle intersection test is performed. Since paths aren't typically rectangular, sometimes nearby but non-overlapping paths will be considered intersecting. There are more involved algorithms that can improve on this mentioned in #88, but:

a) the bounding box check is fairly good and the benefits of merging even odd paths outweigh the losses w.r.t. occasionally not merging two paths that don't overlap

b) the downside is a slightly larger than optimal graphic, but not an incorrect graphic, so improvements regarding intersection precision should only really shrink the graphic—not change its semantics.

Fixes #88, Fixes #101

@jzbrooks
Copy link
Owner Author

jzbrooks commented Nov 27, 2024

I used https://codepen.io/branneman/pen/nBjeLo to sketch the bounding boxes to visually verify.

(some of these screenshots were taken before I doubled the interpolation resolution)

absolute elliptical arc

absolute-elliptical-arc

absolute polyquadratic

absolute-polyquadratic

absolute smooth polyquadratic

absolute-smooth-polyquadratic

rotated elliptical arc (toggling sweep flag)

The elliptical arc's box is computed for the whole ellipse, which you can see in the recording by me flipping the sweep flag. Not totally ideal, but good enough for now. The downside is similar to the bounding box approach in general—at worst we avoid merging paths that really could be merged but the image is not warped. Interpolating the ellipse with endpoint parameterization is kinda tricky.

arc-flip-bounding-box.mov

heart

heart

Minnesota (regression 60)

minnesota

smooth quadratic

quad-with-smooth

relative polyquadratic

relative-polyquadratic

relative smooth polyquadratic

relative-smooth-polyquadratic-10t

standalone smooth curve

standalone-smooth-curve

@jzbrooks jzbrooks enabled auto-merge (squash) November 28, 2024 16:45
@jzbrooks jzbrooks merged commit cc988d3 into master Nov 28, 2024
2 checks passed
@jzbrooks jzbrooks deleted the merge-path-intersection branch November 28, 2024 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Warped image involving relative moveto MergePaths causes warping when paths overlap
1 participant