import { describe, expect, it } from 'vitest'; import { wallFaces } from './walls.js'; import { rectShape } from './shapes.js'; describe('wallFaces', () => { it('builds a quad strip around a rectangle', () => { const wall = wallFaces(rectShape(2, 2), 1); // 4 outline points * 2 vertices each. expect(wall.positions.length / 3).toBe(8); expect(wall.indices.length).toBe(4 * 6); // 4 quads * 2 triangles }); it('has outward-facing normals', () => { const wall = wallFaces(rectShape(2, 2), 1); // Bottom edge (from (-1,-1) to (1,-1)) normal should point -Y. // First two vertices belong to the first outline point (-1,-1). const n = wall.normals.slice(0, 3); expect(n[0]).toBeCloseTo(0, 5); expect(n[1]).toBeCloseTo(-1, 5); expect(n[2]).toBeCloseTo(0, 5); }); it('spans from z=0 to z=height', () => { const wall = wallFaces(rectShape(2, 2), 3); // First vertex is bottom (z=0), second is top (z=3). expect(wall.positions[2]).toBe(0); expect(wall.positions[5]).toBe(3); }); it('uses planar UVs from the top face mapping, independent of z', () => { const wall = wallFaces(rectShape(2, 2), 2); // First outline point is (-1,-1) -> planar UV (0, 0). expect(wall.uvs[0]).toBeCloseTo(0, 5); expect(wall.uvs[1]).toBeCloseTo(0, 5); // The bottom and top vertices of the same outline point share a UV, // so the texture is constant down the wall regardless of z. expect(wall.uvs[2]).toBeCloseTo(wall.uvs[0]!, 5); expect(wall.uvs[3]).toBeCloseTo(wall.uvs[1]!, 5); // Third outline point is (1, 1) -> planar UV (1, 1). expect(wall.uvs[8]).toBeCloseTo(1, 5); expect(wall.uvs[9]).toBeCloseTo(1, 5); }); });