Repository navigation
raster: flatten filled curves without losing area - #77
Merged
Merged
Conversation
Filled curves were flattened into chords, which lie inside convex arcs: the segments between chord and arc were lost, 0.2 % of a circle of radius 50 px and up to 4.6 % of one of glyph size (r = 1.3 px). Glyphs came out measurably thin (-1.3 % ink on glyphs-30000-uncached at 150 dpi against a 600 dpi rendering). Each interval is now drawn as two lines through an apex 4/3 of the sagitta out from the chord. The two lines enclose the arc's area exactly for a parabolic arc; for a cubic interval the remaining error is of higher order. The apex lies a third of the sagitta outside the curve, so intervals may have a sagitta of 3 · flattenTol (fillSag) and the polyline still stays within flattenTol of the curve. Curves with a sagitta below 1/64 px stay one line. Circles of radius 1.3-150 px now enclose their area within 0.16 % (TestCurveArea); glyphs-30000-uncached is within 0.1 % of the 600 dpi rendering. Small curves take two lines instead of one: uncached glyphs are 7-10 % slower, cached text and the other scenes are unchanged within noise. Strokes are not affected (they flatten in the stroker). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 of 3 tasks
timzifer
added a commit
that referenced
this pull request
Nov 13, 2026
gpu/v0.8.0 required v0.18.0, which lacks the core side of the GPU work merged since (#62, #63, #65, #66, #67): outside this repository, where the replace directive does not apply, the module got the older core. v0.19.0 has it, and filled curves flattened without losing area (#77). gpu/v0.8.1 is tagged on the commit that merges this. Co-authored-by: Tim Ebbinghaus <tim@ebbinghaus.name> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Filled curves were flattened into chords that lie inside convex arcs, so the area between chord and arc was always lost: 0.2 % for a circle with r = 50 px, up to 4.6 % at glyph size. Glyphs came out thin (−1.3 % ink on
glyphs-30000-uncachedat 150 dpi, measured against a 600 dpi rendering).3 · flattenTol(fillSag). The polyline still stays withinflattenTolof the curve, and edge counts stay similar for larger curves.raster.goandshape.go(the unclipped recorder) are changed the same way. Strokes are not affected; they flatten in the stroker.Accuracy
glyphs-30000-uncached: 150 dpi ink vs 600 dpi ink went from 0.9869 to 0.9990.The scene still misses the pdfbench target against PDFium, now from the other side: PDFium's own flattening loses roughly 0.9 % on these curves. The hairline scene misses because PDFium over-inks edge pixels (+0.5 to 0.8 % on diagonal lines). Both are reference bias, not stilus errors.
Performance
BenchmarkScenes(M4, n=6): small curves now take two lines instead of one, soglyphs-30000-uncachedis +7 to +10 % slower. Cached text and all other scenes are unchanged within noise; the geomean over all scenes is −1.2 %.Test plan
TestCurveArea: cubic and quadratic circles, r = 1.3 to 150 px, within 0.4 %. It fails on the old code.go vet ./...,go test ./...(core, harness)🤖 Generated with Claude Code