From 2f7cde4e441a8668d7e771f23037de92ff051940 Mon Sep 17 00:00:00 2001 From: timbogdanov Date: Tue, 18 Aug 2026 21:04:01 -0500 Subject: [PATCH] Port the parametric DSL into the editor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) Claude-Session: https://claude.ai/code/session_01UCrKKTD2mwHx8Fm1EnJiQ3 --- app/patternfront.html | 336 +++++ tests/fixtures/dsl.json | 2430 +++++++++++++++++++++++++++++++++++++ tools/gen-dsl-fixtures.py | 188 +++ tools/verify-all.sh | 2 + tools/verify-dsl.js | 142 +++ 5 files changed, 3098 insertions(+) create mode 100644 tests/fixtures/dsl.json create mode 100644 tools/gen-dsl-fixtures.py create mode 100644 tools/verify-dsl.js diff --git a/app/patternfront.html b/app/patternfront.html index 0691d22..9f64774 100644 --- a/app/patternfront.html +++ b/app/patternfront.html @@ -349,6 +349,7 @@ + @@ -537,6 +538,20 @@ + +