Involved Source Files Package scanline rasterizes D2's closed vector paths with non-zero winding.
The implementation is deliberately specialized for D2's renderer: paths are
consumed in device coordinates and painted as a uniform color, written to an
Alpha image, or exposed row-wise for direct paint compositing. Each directed
edge contributes its exact signed area to the pixels it crosses; a row-sized
difference buffer carries winding across interior spans. This avoids both
supersampling and a canvas-sized accumulation image.
Package-Level Type Names (total 2)
/* sort by: | */
Rasterizer retains reusable path and scanline storage between Reset calls.
It is not safe for concurrent use. ClosePath closes the current subpath with a straight edge. CubeTo appends a cubic Bezier curve. Curves are flattened in device space so
the tolerance is independent of the source transform. CubeTo64 appends a cubic curve using reference rounding for its control and
end points before applying the configured origin translation. DrawRGBA paints the current paths over dst using a uniform, unpremultiplied
color. Rasterizer coordinates start at dst.Bounds().Min. Work is charged to
budget and cancellation is checked within long scan loops. EdgeCount reports the number of non-horizontal finite edges in the current
path, capped at the configured limit. Err reports any edge-budget or curve-complexity error from path construction. LineTo appends a straight edge to the current subpath. LineTo64 appends an edge using the reference rounding and origin translation
described by MoveTo64. MoveTo starts a new subpath at x, y. MoveTo64 starts a subpath, rounding relative to the reference origin before
applying the translation configured by SetOriginOffset. ReserveEdges bounds path construction and reserves the corresponding
reusable edge, scan-edge, and active-edge capacities. Reset clears the current paths while retaining bounded scratch capacity. SetOriginOffset sets the translation applied by the 64-bit path methods
after their coordinates have been rounded to float32. This lets a cropped
target preserve the coordinate rounding of a larger reference target.
Reset clears the translation; the original float32 methods ignore it. WalkCoverage rasterizes the current paths and visits each row segment that
can contain non-zero coverage. partial and difference are transient views
into the Rasterizer's reusable accumulation storage, aligned so index zero
corresponds to minX. The callback must consume them before returning and
must not retain either slice.
Callers reconstruct each pixel's coverage in increasing index order with:
winding += difference[index]
alpha := QuantizeCoverage(partial[index] + winding)
Rasterizer coordinates start at the caller's target origin. Work is charged
to budget and cancellation is checked during scan conversion; callbacks that
perform substantial per-pixel work should also check their context. WorkBound returns a conservative bound derived from aggregate edge metrics.
The rasterizer records only counts, clipped row spans, monotone horizontal
travel, and a touched rectangle, so count-only preflight remains O(1) space. WriteAlpha writes opaque path coverage into a freshly zeroed dst. Rasterizer
coordinates start at dst.Bounds().Min. Work is charged to budget and
cancellation is checked within long scan loops.
func NewCounter(width, height, edgeLimit int) *Rasterizer
func NewRasterizer(width, height int) *Rasterizer
MaxEdgesForBytes returns the largest edge count whose retained edge arrays
fit in bytes. It is used to stop count-only flattening before preflight can
itself exceed the configured offscreen budget.
NewCounter returns a rasterizer that performs the same path flattening as a
drawing rasterizer without allocating edge or scanline storage. At most
edgeLimit edges are counted before ErrEdgeLimit is reported.
NewRasterizer returns an empty rasterizer for a width by height target.
NewWorkBudget returns a budget with limit available operation units.
QuantizeCoverage converts a signed analytic pixel area into the same 8-bit
absolute coverage used by DrawRGBA and WriteAlpha.
RetainedBytes returns the backing-storage bytes retained after visiting
targets up to maxWidth and maxHeight and paths up to maxEdges. Width and
height are independent maxima because Reset retains both capacities.
WorkBound returns the worst-case operation units for rasterizing edges into
a width by height target. Callers that submitted geometry should prefer the
Rasterizer method, whose O(1) aggregate metrics preserve the same safety
proof without multiplying every small path by the complete target bounds.
Package-Level Variables (total 3)
ErrCurveLimit reports that a curve remains unresolved at the safety depth.
Returning an error avoids silently replacing extreme geometry with an
inaccurate chord.
ErrEdgeLimit reports that path flattening would exceed the caller's
retained edge-storage budget.
ErrWorkLimit reports that scan conversion exhausted its explicit operation
budget. The budget is shared across rasterizer calls for one frame.
The pages are generated with Goldsv0.8.7. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.