Expand description
L-system grammar expansion: pure, deterministic string rewriting. Applies a
production rule set to an axiom depth times — each character is replaced by
its successor (or kept if no rule matches). expand is a build-time step
(runs inside Scene::configure, off the hot path), not per-frame work.
Stream is the per-frame half: an allocation-free lazy depth-first walk of
the same derivation, one symbol per Stream::next_symbol, over stacks
preallocated at load, which an endless figure advances every frame.
Deterministic by construction: a fixed (axiom, rules, depth) always yields
the exact same string (NFR 6), which is what makes it directly unit-testable.
Structs§
- Stream
- The derivation of an axiom to a fixed depth, produced one symbol at a
time by a depth-first walk, instead of expanded into a string: the
leaves in exactly the order
expandwould write them, at the cost of one frame per level.
Constants§
- STREAM_
DEPTH - The derivation depth an endless figure’s stream walks: the grammar is expanded this many times, lazily, and the stream is its leaves in order.
Functions§
- bracket_
bound - The most branch pushes the stream can hold open at once, for a grammar
whose successors balance their brackets: the axiom’s own nesting, plus
each of the
depthexpansion levels opening at most its deepest successor’s. An unbalanced grammar can open more; the turtle’s stack is sized to this and refuses a push past it. - expand
- Expand
axiomby applyingrulesdepthtimes. Each rule is(predecessor, successor); a character with no matching rule maps to itself (the standard context-free L-system semantics). Pure and deterministic. - is_draw
- Whether
chis a draw step: the symbols the turtle strokes a segment for. - nesting
- The deepest run of open
[ins: the most branch pushes any prefix of it leaves open. A stray]closes nothing. - stream_
draws - How many draw steps the derivation of
axiomunderrulestodepthholds, counted without expanding it: per rule, the draws its successor yields one level down, built up level by level. Saturates atu64::MAX.