BlueGit

timfa raytracer

Files

raytracer / test / depthDecode.test.js

depthDecode.test.js

depthDecode.test.js 1.5 KiB Download Raw
1"use strict";
2const { describe, it } = require("node:test");
3const assert = require("node:assert/strict");
4const DepthDecode = require("../src/ppda/depthDecode.js");
5
6describe("DepthDecode encodings", () =>
7{
8 it("gray 8/16 roundtrip via encode/decode value", () =>
9 {
10 for (const bits of [8, 16])
11 {
12 const fmt = DepthDecode.parseFormat("gray", bits);
13 for (const t of [0, 0.25, 0.5, 1])
14 {
15 const enc = DepthDecode.encodeValue(fmt, t);
16 const back = DepthDecode.decodeValue(fmt, enc[0], enc[1], enc[2]);
17 assert.ok(Math.abs(back - t) < 2e-2, "gray" + bits + " t=" + t);
18 }
19 }
20 });
21
22 it("rgb_bands fills R then G then B", () =>
23 {
24 const fmt = DepthDecode.parseFormat("rgb_bands", 8);
25 const mid = DepthDecode.encodeValue(fmt, 0.5);
26 assert.equal(mid[0], 255);
27 assert.ok(mid[1] > 0);
28 const pix = DepthDecode.decodePixelChannels(fmt, [255, 100, 0, 255]);
29 assert.ok(pix.gray > 0 && pix.alpha === 65535);
30 });
31
32 it("rgb_bands rejects invalid order", () =>
33 {
34 const fmt = DepthDecode.parseFormat("rgb_bands", 8);
35 assert.throws(() => DepthDecode.decodePixelChannels(fmt, [100, 1, 0, 255]));
36 });
37
38 it("rgb_packed positional", () =>
39 {
40 const fmt = DepthDecode.parseFormat("rgb_packed", 8);
41 const enc = DepthDecode.encodeValue(fmt, 0.5);
42 const back = DepthDecode.decodeValue(fmt, enc[0], enc[1], enc[2]);
43 assert.ok(Math.abs(back - 0.5) < 2e-2);
44 });
45
46 it("distanceMeters uses near/far", () =>
47 {
48 assert.equal(DepthDecode.distanceMeters(0, 1, 3), 1);
49 assert.equal(DepthDecode.distanceMeters(65535, 1, 3), 3);
50 });
51});