Module shapes

Source
Expand description

Vector shapes and recorded drawings -> RGBA layers (CPU rasteriser; the GPU path samples the result).

render(style, scale, local_t) draws the shape centred in its own tight layer:

  • Rect / Ellipse / Triangle / Polygon / Star: fill plus an optional stroke outline of stroke_width (project px x scale); rounded corners for Rect via corner.
  • Line / Arrow: from (-w, -h) to (+w, +h) in layer space, head sized by corner.
  • Draw: the recorded strokes revealed up to local_t * draw_rate (0 = all at once) on the optional page background. Anti-aliased with a coverage rasteriser (no new deps). Cached by ShapeStyle::cache_key() + size + reveal bucket.

StructsΒ§

Edge πŸ”’
A non-horizontal edge, top to bottom.
Path πŸ”’
pts[ends[i-1]..ends[i]] is one closed subpath, all wound the same way so a nonzero fill unions overlapping pieces instead of cancelling them.
ShapeRasterizer

ConstantsΒ§

CACHE_MAX πŸ”’
MAX_DIM πŸ”’
Layer dimensions are clamped to this; scale shrinks instead so the geometry stays consistent.
MAX_PIXELS πŸ”’
…and so is the total pixel count (64 MB RGBA), which a 4K full-canvas shape stays well under.
REVEAL_HZ πŸ”’
Reveal-time quantisation for the cache (a drawing re-rasterises 30x/s at most).
STAR_INNER πŸ”’
Star inner radius as a fraction of the outer one.
SUB πŸ”’
Vertical sub-scanlines per pixel row (horizontal coverage is exact, so 4 is plenty).

FunctionsΒ§

add_disc πŸ”’
add_span πŸ”’
add_stroke πŸ”’
Thick polyline in layer px: one quad per segment plus a disc at every vertex (round caps/joins).
arc_steps πŸ”’
Segments per quarter turn for a curve of pixel radius r_px (sagitta stays well under a pixel).
arrow_head πŸ”’
Arrow head length in project px (corner, or a stroke-relative default when it is 0).
blend πŸ”’
Source-over in straight (non-premultiplied) alpha.
bucket_time πŸ”’
draw_half_size πŸ”’
Half-size of a drawing: the strokes are relative to the layer centre, so the layer is symmetric.
fill_path πŸ”’
Scanline fill with 4x vertical sub-sampling and exact horizontal coverage. Writes cov (zeroing only the band it touches) and returns that band as (x0, y0, x1, y1).
half_size πŸ”’
ngon πŸ”’
Regular polygon (or star: 2x the vertices, alternating radii) inscribed in the w x h ellipse, first vertex pointing up.
reveal_bucket πŸ”’
Reveal bucket for the cache key: 0 = not a drawing, u32::MAX = fully revealed.
revealed πŸ”’
Points of a stroke revealed at reveal seconds (the last segment is cut proportionally).
shape_outline πŸ”’
Closed outline of a filled shape in project px, centred at the origin. s only sets how finely curves are subdivided (so a big shape at a big scale stays smooth).
signed_half πŸ”’
Half-extents WITH their sign, for the shapes whose extents encode a direction. Line and Arrow run from (-w, -h) to (+w, +h), so making them absolute (as half_size must, for a layer size) collapses every line onto the same diagonal whichever way it was actually drawn.
to_layer πŸ”’