Skip to content

fix bounding box, force 1st absolute M #49

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

Closed
wants to merge 1 commit into from

Conversation

herrstrietzel
Copy link

Referring to issue 47: "getPathBBox () in versions":

The latest build 2.1.8 struggles with pathdata starting with pseudo-relative M commands - causing the bbox calculation to fail:

M 77.7553 122.1843 a 15.6631 5.5 45 0 1 14.9646 7.1864 l 8.053 8.053 a 15.6631 5.5 45 0 1 -7.7782 7.7782 l -8.053 -8.053 a 15.6631 5.5 45 0 1 -7.1864 -14.9646

would return the expected bbox of width:31.529978953390923, height:31.529978953390895

m 77.7553 122.1843 a 15.6631 5.5 45 0 1 14.9646 7.1864 l 8.053 8.053 a 15.6631 5.5 45 0 1 -7.7782 7.7782 l -8.053 -8.053 a 15.6631 5.5 45 0 1 -7.1864 -14.9646

would fail and return an incorrect one width:108.62229440861523, height:153.0512944086152]

This also applies to cubic approximations like

m77.7553 122.1843
C 79.9 120.04 86.6 123.25 92.72 129.37
L 100.77 137.42
C 106.88 143.54 110.11 150.24 107.96 152.39
C 105.81 154.54 99.11 151.31 92.99 145.2
L 84.94 137.15
C 78.82 131.03 75.61 124.33 77.76 122.18

Forcing the first M command to use an uppercase type identifier fixes this issue.
However, this quick fix may be more suitable in the getPathBBox.ts

See codepen
2.1.8
2.1.8.1 - fix

@thednp thednp closed this in 1fedc25 Jan 28, 2025
@thednp
Copy link
Owner

thednp commented Jan 28, 2025

@herrstrietzel
Thank you for the contribution, I've patched this and I will publish 2.1.8 then.

PS: Sorry I didn't merge your PR, there was a problem with the tests.

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.

2 participants