Expand description
Pure 2D math for valo: points, rects, affine transforms, color. Zero dependencies (serde optional) — usable anywhere, no GPU, no unicode.
Conventions (fixed across all of valo):
- y-down, origin top-left, units are logical pixels until a transform says otherwise.
- The public transform is a full 4×4 (glam-backed); the renderer folds depth in ( is a renderer concern — clips consume z, the user never sees it).
Coloris straight (unpremultiplied) sRGB; premultiplication happens at the GPU boundary. Blending is performed in sRGB space (the CSS/Skia-compatible look) — linear/wide-gamut blending is deliberately deferred.
Structs§
- Color
- Straight (unpremultiplied) sRGB color, components 0..=1.
- Contour
- One flattened contour.
closedis METADATA from the path’s Close verb (Impeller’sEndContour(origin, with_close)) — never inferred from point coincidence, so an open contour that happens to end at its start keeps its caps. Closed contours end with the start point repeated: the closing edge is part of the polyline (dashing and length walks see it); the stroker drops the duplicate and joins at the seam instead of capping. - Contour
Measure - One contour, measured. Build these with
crate::Path::measure. - Dash
- On/off intervals cycled along each contour,
phasepx into the cycle. - Matrix
- Full 4×4 column-major transform (glam-backed — the byte layout Flutter and Impeller use).
- Path
- An immutable path: verb + point arrays (SoA), built once via
PathBuilder, shared byArcinside display-list ops (cloning a recorded list never copies point data). Flattening is the CALLER’s move because tolerance depends on the device scale at draw time — a path has no scale of its own. - Path
Builder - Records verbs/points and tracks bounds;
buildfreezes into anArc<Path>. - Path
Sample - A point on a contour and the direction the contour runs there.
- Point
- Rect
- Axis-aligned rectangle,
(x, y)= top-left, y-down. - Size
- Stroke
Enums§
- Cap
- Fill
Rule - Join
- Matrix
Kind - What the fast paths may assume about a matrix — computed when the transform stack changes, consulted per draw.
- Winding
- Which way a closed contour is traversed.
Functions§
- constrain_
radii - Skia’s radii rule: shrink ALL four corners by ONE factor until every
adjacent pair fits its side — corners never overlap and the shape keeps
its proportions. Order is clockwise from top-left:
[tl, tr, br, bl]. - constrain_
radii_ elliptical - The CSS/Skia overlap rule, per axis: each EDGE compares the two adjacent radii’s component ALONG it (top edge: tl.x + tr.x vs width; right edge: tr.y + br.y vs height; …) and every radius scales by the smallest fit so neighbouring arcs never cross.
- dash_
contours - Split contours into the dash pattern’s ON stretches (each stroked with its own caps, always open — a closed contour starts dashing at its seam). Invalid patterns disable dashing, like Skia’s SkDashPathEffect.
- local_
tolerance - Device-space flattening tolerance for a draw under
transform: keep curve deviation under a quarter pixel wherever the content lands on screen. - stroke_
contains - Whether
pointlands on the inkstroke_stripwould produce — Canvas2D’sisPointInStroke. - stroke_
strip - Strip vertices (x,y pairs) stroking
contours; contours stitch with degenerate triangles.tolerancesizes round join/cap arcs, like the flattener sizes curves.