forked from phenom/healer-man
43 lines
2.1 KiB
JavaScript
43 lines
2.1 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
import { readFile } from "node:fs/promises";
|
|
import { sourceNavigationAnchors } from "./source-navigation-anchors.mjs";
|
|
|
|
test("Raksha anchor policy reproduces source entrance and boss positions with strict guards", async () => {
|
|
const recipe = JSON.parse(await readFile(new URL("../recipes/raksha-temple.json", import.meta.url), "utf8"));
|
|
const anchors = sourceNavigationAnchors(recipe, {
|
|
translation: [1857.20312, 86.8668671, 1274.34656], rotation: [0, 0, 0, 1], scale: [1, 1, 1],
|
|
});
|
|
const entry = anchors.find(anchor => anchor.id === "lua-entry");
|
|
const boss = anchors.find(anchor => anchor.id === "shadoj-source-spawn");
|
|
assert.ok(Math.abs(entry.position[1] - 21.01331329) < 1e-8);
|
|
assert.ok(Math.abs(entry.position[2] - 11.334656) < 1e-8);
|
|
assert.ok(Math.abs(boss.position[0] + 115.04822948) < 1e-8);
|
|
assert.equal(entry.maximumDistance, 0.5);
|
|
assert.equal(boss.maximumDistance, 0.25);
|
|
assert.equal(entry.required, true);
|
|
assert.equal(boss.required, true);
|
|
const altered = structuredClone(recipe);
|
|
altered.source.entryCoordinates.position[1] += 1;
|
|
assert.throws(() => sourceNavigationAnchors(altered, {
|
|
translation: [0, 0, 0], rotation: [0, 0, 0, 1], scale: [1, 1, 1],
|
|
}), /must match the authoritative source entry/);
|
|
});
|
|
|
|
test("source anchor conversion includes inverse parent rotation, scale and handedness", () => {
|
|
const recipe = {
|
|
coordinateSystem: { metersPerSourceUnit: 0.1 },
|
|
source: { sourceAnchorSupport: { points: [[14, 8, 18]] } },
|
|
navigation: { includeDetourTopology: true, sourceAnchorComponents: {
|
|
kind: "native-source-anchor-components-v1", maximumProjectionDistance: 4,
|
|
requiredSourcePoints: [{ id: "guard", sourcePosition: [14, 8, 18], maximumDistance: 0.5, evidence: "fixture" }],
|
|
} },
|
|
};
|
|
const anchors = sourceNavigationAnchors(recipe, {
|
|
translation: [10, 2, 20], rotation: [0, Math.SQRT1_2, 0, Math.SQRT1_2], scale: [2, 3, 4],
|
|
});
|
|
for (const [axis, expected] of [0.1, 0.2, -0.1].entries()) {
|
|
assert.ok(Math.abs(anchors[0].position[axis] - expected) < 1e-8);
|
|
}
|
|
});
|