~/bend-docscommunity

cover.bend relies on unsafe/foreign

raw source on the hub · import gralha-coverage@0.1.0.1/cover.bend as Cover

Analytic coverage: line lists in pixel space are scan-converted with a winding count on a few sub-scanlines per row (exact span extents in x, so the fill rule holds even where contours overlap), and the result is a sparse quadtree mask.

2 imports
import Base
import gralha-text-scan@0.1.0.1/scan.bend as U

Types

type CovLine source · line 9 · raw

Data

A directed line in pixel coordinates of the target grid.

type CovTree source · line 13 · raw

Data

Coverage over a power-of-two square: uniform cells collapse to one leaf.

type Run source · line 18 · raw

Data

A run of cells [x0, x1) of one nonzero coverage value in a row.

type CovData source · line 24 · raw

Data

A mask's coverage: rows of runs (top first, ascending runs), which a fill is painted from directly, or the tree, which clip masks and sampled tiles need for block and pixel queries.

type CovMask source · line 30 · raw

Data

A mask placed at pixel (x, y) of its grid, size = 2^depth cells on a side. w by h cells of it hold coverage; size = 2^depth is the tree's side.

type Act source · line 242 · raw

Data

A line on the scanlines: x at the current one is cur; slope is dx/dy.

type Ins source · line 246 · raw

Data

Insert into a list descending by cur, after the elements not below it.

type Take source · line 301 · raw

Data

Lines from the sorted pending list whose top the scanline sy has reached.

type CovEv source · line 330 · raw

Data

type Step source · line 360 · raw

Data

One scanline: walk the ascending list, emit the inside spans' events, and build the descending list for the next scanline sy2.

type EvOrder source · line 375 · raw

Data

Merge two descending event lists, larger cells first.

type Sweep source · line 445 · raw

Data

Sweep state: sum is the total delta at cells >= upper, the runs so far cover cells >= upper, and the open group collects the events of cell c.

type LineOrder source · line 473 · raw

Data

type LineSplit source · line 505 · raw

Data

type Subs source · line 532 · raw

Data

type Scan source · line 554 · raw

Data

type Piece source · line 607 · raw

Data

A line for the exact scan: x = x0 + (y - y0) * slope over [top, bottom).

type PieceTake source · line 858 · raw

Data

Lines whose top the row's bottom has passed become pieces; a horizontal one is skipped. The cursor k walks the order array.

type XState source · line 916 · raw

Data

Reading the runs off the buffer, touched cells only, from hi down to lo: a cell's coverage is the magnitude of its direct area minus the deltas to its right (a row's deltas cancel), clamped to one, and the untouched cells between two touched ones share the magnitude of those deltas. A magnitude past one marks an overlap. Every slot and bitmap word read is cleared, so the buffer is empty for the next row.

type XData source · line 990 · raw

Data

The scan state: the row buffer, the line arrays, and the rest as a record.

type Halves source · line 1060 · raw

Data

A row's runs cut at mid into the left and right halves, with the row's uniform value over [x0, x1): 0 for no runs, the value of a single run that spans the columns, -1 otherwise.

type Node source · line 1083 · raw

Data

A node's uniform value (2 before any row, -1 once rows disagree) and its quarters' rows; flat holds when the node is uniform (no rows means empty).

type CovBox source · line 1128 · raw

Data

type CovLines source · line 1257 · raw

Data

Lines gathered with their bounds and count as they are made, so the mask needs no pass of its own over them; only a handful of lines can be a rectangle, so the others skip that test too.

Definitions

def mask.none source · line 33 · raw

CovMask

def runs.at source · line 37 · raw

@rs:List<&2, Run> -> @+x:U32 -> F32

Coverage of a cell from rows of runs; a slow path for masks built without a tree.

def rows.at source · line 46 · raw

@rows:List<&2, List<&2, Run>> -> @+y:U32 -> @+x:U32 -> F32

def mask.present source · line 51 · raw

@+m:CovMask -> Bool

def data.at source · line 67 · raw

@d:CovData -> @+half:U32 -> @+x:U32 -> @+y:U32 -> F32

def mask.at.in source · line 72 · raw

@outside:Bool -> @d:CovData -> @+half:U32 -> @+x:U32 -> @+y:U32 -> F32

def mask.at source · line 79 · raw

@+m:CovMask -> @+px:F32 -> @+py:F32 -> F32

Coverage of the pixel containing (px, py), in grid pixel coordinates; the reads branch through matches, not lambdas, since they run once per pixel.

def tree.same.as source · line 93 · raw

@+v:F32 -> @+u:F32 -> F32

Coverage over the cell rectangle [x0, x1) by [y0, y1) of a node's square at (nx, ny) of side size, when every cell in it holds the same value; -1 otherwise. acc is 2 before any cell is seen, -1 once cells disagree, else the value so far.

def tree.overlaps source · line 96 · raw

@+nx:U32 -> @+ny:U32 -> @+size:U32 -> @+x0:U32 -> @+y0:U32 -> @+x1:U32 -> @+y1:U32 -> Bool

def runs.over source · line 115 · raw

@rs:List<&2, Run> -> @+x0:U32 -> @+x1:U32 -> @+acc:F32 -> F32

The mask's coverage over the grid rectangle [x0, x1) by [y0, y1) when it is uniform (2 means "unvisited", so an empty rectangle reads as uniform 0), else -1. The uniform value of runs over the columns [x0, x1): a run covering them all gives its value, none touching them gives 0, anything else -1.

def data.uniform source · line 136 · raw

@d:CovData -> @+mx:U32 -> @+my:U32 -> @+sz:U32 -> @+x0:U32 -> @+y0:U32 -> @+x1:U32 -> @+y1:U32 -> F32

def mask.uniform.in source · line 141 · raw

@+m:CovMask -> @+x0:U32 -> @+y0:U32 -> @+x1:U32 -> @+y1:U32 -> F32

def mask.uniform source · line 151 · raw

@+m:CovMask -> @+x0:U32 -> @+y0:U32 -> @+x1:U32 -> @+y1:U32 -> F32

def line.split source · line 156 · raw

@l:CovLine -> @+at:F32 -> List<&2, CovLine>

def lines.append source · line 168 · raw

@xs:List<&2, CovLine> -> @ys:List<&2, CovLine> -> List<&2, CovLine>

def lines.split source · line 173 · raw

@xs:List<&2, CovLine> -> @+at:F32 -> List<&2, CovLine>

def lines.clamp source · line 180 · raw

@xs:List<&2, CovLine> -> @+w:F32 -> @acc:List<&2, CovLine> -> @+n:U32 -> Pair(List<&2, CovLine>, U32)

Pieces left of 0 or right of w become vertical lines on that boundary, which keeps the winding of every cell inside [0, w) intact.

def lines.clip source · line 186 · raw

@xs:List<&2, CovLine> -> @+w:F32 -> Pair(List<&2, CovLine>, U32)

The clipped lines, in no particular order, with their count.

def line.push source · line 193 · raw

@+ax:F32 -> @+ay:F32 -> @+bx:F32 -> @+by:F32 -> @+w:F32 -> @st:Pair(List<&2, CovLine>, U32) -> Pair(List<&2, CovLine>, U32)

One pass over the lines: shift by the mask's origin, split at the grid's left and right edges and clamp the pieces to it, counting them. Pieces left of 0 or right of w become vertical lines on that edge, which keeps the winding of every cell inside intact.

def line.cut.at source · line 199 · raw

@cross:Bool -> @+ax:F32 -> @+ay:F32 -> @+bx:F32 -> @+by:F32 -> @+at:F32 -> @+w:F32 -> @st:Pair(List<&2, CovLine>, U32) -> Pair(Pair(List<&2, CovLine>, U32), Pair(F32, F32))

Split at x = at when the line crosses it, pushing the piece before the crossing; the rest continues.

def line.cut source · line 206 · raw

@+ax:F32 -> @+ay:F32 -> @+bx:F32 -> @+by:F32 -> @+at:F32 -> @+w:F32 -> @st:Pair(List<&2, CovLine>, U32) -> Pair(Pair(List<&2, CovLine>, U32), Pair(F32, F32))

def line.prepare.last source · line 209 · raw

@got:Pair(Pair(List<&2, CovLine>, U32), Pair(F32, F32)) -> @+bx:F32 -> @+by:F32 -> @+w:F32 -> Pair(List<&2, CovLine>, U32)

def line.prepare.right source · line 213 · raw

@got:Pair(Pair(List<&2, CovLine>, U32), Pair(F32, F32)) -> @+bx:F32 -> @+by:F32 -> @+w:F32 -> Pair(List<&2, CovLine>, U32)

def lines.prepare source · line 217 · raw

@xs:List<&2, CovLine> -> @+dx:F32 -> @+dy:F32 -> @+w:F32 -> @st:Pair(List<&2, CovLine>, U32) -> Pair(List<&2, CovLine>, U32)

def line.top source · line 237 · raw

@+l:CovLine -> F32

def act.ins.pick source · line 250 · raw

@hit:Bool -> @a:Act -> @h:Act -> @t:List<&2, Act> -> Ins

def act.insert source · line 268 · raw

@a:Act -> @xs:List<&2, Act> -> List<&2, Act>

def act.reverse source · line 277 · raw

@xs:List<&2, Act> -> @acc:List<&2, Act> -> List<&2, Act>

def act.keep source · line 283 · raw

@keep:Bool -> @+x0:F32 -> @+y0:F32 -> @+slope:F32 -> @+bottom:F32 -> @+dir:F32 -> @+sy:F32 -> @acc:List<&2, Act> -> List<&2, Act>

The line as it will stand on scanline sy, placed into the descending list.

def act.add source · line 290 · raw

@l:CovLine -> @+sy:F32 -> @acc:List<&2, Act> -> List<&2, Act>

A line covers [top, bottom) so a shared vertex counts once; a horizontal line never crosses. Lines whose bottom the scanline has passed are dropped.

def take.pick source · line 304 · raw

@hit:Bool -> @l:CovLine -> @rest:List<&2, CovLine> -> @+sy:F32 -> @acc:List<&2, Act> -> Take

def ev.push.if source · line 333 · raw

@skip:Bool -> @+cell:U32 -> @+direct:F32 -> @+delta:F32 -> @acc:List<&2, CovEv> -> List<&2, CovEv>

def ev.push source · line 338 · raw

@+cell:U32 -> @+direct:F32 -> @+delta:F32 -> @acc:List<&2, CovEv> -> List<&2, CovEv>

def span.events.cells source · line 341 · raw

@one:Bool -> @+ia:U32 -> @+ib:U32 -> @+xa:F32 -> @+xb:F32 -> @+w:F32 -> @acc:List<&2, CovEv> -> List<&2, CovEv>

def span.events source · line 347 · raw

@inside:Bool -> @+xa:F32 -> @+xb:F32 -> @+w:F32 -> @acc:List<&2, CovEv> -> List<&2, CovEv>

Events of the span [xa, xb) when it is inside; both ends lie within [0, width].

def winding.inside source · line 355 · raw

@+wind:F32 -> @+even:Bool -> Bool

def ev.cell source · line 378 · raw

@+e:CovEv -> U32

def ev.order.pick source · line 382 · raw

@hit:Bool -> @x:CovEv -> @xt:List<&2, CovEv> -> @y:CovEv -> @yt:List<&2, CovEv> -> EvOrder

def ev.order source · line 387 · raw

@x:CovEv -> @xt:List<&2, CovEv> -> @y:CovEv -> @yt:List<&2, CovEv> -> EvOrder

def ev.merge source · line 403 · raw

@xs:List<&2, CovEv> -> @ys:List<&2, CovEv> -> List<&2, CovEv>

def run.snap source · line 419 · raw

@+v:F32 -> F32

Sums of a weight's multiples cancel exactly for power-of-two sub counts and to within rounding otherwise; noise below a millionth reads as empty.

def runs.emit.join source · line 422 · raw

@join:Bool -> @+x0:U32 -> @+x1:U32 -> @+v:F32 -> @+b:U32 -> @head:Run -> @rest:List<&2, Run> -> List<&2, Run>

def runs.emit.some source · line 427 · raw

@skip:Bool -> @+x0:U32 -> @+x1:U32 -> @+v:F32 -> @acc:List<&2, Run> -> List<&2, Run>

def runs.emit source · line 440 · raw

@+x0:U32 -> @+x1:U32 -> @+v:F32 -> @acc:List<&2, Run> -> List<&2, Run>

Prepend the run [x0, x1) of value v, extending the head when they meet with one value.

def sweep.flush source · line 449 · raw

@+sum:F32 -> @+upper:U32 -> @+c:U32 -> @+direct:F32 -> @acc:List<&2, Run> -> List<&2, Run>

Close the group at c: the gap (c, upper) holds -sum, cell c adds its directs.

def sweep.step source · line 452 · raw

@same:Bool -> @+cell:U32 -> @+direct:F32 -> @+delta:F32 -> @+sum:F32 -> @+upper:U32 -> @+c:U32 -> @+dsum:F32 -> @+dlsum:F32 -> @acc:List<&2, Run> -> Sweep

def row.runs source · line 468 · raw

@evs:List<&2, CovEv> -> @+w:U32 -> List<&2, Run>

The runs of a row of width w from its descending events.

def lines.order.pick source · line 476 · raw

@hit:Bool -> @x:CovLine -> @xt:List<&2, CovLine> -> @y:CovLine -> @yt:List<&2, CovLine> -> LineOrder

def lines.order source · line 481 · raw

@x:CovLine -> @xt:List<&2, CovLine> -> @y:CovLine -> @yt:List<&2, CovLine> -> LineOrder

def lines.merge source · line 497 · raw

@xs:List<&2, CovLine> -> @ys:List<&2, CovLine> -> List<&2, CovLine>

def lines.deal source · line 508 · raw

@xs:List<&2, CovLine> -> @left:List<&2, CovLine> -> @right:List<&2, CovLine> -> LineSplit

def lines.sort source · line 523 · raw

@xs:List<&2, CovLine> -> List<&2, CovLine>

def subs.done source · line 535 · raw

@t:Take -> @events:List<&2, CovEv> -> Subs

def subs.after source · line 539 · raw

@s:Step -> @pending:List<&2, CovLine> -> @+sy2:F32 -> @events:List<&2, CovEv> -> Subs

def subs.step source · line 543 · raw

@st:Subs -> @+sy:F32 -> @+dy:F32 -> @+even:Bool -> @+weight:F32 -> Subs

def scan.row.done source · line 557 · raw

@st:Subs -> @rows:List<&2, List<&2, Run>> -> @+w:U32 -> Scan

def scan.row source · line 561 · raw

@st:Scan -> @+y:U32 -> @+sub:U32 -> @+even:Bool -> @+w:U32 -> Scan

def rows.reverse source · line 572 · raw

@rows:List<&2, List<&2, Run>> -> @acc:List<&2, List<&2, Run>> -> List<&2, List<&2, Run>>

def scan.done source · line 577 · raw

@st:Scan -> List<&2, List<&2, Run>>

def scan.start source · line 581 · raw

@t:Take -> Scan

def scan.rows source · line 586 · raw

@+h:U32 -> @+sub:U32 -> @sorted:List<&2, CovLine> -> @+even:Bool -> @+w:U32 -> List<&2, List<&2, Run>>

The rows of runs (top first) of the lines, sorted by top, over a width by height grid.

def piece.of source · line 610 · raw

@l:CovLine -> Piece

def piece.bottom source · line 618 · raw

@+p:Piece -> F32

def buf.add.got source · line 627 · raw

@got:Pair(Array<F32>, F32) -> @+i:U32 -> @+v:F32 -> Array<F32>

def buf.add source · line 631 · raw

@a:Array<F32> -> @+i:U32 -> @+v:F32 -> Array<F32>

def bits.set.got source · line 634 · raw

@got:Pair(Array<U32>, U32) -> @+i:U32 -> @+bit:U32 -> Array<U32>

def bits.set source · line 638 · raw

@bm:Array<U32> -> @+c:U32 -> Array<U32>

def buf.put source · line 644 · raw

@b:Pair(Pair(Array<F32>, Array<U32>), Pair(U32, U32)) -> @+cell:U32 -> @+direct:F32 -> @+delta:F32 -> @+w:U32 -> Pair(Pair(Array<F32>, Array<U32>), Pair(U32, U32))

A cut's direct area goes to its cell (dropped at or past the width, which lies outside the row) and its delta to the next cell, capped at the width so every delta still counts in the sum.

def buf.put.if source · line 650 · raw

@skip:Bool -> @b:Pair(Pair(Array<F32>, Array<U32>), Pair(U32, U32)) -> @+cell:U32 -> @+direct:F32 -> @+delta:F32 -> @+w:U32 -> Pair(Pair(Array<F32>, Array<U32>), Pair(U32, U32))

def piece.events source · line 680 · raw

@p:Piece -> @+y:F32 -> @+w:U32 -> @b:Pair(Pair(Array<F32>, Array<U32>), Pair(U32, U32)) -> Pair(Pair(Array<F32>, Array<U32>), Pair(U32, U32))

The contributions of a line piece clipped to the row [y, y + 1).

def piece.keep source · line 694 · raw

@keep:Bool -> @p:Piece -> @active:List<&2, Piece> -> List<&2, Piece>

def pieces.retire source · line 709 · raw

@xs:List<&2, Piece> -> @+bottom:F32 -> @acc:List<&2, Piece> -> List<&2, Piece>

def piece.line source · line 718 · raw

@+p:Piece -> @+y:F32 -> CovLine

A piece as a line shifted so the row starts at zero, for the sub-scanline scan of a row whose exact areas showed an overlap.

def pieces.lines source · line 729 · raw

@xs:List<&2, Piece> -> @+y:F32 -> @acc:List<&2, CovLine> -> List<&2, CovLine>

def line.bottom source · line 734 · raw

@+l:CovLine -> F32

def row.of source · line 744 · raw

@+top:F32 -> @+h:U32 -> U32

def counts.inc.got source · line 747 · raw

@got:Pair(Array<U32>, U32) -> @+r:U32 -> Array<U32>

def counts.inc source · line 751 · raw

@c:Array<U32> -> @+r:U32 -> Array<U32>

def soa.store.go source · line 755 · raw

@xs:List<&2, CovLine> -> @a:Array<F32> -> @counts:Array<U32> -> @+i:U32 -> @+h:U32 -> Pair(Array<F32>, Array<U32>)

Store each line at 4i and count its top row.

def counts.prefix.got source · line 766 · raw

@got:Pair(Array<U32>, U32) -> @+i:U32 -> @+acc:U32 -> Pair(Array<U32>, U32)

Turn counts into starting positions.

def counts.done source · line 777 · raw

@st:Pair(Array<U32>, U32) -> Array<U32>

def soa.place.pos source · line 782 · raw

@got:Pair(Array<U32>, U32) -> @a:Array<F32> -> @order:Array<U32> -> @+i:U32 -> @+r:U32 -> Pair(Array<F32>, Pair(Array<U32>, Array<U32>))

Place line i at its row's next position.

def soa.place.y1 source · line 787 · raw

@got:Pair(Array<F32>, F32) -> @starts:Array<U32> -> @order:Array<U32> -> @+y0:F32 -> @+i:U32 -> @+h:U32 -> Pair(Array<F32>, Pair(Array<U32>, Array<U32>))

def soa.place.y0 source · line 792 · raw

@got:Pair(Array<F32>, F32) -> @starts:Array<U32> -> @order:Array<U32> -> @+i:U32 -> @+h:U32 -> Pair(Array<F32>, Pair(Array<U32>, Array<U32>))

def soa.placed source · line 803 · raw

@st:Pair(Array<F32>, Pair(Array<U32>, Array<U32>)) -> Pair(Array<F32>, Array<U32>)

def soa.stored source · line 807 · raw

@st:Pair(Array<F32>, Array<U32>) -> @+n:U32 -> @+h:U32 -> Pair(Array<F32>, Array<U32>)

def soa.build source · line 812 · raw

@xs:List<&2, CovLine> -> @+n:U32 -> @+h:U32 -> Pair(Array<F32>, Array<U32>)

The lines as (values, order) arrays, ordered by top row.

def soa.line.x1 source · line 816 · raw

@got:Pair(Array<F32>, F32) -> @+x0:F32 -> @+y0:F32 -> @+y1:F32 -> @acc:List<&2, CovLine> -> Pair(Array<F32>, List<&2, CovLine>)

The lines back as a list in order, for the sub-scanline scans.

def soa.line.y1 source · line 820 · raw

@got:Pair(Array<F32>, F32) -> @+x0:F32 -> @+y0:F32 -> @+base:U32 -> @acc:List<&2, CovLine> -> Pair(Array<F32>, List<&2, CovLine>)

def soa.line.y0 source · line 824 · raw

@got:Pair(Array<F32>, F32) -> @+x0:F32 -> @+base:U32 -> @acc:List<&2, CovLine> -> Pair(Array<F32>, List<&2, CovLine>)

def soa.line.x0 source · line 828 · raw

@got:Pair(Array<F32>, F32) -> @+base:U32 -> @acc:List<&2, CovLine> -> Pair(Array<F32>, List<&2, CovLine>)

def soa.line.pair source · line 832 · raw

@got:Pair(Array<F32>, List<&2, CovLine>) -> @order:Array<U32> -> Pair(Array<F32>, Pair(Array<U32>, List<&2, CovLine>))

def soa.line.idx source · line 836 · raw

@got:Pair(Array<U32>, U32) -> @a:Array<F32> -> @acc:List<&2, CovLine> -> Pair(Array<F32>, Pair(Array<U32>, List<&2, CovLine>))

def soa.lines.done source · line 848 · raw

@st:Pair(Array<F32>, Pair(Array<U32>, List<&2, CovLine>)) -> List<&2, CovLine>

def soa.lines source · line 852 · raw

@arrays:Pair(Array<F32>, Array<U32>) -> @+n:U32 -> List<&2, CovLine>

def piece.take.x1 source · line 861 · raw

@got:Pair(Array<F32>, F32) -> @order:Array<U32> -> @+x0:F32 -> @+y0:F32 -> @+y1:F32 -> @+k:U32 -> @+n:U32 -> @active:List<&2, Piece> -> Pair(Pair(Array<F32>, Array<U32>), PieceTake)

def piece.take.x0 source · line 865 · raw

@got:Pair(Array<F32>, F32) -> @order:Array<U32> -> @+y0:F32 -> @+y1:F32 -> @+base:U32 -> @+k:U32 -> @+n:U32 -> @active:List<&2, Piece> -> Pair(Pair(Array<F32>, Array<U32>), PieceTake)

def piece.take.pick source · line 869 · raw

@hit:Bool -> @flat:Bool -> @a:Array<F32> -> @order:Array<U32> -> @+y0:F32 -> @+y1:F32 -> @+base:U32 -> @+k:U32 -> @+n:U32 -> @active:List<&2, Piece> -> Pair(Pair(Array<F32>, Array<U32>), PieceTake)

def piece.take.y1 source · line 877 · raw

@got:Pair(Array<F32>, F32) -> @order:Array<U32> -> @+y0:F32 -> @+base:U32 -> @+k:U32 -> @+n:U32 -> @+bottom:F32 -> @active:List<&2, Piece> -> Pair(Pair(Array<F32>, Array<U32>), PieceTake)

def piece.take.y0 source · line 883 · raw

@got:Pair(Array<F32>, F32) -> @order:Array<U32> -> @+base:U32 -> @+k:U32 -> @+n:U32 -> @+bottom:F32 -> @active:List<&2, Piece> -> Pair(Pair(Array<F32>, Array<U32>), PieceTake)

def piece.take.idx source · line 887 · raw

@got:Pair(Array<U32>, U32) -> @a:Array<F32> -> @+k:U32 -> @+n:U32 -> @+bottom:F32 -> @active:List<&2, Piece> -> Pair(Pair(Array<F32>, Array<U32>), PieceTake)

def piece.take.more source · line 892 · raw

@arrays:Pair(Array<F32>, Array<U32>) -> @more:Bool -> @+k:U32 -> @+n:U32 -> @+bottom:F32 -> @active:List<&2, Piece> -> Pair(Pair(Array<F32>, Array<U32>), PieceTake)

def xrun.value source · line 919 · raw

@+v:F32 -> F32

def xrow.delta source · line 922 · raw

@got:Pair(Array<F32>, F32) -> @bm:Array<U32> -> @+direct:F32 -> @+c:U32 -> @st:XState -> Pair(Pair(Array<F32>, Array<U32>), XState)

def xrow.direct source · line 932 · raw

@got:Pair(Array<F32>, F32) -> @bm:Array<U32> -> @+c:U32 -> @st:XState -> Pair(Pair(Array<F32>, Array<U32>), XState)

def xrow.cell source · line 936 · raw

@arrays:Pair(Array<F32>, Array<U32>) -> @hit:Bool -> @+c:U32 -> @st:XState -> Pair(Pair(Array<F32>, Array<U32>), XState)

def xrow.word.if source · line 950 · raw

@empty:Bool -> @a:Array<F32> -> @bm:Array<U32> -> @+i:U32 -> @+word:U32 -> @st:XState -> Pair(Pair(Array<F32>, Array<U32>), XState)

def xrow.word source · line 955 · raw

@got:Pair(Array<U32>, U32) -> @a:Array<F32> -> @+i:U32 -> @st:XState -> Pair(Pair(Array<F32>, Array<U32>), XState)

def xrow.word.of source · line 960 · raw

@st:Pair(Pair(Array<F32>, Array<U32>), XState) -> @+i:U32 -> Pair(Pair(Array<F32>, Array<U32>), XState)

def xrow.done source · line 972 · raw

@st:Pair(Pair(Array<F32>, Array<U32>), XState) -> @+w:U32 -> Pair(Pair(List<&2, Run>, Bool), Pair(Pair(Array<F32>, Array<U32>), Pair(U32, U32)))

A row's result: ((runs, overlap seen), the cleared buffer).

def xrow.count source · line 978 · raw

@+lo:U32 -> @+hi:U32 -> U32

def xrow.from source · line 981 · raw

@arrays:Pair(Array<F32>, Array<U32>) -> @+lo:U32 -> @+hi:U32 -> @+w:U32 -> Pair(Pair(List<&2, Run>, Bool), Pair(Pair(Array<F32>, Array<U32>), Pair(U32, U32)))

def xrow.runs source · line 985 · raw

@b:Pair(Pair(Array<F32>, Array<U32>), Pair(U32, U32)) -> @+w:U32 -> Pair(Pair(List<&2, Run>, Bool), Pair(Pair(Array<F32>, Array<U32>), Pair(U32, U32)))

The runs of a row from its buffer, which comes back cleared.

def rows.head source · line 993 · raw

@rows:List<&2, List<&2, Run>> -> List<&2, Run>

def xscan.fix source · line 1001 · raw

@bad:Bool -> @runs:List<&2, Run> -> @active:List<&2, Piece> -> @+y:F32 -> @+sub:U32 -> @+w:U32 -> Pair(List<&2, Run>, List<&2, Piece>)

A row whose exact areas showed an overlap is scanned again with the sub-scanlines over its own pieces; other rows keep their runs. Either way the pieces the next row no longer reaches are retired.

def xscan.push source · line 1008 · raw

@fixed:Pair(List<&2, Run>, List<&2, Piece>) -> @buf:Pair(Pair(Array<F32>, Array<U32>), Pair(U32, U32)) -> @lines:Pair(Array<F32>, Array<U32>) -> @rows:List<&2, List<&2, Run>> -> @+k:U32 -> @+n:U32 -> @+sub:U32 -> Pair(Pair(Pair(Array<F32>, Array<U32>), Pair(Array<F32>, Array<U32>)), XData)

def xscan.swept source · line 1013 · raw

@r:Pair(Pair(List<&2, Run>, Bool), Pair(Pair(Array<F32>, Array<U32>), Pair(U32, U32))) -> @lines:Pair(Array<F32>, Array<U32>) -> @rows:List<&2, List<&2, Run>> -> @active:List<&2, Piece> -> @+y:F32 -> @+k:U32 -> @+n:U32 -> @+sub:U32 -> @+w:U32 -> Pair(Pair(Pair(Array<F32>, Array<U32>), Pair(Array<F32>, Array<U32>)), XData)

def xscan.rowed source · line 1017 · raw

@s:Pair(List<&2, Piece>, Pair(Pair(Array<F32>, Array<U32>), Pair(U32, U32))) -> @lines:Pair(Array<F32>, Array<U32>) -> @rows:List<&2, List<&2, Run>> -> @+y:F32 -> @+k:U32 -> @+n:U32 -> @+sub:U32 -> @+w:U32 -> Pair(Pair(Pair(Array<F32>, Array<U32>), Pair(Array<F32>, Array<U32>)), XData)

def xscan.taken source · line 1021 · raw

@t:Pair(Pair(Array<F32>, Array<U32>), PieceTake) -> @buf:Pair(Pair(Array<F32>, Array<U32>), Pair(U32, U32)) -> @rows:List<&2, List<&2, Run>> -> @+y:F32 -> @+sub:U32 -> @+w:U32 -> Pair(Pair(Pair(Array<F32>, Array<U32>), Pair(Array<F32>, Array<U32>)), XData)

def xscan.row source · line 1026 · raw

@st:Pair(Pair(Pair(Array<F32>, Array<U32>), Pair(Array<F32>, Array<U32>)), XData) -> @+y:U32 -> @+w:U32 -> Pair(Pair(Pair(Array<F32>, Array<U32>), Pair(Array<F32>, Array<U32>)), XData)

def xscan.done source · line 1038 · raw

@st:Pair(Pair(Pair(Array<F32>, Array<U32>), Pair(Array<F32>, Array<U32>)), XData) -> List<&2, List<&2, Run>>

def xscan.rows source · line 1045 · raw

@+h:U32 -> @lines:Pair(Array<F32>, Array<U32>) -> @+n:U32 -> @+sub:U32 -> @+w:U32 -> List<&2, List<&2, Run>>

The rows of runs of the lines (in their arrays, n of them) by exact areas, rows with an overlap done with sub scanlines.

def halves.place source · line 1063 · raw

@onLeft:Bool -> @onRight:Bool -> @+v:F32 -> @+a:U32 -> @+b:U32 -> @+u:F32 -> @+mid:U32 -> @left:List<&2, Run> -> @right:List<&2, Run> -> Halves

def halves.push source · line 1069 · raw

@h:Halves -> @+a:U32 -> @+b:U32 -> @+u:F32 -> @+mid:U32 -> @+x0:U32 -> @+x1:U32 -> Halves

def runs.halves source · line 1076 · raw

@rs:List<&2, Run> -> @+mid:U32 -> @+x0:U32 -> @+x1:U32 -> Halves

def node.push source · line 1086 · raw

@n:Node -> @h:Halves -> @top:Bool -> Node

def node.rows source · line 1094 · raw

@rows:List<&2, List<&2, Run>> -> @+i:U32 -> @+size:U32 -> @+half:U32 -> @+x0:U32 -> Node

Rows past the end of the list are empty; row i of size is a top row when i < half.

def node.mark source · line 1099 · raw

@n:Node -> Node

def node.of source · line 1104 · raw

@rows:List<&2, List<&2, Run>> -> @+size:U32 -> @+x0:U32 -> Node

def node.value source · line 1107 · raw

@+v:F32 -> F32

def lines.bounds source · line 1131 · raw

@xs:List<&2, CovLine> -> @+x0:F32 -> @+y0:F32 -> @+x1:F32 -> @+y1:F32 -> CovBox

def lines.shift source · line 1145 · raw

@xs:List<&2, CovLine> -> @+dx:F32 -> @+dy:F32 -> List<&2, CovLine>

def mask.data source · line 1150 · raw

@trees:Bool -> @rows:List<&2, List<&2, Run>> -> @+size:U32 -> @+depth:Nat -> CovData

def mask.arrays source · line 1155 · raw

@xs:List<&2, CovLine> -> @+n:U32 -> @+h:U32 -> @+sub:U32 -> @+w:U32 -> List<&2, List<&2, Run>>

def mask.scan source · line 1159 · raw

@clipped:Pair(List<&2, CovLine>, U32) -> @even:Bool -> @+h:U32 -> @+sub:U32 -> @+w:U32 -> List<&2, List<&2, Run>>

Even-odd fills rely on the winding parity, which only the sub-scanline scan follows.

def mask.build source · line 1165 · raw

@xs:List<&2, CovLine> -> @+gx:U32 -> @+gy:U32 -> @+w:U32 -> @+h:U32 -> @+even:Bool -> @+sub:U32 -> @+trees:Bool -> CovMask

def mask.box source · line 1171 · raw

@+xs:List<&2, CovLine> -> @+even:Bool -> @+width:U32 -> @+height:U32 -> @+sub:U32 -> @box:CovBox -> @+trees:Bool -> CovMask

def line.on.box source · line 1183 · raw

@+ax:F32 -> @+ay:F32 -> @+bx:F32 -> @+by:F32 -> @+x0:F32 -> @+y0:F32 -> @+x1:F32 -> @+y1:F32 -> Bool

A closed rectangle on whole pixels: four axis-aligned lines on the box edges with integer coordinates (the usual viewport clip and the common rect), whose mask is a tree of full and empty leaves with no scan at all.

def lines.on.box source · line 1187 · raw

@xs:List<&2, CovLine> -> @+x0:F32 -> @+y0:F32 -> @+x1:F32 -> @+y1:F32 -> @+count:U32 -> Bool

Zero-length lines (a path's move and close) are ignored; the four real ones must lie on the box.

def whole source · line 1198 · raw

@+v:F32 -> Bool

def rect.aligned source · line 1201 · raw

@+xs:List<&2, CovLine> -> @+box:CovBox -> Bool

def rect.rows source · line 1218 · raw

@n:Nat -> @+w:U32 -> @acc:List<&2, List<&2, Run>> -> List<&2, List<&2, Run>>

A full rectangle as rows: one run per row.

def rect.data source · line 1223 · raw

@trees:Bool -> @+depth:Nat -> @+w:U32 -> @+h:U32 -> CovData

def mask.rect source · line 1228 · raw

@+width:U32 -> @+height:U32 -> @+box:CovBox -> @+trees:Bool -> CovMask

def mask.shape source · line 1240 · raw

@aligned:Bool -> @+xs:List<&2, CovLine> -> @+even:Bool -> @+width:U32 -> @+height:U32 -> @+sub:U32 -> @+box:CovBox -> @+trees:Bool -> CovMask

def mask source · line 1250 · raw

@+xs:List<&2, CovLine> -> @+even:Bool -> @+width:U32 -> @+height:U32 -> @+sub:U32 -> @+trees:Bool -> CovMask

Rasterize closed contours given as directed lines in pixel coordinates of a width by height grid, with sub scanlines per pixel row; nonzero winding, or even-odd when even holds. even-odd when even holds; with trees the mask carries the quadtree that block and pixel queries need, else only its rows of runs.

def lines.empty source · line 1260 · raw

CovLines

def lines.add source · line 1263 · raw

@l:CovLines -> @+ax:F32 -> @+ay:F32 -> @+bx:F32 -> @+by:F32 -> CovLines

def mask.lined.pick source · line 1267 · raw

@few:Bool -> @xs:List<&2, CovLine> -> @box:CovBox -> @+even:Bool -> @+width:U32 -> @+height:U32 -> @+sub:U32 -> @+trees:Bool -> CovMask

def mask.lined source · line 1275 · raw

@l:CovLines -> @+even:Bool -> @+width:U32 -> @+height:U32 -> @+sub:U32 -> @+trees:Bool -> CovMask

def mask.scanned source · line 1279 · raw

@+xs:List<&2, CovLine> -> @+even:Bool -> @+width:U32 -> @+height:U32 -> @+sub:U32 -> @+trees:Bool -> CovMask

Unsafe

unsafe tree.at source · line 56 · raw

@t:CovTree -> @+half:U32 -> @+x:U32 -> @+y:U32 -> F32

unsafe tree.uniform source · line 100 · raw

@t:CovTree -> @+nx:U32 -> @+ny:U32 -> @+size:U32 -> @+x0:U32 -> @+y0:U32 -> @+x1:U32 -> @+y1:U32 -> @+acc:F32 -> F32

unsafe rows.over source · line 129 · raw

@rows:List<&2, List<&2, Run>> -> @+y:U32 -> @+x0:U32 -> @+y0:U32 -> @+x1:U32 -> @+y1:U32 -> @+acc:F32 -> F32

The uniform value of rows over the cell rectangle [x0, x1) by [y0, y1) in grid cells relative to the mask; rows past the list are empty.

unsafe act.insert.go source · line 256 · raw

@i:Ins -> List<&2, Act>

unsafe take.go source · line 310 · raw

@t:Take -> @+sy:F32 -> Take

unsafe step source · line 364 · raw

@xs:List<&2, Act> -> @+sy2:F32 -> @+wind:F32 -> @+last:F32 -> @+even:Bool -> @+weight:F32 -> @evs:List<&2, CovEv> -> @acc:List<&2, Act> -> Step

unsafe ev.merge.go source · line 393 · raw

@o:EvOrder -> List<&2, CovEv>

unsafe sweep source · line 458 · raw

@st:Sweep -> @evs:List<&2, CovEv> -> List<&2, Run>

unsafe lines.merge.go source · line 487 · raw

@o:LineOrder -> List<&2, CovLine>

unsafe lines.sort.go source · line 516 · raw

@s:LineSplit -> List<&2, CovLine>

Merge sort by top.

unsafe scan.subs source · line 549 · raw

@st:Subs -> @n:Nat -> @+sy:F32 -> @+dy:F32 -> @+even:Bool -> @+weight:F32 -> Subs

unsafe scan.rows.go source · line 567 · raw

@st:Scan -> @n:Nat -> @+y:U32 -> @+sub:U32 -> @+even:Bool -> @+w:U32 -> Scan

unsafe depth.for source · line 590 · raw

@+size:U32 -> @+side:U32 -> @+depth:Nat -> Nat

unsafe piece.cuts source · line 661 · raw

@done:Bool -> @n:Nat -> @+xa:F32 -> @+ya:F32 -> @+xb:F32 -> @+yb:F32 -> @+dir:F32 -> @+slope:F32 -> @+w:U32 -> @b:Pair(Pair(Array<F32>, Array<U32>), Pair(U32, U32)) -> Pair(Pair(Array<F32>, Array<U32>), Pair(U32, U32))

The piece of a line between heights ya and yb, from xa to xb, cut at the cell boundaries it crosses: each cut of height dy within cell i adds the area to its right, dy * (i + 1 - mid x), to cell i and dy to the cells beyond. n bounds the cuts (the cells crossed plus one); done holds once a cut reached yb.

unsafe pieces.row source · line 702 · raw

@xs:List<&2, Piece> -> @+y:F32 -> @+w:U32 -> @active:List<&2, Piece> -> @b:Pair(Pair(Array<F32>, Array<U32>), Pair(U32, U32)) -> Pair(List<&2, Piece>, Pair(Pair(Array<F32>, Array<U32>), Pair(U32, U32)))

The row's pieces all go into the buffer and come back as a list (in any order); those the next row no longer reaches are retired afterwards.

unsafe counts.prefix source · line 771 · raw

@st:Pair(Array<U32>, U32) -> @n:Nat -> @+i:U32 -> Pair(Array<U32>, U32)

unsafe soa.place source · line 797 · raw

@st:Pair(Array<F32>, Pair(Array<U32>, Array<U32>)) -> @n:Nat -> @+i:U32 -> @+h:U32 -> Pair(Array<F32>, Pair(Array<U32>, Array<U32>))

unsafe soa.lines.go source · line 842 · raw

@st:Pair(Array<F32>, Pair(Array<U32>, List<&2, CovLine>)) -> @n:Nat -> @+k:U32 -> Pair(Array<F32>, Pair(Array<U32>, List<&2, CovLine>))

unsafe piece.take source · line 899 · raw

@st:Pair(Pair(Array<F32>, Array<U32>), PieceTake) -> @+bottom:F32 -> Pair(Pair(Array<F32>, Array<U32>), PieceTake)

unsafe xrow.bits source · line 944 · raw

@st:Pair(Pair(Array<F32>, Array<U32>), XState) -> @n:Nat -> @+word:U32 -> @+mask:U32 -> @+cell:U32 -> Pair(Pair(Array<F32>, Array<U32>), XState)

The set bits of a word, from bit 31 down: mask halves at each step.

unsafe xrow.words source · line 966 · raw

@st:Pair(Pair(Array<F32>, Array<U32>), XState) -> @n:Nat -> @+i:U32 -> Pair(Pair(Array<F32>, Array<U32>), XState)

Words from the one holding hi down to the one holding lo.

unsafe xscan.rows.go source · line 1033 · raw

@st:Pair(Pair(Pair(Array<F32>, Array<U32>), Pair(Array<F32>, Array<U32>)), XData) -> @n:Nat -> @+y:U32 -> @+w:U32 -> Pair(Pair(Pair(Array<F32>, Array<U32>), Pair(Array<F32>, Array<U32>)), XData)

unsafe tree.node source · line 1111 · raw

@n:Node -> @depth:Nat -> @+x0:U32 -> @+size:U32 -> CovTree

unsafe tree.rect source · line 1206 · raw

@depth:Nat -> @+x:U32 -> @+y:U32 -> @+w:U32 -> @+h:U32 -> CovTree