A position is a place, not just a number (#1421) #1422

Merged
jaylouisw merged 1 commit from fix/layout-position-world into main 2026-11-11 04:27:39 +00:00
Owner

Closes #1421.

Two doors set a device's position — POST /layout and fromJSON() — and both asked for two finite numbers, with the endpoint keeping its own copy of that sentence inline while the engine asked isPosition(). Both accepted 1e308, which is finite and is not a place:

fitView():  bw = maxX - minX = Infinity     ->  zoom clamps to 0.25
            translate(-1e+308,-1e+308)      ->  the canvas draws nothing
            "Fit to view" computes the same arithmetic, so nothing brings it back

The rule, in one place

engine/topology.js: WORLD_LIMIT = 1e6 pixels from the origin (a person drags across a canvas; the largest lab the catalogue builds spans tens of thousands), isPosition(p) for the verdict, positionProblem(p) for the words — so a refusal and the rule cannot disagree.

door before now
POST /layout, 1e308 200, stored 400 E_BAD_POSITION, reason names the limit, nothing stored
POST /layout, positions: [..] / "abc" / {} 200 {"ok":true}, nothing happened 400, says what a map of positions is
POST /layout, unknown device id dropped in silence 200 { ignored: ["ghost"] }
/load, 1e308 adopted, no issue entry dropped, E_LAYOUT_BAD_ENTRY names the limit, board still opens
fitView(), out-of-world position translate(-1e+308), blank framing checked against its own result; default view

The canvas guard is deliberately expressed as "framing the board has to show the board" — the centre of what was measured must land in the viewport — rather than as a copy of WORLD_LIMIT, because a second copy of the number is the thing this PR is about.

Evidence

test/layout-positions.test.js, 18 checks:

  • one table of 15 shapes (the origin, the corners of the world, one pixel past it, ±1e308, strings, nulls, half a position, arrays, scalars) driven through both doors and required to answer identically, with a refusal that names which of the two things is wrong and changes nothing;
  • the bad-positions shapes and the ignored list;
  • what the door stored is what the loader restores;
  • then the real web/canvas.js in a stub DOM: a board spanning the whole world frames at a real scale with its centre near the viewport; a board holding 1e308 opens at the default view instead of blank; an empty board and an ordinary board are unchanged.

Reverts: engine bound → 4/18 fail; endpoint's own copy restored → 1/18; canvas guard removed → 1/18, quoting {"panX":-1e+308,"panY":-1e+308,"zoom":1}.

Suite: 211 suites, 8,064 assertions, 0 failed; syntax 279 files OK. Docs: docs/ARCHITECTURE.md, "A position is a place, not just a number".

Closes #1421. Two doors set a device's position — `POST /layout` and `fromJSON()` — and both asked for two *finite* numbers, with the endpoint keeping its own copy of that sentence inline while the engine asked `isPosition()`. Both accepted `1e308`, which is finite and is not a place: ``` fitView(): bw = maxX - minX = Infinity -> zoom clamps to 0.25 translate(-1e+308,-1e+308) -> the canvas draws nothing "Fit to view" computes the same arithmetic, so nothing brings it back ``` ### The rule, in one place `engine/topology.js`: `WORLD_LIMIT = 1e6` pixels from the origin (a person drags across a canvas; the largest lab the catalogue builds spans tens of thousands), `isPosition(p)` for the verdict, `positionProblem(p)` for the words — so a refusal and the rule cannot disagree. | door | before | now | |---|---|---| | `POST /layout`, `1e308` | `200`, stored | `400 E_BAD_POSITION`, reason names the limit, **nothing stored** | | `POST /layout`, `positions: [..]` / `"abc"` / `{}` | `200 {"ok":true}`, nothing happened | `400`, says what a map of positions is | | `POST /layout`, unknown device id | dropped in silence | `200 { ignored: ["ghost"] }` | | `/load`, `1e308` | adopted, no issue | entry dropped, `E_LAYOUT_BAD_ENTRY` names the limit, board still opens | | `fitView()`, out-of-world position | `translate(-1e+308)`, blank | framing checked against its own result; default view | The canvas guard is deliberately expressed as *"framing the board has to show the board"* — the centre of what was measured must land in the viewport — rather than as a copy of `WORLD_LIMIT`, because a second copy of the number is the thing this PR is about. ### Evidence `test/layout-positions.test.js`, 18 checks: - one table of 15 shapes (the origin, the corners of the world, one pixel past it, `±1e308`, strings, nulls, half a position, arrays, scalars) driven through **both** doors and required to answer identically, with a refusal that names which of the two things is wrong and changes nothing; - the bad-`positions` shapes and the `ignored` list; - what the door stored is what the loader restores; - then the **real `web/canvas.js`** in a stub DOM: a board spanning the whole world frames at a real scale with its centre near the viewport; a board holding `1e308` opens at the default view instead of blank; an empty board and an ordinary board are unchanged. Reverts: engine bound → 4/18 fail; endpoint's own copy restored → 1/18; canvas guard removed → 1/18, quoting `{"panX":-1e+308,"panY":-1e+308,"zoom":1}`. Suite: **211 suites, 8,064 assertions, 0 failed**; syntax 279 files OK. Docs: `docs/ARCHITECTURE.md`, "A position is a place, not just a number".
A position is a place, not just a number (#1421)
All checks were successful
CI / Classify the change (pull_request) Successful in 12s
PR rebase / Rebase onto main and arm auto-merge (pull_request) Successful in 15s
CI / Test (Node 20) (pull_request) Successful in 2m46s
CI / Test (Node 18) (pull_request) Successful in 2m58s
CI / Server smoke test (pull_request) Successful in 28s
CI / Docker build (pull_request) Successful in 44s
CI / Test (Node 22) (pull_request) Successful in 2m36s
031131cf12
Two doors set a device position: POST /layout (the drag, and the tidy-up button) and fromJSON(). Both asked for two finite numbers, and the endpoint kept its own copy of that sentence inline while the engine asked isPosition() - the same one-rule-two-implementations shape that has drifted six times here.

Both accepted 1e308. That is a finite number and not a place: fitView() takes the board width as the largest x minus the smallest, which is Infinity for two such positions, zoom clamps to its 0.25 floor, translate() is handed -1e308, and the canvas draws nothing. 'Fit to view' computes the same arithmetic, so the board cannot be recovered from the UI. The lab is not lost; it cannot be seen, which for a person is the same thing.

Fixed by making the rule one thing in one place: WORLD_LIMIT (1e6 pixels from the origin - generous, a person drags across a canvas and the largest lab the catalogue builds spans tens of thousands), isPosition() for the verdict, positionProblem() for the words. Both doors ask it. A bad entry is refused with E_BAD_POSITION and the reason and nothing is stored; on load the entry is dropped and reported as E_LAYOUT_BAD_ENTRY naming the limit, so the board still opens. A 'positions' that is not a map is 400 instead of 200 {ok:true} that changed nothing, and an id that is not on the board comes back in 'ignored' rather than in silence.

web/canvas.js fitView() checks its own result: if the centre of what it measured does not land in the viewport, the framing failed and the default view is the honest answer - which covers documents written before the limit existed.

Evidence: test/layout-positions.test.js, 18 checks. One table of 15 shapes through both doors, required to answer identically; then the real web/canvas.js in a stub DOM, asserting the property the limit exists for - every position the doors accept is one fitView() can frame. Reverting the engine bound fails 4/18; the endpoint's own copy fails 1/18; the canvas guard fails 1/18 with panX=-1e+308 quoted. Suite: 211 suites, 8,064 assertions, 0 failed; syntax 279 files OK.
jaylouisw scheduled this pull request to auto merge when all checks succeed 2026-11-11 04:27:36 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
jaylouisw/packetforge!1422
No description provided.