| 1 | "use strict"; |
| 2 | /** |
| 3 | * Pixel-level check: with a synthetic N-column palette texture, each screen |
| 4 | * column's chosen source index must be exactly one texel column (sw=1) and |
| 5 | * the mapping must be able to reach every source column. |
| 6 | */ |
| 7 | const { describe, it } = require("node:test"); |
| 8 | const assert = require("node:assert/strict"); |
| 9 | const { textureColumnIndex, textureColumnUv } = require("../src/textureColumn.js"); |
| 10 | |
| 11 | describe("column pixel contract", () => |
| 12 | { |
| 13 | it("legacy bug (sw=widthLine, max(1,...)) cannot reach column 0 or use sw=1", () => |
| 14 | { |
| 15 | const texW = 400; |
| 16 | const widthLine = 4; // typical screen column width at low resolution |
| 17 | function legacySubImg (tileX) |
| 18 | { |
| 19 | return Math.min(texW - widthLine, Math.max(1, tileX * texW)); |
| 20 | } |
| 21 | assert.notEqual(legacySubImg(0), 0); |
| 22 | assert.ok(legacySubImg(0.999) <= texW - widthLine); |
| 23 | const fixed = textureColumnUv(0, texW); |
| 24 | assert.equal(fixed.sx, 0); |
| 25 | assert.equal(fixed.sw, 1); |
| 26 | assert.equal(textureColumnIndex(0.999, texW), texW - 1); |
| 27 | }); |
| 28 | |
| 29 | it("simulated wall sample uses one source column per screen column", () => |
| 30 | { |
| 31 | const texW = 128; |
| 32 | const screenCols = 240; |
| 33 | const used = new Set(); |
| 34 | for (let i = 0; i < screenCols; i++) |
| 35 | { |
| 36 | const tileX = i / screenCols; |
| 37 | const uv = textureColumnUv(tileX, texW); |
| 38 | assert.equal(uv.sw, 1); |
| 39 | assert.equal(Math.round((uv.u1 - uv.u0) * texW), 1); |
| 40 | used.add(uv.sx); |
| 41 | } |
| 42 | assert.ok(used.size > 1); |
| 43 | assert.ok(used.has(0)); |
| 44 | assert.ok(used.has(texW - 1) || used.has(texW - 2)); |
| 45 | }); |
| 46 | }); |