Skip to content

Conversation

@tomcur
Copy link
Member

@tomcur tomcur commented Sep 14, 2025

Draft, as this ideally uses linebender/kurbo#505 and requires the comments to be updated. Wanted to test this on CI in the meantime.

This tightens the bounds of the early curve-to-line-segment flattening we've introduced in #1214, by projecting the control points onto the line segment, rather than just checking the distance to the end points. This detects Beziers that are nearly lines with control points near the interior, not just those with small control point lengths, detecting more such near-line Beziers in larger-scale geometry as well.

@LaurenzV
Copy link
Contributor

image image image image image

@tomcur
Copy link
Member Author

tomcur commented Sep 14, 2025

Nice, thanks for the benchmarks! As I suspected, this helps especially bring down the timings on some of the larger geometry, too (relative to #1214, which impacted smaller geometry especially), as all Beziers that are nearly lines with control points near the interior should now be detected; not just those with small control point lengths.

I've run the tests locally (CPU-only, GPU crashes for me), and there are 63 failures, all on glyph:: or recording::. Will look into the failures more closely later, but it may well be that these are brushing up against the tolerance of 0.25 pixels, causing some coverage differences.

@LaurenzV
Copy link
Contributor

LaurenzV commented Sep 15, 2025

This seems to be the failure for the "glyphs_filled" test. Previously, we generated two segments, now it's just one:
QuadBez { p0: (50.26953125, 46.0), p1: (52.66015625, 46.0), p2: (54.31640625, 45.140625) }. At least intuitively, it does seem like it should be within the threshold.

@LaurenzV
Copy link
Contributor

I've run this through the PDF test suite and there are pixel differences in nearly all images (highlighting how common such small curves are!) but nothing that stands out as a regression. So, assuming this is mathematically valid, seems good to me.

@tomcur
Copy link
Member Author

tomcur commented Sep 15, 2025

This seems to be the failure for the "glyphs_filled" test. Previously, we generated two segments, now it's just one: QuadBez { p0: (50.26953125, 46.0), p1: (52.66015625, 46.0), p2: (54.31640625, 45.140625) }. At least intuitively, it does seem like it should be within the threshold.

The max distance between that quadratic and the line segment [p0,p2] is approximately 0.2483 and the current tolerance is 0.25, so that's right around the threshold. Makes sense that it got subdivided before, as even a slight overestimation in error would bump it over.

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.

2 participants