Repository navigation
fix: replace int() with round() to implement rounding in scale_bounding_box() - #1974
Conversation
…ng in `scale_bounding_box` The comment in `scale_bounding_box` specifies rounding, yet it directly uses `int()` to truncate the value. This may prevent achieving `better simulation` and could cause confusion during debugging, as its return value differs from the actual result of the transform.
|
Thanks for this interesting PR! 💚 After having spent some time on this, I wonder if we should round there at all. What I have found:
Looking at the more complicated scale code that is farther up, I believe that also there it is better to use the unrounded values. The point coordinates are checked after real scaling anyhow 🤔 So we have this # Drop nonintegral part of nodes' coordinates; ttf will do it anyhow, otf will be much smaller
self.sourceFont[currentSourceFontGlyph].round()and if scale_ratio_x != 1.0 or scale_ratio_y != 1.0:
# scale a tiny bit too small to avoid rounding problems
scale_ratio_x *= self.sourceFont.em / (self.sourceFont.em + 1)which should take care of most rounding issues. The rounding down (i.e. What do you think, is not-rounding at all not the better solution? I remember writing that |
That is not true, the extrema of the virtual bounding box is always some real node. 🤔 |
Finii
left a comment
There was a problem hiding this comment.
Approve, but maybe you have time to think about dropping any rounding.
|
Thank you for your review!❤
In summary, the first approach is convenient but sacrifice some precision. The second method offers accuracy but require significant changes and potentially encounter unforeseen challenges. So, what do you think?🤔 |
|
Thank you for your active interest and for sharing some fascinating details with me. |
|
@allcontributors pleas add @GoldPigg for code |
|
I've put up a pull request to add @GoldPigg! 🎉 |





Description
The following function is used to simulate
transform, so its comment mentions "round values for better simulation". However, its implementation usesint()instead ofround().nerd-fonts/font-patcher
Lines 1943 to 1955 in a861c72
This may introduce minor errors (results being 1 less than
transform). While this likely has negligible impact on final outcomes, it can cause confusion during debugging—leaving developers(eg. me) scratching their heads over two values that should be equal but consistently differ by 1.Requirements / Checklist
Issue number where discussion took place: #xxx
What does this Pull Request (PR) do?
Replace
int()withround()to implement rounding inscale_bounding_box()How should this be manually tested?
When patching

Go-Mono.ttf, glyph0x259fhas the same bounding box as scale_data. In this specific case, the expected outcome is thatscale_bounding_box()should yield the same result assys_dim. However,sym_dimdoes not equalscaleglyph_dim. This can be tested as shown in the image below.Any background context you can provide?
What are the relevant tickets (if any)?
Screenshots (if appropriate or helpful)