You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A path M2 2h2h3v1v3h-2v-1l-1-1l-2-2 could be simplified to M2 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:
Add each path to the output stack
Compare the direction of the last two entries, e.g. by calculating atan2 of l-1-1 and l-2-2
If the direction matches, compare the paths
Also remove zero-length segments, e.g. l-1-1h0l-2-2 to l-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 to l -3 -3 or h3 0 2 which could be simplified to h5 as well as combinations of these. It analyses the segments and combines them. It converts all h and v segments into l and only supports relative coordinates with the exception of mMzZ, which are just passed through. Thus it also doesn't support curves, sorry! Optimising the output back into h and v shorthands, changing precision etc. could be done with the already existing optimisation steps of SVGOMG.
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.The text was updated successfully, but these errors were encountered: