Repository navigation
PNG rasterizer: exact and bounded on far-off geometry - #85
Merged
Merged
Conversation
Geometry far outside the canvas could make the PNG rasterizer walk a dash pattern for ever, overflow its integer pixel arithmetic or crash: a dashed line a million points long, a pen a trillion points wide, a path out at 1e15. - clip_to_box and clip_segment cut a path to a box about the canvas before it is filled or stroked, interpolating from the near end and bisecting where both ends are far, so that nothing far off reaches the pixel arithmetic. - stroke_dashed walks a dash pattern only over the part of a segment whose dashes can reach the canvas, and lands on its far end exactly; where a wide pen with butt ends is wider than the canvas, only over the canvas's span along the segment. Joins at skipped vertices come back as capless stubs, only where a dash runs through. - A dash pattern shorter than half a pixel, whose dashes cannot be told apart, is drawn as a solid line at the share of the line it would cover; walking it dash by dash could take without end. This is the one approximation, and the source documents it. Every other shortcut draws exactly what the full walk of every dash draws, up to the rounding of where along a very long segment the pattern stands. full_walk, a switch for the tests, turns every shortcut off; the new tests/test_missing.f90 compares the two on fixed cases, sweeps of offsets and caps, and 400 random strokes, and requires them to agree to the pixel.
This was referenced Nov 22, 2026
This was referenced Nov 22, 2026
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.
PNG rasterizer: exact and bounded on far-off geometry
Geometry far outside the canvas could make the PNG rasterizer walk a dash pattern for ever, overflow its integer pixel arithmetic or crash: a dashed line a million points long, a pen a trillion points wide, a path out at 1e15. This PR changes only
src/fplotlib_raster.f90, and adds its tests.clip_to_boxandclip_segmentcut a path to a box about the canvas before it is filled or stroked. They interpolate from the near end, and bisect where both ends are far, so nothing far off reaches the pixel arithmetic. (The plotting layer uses them in the next PR.)stroke_dashedwalks a pattern only over the part of a segment whose dashes can reach the canvas, and lands exactly on the segment's far end. For a butt-ended pen wider than the canvas, it walks only over the canvas's span along the segment. Joins at skipped vertices come back as capless stubs, only where a dash runs through.full_walk, a test-only switch, turns every shortcut off. The newtests/test_missing.f90compares the two on fixed cases, sweeps of offsets and caps, and 400 random strokes, and requires them to agree to the pixel. Every test picture is unchanged.This is part of a stack of five PRs that together are exactly #83 (the final tree of the last one is byte for byte #83's), split so that each can be reviewed and merged on its own. Each one builds and passes the whole test suite with gfortran, gfortran
-O3 -march=native, flang, flang-O3 -march=nativeand LFortran, and the docs build.status_t(the error API)Merge them in order; each PR's base is the one before it. #83 went through 30 rounds of independent review, the last with no blockers.