| 1 | "use strict"; |
| 2 | const { describe, it } = require("node:test"); |
| 3 | const assert = require("node:assert/strict"); |
| 4 | const PpdaViewFrame = require("../src/ppda/viewFrame.js"); |
| 5 | |
| 6 | describe("PpdaViewFrame", () => |
| 7 | { |
| 8 | it("picks nearest yaw", () => |
| 9 | { |
| 10 | const yaws = [0, 30, 60, 90]; |
| 11 | assert.equal(PpdaViewFrame.pickYaw(10, yaws), 0); |
| 12 | assert.equal(PpdaViewFrame.pickYaw(20, yaws), 30); |
| 13 | assert.equal(PpdaViewFrame.pickYaw(350, yaws), 0); |
| 14 | }); |
| 15 | |
| 16 | it("frameIndex wraps", () => |
| 17 | { |
| 18 | assert.equal(PpdaViewFrame.frameIndex(0, 4, 4), 0); |
| 19 | assert.equal(PpdaViewFrame.frameIndex(1, 4, 4), 0); |
| 20 | assert.equal(PpdaViewFrame.frameIndex(0.6, 4, 4), 2); |
| 21 | }); |
| 22 | |
| 23 | it("uvRect from view", () => |
| 24 | { |
| 25 | const uv = PpdaViewFrame.uvRect({ x: 10, y: 20, w: 5, h: 8 }, 100, 200); |
| 26 | assert.equal(uv.u0, 0.1); |
| 27 | assert.equal(uv.v0, 0.1); |
| 28 | assert.equal(uv.u1, 0.15); |
| 29 | assert.equal(uv.v1, 0.14); |
| 30 | }); |
| 31 | |
| 32 | it("relativeYawDeg front when looking at facing NPC", () => |
| 33 | { |
| 34 | // NPC at origin facing +X (0). Player at +X → sees front → rel ~0 |
| 35 | const rel = PpdaViewFrame.relativeYawDeg(10, 0, 0, 0, 0); |
| 36 | assert.ok(rel < 1 || rel > 359); |
| 37 | }); |
| 38 | }); |