jakearchibald / svgomg

Web GUI for SVGO
https://jakearchibald.github.io/svgomg/
MIT License
5.8k stars 482 forks source link

Precision 0 not removing assumed-to-be-removable decimal places #385

Open burntcustard opened 2 years ago

burntcustard commented 2 years ago

I threw an SVG into SVGOMG and expected to be able to remove some decimal places by reducing the precision slider to 0, but got unexpected results, with precision 0 being almost identical to precision 1, in that it had removed some but not all of the decimal places:

Precision 2

<linearGradient id="d" x1="429.25" x2="2060.11" y1="1381.38" y2="1949.74" gradientUnits="userSpaceOnUse">
  ...
</linearGradient>

Precision 1

<linearGradient id="d" x1="429.3" x2="2060.1" y1="1381.4" y2="1949.7" gradientUnits="userSpaceOnUse">
  ...
</linearGradient>

Precision 0

<linearGradient id="d" x1="429.3" x2="2060.1" y1="1381.4" y2="1949.7" gradientUnits="userSpaceOnUse">
  ...
</linearGradient>

I had perhaps incorrectly assumed that 0 meant "as un-precise as possible". I'm not sure if this is specifically an SVGOMG or an SVGO issue, and I'm not 100% sure what the desired solution would be. Either there's something going wrong, which is resulting in the lower precision values incorrectly not being rounded, or it is intended behaviour, but then a) it's not clear what 0 means, and b) maybe an even lower (-1?) option would be helpful for situations like mine?

Entire SVG code

Click to view ``` ```
burntcustard commented 2 years ago

After a little investigating I found this snippet: https://github.com/jakearchibald/svgomg/blob/b925d7abeb20933bb5e2548e3dfb73ffa6146783/src/js/svgo-worker/index.js#L48-L54 Which I suspect has something to do with my issue. I could attempt to look into the root cause of cleanupNumbericValues with a value of 0 breaking images in SVGO? Or perhaps adding a -1 to the precision slider, or yet another feature toggle of "Allow potentially breaking rounding" would be more likely to be helpful?

burntcustard commented 2 years ago

This remains an issue with v1.16.0, with it's renamed 'Number precision' slider.