Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

altered paths #1858

Open
nschloe opened this issue Nov 29, 2023 · 3 comments
Open

altered paths #1858

nschloe opened this issue Nov 29, 2023 · 3 comments
Labels

Comments

@nschloe
Copy link

nschloe commented Nov 29, 2023

Running

svgo in.svg

on

in

gives

in-opti

This is with svgo 3.0.4.

@nschloe nschloe added the bug label Nov 29, 2023
@SethFalco
Copy link
Member

SethFalco commented Nov 29, 2023

Hey! Thanks for reporting the issue.

The issue is caused due to rounding. By default, SVGO reduces the precision of floating-point numbers to 5 decimal places.

In most cases, this is fine. However, in this SVG some of the numbers are super inflated, with matrixes applied that are really miniscule.

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 673 205">
  <path d="M0 0L6235704.138785 2260595.537351" transform="matrix(0.0000431728,0,0,0.0000431865,60.47463,20.8221)" stroke-width="12700" stroke="black"/>
</svg>

Here is a trimmed down version of the SVG that showcases the issue. See how the path commands use numbers like 6,235,704, and then to scale it down to fit in the viewport a transform is applied using numbers like 0.0000431728. The 0.0000431728 is being rounded down to 0.00004. With numbers at this scale, this ends up making a significant difference.

For now, a workaround you can do is increase the transform precision of the convertTransform plugin. You can create the following config in the directory you're running the command in, then try again.

svgo.config.js

module.exports = {
  plugins: [
    {
      name: "preset-default",
      params: {
        overrides: {
          convertTransform: {
            transformPrecision: 10
          }
        }
      }
    }
  ]
}

@nschloe
Copy link
Author

nschloe commented Nov 30, 2023

Interesting! Is there a way to disable the float clipping entirely?

@SethFalco
Copy link
Member

SethFalco commented Nov 30, 2023

As far as I know (reviewing documentation and the current implementation) we don't have anything to disable the rounding entirely. (Apart from disabling the plugin.)

Later, I can review if we should allow passing false to precision parameters to disable modifying the value for floating points at all, beyond trimming redundant zeros and the like.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants