package scanline

Import Path
	github.com/pancsta/d2/d2renderers/d2raster/internal/scanline (on go.dev)

Dependency Relation
	imports 7 packages, and imported by one package

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
WorkBudget accounts scan-conversion operations across rasterizer calls. It is intentionally not concurrency-safe; one renderer owns it for one frame. Remaining reports the unconsumed operation units. func NewWorkBudget(limit int64) WorkBudget func (*Rasterizer).DrawRGBA(ctx context.Context, budget *WorkBudget, dst *image.RGBA, paint color.NRGBA) error func (*Rasterizer).WalkCoverage(ctx context.Context, budget *WorkBudget, writeRow func(y, minX int, partial, difference []float32) error) error func (*Rasterizer).WriteAlpha(ctx context.Context, budget *WorkBudget, dst *image.Alpha) error
Package-Level Functions (total 7)
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.