"use strict"; const { describe, it } = require("node:test"); const assert = require("node:assert/strict"); const PpdaViewFrame = require("../src/ppda/viewFrame.js"); describe("PpdaViewFrame", () => { it("picks nearest yaw", () => { const yaws = [0, 30, 60, 90]; assert.equal(PpdaViewFrame.pickYaw(10, yaws), 0); assert.equal(PpdaViewFrame.pickYaw(20, yaws), 30); assert.equal(PpdaViewFrame.pickYaw(350, yaws), 0); }); it("frameIndex wraps", () => { assert.equal(PpdaViewFrame.frameIndex(0, 4, 4), 0); assert.equal(PpdaViewFrame.frameIndex(1, 4, 4), 0); assert.equal(PpdaViewFrame.frameIndex(0.6, 4, 4), 2); }); it("uvRect from view", () => { const uv = PpdaViewFrame.uvRect({ x: 10, y: 20, w: 5, h: 8 }, 100, 200); assert.equal(uv.u0, 0.1); assert.equal(uv.v0, 0.1); assert.equal(uv.u1, 0.15); assert.equal(uv.v1, 0.14); }); it("relativeYawDeg front when looking at facing NPC", () => { // NPC at origin facing +X (0). Player at +X → sees front → rel ~0 const rel = PpdaViewFrame.relativeYawDeg(10, 0, 0, 0, 0); assert.ok(rel < 1 || rel > 359); }); it("walk-around: front → left (90) → back (180) → right (270)", () => { // NPC at origin facing +X. Yaw 0=front, 90=model left. const yaws = [0, 90, 180, 270]; const facing = 0; // Front: player east assert.equal(PpdaViewFrame.pickYaw( PpdaViewFrame.relativeYawDeg(10, 0, 0, 0, facing), yaws), 0); // NPC's left = north (−Y) assert.equal(PpdaViewFrame.pickYaw( PpdaViewFrame.relativeYawDeg(0, -10, 0, 0, facing), yaws), 90); // Back: west assert.equal(PpdaViewFrame.pickYaw( PpdaViewFrame.relativeYawDeg(-10, 0, 0, 0, facing), yaws), 180); // Right = south (+Y) assert.equal(PpdaViewFrame.pickYaw( PpdaViewFrame.relativeYawDeg(0, 10, 0, 0, facing), yaws), 270); }); it("pickPitchFromHeight ignores look; same height → 0", () => { const pitches = [-45, 0, 45]; assert.equal(PpdaViewFrame.pickPitchFromHeight(16, 16, 50, pitches), 0); // NPC much higher than eye → view from below → negative paperdoll pitch. assert.equal(PpdaViewFrame.pickPitchFromHeight(0, 100, 50, pitches), -45); // NPC much lower → from above → +45 assert.equal(PpdaViewFrame.pickPitchFromHeight(100, 0, 50, pitches), 45); }); });