Skip to main content

Module path

Module path 

Source
Expand description

Paths: what a path node draws (docs/adr/0040-a-path-is-a-mask-in-the-atlas.md).

A path is a list of PathOps — SVG’s d with every coordinate absolute and H, V, S, T and the relative forms expanded by Path::parse, the one parser every binding goes through — filled by a rule and, optionally, stroked. The core flattens it once per frame for the hit outline, rasterizes it through zeno (swash’s rasterizer, already in the tree for glyphs) into an alpha mask at the node’s physical scale, keeps the mask in the glyph atlas keyed on a hash of the ops, and draws it as a GlyphMask quad tinted by the fill or the stroke colour. The ops live in a per-frame list beside the tree, as a line’s points do, and a node refers to its run by PathId.

Structs§

Path
A path as an app builds one: the ops, the fill rule, and an optional stroke. The fill colour is the node’s bg; the stroke’s width and colour are the crate::line::Stroke’s (curve is ignored).
PathError
Where a d string went wrong: the byte offset and what was expected.
PathId
Index into the frame’s path list.
PathStore
The frame’s paths, and the previous frame’s while an exit needs it.
PathTexture
A mask drawn from a texture of its own rather than the atlas (ADR 0040, decisions 7 and 8): the handle the backend caches it under, and the pixels it uploads from.
PathTextures
The texture-backed masks of one core, by the mask key the atlas would have held them under. One a frame does not draw is dropped at the next frame’s start, its handle handed to the display list for the backend to free; an animating path, whose key is new each frame, thus uploads one texture a frame and frees one. The ones a core still holds when it goes go the way a removed image does: to the session, for the next display list any of its windows builds (RG112).
Turn
A path’s turn (docs/adr/0041-a-mask-turns-about-its-centre.md): how far it is turned, in turns — clockwise with y down, as Path::sector counts them — and the point it turns about, in the path’s own coordinates; None is the centre of the outline’s box. A path with a turn is boxed by the square the turn sweeps, so its mask is one mask at every angle and the quad that draws it carries the angle.

Enums§

FillRule
How a path’s inside is decided: SVG’s default, or the polygon’s rule.
MaskPaint
What one mask paints: the fill by its rule, bled half a pixel so two fills sharing an edge meet without the background showing, or the outline stroked width physical px wide — whole, or cut into the marks of a dash pattern (backlog V2), its lengths physical too.
PathOp
One drawing command, every coordinate absolute, in the space the path was declared in.

Constants§

ANIMATING_WINDOW
How many frames apart two changes of one key’s ops may be and still be an animation: a shape driven at a quarter of the frame rate, or one whose changes have a frame between them that something else asked for, moves as surely as one that changes every frame, and each of its shapes would be a slot the atlas never reuses.
CONTOUR_BREAK
Separates two contours in a flattened outline: a point that is not a point. in_path reads it as the end of one closed contour and the start of the next.
FLATTEN_TOLERANCE
How far a flattened curve may stray from the true one, logical px. The hit outline’s tolerance; the rasterizer flattens on its own.
MAX_ATLAS_MASK_TEXELS
The texels a mask may take of the atlas before it goes to a texture of its own: a quarter of the biggest page, since four of them would empty it every frame.
MAX_MASK_SIDE
The widest or tallest a mask may be and still be drawn from a texture of its own: a texture every device kui runs on can hold — kui-wgpu opens its device with wgpu’s default limits, whose max_texture_dimension_2d is this number whatever the adapter could do, so the core’s limit and the renderer’s are one. Past it the node draws nothing, with path-too-large. A host that draws the list itself on a device that holds less refuses the texture on its side.
OP_ARC
OP_CLOSE
OP_CUBIC
OP_LINE
OP_MOVE
The op codes of the flat wire form: a code, then its operands.
OP_QUAD
SETTLED_AFTER
How many frames an animating key’s shape stays the same before it is a still shape again, and its mask the atlas’s: a second at 120 Hz. A spinner that pauses for a frame or ten stays out; one that stopped stops costing a texture and a draw of its own.

Functions§

bounds
The bounding box of a flattened outline, ignoring contour breaks; None for no points.
flatten
Flattens ops into closed contours in out, each contour’s points followed by CONTOUR_BREAK. Every subpath is closed for the purpose of a fill, as SVG closes it. A move with nothing after it adds nothing.
flatten_stroke
Flattens ops into the polylines a stroke draws, each followed by CONTOUR_BREAK: a subpath its Z closed ends back on its start, an open one ends where it was left, so a stroke’s hit pieces are the pieces it paints and no chord across an open curve is among them.
hash_ops
FNV-1a over the ops’ bits: what a mask is keyed on. The same ops are the same hash in every binding, since the floats crossed as floats.
in_path
Whether p is inside the flattened contours pts (as flatten lays them out) by rule. A point on an edge counts as inside on one side and outside on the other, so of two wedges sharing an edge exactly one takes it.
rasterize
Rasterizes ops (in logical px, relative to the node’s box) into a w × h alpha mask at scale, the node’s box shifted by bin quarter-pixels so a node at a fractional position lands on the pixel grid as it would be drawn. w * h bytes, row after row.
rasterize_at
rasterize with the box’s origin off physical px into the mask: what a turning path’s mask is drawn with, its pivot at the mask’s centre.
turned
p turned by angle radians (clockwise, y down) about c.

Type Aliases§

DashCut
A dash pattern as the rasterizer takes it: the centre-line lengths of a mark, a gap, a mark and a gap, and how far into them the stroke starts. crate::line::Dash is what an app declares.