Enable processing pixel lengths as float #415
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hey, this is still very much WIP, but I would like to get some feedback on it.
I've started work on converting the whole library to use
float
rather thanint
when calculating the length of things in pixels, to avoid compounding rounding errors. This is something users have requested a few times by now. The general plan was:pixel_t
typedef intypes.h
to represent pixel sizes, just pointing toint
initiallyint
everywhere, and if it represents a size in pixels, replace it withpixel_t
pixel_t
point tofloat
insteadAt this point I have looked through the code and replaced everything. I've also tested it with
float
and it does compile, but there are a few things to fix still.I do have a few questions though on how to proceed:
Are you sure you would want to support both
int
andfloat
pixel types?It seems like this would be quite annoying. Both variants would have to be tested, or if one isn't tested it might break. I'm not sure what the benefit of
int
would be (other than backward compatibility maybe). A page would have to be several million pixels large before precision becomes a problem. The performance seems about the same from what I've measured.How should the API be handled?
I think it would make the most sense to keep the pixels as
float
all the way until the document container, and then that can decide what to do with them. But then this would be a breaking change. From what I can tell the API surface is basically most things in the include folder, and a lot of that has changed. In theory it might be possible to keep having the API useint
by duplicating a bunch of structures, but that would be very painful.Right now, with
pixel_t
being an alias forint
, there is no breakage, so keeping that the default and adding a switch could solve this problem.Also there are some structures whose name doesn't make sense now, like
typed_int
andint_int_cache
. These also always store pixel sizes so they now usepixel_t
. But they are part of the API surface so renaming them would be breaking.I've also replaced font size and media query related pixel values with
pixel_t
for consistency, though I'm not sure how necessary that is really.As a demonstration consider an example similar to #14:
HTML
int
:float
:The right edge of the red box should line up with the right edge of the green box, but with
int
there is a noticeable gap. Usingfloat
fixes this.Closes #47
Closes #14