Weird artifacts with arcs in some paths
See original GitHub issueHi, I’ve run into an issue, where an arc segment seems to go missing when I convert a parsed path back to a string with d()
. Here’s a visual example of what is happening:
The left side is the original path and the right side is what I got by running the path through parse_path("...").d()
. It looks like an arc segment is just left out.
To understand better what’s going on, here are the paths that create the two hearts above:
<!-- Original -->
<path
d="
m 1672.2372,-54.8161
a 14.5445,14.5445 0 0 0 -11.3152,23.6652
l 27.2573,27.2572 27.2572,-27.2572
a 14.5445,14.5445 0 0 0 -11.3012,-23.634
a 14.5445,14.5445 0 0 0 -11.414,5.4625
l -4.542,4.5420
l -4.5437,-4.5420
a 14.5445,14.5445 0 0 0 -11.3984,-5.4937
z"
fill="none" stroke="#FF423F" stroke-width="2" stroke-linecap="square"
/>
<!-- Parsed -->
<path
d="
M 1772.24,-54.8161
A 14.5445,14.5445 0 0,0 1760.92,-31.1509
L 1788.18,-3.8937 L 1815.44,-31.1509
A 14.5445,14.5445 0 0,0 1804.14,-54.7849
A 14.5445,14.5445 0 0,0 1792.72,-49.3224
L 1788.18,-44.7804
L 1783.64,-49.3224
Z"
fill="none" stroke="#FF423F" stroke-width="2" stroke-linecap="square"
/>
The final arc before Z is clearly missing for some reason.
Also here’s what I ran on the python prompt to get the result above:
>>> p = parse_path("m 1772.2372,-54.8161 a 14.5445,14.5445 0 0 0 -11.3152,23.6652 l 27.2573,27.2572 27.2572,-27.2572 a 14.5445,14.5445 0 0 0 -11.3012,-23.634 14.5445,14.5445 0 0 0 -11.414,5.4625 l -4.542,4.5420 -4.5437,-4.5420 a 14.5445,14.5445 0 0 0 -11.3984,-5.4937 z")
>>> p
Path(Move(to=(1772.2372-54.8161j)), Arc(start=(1772.2372-54.8161j), radius=(14.5445+14.5445j), rotation=0.0, arc=False, sweep=False, end=(1760.922-31.1509j)), Line(start=(1760.922-31.1509j), end=(1788.1793-3.893699999999999j)), Line(start=(1788.1793-3.893699999999999j), end=(1815.4365-31.1509j)), Arc(start=(1815.4365-31.1509j), radius=(14.5445+14.5445j), rotation=0.0, arc=False, sweep=False, end=(1804.1353-54.7849j)), Arc(start=(1804.1353-54.7849j), radius=(14.5445+14.5445j), rotation=0.0, arc=False, sweep=False, end=(1792.7213-49.3224j)), Line(start=(1792.7213-49.3224j), end=(1788.1793-44.7804j)), Line(start=(1788.1793-44.7804j), end=(1783.6356-49.3224j)), Arc(start=(1783.6356-49.3224j), radius=(14.5445+14.5445j), rotation=0.0, arc=False, sweep=False, end=(1772.2372-54.8161j)), closed=True)
>>> p.d()
'M 1772.24,-54.8161 A 14.5445,14.5445 0 0,0 1760.92,-31.1509 L 1788.18,-3.8937 L 1815.44,-31.1509 A 14.5445,14.5445 0 0,0 1804.14,-54.7849 A 14.5445,14.5445 0 0,0 1792.72,-49.3224 L 1788.18,-44.7804 L 1783.64,-49.3224 Z'
EDIT: I did some testing and it seems like this is what ommits the last arc: https://github.com/regebro/svg.path/blob/master/src/svg/path/path.py#L434
Not sure what a real fix should be like, but I can probably work around it at least in some cases, by just doing p.closed = False
before p.d()
.
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
Yes that works, I mentioned it at the end of the issue 😃
Great, I’ll try to report back when I get round to testing this. Thank you! 👍