Skip to content

hex-grid: add all_tris transformer + v2 JSON payload, refactor svg around SerializeGeo - #37

Merged
dynnamitt merged 2 commits into
mainfrom
claude/implement-issue-36-lLjqX
Apr 27, 2026
Merged

hex-grid: add all_tris transformer + v2 JSON payload, refactor svg around SerializeGeo#37
dynnamitt merged 2 commits into
mainfrom
claude/implement-issue-36-lLjqX

Conversation

@dynnamitt

Copy link
Copy Markdown
Owner

Closes #36.

Summary

  • HGridLayout::hex_face_tris() — center-fan flat-top tris (6 per hex, hard-coded fan).
  • HGridLayout::all_tris() — unified triangle stream: gap quads split along the canonical [v0, v2] diagonal, gap junction tris, hex face tris. Diagonal choice now owned in rust, not on the JS client.
  • crates/hex-grid/src/serialize.rs (new) — SerializeGeo trait with four implementors:
    • SvgPlain / SvgRich — existing SVG variants
    • JsonV1 — gen1 payload, byte-compatible with consumers of hex-grid.json (hexes / edges / quads / tris)
    • JsonV2 — gen2 payload { version: 2, tris: [...] } from all_tris()
  • Example renamed svg.rsgeo_export.rs, now a thin CLI wrapper dispatching by --format <svg|svg-rich|json-v1|json-v2>. --rich and --json kept as backward-compat aliases.
  • Makefile — all targets switched to --example geo_export; new svg-json-v2 target emits hex-terrain.json; included in svg-preview deps.
  • web/hex-terrain.html — fetches hex-terrain.json (v2), feeds the unified tris field directly to weldedMesh. The per-source toggles (hex faces / gap quads / gap tris) collapse — only filled / wireframe / flat-shading remain, since the per-source split no longer exists client-side.
  • web/hex-terrain.js — drops unused hexFaceQuads / hexFaceTris helpers (their work moved to rust).
  • crates/hex-grid/README.md — documents the rename, the --format flag, and the new JsonV2 variant.

web/svg-preview.html continues to consume v1 (hex-grid.json) — gen1 stays byte-identical for backward compat.

Decisions (per the issue)

  • v2 payload field name: tris (not all_tris) — JSON only has one tri stream so the prefix is redundant.
  • hex_face_tris() triangulation: center-fan, fastest path.
  • SerializeGeo lives in the lib (crates/hex-grid/src/serialize.rs), not the example.
  • Gap-quad diagonal: [v0, v2] to match prior JS behaviour. Documented on all_tris(); revisit after a visual A/B.

Test plan

  • cargo test -p hex-grid — 35 tests pass (4 new: hex_face_tris_count_is_six_per_hex, hex_face_tris_share_height_per_hex, all_tris_count_matches_components, plus four serialize::tests for each format)
  • cargo build (full workspace) — clean
  • cargo clippy -p hex-grid --examples --tests — clean
  • Smoke test: geo_export -- 2 0.6 --format json-v2 produces {"version":2,"tris":[...]}; --format json-v1 produces the gen1 shape; --rich still works
  • Manual: make svg-preview and load target/svg-preview/hex-terrain.html in a browser to confirm the welded mesh renders identically (rust-owned diagonal vs. JS-owned diagonal)

https://claude.ai/code/session_01QQ3Xnp4qT61EV1Kr6b8HtH


Generated by Claude Code

claude added 2 commits April 27, 2026 08:35
…ound SerializeGeo

Closes #36.

- HGridLayout::hex_face_tris() — center-fan flat-top tris (6 per hex)
- HGridLayout::all_tris() — unified stream: gap quads split along v0→v2,
  gap junction tris, hex face tris. Diagonal choice now owned in rust.
- New crates/hex-grid/src/serialize.rs with SerializeGeo trait and four
  implementors: SvgPlain, SvgRich, JsonV1 (gen1: hexes/edges/quads/tris),
  JsonV2 (gen2: { version, tris }).
- Example renamed svg.rs → geo_export.rs, now a thin CLI wrapper around
  SerializeGeo. --format <svg|svg-rich|json-v1|json-v2>; --rich/--json
  remain as backward-compat aliases.
- Makefile: switch all targets to --example geo_export, add svg-json-v2
  target emitting hex-terrain.json, include in svg-preview deps.
- web/hex-terrain.html now fetches hex-terrain.json (v2), feeds tris
  directly to weldedMesh — drops hex-faces / gap-quads / gap-tris toggles
  since the per-source split is gone client-side.
- web/hex-terrain.js: drop unused hexFaceQuads/hexFaceTris helpers.

https://claude.ai/code/session_01QQ3Xnp4qT61EV1Kr6b8HtH
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 0% with 90 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.29%. Comparing base (d920619) to head (5c3fc73).

Files with missing lines Patch % Lines
crates/hex-grid/src/serialize.rs 0.00% 74 Missing ⚠️
crates/hex-grid/src/layout.rs 0.00% 16 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #37      +/-   ##
==========================================
- Coverage   76.73%   68.29%   -8.45%     
==========================================
  Files          20       21       +1     
  Lines         748      839      +91     
==========================================
- Hits          574      573       -1     
- Misses        174      266      +92     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dynnamitt
dynnamitt merged commit 20e5b3b into main Apr 27, 2026
3 checks passed
@dynnamitt
dynnamitt deleted the claude/implement-issue-36-lLjqX branch April 27, 2026 08:52
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.

Add all_tris transformer + v2 JSON payload, refactor svg.rs around a SerializeGeo trait

3 participants