Open Windowsfreak opened 5 months ago
We already join consecutive h
or v
.
We already remove 0-length commands when applicable.
We already replace closing lines with z
when applicable.
I'm not sure how you missed out on those - maybe SVGOMG is that out of date.
The only thing we don't do is join l
when the slope is the same.
Problem statement:
A path
M2 2h2h3v1v3h-2v-1l-1-1l-2-2
could be simplified toM2 2h5v4h-2v-1l-3-3
.If you compare these paths, the same shape as above can be represented with less points, thus saving precious bytes: Technically, the last step could be replaced with a
z
, but this goes beyond the scope of this optimisation.In a nutshell:
l-1-1
andl-2-2
l-1-1h0l-2-2
tol-3-3
Example Python code:
This example code parses a path of Saxony, Germany which contains segments such as:
l -1 -1 -2 -2
which could be simplified tol -3 -3
orh3 0 2
which could be simplified toh5
as well as combinations of these. It analyses the segments and combines them. It converts allh
andv
segments intol
and only supports relative coordinates with the exception ofmMzZ
, which are just passed through. Thus it also doesn't support curves, sorry! Optimising the output back intoh
andv
shorthands, changing precision etc. could be done with the already existing optimisation steps of SVGOMG.