Repository navigation
feat: add stated relations between boxes to the layout format - #153
Draft
ViktorMikhalkin wants to merge 14 commits into
Draft
ViktorMikhalkin wants to merge 14 commits into
ViktorMikhalkin wants to merge 14 commits into
Conversation
Add relation, align, between and equalSpacing hints with their grammar (gaps on the 1/64 grid, k of n positions, axes) and reference checks. Until the shared solver places them, preferred hints are reported as unsupported and required hints are refused by the engine. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CEu3FJNYjbZ19DyaMxzVhb
check() measures each relation, align, between and equalSpacing hint on the drawn boxes with a tolerance of 1/128 unit, so hand drawings off the grid can pass, and reports the measured and stated values. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CEu3FJNYjbZ19DyaMxzVhb
Each hint becomes difference bounds or integer equalities in 1/64 ticks, with doubled centres for alignment and midpoints, and every row names its hint path, axis and role. Tests tie each row to the geometry that check() measures. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CEu3FJNYjbZ19DyaMxzVhb
Place accepted relations axis by axis on the exact grid, starting from the engine drawing and freeing only the boxes a certificate or a missing grid point names. A contradiction that needs no engine row comes with a certificate in source terms; one that needs the engine's order is a branch conflict; a search without a result is undecided. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CEu3FJNYjbZ19DyaMxzVhb
After the engine and the other hint stages, a lazily loaded stage places required relations, then preferred ones in source order, and reroutes the arrows of moved boxes. Required failures throw StatedRelationsError with a contradiction certificate, a branch conflict or an undecided result; dropped preferred relations reach onUnsupportedHints with their reason. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CEu3FJNYjbZ19DyaMxzVhb
Keep every file under 200 lines and every function under 40, as the repository's budgets require, and give the stated-relation error its own module. Behaviour is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CEu3FJNYjbZ19DyaMxzVhb
A contradiction certificate names each row by a stable id, its hint path, role and origin, with exact weights. A separate checker rebuilds the rows from the source and confirms the weighted sum is impossible; layout never reports a contradiction the checker rejects. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CEu3FJNYjbZ19DyaMxzVhb
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CEu3FJNYjbZ19DyaMxzVhb
Each box a relation frees is held at the nearest feasible offset from its engine position, so results no longer depend on the solver's arbitrary point and translate with the drawing. Property tests cover hints read off a grid drawing, swapped between ends, mirrored relations and translation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CEu3FJNYjbZ19DyaMxzVhb
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CEu3FJNYjbZ19DyaMxzVhb
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CEu3FJNYjbZ19DyaMxzVhb
Placement needs one checked grid point, not two, so preferred relations are no longer dropped as undecided when the system is merely not fixed. When arrows cannot be routed, preferred relations are dropped and the required ones are routed alone. The new example uses all four kinds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CEu3FJNYjbZ19DyaMxzVhb
Lanes are bands along the rank direction, so their order is now a row on that axis and moved lanes fit their members with the engine padding. Tests add an exhaustive small-grid oracle, lanes with required pins in both directions, and a contradiction against lane order. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CEu3FJNYjbZ19DyaMxzVhb
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CEu3FJNYjbZ19DyaMxzVhb
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes for users
Maps can state how boxes relate to each other instead of where they are. Four new hints in
layout.hints, eachpreferred(default) orrequired:relation: a box is right of, left of, above or below another, at leastgapapart (or exactly, with"exact": true). Withoutgap, the layout spacing is used: 64 along the rank direction, 32 across it.align: two or more boxes share a vertical (same: "x") or horizontal (same: "y") line, by centre, start or end.between: a box's centre sitsk/nof the way between two others (the midpoint by default), on one or both axes.equalSpacing: three or more boxes in order with equal gaps between them.layout()places them with dagre, ELK or any engine: after the engine and the other hint stages, a stage loaded only for maps that state these hints moves the boxes the relations need on the exact 1/64 grid and reroutes their arrows. Required relations must all hold. Preferred relations follow in source order; each is accepted whole or reported throughonUnsupportedHintswith reasoncontradictionorundecided. A required relation that cannot be placed throws the newStatedRelationsError, whosedata.statussays which statement layout makes:contradiction, with a certificate: exact weights on rows named by hint paths, pins, same-rank groups and lanes, checked again by an independent checker that rebuilds the rows from the source;branch, when only the engine's drawing order stands in the way;undecided, when no grid placement was found — not a proof about the map;routing, when the boxes were placed but arrows could not be routed.check(source, resolved)judges every relation from the drawing alone with a tolerance of 1/128 unit, so the hints also check maps drawn by hand. The JSON Schema, API report,docs/FORMAT.md,docs/LAYOUT.md, the layout ADR and a new example (examples/relations) describe all of this.Why
Authors often know relations, not coordinates: "the receipt is next to the cashier", "the menu board is halfway between". Pins fix absolute positions and same-rank only lines boxes up along one axis. These hints state the intent directly and keep it checkable.
The meaning is exact on purpose. Each hint compiles to difference bounds or integer equalities in grid ticks, with doubled centres so half-tick midpoints stay exact. A system that has a solution in fractions but none on the grid is reported as undecided, never as a contradiction, and a certificate is only reported after the independent checker accepts it. A conflict that needs the engine's choice of order is reported as such, not as a fault of the map.
Evidence
npm run verify(everything except browser tests, which run in CI): passes; 195 test files, 1567 unit tests.check()(property tests);check()verdicts, tolerance and default gaps;betweenends withk → n − k, mirrored relations, translation;Decisions for the author to review
Not done
Changelog
BEGIN_COMMIT_OVERRIDE
feat: add stated relations between boxes to the layout format
END_COMMIT_OVERRIDE
Generated by Claude Code