"use strict"; const { describe, it } = require("node:test"); const assert = require("node:assert/strict"); const { textureColumnIndex, textureColumnUv, faceTileX } = require("../src/textureColumn.js"); describe("textureColumnIndex", () => { it("maps 0 to first column", () => { assert.equal(textureColumnIndex(0, 400), 0); }); it("maps almost-1 to last column", () => { assert.equal(textureColumnIndex(0.999, 400), 399); }); it("clamps above 1", () => { assert.equal(textureColumnIndex(1.5, 64), 63); }); it("clamps below 0", () => { assert.equal(textureColumnIndex(-0.2, 64), 0); }); it("covers every source column for a dense tileX sweep", () => { const w = 64; const seen = new Set(); for (let i = 0; i < w; i++) { seen.add(textureColumnIndex((i + 0.5) / w, w)); } assert.equal(seen.size, w); for (let i = 0; i < w; i++) { assert.ok(seen.has(i), "missing column " + i); } }); }); describe("textureColumnUv", () => { it("always has source width 1 in UV space", () => { const w = 100; for (const t of [0, 0.5, 0.999]) { const uv = textureColumnUv(t, w); assert.equal(uv.sw, 1); assert.ok(Math.abs((uv.u1 - uv.u0) * w - 1) < 1e-9); assert.equal(uv.sx, textureColumnIndex(t, w)); } }); }); describe("faceTileX (no +1 bias)", () => { it("north face uses local/size without +1/size shift", () => { assert.ok(Math.abs(faceTileX(16, 32, "north") - 0.5) < 1e-9); assert.ok(Math.abs(faceTileX(0, 32, "north") - 0) < 1e-9); }); it("south face mirrors", () => { assert.ok(Math.abs(faceTileX(8, 32, "south") - (1 - 0.25)) < 1e-9); }); });