// ── How a world position reaches a pixel (PLAN.md §30.3) ───────────────── // // The grid cases are the GAME's answers, not this file's: on 2026-09-25 a probe // on the Oxide rig (a 3000 map, seed 1234) asked `MapHelper.PositionToString` // for these positions and wrote down what it said. A label the page draws that // disagrees with the in-game map is a player walking to the wrong square — and // phase 3's plugin did exactly that for three weeks with a 146.3 m cell (D119). import test from 'node:test' import assert from 'node:assert/strict' import { boundsOf, column, countdown, grid, gridLabel, scaleOf, toLatLng } from '../src/lib/mapGeometry.js' // The rig's map as `GET /map` describes it. const RIG = { worldSize: 3000, oceanMargin: 500, width: 2500, height: 2500, gridCells: 20, gridCellSize: 150 } test('the grid label is the game’s, at every probed position', () => { const probed = [ ['ue_jungle_swamp_a', 764.7, 167.4, 'P8'], ['ue_jungle_swamp_a', 733.7, -556.0, 'O13'], ['harbor_2', 1122.7, 204.6, 'R8'], ['harbor_1', 678.1, 1005.7, 'O3'], ['ferry_terminal_1', 645.4, -1004.1, 'O16'], ['fishing_village_a', -787.8, 224.1, 'E8'], ['fishing_village_c', -203.0, -911.1, 'I16'], ['fishing_village_b', 1142.1, -566.5, 'R13'], ['desert_military_base_c', 94.0, -729.3, 'K14'], ['arctic_research_base_a', -556.9, 840.0, 'G4'], ['powerplant_1', -608.6, -346.4, 'F12'], ['water_treatment_plant_1', 497.8, 84.9, 'N9'], ['nw-corner', -1499, 1499, 'A0'], ['se-corner', 1499, -1499, 'T19'], ['origin', 0, 0, 'K10'], ] for (const [name, x, z, game] of probed) assert.equal(gridLabel(RIG, x, z), game, name) }) test('a 146.3 m cell — phase 3’s constant — would have disagreed with the game', () => { // Kept as a test so the constant cannot come back in a refactor that "fixes" // the cell size to the number community tools quote. assert.notEqual(gridLabel({ ...RIG, gridCells: 21, gridCellSize: 146.3 }, 645.4, -1004.1), 'O16') }) test('columns past Z are spelled the way Rust spells them', () => { assert.equal(column(0), 'A') assert.equal(column(25), 'Z') assert.equal(column(26), 'AA') assert.equal(column(27), 'AB') }) test('the ocean margin is in pixels and is not scaled', () => { assert.equal(scaleOf(RIG), 0.5) // The world's corners sit exactly one margin inside the picture's. assert.deepEqual(toLatLng(RIG, -1500, -1500), [500, 500]) assert.deepEqual(toLatLng(RIG, 1500, 1500), [2000, 2000]) assert.deepEqual(toLatLng(RIG, 0, 0), [1250, 1250]) }) test('north is up: a larger z is a larger latitude, and x is longitude', () => { const [lat1, lng1] = toLatLng(RIG, 100, 100) const [lat2, lng2] = toLatLng(RIG, 100, 400) assert.ok(lat2 > lat1) assert.equal(lng1, lng2) assert.deepEqual(boundsOf(RIG), [[0, 0], [2500, 2500]]) }) test('something off the edge of the world is still placed, outside the picture', () => { // The rig's cargo ship, as the probe found it: past the world AND the margin. const [lat, lng] = toLatLng(RIG, 2691.6, -1453.1) assert.ok(lng > RIG.width) assert.ok(lat > 0 && lat < RIG.height) }) test('the grid has a line per edge and a label per cell, A0 at the north-west corner', () => { const g = grid(RIG) assert.equal(g.lines.length, 2 * (RIG.gridCells + 1)) assert.equal(g.labels.length, RIG.gridCells * RIG.gridCells) const a0 = g.labels.find((l) => l.text === 'A0') assert.deepEqual([a0.x, a0.z], [-1500, 1500]) assert.deepEqual(grid(null), { lines: [], labels: [] }) }) test('a geometry that cannot place anything places nothing rather than NaN everywhere', () => { assert.equal(scaleOf({ worldSize: 0, width: 2500 }), 0) assert.equal(gridLabel({ worldSize: 3000 }, 0, 0), null) }) test('a hack timer reads as minutes and seconds', () => { assert.equal(countdown(540), '9:00') assert.equal(countdown(61.4), '1:01') assert.equal(countdown(-3), '0:00') })