-
Notifications
You must be signed in to change notification settings - Fork 28
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
BezPath's f64 lose precision after cast to f32 when using ReverseContourPen #640
Comments
You can test my WIP branch where I call ReverseContourPen on all the contours with this googlefonts/fontc#475 running ttx_diff.py on e.g. Oswald.glyphs, you'll notice the number of (no-longer-implied) oncurve points in the glyf table increases dramatically |
I believe the initial proposal for the |
Why not just make pen f64? |
this is no longer an issue because we now no longer use a pen to do the contour reversal but rely on the new kurbo::BezPath::reverse_subpaths method |
fontc uses write-fonts' ReverseContourPen to reverse glyph contour's direction (for various reasons), doing something like this:
fontc stores glyph contours as
kurbo::BezPath
, which internally store coordinates as f64.Because the font-types' Pen trait (which ReverseContourPen implements) uses f32 instead of f64, the coordinates get rounded and lose precision. You may argue 32-bit floats should be enough..
However, when I tried to use the ReverseContourPen to implement googlefonts/fontc#174, right before the BezPaths get converted to write-fonts' SimpleGlyphs (using
interpolatable_glyphs_from_bezpaths
method, which is where the implied on-curve midpoints get pruned), because the f64 are cast as f32, losing precision, I end up getting entirely different implied oncurves than when I convert the BezPath to SimpleGlyphs without reversing them first.To match exactly fonttools, remember that we ported the Python
math.isclose
method which is used over there to test if a given point is almost in the middle between two points, and we are even using the same default tolerances as Python's isclose, i.e. rel_tol=1e-9 and abs_tol=0.0 (checkwrite-fonts::util::isclose
).So while we could relax the isclose tolerance, I would rather have a way to pass through the f64 coordinates unrounded and keep the tighter tolerance.
How can we do that? Do we need to make the Pen trait generic over coordinate type? Any help appreciated, thanks
The text was updated successfully, but these errors were encountered: