Handover Port BrickNet from python to TypeScript
- What the output settles
Axis check: axes = -col1, and stud/hole needs a signed dot of at least 0.95. Negating both sides cancels, so my old col1-vs-col1 check gave the same result. The port below now follows Python anyway: normalise first, then compare. Kind check: Python tests Kind.stud against Kind.hole, then looks up the sub pair. My old code only checked subs. Kind ownership (from your samples): Kind hole owns hole, tube and post. Kind stud owns stud and open. This holds only for the four stems you printed. Mate table: it matches core.py exactly.
- I’ve read graph.py, core.py and data.py in full and ported everything in them except the parts that depend on tree.py and collision.py. I haven’t run any of this code.
Not ported yet, and why ry4, RX_PI, _graph_edge_rotation, _edge_matrix, decode_graph, graph_to_ldr: these depend on ry4 and RX_PI, which live in tree.py. I’ve only derived the ry4 sign from the yaw formula. The derivation says ry4 is the standard Y rotation, but I haven’t read it. This is blocked until I see tree.py. serialize_tree and parse_sample: also in tree.py, which I haven’t seen. sample_collision_free_tree: it needs collision.py and the 989 MB collider set, which the browser can’t use. The app would use bounds.json instead. What I derived rather than read Edge order: the output order differs from the Python order, so tests compare edges as sets. Random walks: sampleTree takes an injected rand, so random walks won’t match numpy’s sequence. BFS is exact. Ball-edge Euler angles: these match scipy’s as_euler("xyz") except in gimbal lock. I don’t know which angle scipy zeroes there, so there is a flag in mat.ts. One command below settles it.
- tree.py confirms two things. ry4 is the same matrix as my rotYRad, with c,0,s / 0,1,0 / -s,0,c. RX_PI is diag(1,-1,-1). Your gimbal run settles the Euler question. scipy returned [-10, 90, 0] for [10, 90, 20], so it zeroes the third angle and puts a - c in the first.
The last line also confirms the two export scripts wrote labels.json, aliases.json and golden-car.json where the test looks, which is test-data/bricknet relative to app/.
With tree.py read, I can now port edgeMatrix, graphEdgeRotation, decodeGraph, graphToLdr and the path-text codec (serializeTree, parseSample, id2i, i2id). The collision-free sampler stays out because it needs the 989 MB colliders. Tell me when to write it.
Paste the full output of the test run, including any failures. I’m expecting these in roughly this order:
Frames test: it covers connector order and frames for the first 40 stems of car.ldr. Parse test: it compares aliased stems and orthonormalised poses. Edge-parity test: it covers 136 edges with family, flip and yaw. It’s the one that settles whether the port is faithful.
If the parse test fails, the likely culprits are my Newton-iteration orthonormalisation and the alias wrap ordering. The edge test will name the edge key that differs, and I’ll work from that.
- All 5 tests pass, so the port matches BrickNet on car.ldr:
Connectors: order and frames match for the first 40 stems. Parsing: aliases and orthonormalised poses match. Edges: all 136 edges match as sets, including family, flip and yaw/slide/rot to 1e-7. Components: same sizes and members. Placement: placement then detection reproduces BrickNet’s yaw convention. The 3001-on-3001 case gives 8, 2, 1, 2 edges, with yaw equal to turns × 90°. What this does not prove Family coverage: the parity test only exercises the edge families that car.ldr contains. If the car has no ball, fixed or hinge edges, those branches are unchecked. This shows what it covers: bash cd /home/chinapal/brickheart-web/app node -e "const g=require('./test-data/bricknet/golden-car.json');const c={};g.edges.forEach(e=>c[e.family]=(c[e.family]||0)+1);console.log(c)"
If any family is missing, I’d want a second golden model that uses it. An OMR model with hinges and axles would do.
Frame coverage: frames are only compared for 40 stems. I’d widen the dump to all the car’s stems. The -90° gimbal branch: it’s confirmed against scipy by hand, but no test exercises it.
The unported part of BrickNet is now edgeMatrix, graphEdgeRotation, decodeGraph, graphToLdr and the path-text codec. I haven’t started on it. Say when and I’ll write it, with golden tests for each. For the decode tests I’d have you dump decode_graph output and a serialize_tree string for car.ldr.
-
The snapshot tests pass. The failure is isolated to TypeScript typechecking, and the output gives us three distinct issues to investigate. I won't recommend changing source files until we inspect your TypeScript configuration and installed dependencies. What the errors tell us Error Files Meaning TS1484 catalog.ts, graph.ts, pairs.ts, graph.test.ts Types such as M, Conn, and GEdge are imported as regular values, but your TypeScript configuration requires type-only imports. TS1294 catalog.ts, pairs.ts enum Kind and constructor parameter properties (private labels, private cell) are disallowed by the erasableSyntaxOnly setting. TS2591 decode.test.ts, graph.test.ts TypeScript cannot resolve Node.js declarations for node:test, node:assert/strict, and node:fs. This may be a missing dependency or a configuration issue.
-
The Python export and decode steps completed, and all 12 snapshot tests passed. The SciPy gimbal-lock warning is separate from the TypeScript failure.
That clarifies the intended setup. The app uses TypeScript 6, ESM, bundler resolution, verbatimModuleSyntax, and erasableSyntaxOnly. The new snapshot files should be written to conform to those settings unless there is evidence that the project configuration itself is wrong.
Two important findings:
- @types/node is installed, so blindly installing it again is not justified. The types: ["vite/client"] setting is a likely reason TypeScript cannot see the Node declarations.
- The code uses TypeScript constructs explicitly prohibited by erasableSyntaxOnly. Since the setting is intentional in this configuration, the code should be corrected rather than disabling the check.
The existing @types/node dependency is already present, so no new package is needed. The TypeScript fixes can be made using what the project already has.
One detail from the source matters: Kind is used as a numeric enum, and KIND_NAMES[c.kind] relies on numeric indexing. We can preserve those semantics without a TypeScript enum.
*** Minimal patch applied ***
Commands now pass
bash cd /home/chinapal/bricknet python tools/export_bricknet.py /home/chinapal/brickheart-web/app/test-data/bricknet python tools/dump_decode.py /home/chinapal/brickheart-web/app/test-data/bricknet cd /home/chinapal/brickheart-web/app npm run test:snap npm run typecheck
Paste the full output of both npm commands.
What these tests don’t prove Ball edges. The Euler tests check fromEulerXYZ and eulerXYZ against scipy. Nothing checks the ball branches of buildEdges, makeTreeEdge or treeEdgeRow against BrickNet. For that I need a model that contains a ball joint, for example an OMR model. Text comparisons. The two exact-text tests (graph_to_ldr) could differ in the last digit on a value sitting on a 6-decimal rounding tie. The failure message would show which line. Duplicate part names. If a tree uses a stem whose name is shared with a later stem, deepEqual in the parse round-trip fails. Python behaves the same way, so it’s a real property of the format. Parts with no connectors. For these, Python raises KeyError in _conn. My port raises a ParseError. Not ported. sample_collision_free_tree needs the 989 MB colliders. TS sampleTree with method: 'random' is valid but not identical to numpy’s walks.
14583 parts, 2522 aliases pybullet build time: Oct 18 2026 16:48:27 /home/chinapal/bricknet/tools/dump_decode.py:47: UserWarning: Gimbal lock detected. Setting third angle to zero since it is not possible to uniquely determine all angles. "back": Rotation.from_matrix(r.as_matrix()).as_euler("xyz").tolist()}) 1 component trees, 13 parse cases
app@0.0.0 test:snap esbuild src/snap/.test.ts --bundle --platform=node --format=esm --outdir=.test-build --out-extension:.js=.mjs && node --test ".test-build/.test.mjs"
.test-build/decode.test.mjs 34.1kb .test-build/graph.test.mjs 17.5kb
⚡ Done in 11ms ✔ letter IDs round-trip and match the grammar (12.362631ms) ✔ Python number formatting: round(v, 6) and .12g (0.61942ms) ✔ Euler maths matches scipy, including gimbal lock (0.616156ms) ✔ decode_graph matches BrickNet (2.527565ms) ✔ graph_to_ldr (stored transforms) matches BrickNet text (2.035376ms) ✔ component 0: bfs tree, path text, parse, realization (7.766411ms) ✔ parse_sample errors match BrickNet exactly (1.67715ms) ✔ connector order and frames match BrickNet (3.668229ms) ✔ parse: stems, aliases and orthonormalised poses match (0.430992ms) ✔ edges match BrickNet as sets, with parameters (0.742168ms) ✔ components match (0.359308ms) ✔ 3001 stacked: 8 / 2 / 1 / 2 edges for 0..3 turns, yaw = turns * 90 deg (1.757702ms) ℹ tests 12 ℹ suites 0 ℹ pass 12 ℹ fail 0 ℹ cancelled 0 ℹ skipped 0 ℹ todo 0 ℹ duration_ms 325.713477
app@0.0.0 typecheck tsc --noEmit