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

GetDimensions precision #214

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kwhopper
Copy link

Implementation of #179...

Round SvgExtensions.Transforms.GetDimensions return value to three decimal places. Otherwise, non-integer viewbox dimensions lose precision. This can cause subtle left/top shifts in raster output.

The standard data type for viewbox dimensions is a "number" and can be decimal:
https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#number

SKSize members and all relevant local variables are floats so this should cause no issues. The only unsure part is whether "3" is too arbitrary; a very large ViewBox could have four significant integer figures so a case could be made for "4" instead.

…cimal places. Otherwise, non-integer widths and heights lose precision.
@wieslawsoltes
Copy link
Owner

Implementation of #179...

Round SvgExtensions.Transforms.GetDimensions return value to three decimal places. Otherwise, non-integer viewbox dimensions lose precision. This can cause subtle left/top shifts in raster output.

The standard data type for viewbox dimensions is a "number" and can be decimal: https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#number

SKSize members and all relevant local variables are floats so this should cause no issues. The only unsure part is whether "3" is too arbitrary; a very large ViewBox could have four significant integer figures so a case could be made for "4" instead.

And why 4 is not too arbitrary. If it can be decimal we should use decimal precision everywhere.

@kwhopper
Copy link
Author

kwhopper commented May 3, 2024

And why 4 is not too arbitrary. If it can be decimal we should use decimal precision everywhere.

I believe in the spec it says "real" or "decimal" number in a generic sense so I'm not sure of the best practice for scale in this case. But one way to avoid any arbitrary rounding is to not use Math.Round at all for these values?

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

Successfully merging this pull request may close these issues.

2 participants