| 1 | "use strict"; |
| 2 | const { describe, it } = require("node:test"); |
| 3 | const assert = require("node:assert/strict"); |
| 4 | const { |
| 5 | textureColumnIndex, |
| 6 | textureColumnUv, |
| 7 | faceTileX |
| 8 | } = require("../src/textureColumn.js"); |
| 9 | |
| 10 | describe("textureColumnIndex", () => |
| 11 | { |
| 12 | it("maps 0 to first column", () => |
| 13 | { |
| 14 | assert.equal(textureColumnIndex(0, 400), 0); |
| 15 | }); |
| 16 | |
| 17 | it("maps almost-1 to last column", () => |
| 18 | { |
| 19 | assert.equal(textureColumnIndex(0.999, 400), 399); |
| 20 | }); |
| 21 | |
| 22 | it("clamps above 1", () => |
| 23 | { |
| 24 | assert.equal(textureColumnIndex(1.5, 64), 63); |
| 25 | }); |
| 26 | |
| 27 | it("clamps below 0", () => |
| 28 | { |
| 29 | assert.equal(textureColumnIndex(-0.2, 64), 0); |
| 30 | }); |
| 31 | |
| 32 | it("covers every source column for a dense tileX sweep", () => |
| 33 | { |
| 34 | const w = 64; |
| 35 | const seen = new Set(); |
| 36 | for (let i = 0; i < w; i++) |
| 37 | { seen.add(textureColumnIndex((i + 0.5) / w, w)); } |
| 38 | assert.equal(seen.size, w); |
| 39 | for (let i = 0; i < w; i++) |
| 40 | { assert.ok(seen.has(i), "missing column " + i); } |
| 41 | }); |
| 42 | }); |
| 43 | |
| 44 | describe("textureColumnUv", () => |
| 45 | { |
| 46 | it("always has source width 1 in UV space", () => |
| 47 | { |
| 48 | const w = 100; |
| 49 | for (const t of [0, 0.5, 0.999]) |
| 50 | { |
| 51 | const uv = textureColumnUv(t, w); |
| 52 | assert.equal(uv.sw, 1); |
| 53 | assert.ok(Math.abs((uv.u1 - uv.u0) * w - 1) < 1e-9); |
| 54 | assert.equal(uv.sx, textureColumnIndex(t, w)); |
| 55 | } |
| 56 | }); |
| 57 | }); |
| 58 | |
| 59 | describe("faceTileX (no +1 bias)", () => |
| 60 | { |
| 61 | it("north face uses local/size without +1/size shift", () => |
| 62 | { |
| 63 | assert.ok(Math.abs(faceTileX(16, 32, "north") - 0.5) < 1e-9); |
| 64 | assert.ok(Math.abs(faceTileX(0, 32, "north") - 0) < 1e-9); |
| 65 | }); |
| 66 | |
| 67 | it("south face mirrors", () => |
| 68 | { |
| 69 | assert.ok(Math.abs(faceTileX(8, 32, "south") - (1 - 0.25)) < 1e-9); |
| 70 | }); |
| 71 | }); |