Skip to content

Port the parametric DSL into the editor - #8

Merged
timbogdanov merged 1 commit into
mainfrom
feat/dsl-port
Aug 19, 2026
Merged

Port the parametric DSL into the editor#8
timbogdanov merged 1 commit into
mainfrom
feat/dsl-port

Conversation

@timbogdanov

Copy link
Copy Markdown
Owner

Phase 4 of the v0.2.0 plan — generation.

15 primitives, each with a declared period, composed with set/union/intersect/xor/subtract and sized to a common multiple of every layer's period, so the result tiles seamlessly by construction rather than by luck.

tools/dsl_prototype.py has been the reference implementation since before the editor existed, and tools/dsl_demo.py has proved 28 programs tile exactly on every commit. None of it had ever reached a user.

The panel

Five presets, the program as editable JSON, a live size and ink readout, and a Replace canvas that renders into a two-colour document keeping any duotone already chosen. Bad input reports rather than crashing — an unknown shape type says so, malformed JSON says where. Driven in the real app to confirm all four paths.

Four things that don't survive a literal translation

Each is a silent wrong answer, not an error, so each is named at the top of the ported block:

Python Trap
round() Banker's rounding — round(2.5) is 2 where Math.round gives 3. Decides wave offsets and canvas sizing.
% A floor modulo, not a remainder. Every expression that can go negative routes through floorMod.
// Floors, where |0 truncates toward zero.
_hash2 Multiplies by constants near 2^31 — past 2^53, a plain * drops low bits. Uses Math.imul.

The oracle

tests/fixtures/dsl.json62 programs: the 28 from the gallery, every primitive again at non-default parameters (a port that ignores an argument still passes on defaults), every composition op over the same two shapes, and every post transform on an asymmetric source. Compared as encoded patternData, since a one-pixel difference still changes the string.

What the fixture caught

59 of 62 passed on the first run. All three failures were text, and the cause was mine: I typed the glyph tables by hand instead of using the file I had just emitted mechanically — one wrong row in the 5×7 D, and half of 3×5 rewritten.

They are now emitted from the source tables, and the fixture carries those tables so the next slip reports as:

5x7 font: 1/36 glyphs differ from the source table (D)

rather than as "384 lit pixels, oracle says 400". I verified that check bites by corrupting a glyph.

Verification

./tools/verify-all.sh green, now including DSL oracle and editor DSL vs oracle. Rendered Plaid in the running app: 32×30, sized to the LCM of periods 8 and 6, tiling seamlessly in the preview.

🤖 Generated with Claude Code

https://claude.ai/code/session_01UCrKKTD2mwHx8Fm1EnJiQ3

15 primitives, each with a declared period, composed with set/union/intersect/
xor/subtract and sized to a common multiple of every layer's period so the result
tiles seamlessly by construction. tools/dsl_prototype.py has been the reference
implementation since before the editor existed and tools/dsl_demo.py has proved
28 programs tile exactly on every commit; none of it had ever reached a user.

A Program panel makes it usable by hand: five presets, the program as editable
JSON, live size and ink readout, and a Replace canvas that renders into a
two-colour document. Bad input reports and does not crash — an unknown shape type
says so, malformed JSON says where.

Four things in the Python do not survive a literal translation, and each is a
silent wrong answer rather than an error. They are named at the top of the ported
block:

  round()   banker's rounding, so round(2.5) is 2 where Math.round gives 3. It
            decides wave offsets and canvas sizing.
  %         a floor modulo in Python, a remainder in JS. Every expression that
            can go negative routes through floorMod.
  //        floors, where |0 truncates toward zero.
  _hash2    multiplies by constants near 2^31, which passes 2^53 and silently
            drops low bits, so the mixing steps use Math.imul.

tests/fixtures/dsl.json is the oracle: 62 programs — the 28 from the gallery,
every primitive again at non-default parameters, every composition op over the
same two shapes, and every post transform on an asymmetric source — compared as
encoded patternData, because a one-pixel difference still changes the string.

59 of the 62 passed on the first run. The three failures were all `text`, and the
cause was that the glyph tables had been typed in by hand rather than taken from
the emitted file: one wrong row in the 5x7 'D' and half of 3x5 rewritten. They
are now emitted from the source tables, and the fixture carries those tables so a
future slip is reported as "5x7 font: 1/36 glyphs differ (D)" rather than as a
lit-pixel count being off by sixteen.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UCrKKTD2mwHx8Fm1EnJiQ3
@timbogdanov
timbogdanov merged commit 7263907 into main Aug 19, 2026
5 checks passed
@timbogdanov
timbogdanov deleted the feat/dsl-port branch August 19, 2026 02:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant