Skip to main content

Crate valo_geometry

Crate valo_geometry 

Source
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).
  • Color is 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. closed is METADATA from the path’s Close verb (Impeller’s EndContour(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.
ContourMeasure
One contour, measured. Build these with crate::Path::measure.
Dash
On/off intervals cycled along each contour, phase px 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 by Arc inside 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.
PathBuilder
Records verbs/points and tracks bounds; build freezes into an Arc<Path>.
PathSample
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
FillRule
Join
MatrixKind
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 point lands on the ink stroke_strip would produce — Canvas2D’s isPointInStroke.
stroke_strip
Strip vertices (x,y pairs) stroking contours; contours stitch with degenerate triangles. tolerance sizes round join/cap arcs, like the flattener sizes curves.