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

Remove trailing zeroes from decimal numbers #3

Merged
merged 1 commit into from Mar 11, 2021

Conversation

SkylerLipthay
Copy link
Contributor

Hi! Thank you for creating this library. I noticed a problem using it when precision is set to anything above 0. So, I made a small change to remove trailing zeroes from decimal numbers in the output paths. This change serves two purposes:

  1. The output path will be smaller.
  2. Paths that include the A command will no longer cause some renderers to fail. Previously, the "large-arc" and "sweep" flags were being set to 0.0 instead of 0 and causing some renderers to fail.

For example, try testing the following SVG path (tested in Firefox and Edge w/ WebKit):

M11,0H5A1,1,0,0,0,4,1V4H6V2H10V10H6V8H4V11A1,1,0,0,0,5,12H11A1,1,0,0,0,12,11V1A1,1,0,0,0,11,0zM8,5H3V3L0,6L3,9V7H8V5

This works. Now try changing one inconspicuous 0 to 0.0:

M11,0H5A1,1,0,0.0,0,4,1V4H6V2H10V10H6V8H4V11A1,1,0,0,0,5,12H11A1,1,0,0,0,12,11V1A1,1,0,0,0,11,0zM8,5H3V3L0,6L3,9V7H8V5

This now doesn't work.

If this change is accepted, you may also consider changing the default precision from 0 to something moderate like 4, since trailing zeroes will no longer inflate the output size unnecessarily, and this extra default precision would help the library work better for a wider range of inputs.

Thanks again for your hard work and thanks for reading!

 This change only applies when `options.precision` is nonzero. It serves
 two purposes:

 1) The output path will be smaller.
 2) Paths that include the `ARCTO` command will no longer cause some
    renderers to fail. Previously, the "large-arc" and "sweep" flags
    were being set to `0.0` instead of `0` and causing some renderers to
    fail.
@Fulanko Fulanko merged commit 7250456 into Luxbyte:master Mar 11, 2021
@Fulanko
Copy link
Member

Fulanko commented Mar 11, 2021

Thank you for your contribution!

I merged the pull request and changed the default precision to 4.

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

Successfully merging this pull request may close these issues.

None yet

2 participants