Skip to content

Design: forks + groups + data-strips — separating signal from physical placement #88

Closed

Description

@zackees

This is a design call, not an implementation plan. The goal is to invite research and agreement on a richer data model before any code lands.

What we have today

One concept does the job of three:

// src/shapeeditor/strips-model.ts
interface StripEntry {
  name: string;
  points: [number, number][];   // physical placement
  offset: number;               // index in the global flat array
  count: number;                // how many LEDs
  pin: string;                  // controller output
  video_offset: number;         // sampling offset into the source video
  // ...
}

A "strip" today simultaneously means:

  1. What FastLED writes to. A run of LED indices fed from one pin.
  2. A physical chain. A contiguous sequence of LEDs in space.
  3. A semantic region. Whatever the artist mentally calls "panel 3, quad 0".

That fusion breaks down at the densities we now want to support (4096-LED layouts) and prevents real-world wiring patterns that the hardware already supports.

Three concepts we want to separate

1. Data strip — what FastLED writes

A pure signal, no position. The thing the controller's pin emits.

interface DataStrip {
  id: string;             // e.g. "pin1"
  length: number;         // number of LED slots on the wire
  // No points. No (x, y). Position is somebody else's job.
}

2. Group (a.k.a. segment) — a named index range with physical points

The thing the UI lets you select, color, and visualize. A group says "this range of indices on this data strip physically lives here."

interface Group {
  name: string;             // e.g. "q0_p0"
  dataStripId: string;      // which DataStrip's index space we're in
  start: number;            // inclusive
  end: number;              // inclusive
  points: [number, number][]; // physical (x, y) for each LED in [start..end]
  diameter?: number;
}

3. Fork — the same signal physically appears in N places

Real installations Y-split the data line so the same FastLED output drives multiple physical chains. Today our model cannot say "indices 11..33 of pin1 appear in both group B and group C." A fork is the mechanism:

// Two groups sharing the same DataStrip index range = a fork.
{
  dataStripId: "pin1",
  start: 11, end: 33,
  points: [...]  // physical chain B
},
{
  dataStripId: "pin1",
  start: 11, end: 33,
  points: [...]  // physical chain C — same indices, different (x, y)
}

Both groups receive the same color frame for index 17; both render it at their own (x, y).

Worked example

Imagine pin1 has length 100. Wire diagram:

pin1 --[0..10]-- A --fork--+--[11..33]-- B
                           +--[11..33]-- C
                --[34..99]-- D

Data strip:

  • { id: "pin1", length: 100 }

Groups:

  • { name: "A", dataStripId: "pin1", start: 0, end: 10, points: [11 (x,y)s] }
  • { name: "B", dataStripId: "pin1", start: 11, end: 33, points: [23 (x,y)s] }
  • { name: "C", dataStripId: "pin1", start: 11, end: 33, points: [23 (x,y)s] } ← fork twin of B
  • { name: "D", dataStripId: "pin1", start: 34, end: 99, points: [66 (x,y)s] }

The fork is implicit — it is whenever two groups on the same data strip claim overlapping index ranges.

Open design questions

A. Forking

  • Implicit (two groups with overlapping ranges = a fork) or explicit (a forkOf field naming the parent group)? Implicit is less ceremony; explicit is easier to validate and easier to render "fork-aware" UI for.
  • Fork shape constraints: must forked groups have the same end - start + 1? (Probably yes — a fork copies a signal range, so the lengths must match.)
  • Partial forks: can group C cover [15..33] while group B covers [11..33]? I.e., a fork that taps mid-range. This complicates validation but matches real hardware.
  • Color-coding forks in the UI: should forked twins share a color hue with a brightness/saturation modifier so they are identifiable as the same signal but visually distinct?
  • Realtime video sampling implications: the screenmap drives moviemaker, which samples a video frame at each LED's (x, y) and writes the sample into the data strip. With forks, both physical LEDs at the fork get the same color — which one's (x, y) does the sampler use? Simplest answer: the sampler reads at the first group's (x, y); forks just replicate the resulting color. Worth confirming.

B. Partitioning

  • Must groups partition the data strip's index space (every index appears in exactly one non-fork group)? Or are ungrouped indices fine ("dead" indices that exist in the data strip but have no physical home)?
  • With forks, partitioning becomes "every index appears in >= 1 group." Is that the right rule, or do we want "every index appears in exactly 1 parent and >= 0 forks"?
  • Should the editor warn (not block) when index ranges are missing? Block at save?

C. Persistence + interop

The screenmap.json is consumed by:

  • The on-device firmware (FastLED + ScreenMap)
  • The moviemaker tool, which samples realtime video onto the surface
  • The shape editor itself (round-trip)
  • Future tools (shapeviewer, etc.)

Open:

  • Should the JSON keep the current per-strip shape for backward compat and add a groups: [...] and dataStrips: [...] block alongside? Or rewrite the schema and provide a migrator?
  • Firmware does not care about groups (only data strips + the flat color buffer). Can we tag the JSON so a firmware build picks up just dataStrips/lengths and a video-sampling build picks up groups?
  • Local-only UI state (collapsed groups, selected group, etc.) — localStorage only, or in JSON?

D. UI panels

Today the strips panel is one flat list. With three concepts:

  • One unified hierarchical panel: data strip -> groups -> (fork siblings) -> points? Risks panel real estate.
  • Tabbed panels: a Strips tab (data strips, lengths, pin assignments) and a Groups tab (the visual segments)?
  • Selection model with three scopes: hovering an index, hovering a group, hovering a data strip. The arrow-hover X-ray UX wants to know "which group is selected." Do we need to also support "all groups on this data strip are selected"?

E. Naming / editor workflow

  • Auto-name groups ("q0_p0" style) vs. user-named?
  • When the user splits a strip (today's "split pin" workflow), does it produce two groups inside one data strip, or two data strips?
  • Reverse-group, reorder-group, repin (move group to a different data strip), merge-groups, fork-group — which operations are first-class?

F. Migration

  • The current screenmap.json files in the wild have one strip = one chain. The migrator should treat each existing strip as a { DataStrip, single Group, no fork } triplet.
  • The unit tests in tests/unit/strips-model.test.ts and screenmap-store.test.ts are the existing contracts. The new model needs equivalent coverage.

Goals

  • Real-world LED wiring patterns (forks, daisy-chained panels with shared data) become first-class.
  • The UI/UX enhancement work (arrow-hover X-ray on selected group, dense-layout legibility) gets a meaningful "selected group" to operate on.
  • Existing screenmap.json files keep loading.
  • Moviemaker (realtime video -> LED) keeps working with the new model and gains the ability to sample once and replicate to forked twins.

Non-goals (this design pass)

  • Picking a final JSON schema.
  • Implementation.
  • Rewriting strips-model.ts.

What I would like out of this issue

  1. Agreement (or pushback) on the three-concept split.
  2. Decisions on the A-F questions above — at least a leading direction for each.
  3. A short list of real-world examples (from your installs / from the FastLED community) that exercise forks, so we have concrete shapes to validate against.
  4. A follow-up issue with a concrete schema + migration plan once 1-3 settle.

Cross-reference: this work was sparked by the dense-layout hover/arrow UX thread and the request to separate strips from logical groups.

Activity

  1. zackees commented on Jun 14, 2026

    @zackees
    OwnerAuthor

    Hard constraint: keep the base screenmap.json schema fixed

    The screenmap.json shape this project produces is consumed by FastLED-firmware devices (and by WLED-family firmware that includes FastLED's ScreenMap parser). The base schema cannot change — any group/fork/data-strip work has to be additive (new top-level keys that legacy parsers ignore), not a rewrite.

    The locked-in base schema

    Canonical source: FastLED's ScreenMap::ParseJson in src/fl/math/screenmap.cpp.hpp and its header at src/fl/math/screenmap.h.

    Top-level shape:

    {
      "map": {
        "<segment_name>": {
          "x":        [<float>, ...],
          "y":        [<float>, ...],
          "diameter": <float, optional>
        },
        "<another_segment>": { "x": [...], "y": [...], "diameter": ... }
      }
    }

    Parser contract (paraphrased from the FastLED source):

    Field Type Required Notes
    map object yes Top-level. Parser bails if missing or not an object.
    map.<name> object yes per entry Segment name = arbitrary key. Each value must be an object.
    map.<name>.x array of floats yes Per-LED x coordinate (cm).
    map.<name>.y array of floats yes Per-LED y coordinate (cm). Must match x.length.
    map.<name>.diameter float optional LED diameter in cm (used for spacing/rendering).

    Any extra top-level keys are silently ignored by FastLED. That is the seam this design must use.

    Where the new model fits without breaking compat

    To stay compatible, all new concepts ride alongside map rather than inside it:

    {
      "map": { /* unchanged, FastLED-parseable */ },
    
      "dataStrips": [
        { "id": "pin1", "length": 100 }
      ],
    
      "groups": [
        { "name": "A", "dataStripId": "pin1", "start": 0,  "end": 10, "mapName": "A" },
        { "name": "B", "dataStripId": "pin1", "start": 11, "end": 33, "mapName": "B" },
        { "name": "C", "dataStripId": "pin1", "start": 11, "end": 33, "mapName": "C" },
        { "name": "D", "dataStripId": "pin1", "start": 34, "end": 99, "mapName": "D" }
      ]
    }

    Implications:

    • A FastLED firmware build sees only map.A, map.B, map.C, map.D — the legacy view, ignored extra keys. Forks just appear as two map entries with their own (x, y).
    • A video-sampling / shape-editor build reads dataStrips + groups, recovers fork semantics, and can produce the X-ray UX.
    • groups[].mapName is the bridge: it names which map entry holds the (x, y) points for that group. The points field that earlier drafts of this issue put inside Group lives in the map block instead — single source of truth, no duplication.

    Note on WLED specifically

    Stock WLED's own ledmap.json is a different format — a flat 1D pixel-reorder array, optionally with width/height for 2D matrices (WLED docs). It is not the same schema as FastLED's ScreenMap. Compatibility-with-WLED means compatibility with FastLED-flavored builds (e.g. WLED MoonModules, custom FastLED firmware) that link the ScreenMap parser — not with wled/WLED's stock ledmap.json. If targeting stock WLED is also a goal, we would need a separate exporter that converts the map block into the WLED pixel-reorder shape; flag if so.

    What this changes in the design questions

    • (B) Partitioning: must hold across the union of all map.<name> entries (every physical LED appears once in the rendered overlay), but the index space (groups[].start..end) can be sparse without breaking the firmware view.
    • (C) Persistence: answered. Add dataStrips + groups top-level keys alongside map. No schema rewrite, no migrator needed for forward direction. Old files load as-is and the editor synthesizes a default dataStrips + one-group-per-map-entry on import.
    • (F) Migration: in-place. Old screenmap.json -> read map, treat each entry as { DataStrip(id=key, length=x.length), Group(start=0, end=x.length-1, mapName=key) }.

    Source for the WLED ledmap.json format note: WLED docs - Mapping, WLED MoonModules - Mapping.

  2. zackees commented on Jun 14, 2026

    @zackees
    OwnerAuthor

    Proposed API: data strips + groups + forks + optional 3D

    Following on from the schema-compat constraint above. This is a concrete API proposal — discussion welcome before any of it lands. Everything sits on top of the existing FastLED ScreenMap shape; nothing removes or moves existing keys.

    Design principle: one source of truth for physical points

    Physical (x, y[, z]) points live in exactly one place: the existing map.<name> block. Groups don't duplicate points; they reference a map entry by name. Two reasons:

    1. Edits stay atomic — moving an LED in the editor touches one array, not two-plus-the-fork-twin.
    2. The FastLED parser sees the rendered geometry directly. No risk of map and groups getting out of sync.

    Layer 1 — DataStrip (signal, no position)

    export interface DataStrip {
      id: string;        // "pin1", "pin2", ... — stable identifier
      length: number;    // number of LED slots on the wire
    }

    A DataStrip is exactly what FastLED's controller writes to. No (x, y). No physical reality. Just "this output emits length colored slots."

    Layer 2 — ScreenmapGroup (UI region + index range, plus fork)

    export interface ScreenmapGroup {
      id: string;             // stable internal ID (e.g. "g_001")
      name: string;           // user-facing label (e.g. "q0_p0")
      dataStripId: string;    // which DataStrip's index space we're in
      start: number;          // inclusive
      end: number;            // inclusive
      mapName: string;        // key into the top-level `map` block — that's where (x, y, z) live
    
      // Fork mechanism: explicit parent reference.
      // null/undefined => this is a primary group.
      // Set to another group's id => this is a fork twin of that group.
      parentGroupId?: string;
    
      // UI metadata (also part of localStorage state)
      color?: string;         // override auto-assigned HSL
      collapsed?: boolean;
    }

    Cardinality rules:

    • A primary group's [start..end] range must be disjoint from every other primary's range on the same dataStripId.
    • A fork twin's start and end must equal its parent's exactly (initial constraint — partial-tap forks can come later if real installs need them, see Design: forks + groups + data-strips — separating signal from physical placement #88 question A).
    • A primary group's mapName points to a map.<name> entry whose x.length === end - start + 1.

    Layer 3 — optional 3D via z

    Existing ScreenmapStrip (matches FastLED parser):

    export interface ScreenmapStrip {
      x: number[];
      y: number[];
      z?: number[];      // NEW: same length as x/y when present
      diameter?: number;
      // ... existing legacy fields (pin, video_offset, ...) unchanged
    }

    The FastLED ScreenMap::ParseJson source (screenmap.cpp.hpp) only reads x, y, diameter from each segment and silently ignores other keys. Adding z is therefore non-breaking — old firmware sees only the 2D projection.

    3D-aware tools (future shapeviewer 3D mode, possibly moviemaker with depth-aware sampling later) pick z up when present; everything else treats it as if it isn't there.

    Putting it together — the schema on disk

    {
      "map": {
        "A": { "x": [...11 floats], "y": [...11 floats],            "diameter": 0.5 },
        "B": { "x": [...23 floats], "y": [...23 floats], "z": [...23 floats], "diameter": 0.5 },
        "C": { "x": [...23 floats], "y": [...23 floats], "z": [...23 floats], "diameter": 0.5 },
        "D": { "x": [...66 floats], "y": [...66 floats],            "diameter": 0.5 }
      },
      "dataStrips": [
        { "id": "pin1", "length": 100 }
      ],
      "groups": [
        { "id": "g_A", "name": "A", "dataStripId": "pin1", "start": 0,  "end": 10, "mapName": "A" },
        { "id": "g_B", "name": "B", "dataStripId": "pin1", "start": 11, "end": 33, "mapName": "B" },
        { "id": "g_C", "name": "C", "dataStripId": "pin1", "start": 11, "end": 33, "mapName": "C", "parentGroupId": "g_B" },
        { "id": "g_D", "name": "D", "dataStripId": "pin1", "start": 34, "end": 99, "mapName": "D" }
      ]
    }

    Walk-through:

    • Total LED slots fed by pin1: 100. Length-validation guard: sum(primary group lengths on pin1) === dataStrips[pin1].length AND every fork twin's length === its parent's length.
    • B / C are a fork pair. Same indices [11..33] on pin1. B has its own physical chain (23 points in map.B), C has its own physical chain (23 points in map.C). Both render the same color frame because they read the same indices off pin1.
    • B and C are 3D (have z), the rest are 2D. Firmware ignores z. The editor projects to the canvas plane when rendering in 2D mode, lights it up in a future 3D view.

    Sampling semantics — moviemaker side

    This is what makes forks actually work for realtime video → LED:

    1. For each DataStrip, allocate one color buffer of length slots.
    2. For each primary group: at each index i ∈ [start..end], sample the video at map[mapName].x[i - start], y[i - start]. Write the color into dataStrip[dataStripId][i].
    3. Skip fork twins entirely during sampling. Their indices already received colors from the primary's pass.
    4. For each group (primary AND fork): render the LEDs at map[mapName] positions using the color from dataStrip[dataStripId][i].

    Net result: sampler does the work once per signal index, both physical chains light up, and the firmware bit-stream is identical to what the device actually receives.

    If both B and C should sample from their own positions (e.g. you want C to mirror a different region of the video), that's not a fork — that's two independent groups on two independent data strips. The current "fork" semantics are strict: same signal, same color, two physical placements.

    UI selection model

    selectedGroupId becomes the unit of UI selection (was selectedStripIdx).

    • Strips panel: hierarchical — DataStrip (header, shows pin1 · 100 LEDs · 3 groups + 1 fork) → primary groups (indented) → fork twins (further indented under their parent, with a 🔀 marker).
    • Arrow-hover X-ray UX: hover on a primary highlights arrows for that group's index range; hovering a fork twin highlights the parent + both twins (they share a signal — they should highlight together).
    • Cursor cutout: same as the original proposal — suppress arrows in a small radius under the pointer so LEDs underneath are grabbable.

    Migration from existing screenmap.json

    A file with just map (no dataStrips, no groups) loads like this:

    function synthesizeDefaults(map: Record<string, ScreenmapStrip>) {
      const dataStrips: DataStrip[] = [];
      const groups: ScreenmapGroup[] = [];
      for (const [name, strip] of Object.entries(map)) {
        const id = `pin_${name}`;
        const len = Math.min(strip.x.length, strip.y.length);
        dataStrips.push({ id, length: len });
        groups.push({
          id: `g_${name}`,
          name,
          dataStripId: id,
          start: 0,
          end: len - 1,
          mapName: name,
        });
      }
      return { dataStrips, groups };
    }

    In other words: each old strip becomes one DataStrip + one Group, no forks. The editor presents the legacy file identically to before.

    Validation invariants (would live in strips-model.ts)

    • groups.length >= dataStrips.length (each data strip has ≥1 group).
    • For each dataStripId: primary groups' [start..end] ranges partition [0..length-1] exactly, OR cover a subset (ungrouped indices are allowed but warned in the editor).
    • Fork twin start/end exactly match parent.
    • mapName resolves to a map entry whose x.length === end - start + 1.
    • For every map entry: x.length === y.length, and if z is present, z.length === x.length.

    These would each get a unit test, joined by the parser regression test in #89.

    What this changes in #88's open questions

    Question Resolution
    A. Fork explicit vs implicit Explicit via parentGroupId. Reasons: easier validation, easier "highlight the whole fork as one" UX, sampler can skip twins by checking parentGroupId != null.
    A. Fork length constraints Same length (strict for v1). Partial-tap forks deferred.
    A. Sampling at a fork Sample at the primary's position; replicate the color to twins. Codified above.
    B. Partitioning Subset coverage allowed (warned, not blocked). Forks contribute extra coverage of the parent's range.
    C. Persistence Additive top-level keys (dataStrips, groups). No schema rewrite.
    C. UI-only state in JSON? collapsed and color overrides live in groups[] so they round-trip. Pure ephemeral state (currently-selected group, ruler position) stays in localStorage.
    F. Migration synthesizeDefaults() above. One DataStrip + one Group per legacy map entry.

    Still open after this proposal:

    • D (panel layout): single hierarchical tree vs tabs — needs an actual mockup pass.
    • E (operations): which operations get first-class buttons (split-group, fork-group, merge-groups, repin-group)?
    • Color modeling for forks: do twins inherit the parent's hue with a saturation modifier, or get their own auto-assigned color with a 🔀 badge?

    Happy to convert this into a follow-up issue with a concrete TS PR plan once the shape is agreed.

  3. zackees commented on Jun 14, 2026

    @zackees
    OwnerAuthor

    v2 schema — clean rewrite

    Dropping the "additive on top of FastLED" constraint. Editor and on-disk format become v2; firmware consumption goes through an explicit exporter that emits the legacy FastLED ScreenMap shape — separating "what the editor edits" from "what the device reads" is a cleaner split anyway.

    Two principles drive the rewrite:

    1. Forks are intrinsic to a group, not a separate twin/parent relationship. A group is "this index range on this strip, rendered at one-or-more physical placements." Multiple placements = a fork. No parentGroupId. No invariants between sibling groups.
    2. Parallel x[] / y[] / z[] arrays. Spans of floats stay intact for efficient processing (typed arrays, SIMD-friendly walks, video-sampler readback in row-major).

    Schema

    {
      "version": 2,
      "title": "Optional human-readable name",
      "strips": [
        {
          "id": "pin1",
          "length": 100,
          "groups": [
            {
              "id": "A",
              "name": "Top panel quad 0",
              "start": 0,
              "count": 11,
              "placements": [
                {
                  "x": [ /* 11 floats */ ],
                  "y": [ /* 11 floats */ ],
                  "z": [ /* 11 floats — optional */ ],
                  "diameter": 0.5
                }
              ],
              "color": "#3b82f6",
              "collapsed": false
            }
          ]
        }
      ],
      "ui": {
        "selectedGroupId": "A",
        "viewport": { "panX": 0, "panY": 0, "zoom": 1.0 }
      }
    }

    Field rules:

    Field Type Required Notes
    version 2 yes Hard-codes parser dispatch.
    title string no Display only.
    strips DataStrip[] yes Array order = panel order.
    strips[].id string yes Unique within file.
    strips[].length int yes Total LED slots the firmware writes for this output.
    strips[].groups Group[] yes Array order = panel order within the strip.
    groups[].id string yes Unique within strip.
    groups[].name string yes User-facing, can collide across groups.
    groups[].start int yes Inclusive index into the parent strip.
    groups[].count int yes Number of LEDs in this group.
    groups[].placements Placement[] yes length >= 1 for a normal group; length >= 2 is a fork.
    placements[].x float[] yes length === groups[].count.
    placements[].y float[] yes length === groups[].count.
    placements[].z float[] no When present, length === count. Enables 3D installs.
    placements[].diameter float no Per-placement, defaults inherited from group/screenmap if absent.
    groups[].color string no UI override; otherwise auto-assigned HSL.
    groups[].collapsed bool no Panel UI state, persisted.
    ui object no Round-trip editor state. Pure ephemeral things (drag offsets, hover) stay in localStorage.

    Forks, with no ceremony

    A fork is just "this signal range physically appears in N spots":

    {
      "id": "B", "name": "Mirror panel", "start": 11, "count": 23,
      "placements": [
        { "x": [ /* 23 floats — chain A */ ], "y": [...], "diameter": 0.5 },
        { "x": [ /* 23 floats — chain B */ ], "y": [...], "diameter": 0.5 }
      ]
    }

    No parentGroupId. No "twin." No special-case validation that two groups must mirror each other's ranges. The group says "I am 23 LEDs starting at index 11, and you can find me physically in these two places."

    Sampling (moviemaker / video → LED)

    Per group, the sampler:

    1. Picks one placement as the sampling source (default: first; configurable later if real installs want "average all placements" or "sample the one with the largest area").
    2. Reads color at each (x[i], y[i]) (and z[i] if depth-aware), produces a length-count color stream.
    3. Writes that stream into the parent data strip's color buffer at [start..start+count).

    Rendering walks every placement of every group and draws at (x[i], y[i]) with the color from the data strip buffer. No double-sampling work for forks.

    Validation invariants

    Each becomes a unit test in strips-model.test.ts:

    • strips[].id unique.
    • groups[].id unique within strip.
    • groups[].start + count <= strips[].length.
    • Within a strip: group [start, start+count) ranges are disjoint. (Subset coverage is allowed — ungrouped indices are dark but warned in the editor.)
    • Each placement: x.length === y.length === count. If z present, z.length === count.

    TypeScript

    export interface Placement {
      x: number[];
      y: number[];
      z?: number[];
      diameter?: number;
    }
    
    export interface Group {
      id: string;
      name: string;
      start: number;
      count: number;
      placements: Placement[];   // >= 1 for normal, >= 2 for fork
      color?: string;
      collapsed?: boolean;
    }
    
    export interface DataStrip {
      id: string;
      length: number;
      groups: Group[];
    }
    
    export interface UiState {
      selectedGroupId?: string;
      viewport?: { panX: number; panY: number; zoom: number };
    }
    
    export interface ScreenmapV2 {
      version: 2;
      title?: string;
      strips: DataStrip[];
      ui?: UiState;
    }

    Firmware exporter — keeps the device happy

    Editor stays in v2 forever. When the user hits Export for device, we emit the legacy FastLED ScreenMap shape — one map.<key> entry per placement, names auto-generated to be stable (e.g. <groupName> for single-placement groups, <groupName>_p0, <groupName>_p1 for forked ones):

    function exportToFastLed(v2: ScreenmapV2): FastLedScreenmap {
      const map: Record<string, { x: number[]; y: number[]; diameter?: number }> = {};
      for (const strip of v2.strips) {
        for (const group of strip.groups) {
          group.placements.forEach((p, i) => {
            const key = p.placements.length > 1 ? `${group.name}_p${i}` : group.name;
            map[key] = { x: p.x, y: p.y, ...(p.diameter !== undefined && { diameter: p.diameter }) };
          });
        }
      }
      return { map };
    }

    Two consequences:

    • 3D z is silently dropped on export (firmware doesn't use it). The 2D projection is what the device sees, which is what was already true.
    • Fork twins each get their own map.<key> entry — the device renders both physically, exactly as today's multi-map flow does. Whoever is reading the v1 screenmap.json doesn't notice forks at all (they just see N entries).

    A round-tripper in the other direction (import a v1 file → v2) synthesizes one group per map entry, no forks, no z. One-shot, run once at load.

    Worked example (the pin1 length=100, fork at [11..33] case)

    {
      "version": 2,
      "title": "Fork demo",
      "strips": [
        {
          "id": "pin1",
          "length": 100,
          "groups": [
            {
              "id": "A", "name": "A", "start": 0, "count": 11,
              "placements": [
                { "x": [0,1,2,3,4,5,6,7,8,9,10], "y": [0,0,0,0,0,0,0,0,0,0,0], "diameter": 0.5 }
              ]
            },
            {
              "id": "B", "name": "B", "start": 11, "count": 23,
              "placements": [
                { "x": [11,12,13,/*...*/,33], "y": [0,0,0,/*...*/,0], "diameter": 0.5 },
                { "x": [200,201,/*...*/,222], "y": [10,10,/*...*/,10], "diameter": 0.5 }
              ]
            },
            {
              "id": "D", "name": "D", "start": 34, "count": 66,
              "placements": [
                { "x": [/* 66 floats */], "y": [/* 66 floats */], "diameter": 0.5 }
              ]
            }
          ]
        }
      ]
    }

    Reads as: pin1 has 100 LED slots. Group A owns the first 11 (one physical chain). Group B owns the next 23 and renders them in two places (the fork). Group D owns the last 66.

    What this leaves open

    • Sampling-source policy for forks: default to placement[0]; deferred whether to expose "first / largest area / average" as a per-group setting.
    • Naming during export: group_p0 / group_p1 is a reasonable default; expose an override?
    • Schema validation library: hand-rolled with named errors, or a JSON-schema doc + ajv at editor boundary? (Lean toward hand-rolled — the parser already has the structure walks.)

    If this shape lands, the next concrete piece of work is a new tests/unit/screenmap-v2-schema.test.ts (the v2 equivalent of #89) plus a v1→v2 importer with its own round-trip test.

  4. zackees commented on Jun 14, 2026

    @zackees
    OwnerAuthor

    v2-flat — two tables, depth 2

    Same goals, lower nesting. Two top-level arrays — strips and segments — and that's it. No nested groups[], no nested placements[], no parentGroupId. A segment carries everything: signal binding, physical points, optional UI grouping label.

    Schema

    {
      "version": 2,
      "title": "Optional name",
      "strips": [
        { "id": "pin1", "length": 100 }
      ],
      "segments": [
        {
          "id":     "A",
          "strip":  "pin1",
          "start":  0,
          "count":  11,
          "x":      [ /* 11 floats */ ],
          "y":      [ /* 11 floats */ ],
          "z":      [ /* 11 floats — optional */ ],
          "diameter": 0.5,
          "group":  "topRow"
        }
      ]
    }

    How the concepts collapse

    Concept Where it lives
    Data strip (signal) strips[] — just id + length.
    Physical placement (one chain of LEDs in space) segments[] — one row per chain. Each segment has its own x[]/y[]/z[]?.
    Fork (same signal, multiple physical chains) Two or more segments with the same (strip, start, count) triple. No parent/child, no twin field, no shared key beyond what the firmware already knows.
    UI grouping (collapse, color, hover-X-ray scope) segments[].group — a string label. Segments with the same group value are treated as one unit by the UI. Defaults to the segment's id when absent (= each segment is its own group).

    That's it. No third entity, no joined keys, no "first ID wins" rule.

    Worked example — pin1 length 100, fork at indices [11..33]

    {
      "version": 2,
      "title": "Fork demo",
      "strips": [
        { "id": "pin1", "length": 100 }
      ],
      "segments": [
        {
          "id": "A",  "strip": "pin1", "start": 0,  "count": 11,
          "x": [0,1,2,3,4,5,6,7,8,9,10],
          "y": [0,0,0,0,0,0,0,0,0,0,0],
          "diameter": 0.5,
          "group": "row0"
        },
        {
          "id": "B0", "strip": "pin1", "start": 11, "count": 23,
          "x": [11,12, /*...*/ ,33],
          "y": [0, 0, /*...*/ , 0],
          "diameter": 0.5,
          "group": "mirror"
        },
        {
          "id": "B1", "strip": "pin1", "start": 11, "count": 23,
          "x": [200,201, /*...*/ ,222],
          "y": [10, 10, /*...*/ ,10],
          "diameter": 0.5,
          "group": "mirror"
        },
        {
          "id": "D",  "strip": "pin1", "start": 34, "count": 66,
          "x": [ /* 66 floats */ ],
          "y": [ /* 66 floats */ ],
          "diameter": 0.5,
          "group": "row1"
        }
      ]
    }

    Reads as: pin1 has 100 LED slots. A owns slots 0-10, one chain. B0 and B1 both claim slots 11-33 → fork, same color stream, two physical chains. D owns 34-99. UI groups: row0, mirror (contains both fork halves), row1.

    TypeScript

    export interface DataStrip {
      id: string;
      length: number;
    }
    
    export interface Segment {
      id: string;
      strip: string;            // foreign key into strips[]
      start: number;            // inclusive index in strip
      count: number;            // number of LEDs in this segment
      x: number[];              // length === count
      y: number[];              // length === count
      z?: number[];             // length === count when present (3D)
      diameter?: number;
      group?: string;           // UI grouping label; defaults to `id`
    }
    
    export interface ScreenmapV2 {
      version: 2;
      title?: string;
      strips: DataStrip[];
      segments: Segment[];
    }

    Optional UI state — only if we want round-trip

    export interface ScreenmapV2 {
      /* ... */
      ui?: {
        selectedSegmentId?: string;
        selectedGroup?: string;
        viewport?: { panX: number; panY: number; zoom: number };
        groupCollapsed?: Record<string, boolean>;
        groupColor?: Record<string, string>;
      };
    }

    Pure-ephemeral state (hover, drag offsets, currently-dragged handle) stays in localStorage. Anything you want preserved across opens lives in ui.

    Sampling, in two lines

    For each (strip, start, count) tuple present in segments[], sample once at the first matching segment's (x[i], y[i]) and write the resulting color stream into the strip's color buffer at [start..start+count). Then render every segment by reading colors out of the strip buffer at its index range and drawing at its own (x[i], y[i]). Forks render twice from one sample.

    Validation invariants

    • strips[].id unique.
    • segments[].id unique.
    • For every segment: segments[i].strip resolves to a strips[] entry; start + count <= strip.length; x.length === y.length === count; if z present, z.length === count.
    • For any (strip, start, count) tuple that appears more than once (= a fork), the firmware exporter emits one map.<key> per occurrence.

    Firmware exporter

    Editor stays on v2; firmware reads through an exporter that flattens to FastLED's ScreenMap shape:

    function exportToFastLed(v2) {
      const map = {};
      for (const seg of v2.segments) {
        // Suffix duplicate ranges (= forks) so map keys stay unique.
        const dupCount = v2.segments.filter(s =>
          s.strip === seg.strip && s.start === seg.start && s.count === seg.count
        ).length;
        const baseKey = seg.group ?? seg.id;
        const key = dupCount > 1 ? `${baseKey}_${seg.id}` : baseKey;
        map[key] = { x: seg.x, y: seg.y, ...(seg.diameter !== undefined && { diameter: seg.diameter }) };
      }
      return { map };
    }

    z is silently dropped on export — the firmware never knew about it.

    Compared to the previous v2 (nested)

    Nested v2 Flat v2
    Top-level arrays strips strips, segments
    Depth to reach x[] 4 (strips[i].groups[j].placements[k].x) 2 (segments[i].x)
    Fork representation placements array inside a group Multiple segments sharing (strip, start, count)
    Group representation Object with own children Optional string label on segments
    Lines to express the worked example ~45 ~30

    The price: validating a fork requires walking segments[] looking for matching (strip, start, count) tuples (O(n) once, cached in a Map). The previous design made forks structurally explicit in exchange for that nesting.

  5. zackees commented on Jun 14, 2026

    @zackees
    OwnerAuthor

    Three alternatives to v2-flat

    Recruited three schema designers with different lenses (columnar/Arrow, JSON Schema standards, relational 3NF) and asked each for one alternative to v2-flat. Same fork-at-[11..33] worked example across all three so trade-offs read side by side. None of these is a final pick — they exist to surface what each design philosophy buys and costs.


    Alternative 1 — Columnar / typed-array (Apache Arrow-style)

    Hoist all coordinates into three top-level parallel float buffers (x, y, z) that materialize directly into Float32Array with one allocation per axis. Segments collapse to (offset, count) views — pure integer metadata — so forks are free (two segments pointing at the same span) and the per-frame sampler walks contiguous memory with zero pointer-chasing. Deliberately reject a single stride-3 coords buffer: keeping axes separate preserves SoA layout, lets the sampler skip z entirely in 2D mode without gather instructions, and is friendlier to SIMD / GPU attribute uploads (one BufferAttribute per axis).

    {
      "version": 3,
      "layout": "columnar",
      "title": "Optional name",
      "strips": [
        { "id": "pin1", "length": 100 }
      ],
      "buffers": {
        "x": [ /* 100 floats: 0..10 for A, 11..33 for B (shared by fork), 34..99 for D */ ],
        "y": [ /* 100 floats, same order */ ],
        "z": null
      },
      "segments": [
        { "id": "A",  "strip": "pin1", "start": 0,  "count": 11, "offset": 0,  "diameter": 0.5, "group": "topRow" },
        { "id": "B0", "strip": "pin1", "start": 11, "count": 23, "offset": 11, "diameter": 0.5, "group": "fork" },
        { "id": "B1", "strip": "pin1", "start": 11, "count": 23, "offset": 11, "diameter": 0.5, "group": "fork" },
        { "id": "D",  "strip": "pin1", "start": 34, "count": 66, "offset": 34, "diameter": 0.5 }
      ]
    }
    interface ScreenmapV3 {
      version: 3;
      layout: "columnar";
      title?: string;
      strips: { id: string; length: number }[];
      buffers: {
        x: number[];           // → new Float32Array(buffers.x)
        y: number[];
        z: number[] | null;    // null => 2D mode, sampler skips entirely
      };
      segments: Segment[];
    }
    interface Segment {
      id: string;
      strip: string;
      start: number;           // LED index on strip
      count: number;
      offset: number;          // index into buffers.x/y/z
      diameter?: number;
      group?: string;
    }

    Pros

    • One new Float32Array(json.buffers.x) per axis at load — no per-segment boxing, no GC churn, cache-hot iteration on the hot path.
    • Forks cost ~80 bytes of segment metadata, not a duplicated float span; edits to the shared geometry stay coherent by construction.
    • SoA layout maps 1:1 onto a Three.js BufferAttribute per axis and onto SIMD lanes; z=null is a free 33% bandwidth win in 2D.
    • Segment records are fixed-shape integer structs — trivially convertible to Int32Array for worker postMessage with transferables.

    Cons

    • Loses locality when reading a single segment as JSON — diffs and human inspection are noisier because coordinates live far from the segment that owns them.
    • Adds an invariant (offset + count <= buffers.x.length, axes equal length) the editor must validate on load and maintain on every edit; v2-flat self-validates per segment.
    • Insert/delete inside the middle of a buffer requires a splice + offset rewrite across downstream segments; v2-flat just edits one array in place.
    • Hand-authoring or hand-patching the JSON is meaningfully harder — you can't eyeball segment B0 and see its points.

    Sampler frame: For each segment, read (offset, count, strip.ledBaseIndex + start), then for (let i = 0; i < count; i++) sample the video at (x[offset+i], y[offset+i] [, z[offset+i]]) and write into ledColors[base + i] — one tight contiguous loop, no object dereferences inside the inner body.


    Alternative 2 — JSON Schema canonical (interop-first)

    A self-describing document with a stable $id, explicit type/v discriminator, and a discriminated union over segment kinds so a stock JSON Schema validator rejects malformed files before any tool touches them. Groups live in a normalized table referenced by id, and forks become a first-class "kind": "fork" variant that points at a physical segment instead of duplicating geometry implicitly.

    {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "$id": "https://ledmapper.com/schemas/screenmap-2.0.json",
      "type": "Screenmap",
      "v": "2.0",
      "title": "Optional name",
      "strips": {
        "pin1": { "length": 100 }
      },
      "groups": {
        "topRow": { "name": "Top Row", "color": "#3b82f6", "collapsed": false }
      },
      "segments": {
        "A": {
          "kind": "physical",
          "strip": "pin1",
          "start": 0,
          "count": 11,
          "geometry": {
            "x": [ /* 11 floats */ ],
            "y": [ /* 11 floats */ ]
          },
          "diameter": 0.5,
          "group": "topRow"
        },
        "B0": {
          "kind": "physical",
          "strip": "pin1",
          "start": 11,
          "count": 23,
          "geometry": {
            "x": [ /* 23 floats */ ],
            "y": [ /* 23 floats */ ],
            "z": [ /* 23 floats */ ]
          },
          "diameter": 0.5
        },
        "B1": {
          "kind": "fork",
          "forkOf": "B0",
          "geometry": {
            "x": [ /* 23 floats */ ],
            "y": [ /* 23 floats */ ]
          },
          "diameter": 0.4,
          "group": "topRow"
        },
        "D": {
          "kind": "physical",
          "strip": "pin1",
          "start": 34,
          "count": 66,
          "geometry": {
            "x": [ /* 66 floats */ ],
            "y": [ /* 66 floats */ ]
          },
          "diameter": 0.5
        }
      }
    }
    type StripId = string;
    type GroupId = string;
    type SegmentId = string;
    
    interface Screenmap {
      $schema: string;
      $id?: string;
      type: "Screenmap";
      v: "2.0";
      title?: string;
      strips: Record<StripId, { length: number }>;
      groups?: Record<GroupId, { name?: string; color?: string; collapsed?: boolean }>;
      segments: Record<SegmentId, PhysicalSegment | ForkSegment>;
    }
    
    interface Geometry { x: number[]; y: number[]; z?: number[]; }
    
    interface PhysicalSegment {
      kind: "physical";
      strip: StripId;
      start: number;
      count: number;
      geometry: Geometry;
      diameter?: number;
      group?: GroupId;
    }
    
    interface ForkSegment {
      kind: "fork";
      forkOf: SegmentId;
      geometry: Geometry;
      diameter?: number;
      group?: GroupId;
    }

    Pros

    • A stock Draft 2020-12 validator catches bad strip/group/forkOf refs, missing count, and wrong-kind fields without custom code — interop with third-party tools is basically free.
    • Forks are explicit (kind: "fork" + forkOf) instead of inferred from coincidence on (strip, start, count), so downstream tools never have to guess intent.
    • groups as a normalized table gives color/display/collapsed a real home; no more smearing UI metadata across every segment.
    • $id + v mean future migrations (2.1, 3.0) are dispatchable on a single field, and files are self-identifying when found in the wild.

    Cons

    • Verbose: tiny single-strip files balloon from ~10 lines to ~30; hand-editing is noticeably more annoying than v2-flat.
    • Object-keyed strips/segments/groups lose array ordering — UI z-order or render order needs a separate explicit order field if it matters.
    • The discriminated union means two code paths (physical vs fork) everywhere a tool touches segments, even for tools that don't care about forks.
    • Geometry-length-equals-count is still a semantic rule the validator can't express cleanly without $data or custom keywords, so one runtime check survives.

    A downstream consumer validates by fetching the schema at $id, running it through any standard JSON Schema validator (ajv, jsonschema, etc.), and only then walking the document.


    Alternative 3 — Normalized tables (3NF, forks as first-class)

    A screenmap is a small relational database, not a document. Strips, signal routes, groups, and segments are distinct entities with distinct lifecycles — stop cramming them into one row and stop reconstructing forks by tuple-matching. Model them as four flat tables with explicit foreign keys; a fork is then literally "two segments pointing at the same signal_route_id," not a heuristic.

    {
      "version": 3,
      "title": "Optional name",
      "strips": [
        { "id": "pin1", "length": 100 }
      ],
      "signal_routes": [
        { "id": "r_A",  "strip": "pin1", "start":  0, "count": 11 },
        { "id": "r_B",  "strip": "pin1", "start": 11, "count": 23 },
        { "id": "r_D",  "strip": "pin1", "start": 34, "count": 66 }
      ],
      "groups": [
        { "id": "g_top",  "name": "topRow",   "color": "#3b82f6", "collapsed": false },
        { "id": "g_fork", "name": "forkPair", "color": "#f59e0b", "collapsed": false }
      ],
      "segments": [
        {
          "id": "A",  "signal_route": "r_A",  "group": "g_top",  "diameter": 0.5,
          "x": [ /* 11 floats */ ], "y": [ /* 11 floats */ ], "z": null
        },
        {
          "id": "B0", "signal_route": "r_B",  "group": "g_fork", "diameter": 0.5,
          "x": [ /* 23 floats */ ], "y": [ /* 23 floats */ ], "z": null
        },
        {
          "id": "B1", "signal_route": "r_B",  "group": "g_fork", "diameter": 0.5,
          "x": [ /* 23 floats */ ], "y": [ /* 23 floats */ ], "z": null
        },
        {
          "id": "D",  "signal_route": "r_D",  "group": null,     "diameter": 0.5,
          "x": [ /* 66 floats */ ], "y": [ /* 66 floats */ ], "z": null
        }
      ]
    }
    type Strip = { id: string; length: number };
    type SignalRoute = { id: string; strip: string; start: number; count: number };
    type Group = { id: string; name: string; color?: string; collapsed?: boolean };
    type Segment = {
      id: string;
      signal_route: string;        // FK -> SignalRoute.id
      group: string | null;        // FK -> Group.id
      diameter: number;
      x: number[];
      y: number[];
      z: number[] | null;
    };
    type ScreenmapV3 = {
      version: 3;
      title?: string;
      strips: Strip[];
      signal_routes: SignalRoute[];
      groups: Group[];
      segments: Segment[];
    };

    Pros

    • Forks are a primary-key fact, not a tuple coincidence — diffing, validation, and "rename this route" become trivial.
    • Group metadata (color, collapsed, display name) has somewhere to live instead of being smeared across every segment row.
    • Editing a signal route once updates every segment bound to it; no risk of B0 and B1 drifting out of sync on start/count.
    • Each table validates independently — orphan FKs, overlapping routes, and length overflows are one-pass lint checks.

    Cons

    • More indirection: rendering one segment now requires two joins (segment -> signal_route -> strip) instead of reading one row.
    • File is chattier and less human-greppable; "show me everything about segment A" is no longer a single object.
    • Migration cost from v2-flat is real — every existing tool, exporter, and example file needs a converter.
    • Tiny maps pay a normalization tax (extra ids, extra tables) for a payoff that only matters once forks and groups exist.

    Rendering the fork: find both segment rows where signal_route === "r_B", join to signal_routes for the LED index range [11, 34), join to strips for pin1, and draw each segment's (x, y) array against the shared route.


    Quick side-by-side

    v2-flat Alt 1 (columnar) Alt 2 (JSON Schema) Alt 3 (3NF)
    Top-level tables 2 3 (strips + buffers + segments) 3 maps (strips, groups, segments) 4 (strips, signal_routes, groups, segments)
    Depth to x[] 2 (segments[i].x) 1 (buffers.x) 3 (segments[id].geometry.x) 2 (segments[i].x)
    Forks expressed by Matching (strip, start, count) Matching offset Explicit "kind": "fork" + forkOf Two segments → one signal_route_id
    Group metadata home Smeared across segments Smeared across segments Dedicated groups map Dedicated groups table
    Validation Hand-rolled Hand-rolled + axis-length invariant Stock JSON Schema validator Hand-rolled (FK checks)
    Hot-path sampler cost Per-segment array deref One contiguous Float32Array walk Per-segment geometry deref Per-segment array deref + FK lookups
    Editor-friendliness Highest Lowest (coords far from segments) Medium-low (verbose) Medium

    My read: Alt 1 wins if per-frame sampling is the dominant cost we care about, Alt 2 wins if interop with third-party tools is the primary goal, Alt 3 wins if we expect forks and group metadata to become rich enough to justify the join indirection. v2-flat still wins if we want the smallest-possible model with the lowest learning curve.

  6. zackees commented on Jun 14, 2026

    @zackees
    OwnerAuthor

    Generative / adversarial design loop

    The principles being optimized (set by issue author):

    1. Simple — minimum concepts; one screenmap should be readable at a glance.
    2. Columnar — coordinates as contiguous typed-array-friendly spans of floats.
    3. Hand-writable — a human author can produce a small file in a couple of minutes.
    4. Flat — minimum nesting depth.
    5. Common-simple, uncommon-OK-harder — a simple "one strip, one chain" file should be tiny; forks / groups / 3D can be more verbose.

    Loop: generator proposes a variant taking the last critique into account; adversary scores each principle 1-10 (10 best) and gives a verdict. Ideal = average ≥ 8.5 AND every principle ≥ 7. Otherwise the next iteration begins. Ledger continues below.

    Baseline being iterated on: v2-flat (two top-level arrays strips + segments, each segment carries its own x[]/y[]/z?[]).

  7. zackees commented on Jun 14, 2026

    @zackees
    OwnerAuthor

    Round 1

    Generator — Iteration 1: single-array segments, strip lengths inline

    What changed from v2-flat. Collapsed the two top-level arrays into one: segments. Strip declarations are folded in as a tiny strips map (name → length); everything else lives as a flat list of segments where each segment owns its own contiguous x, y, optional z columnar float arrays. Fork = two segments with identical (strip, at, n) but different x/y. No nesting beyond the segment object itself.

    Schema (worked example).

    {
      "strips": { "pin1": 100 },
      "segments": [
        { "id": "A",  "strip": "pin1", "at": 0,  "n": 11,
          "x": [ /* 11 floats */ ], "y": [ /* 11 floats */ ] },
        { "id": "B0", "strip": "pin1", "at": 11, "n": 23,
          "x": [ /* 23 floats — left copy */ ],
          "y": [ /* 23 floats — left copy */ ] },
        { "id": "B1", "strip": "pin1", "at": 11, "n": 23,
          "x": [ /* 23 floats — right copy */ ],
          "y": [ /* 23 floats — right copy */ ] },
        { "id": "D",  "strip": "pin1", "at": 34, "n": 66,
          "x": [ /* 66 floats */ ], "y": [ /* 66 floats */ ] }
      ]
    }

    Simplest-case file (one strip, one chain, no fork).

    {
      "x": [0,1,2,3,4,5,6,7,8,9],
      "y": [0,0,0,0,0,0,0,0,0,0]
    }

    Loader rule: if root has bare x/y, treat as single anonymous segment on a single anonymous strip starting at 0.

    Adversary critique — iteration 1

    Principle Score Reasoning
    1. Simple 6 Two distinct file shapes (terse bare-x/y vs. full strips+segments) plus a fork-by-convention rule means a reader must learn two formats and one implicit invariant.
    2. Columnar 9 Each segment owns dense parallel x/y/z? arrays that drop straight into Float32Array; only ding is a full chain is split across N segment arrays the consumer must concatenate.
    3. Hand-writable 10 Simplest-case is 4 lines, hitting the top bucket cleanly.
    4. Flat 6 In the canonical form, first float lives at root.segments[0].x[5] — depth 3; the terse form is depth 1 but doesn't count as the real schema.
    5. Common-simple 7 Simplest case is genuinely bare, and fork/group/3D are expressible, but fork relies on a duplicate-(strip, at, n) convention rather than an explicit schema field.

    Average: 7.6 / 10. Lowest: principle 1 (Simple) at 6.

    Specific weaknesses to fix.

    • Collapse to ONE canonical shape. Terse {x, y} and full {strips, segments} are two schemas — pick one and make the simple case fall out by omitted fields.
    • Make forks explicit (fork or branch_of field), not duplicate-tuple convention.
    • Reduce depth in the common case — hoist x/y to root when single-segment as the canonical (not alternate) form.
    • Drop id from the simplest case if not load-bearing.
    • n is redundant with x.length — drop one.

    Verdict: Continue.

  8. zackees commented on Jun 14, 2026

    @zackees
    OwnerAuthor

    Round 2

    Generator — Iteration 2: Root coords, optional segments as overlay

    What changed from iteration 1. One schema: x/y always live at root (addresses adversary's depth + parallel-form complaint); segments[] is an optional overlay that names index ranges (n dropped — x.length is truth); forks are explicit via a fork label shared by sibling segments whose physical arrays differ.

    Schema (worked example).

    {
      "strips": { "pin1": 100 },
      "x": [ /* 100 floats: A(11) | B0(23) | D(66) ... */ ],
      "y": [ /* 100 floats, same layout */ ],
      "segments": [
        { "name": "A",  "strip": "pin1", "at": 0  },
        { "name": "B0", "strip": "pin1", "at": 11, "fork": "B" },
        { "name": "B1", "strip": "pin1", "at": 11, "fork": "B",
          "x": [ /* 23 floats */ ], "y": [ /* 23 floats */ ] },
        { "name": "D",  "strip": "pin1", "at": 34 }
      ]
    }

    Rules: root x/y hold canonical positions for every signal index [0, strip_length). A segment's range is [at, at + (next_at_on_strip or strip_length)) — no n. Segments may override x/y locally; fork: "B" declares siblings that share the same signal range at different physical locations.

    Simplest-case file.

    {
      "x": [0,1,2,3,4,5,6,7,8,9],
      "y": [0,0,0,0,0,0,0,0,0,0]
    }

    Depth to first float in canonical form. root.x[5] — depth 2.

    Adversary critique — iteration 2

    Principle Score Reasoning
    1. Simple 7 One canonical schema with root x/y is clean, but strips, segments, at, fork, and the implicit range-derivation rule add ~4 concepts.
    2. Columnar 10 Root x[]/y[] are contiguous parallel float arrays that map directly to Float32Array with x[i] access.
    3. Hand-writable 10 Simplest-case file is 4 lines, top tier.
    4. Flat 9 Canonical access is root.x[5] — depth 2.
    5. Common-simple 7 Simplest case tiny and forks now explicit, but segment-local x/y overrides reintroduce a parallel coordinate form, and 3D still requires adding z[] at both root and per-segment.

    Average: 8.6 / 10. Lowest: principle 1 (Simple) at 7. (Technically over the ≥8.5/≥7 bar, but the adversary judged that substantive improvements remain.)

    Specific weaknesses to fix.

    • Eliminate the implicit range-derivation rule ([at, next_at)) — either make ranges explicit with n/end, or use a different shape so the reader doesn't have to scan siblings.
    • Remove parallel coordinate form: segment-local x/y overrides mean coordinates live in two places. Move fork-divergent coordinates into a single root-append region indexed by segment at.
    • Collapse strips + segments[].strip redundancy: strips: { pin1: 100 } duplicates information the segment list implies, and forces multi-strip files to declare both.

    Verdict: Continue.

  9. zackees commented on Jun 14, 2026

    @zackees
    OwnerAuthor

    Round 3

    Generator — Iteration 3: Single root coordinate buffer; segments are pure (signal, physical) range pairs

    What changed from iteration 2.

    1. Explicit count on every segment. No more sibling-scan to derive length.
    2. Single coordinate store. Root x/y is the only place floats live. Forks just append extra physical placements at the end; fork twins point via offset.
    3. strips table gone. Strip length = max(at + count) per pin. In the segment-less common case, the strip is an implicit anonymous strip of length x.length.

    Schema (worked example). Strip pin1 length 100. Segment A = signal 0-10. Segments B0 and B1 fork: both bind signal 11-33, B0 placed at root indices 11-33, B1 placed at appended indices 100-122. Segment D = signal 34-99.

    {
      "x": [ /* 123 floats: signal[0..99] then forkB1[100..122] */ ],
      "y": [ /* 123 floats */ ],
      "segments": [
        { "name": "A",  "pin": "pin1", "at": 0,  "count": 11, "offset": 0   },
        { "name": "B0", "pin": "pin1", "at": 11, "count": 23, "offset": 11  },
        { "name": "B1", "pin": "pin1", "at": 11, "count": 23, "offset": 100 },
        { "name": "D",  "pin": "pin1", "at": 34, "count": 66, "offset": 34  }
      ]
    }

    Sugar: offset may be omitted when it equals at. Non-fork segments become pin/at/count.

    Simplest-case file.

    {
      "x": [0, 1, 2, 3],
      "y": [0, 0, 0, 0]
    }

    Depth to first float in canonical form. root.x[0] — depth 2.

    Adversary critique — iteration 3

    Principle Score Reasoning
    1. Simple 7 Two top-level keys plus segments, but reader must remember three implicit rules: offset-defaults-to-at, strip-length = max(at+count), and fork twins live appended to root x/y.
    2. Columnar 10 Exactly one coordinate store at root.x[i], maps 1:1 to a single Float32Array pair.
    3. Hand-writable 10 Simplest-case is 4 lines.
    4. Flat 9 root.x[0] — depth 2.
    5. Common-simple 8 Common case is just x/y; uncommon adds segments + appended-fork convention. Additive but introduces offset/at duality.

    Average: 8.8 / 10. All principles ≥ 7. (Formal threshold met, but adversary still has substantive critiques.)

    Specific weaknesses to fix.

    • The "offset defaults to at" sugar is a hidden third rule. Collapse to one canonical form (always-present offset, or drop at entirely and let offset double as both).
    • "Strip length = max(at+count)" is derived; a malformed file with a gap (at=0,count=10 then at=20,count=5) silently defines a 25-length strip with undefined LEDs 10..19. Make explicit or forbid gaps.
    • Appending fork twins to root x/y mixes signal-order and physical-only points in the same buffer with no marker. Consumers iterating x[i] for "signal index" walk off the end into fork data unless they consult segments first.

    Verdict: Continue.

  10. zackees commented on Jun 14, 2026

    @zackees
    OwnerAuthor

    Round 4

    Generator — Iteration 4: Segment-order is physical-order; one buffer, one concept

    What changed from iteration 3.

    1. No offset field. A segment's slice of root x/y determined by position in array via running sum of prior counts.
    2. No derivable strip length, no possible gaps. Strip length = sum of count for segments on that pin.
    3. No mixed buffer. Root x/y is segment-indexed (concatenation of per-segment placements in declaration order).

    Schema (worked example).

    {
      "x": [ /* 123 floats: A(11) | B0(23) | B1(23) | D(66) */ ],
      "y": [ /* 123 floats */ ],
      "segments": [
        { "pin": "pin1", "at": 0,  "count": 11 },
        { "pin": "pin1", "at": 11, "count": 23 },
        { "pin": "pin1", "at": 11, "count": 23 },
        { "pin": "pin1", "at": 34, "count": 66 }
      ]
    }

    Slices: seg[0] = x[0..11), seg[1] = x[11..34), seg[2] = x[34..57), seg[3] = x[57..123). Forks = two segments with same (pin, at, count).

    Simplest-case file.

    {
      "x": [0, 1, 2, 3],
      "y": [0, 0, 0, 0],
      "segments": [{ "pin": "pin1", "at": 0, "count": 4 }]
    }

    Depth. root.x[0] — depth 2.

    Adversary critique — iteration 4

    Principle Score Reasoning
    1. Simple 7 One buffer and one concept, but the "array order = physical wiring order = running-sum slicing" rule is non-trivial.
    2. Columnar 10 One coordinate store.
    3. Hand-writable 7 Simplest-case is now 5 lines — regression from iter 3.
    4. Flat 9 Depth 2.
    5. Common-simple 7 Mandatory segments array is overhead for the single-strip case.

    Average: 8.0 / 10. Lowest: principles 1, 3, 5 tied at 7. (Regression from iter 3.)

    Specific weaknesses to fix.

    • The at field is fully redundant with running-sum of prior counts. Drop it.
    • Make segments optional: if omitted, default to single implicit segment covering all of x[]. Restores iter-3 minimum.
    • The "array order = physical order" rule is implicit and load-bearing — name it explicitly in the schema or document the running-sum contract inline.

    Verdict: Continue.

  11. zackees commented on Jun 14, 2026

    @zackees
    OwnerAuthor

    Round 5 — Ideal reached

    Generator — Iteration 5: Implicit single-chain with optional chain + fork

    What changed from iteration 4.

    1. Dropped at. Signal index is running sum of prior non-fork counts on the same pin; physical index is running sum of every prior count.
    2. Made segments optional, renamed to chain. If chain is omitted, the file is a single implicit segment spanning all of x[]. Simplest case back to 4 lines.
    3. Named the implicit rule in the field name: chain communicates "array order = wiring order = physical order = signal order (unless fork)."

    Schema (worked example).

    {
      "x": [/* 123 floats */],
      "y": [/* 123 floats */],
      "chain": [
        { "pin": "pin1", "count": 11 },               // A:  signal [0..11),   physical [0..11)
        { "pin": "pin1", "count": 23 },               // B0: signal [11..34),  physical [11..34)
        { "pin": "pin1", "count": 23, "fork": true }, // B1: signal [11..34),  physical [34..57)  (mirrors B0)
        { "pin": "pin1", "count": 66 }                // D:  signal [34..100), physical [57..123)
      ]
    }

    Pin1 signal length = 11 + 23 + 66 = 100. Physical buffer length = 11 + 23 + 23 + 66 = 123. fork: true requires the immediately-preceding segment on the same pin to have matching count.

    Simplest-case file (one strip, one chain, no fork).

    {
      "x": [0, 1, 2, 3],
      "y": [0, 0, 0, 0]
    }

    4 lines. Parser infers one segment of length x.length on a default pin.

    Depth to first float in canonical form. root.x[0] — depth 2.

    Adversary critique — iteration 5

    Principle Score Reasoning
    1. Simple 8 One concept (chain) for the common case; fork is additive opt-in, though "implicit signal index = running sum of non-fork counts" is still an implicit rule.
    2. Columnar 10 Single x[]/y[] store, maps directly to Float32Array.
    3. Hand-writable 10 Simplest-case 4 lines, no chain block required.
    4. Flat 9 root.x[0] — depth 2.
    5. Common-simple 9 Common case trivially small; uncommon cases add chain entries and an optional fork boolean without restructuring.

    Average: 9.2 / 10. Lowest: principle 1 at 8. All principles ≥ 7. Average ≥ 8.5.

    Residual nits (not blocking ideal):

    • "Shares signal range with immediately-preceding segment on same pin" is a non-obvious semantic; an explicit signal offset could remove the preceding-segment coupling.
    • Repeating pin on every chain entry invites typos; not a blocker.
    • Signal-index vs physical-index distinction is implicit — one spec sentence carries weight, but doesn't appear in the data.

    Verdict: Ideal.


    Final schema (the winner)

    {
      "x": [/* parallel float array */],
      "y": [/* parallel float array, same length as x */],
      "z": [/* optional, parallel, same length as x; 3D */],
    
      "chain": [
        { "pin": "pin1", "count": 11 },
        { "pin": "pin1", "count": 23 },
        { "pin": "pin1", "count": 23, "fork": true },
        { "pin": "pin1", "count": 66 }
      ]
    }

    Rules in one paragraph. x/y (optionally z) are parallel float arrays — the only place coordinates live. If chain is omitted, the file is a single implicit segment of length x.length on a default pin. Otherwise, each chain entry is one segment in physical wiring order: its physical slice is x[runningSum(priorCounts)..runningSum + count). Its signal range is [runningSum(priorNonForkCountsOnThisPin)..+count). fork: true re-uses the immediately-preceding segment-on-same-pin's signal range while occupying its own physical slice; counts must match. z, group labels, and per-segment metadata are additive.

    Why this won the loop.

    • Common case: 4 lines, just {x, y}. No ceremony.
    • Forks: one boolean field on a chain entry.
    • 3D: one extra parallel array.
    • Coordinates: single parallel-array store, Float32Array(json.x) works.
    • Depth: 2 to first float in the canonical case.
    • One concept (chain), with one positional rule (array order = wiring order), and one explicit opt-out (fork).

    Ledger closed.

  12. zackees commented on Jun 14, 2026

    @zackees
    OwnerAuthor

    Superseded by #92, which captures the final v2 schema and the parser/dispatch plan to implement. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions