"use strict"; /** * Pixel-level check: with a synthetic N-column palette texture, each screen * column's chosen source index must be exactly one texel column (sw=1) and * the mapping must be able to reach every source column. */ const { describe, it } = require("node:test"); const assert = require("node:assert/strict"); const { textureColumnIndex, textureColumnUv } = require("../src/textureColumn.js"); describe("column pixel contract", () => { it("legacy bug (sw=widthLine, max(1,...)) cannot reach column 0 or use sw=1", () => { const texW = 400; const widthLine = 4; // typical screen column width at low resolution function legacySubImg (tileX) { return Math.min(texW - widthLine, Math.max(1, tileX * texW)); } assert.notEqual(legacySubImg(0), 0); assert.ok(legacySubImg(0.999) <= texW - widthLine); const fixed = textureColumnUv(0, texW); assert.equal(fixed.sx, 0); assert.equal(fixed.sw, 1); assert.equal(textureColumnIndex(0.999, texW), texW - 1); }); it("simulated wall sample uses one source column per screen column", () => { const texW = 128; const screenCols = 240; const used = new Set(); for (let i = 0; i < screenCols; i++) { const tileX = i / screenCols; const uv = textureColumnUv(tileX, texW); assert.equal(uv.sw, 1); assert.equal(Math.round((uv.u1 - uv.u0) * texW), 1); used.add(uv.sx); } assert.ok(used.size > 1); assert.ok(used.has(0)); assert.ok(used.has(texW - 1) || used.has(texW - 2)); }); });