Should empty arc be dropped ?
kpym opened this issue · comments
I know that you follow the W3C where we can read "If the endpoints (x1, y1) and (x2, y2) are identical, then this is equivalent to omitting the elliptical arc segment entirely.".
But this is dangerous because the browsers don't do this. Check the following paths
- "M 0 0 C 0 10 10 10 10 0 A 10 10 0 0 0 10 0 S 20 -10 20 0" (with empty arc segment)
- "M 0 0 C 0 10 10 10 10 0 S 20 -10 20 0" (with empty arc segment removed)
- "M 0 0 C 0 10 10 10 10 0 L 10 0 S 20 -10 20 0" (with empty line segment)
You can see that the browser treats the empty arc like empty line segment, and don't drop it.
The only situation where dropping arc is dangerous is before short commands (S, s, T,t).
By the way this 'drop empty arcs' rule is inconsistent with the other type of segments. Why to drop empty arcs and not to drop empty lines ?
What do you suggest?
Two options :
- simpler : always simplify empty arc to empty line (but don't drop it).
- more complicated : remove empty arcs only if they are not followed by S,s,T or t, else drop them.
In the case of the more complicated choice it could be applied to all empty segments, except M and m.
This is what I do in my repo (see the .normalize()
method).
Could you explain how S/s/T/t are affected by previous arc?
PS. replace with L/l looks ok for me. We removed arc only because of spec, svgpath
is not expected to optimize anything, that's not svgo
.
As you can see in my example if we have "C X S" sequence (with X not C or S, for example =A) the S first control point is considered as the starting point. But if we drop X (=A in our case), in the sequence "C S" the first control point of S is taken from C.
Ah! Got it, thanks!
I came to ask the question on stackoverflow.