63 lines
2.6 KiB
TypeScript
63 lines
2.6 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
import { buildCdslSelectorRuntime } from "./cdsl-selector-runtime";
|
|
|
|
test("maps CDSL selector planes onto preview triangles", () => {
|
|
const runtime = buildCdslSelectorRuntime({
|
|
references: [{
|
|
id: "face_top",
|
|
selectorType: "face",
|
|
label: "top",
|
|
center: [0, 0, 10],
|
|
normal: [0, 0, 1],
|
|
frame: { origin_mm: [0, 0, 10], normal: [0, 0, 1], x_dir: [1, 0, 0], y_dir: [0, 1, 0] },
|
|
bbox: { min: [-10, -10, 0], max: [10, 10, 10] },
|
|
}],
|
|
}, {
|
|
// One source XY triangle at z=10, expressed in the preview's X/-Z/Y basis.
|
|
vertices: new Float32Array([0, -10000, 0, 10000, -10000, 0, 0, -10000, 10000]),
|
|
indices: new Uint32Array([0, 1, 2]),
|
|
bounds: { min: [0, -10000, 0], max: [10000, -10000, 10000] },
|
|
});
|
|
|
|
assert.equal(runtime.references.length, 1);
|
|
assert.equal(runtime.proxy.faceIds.length, 1);
|
|
assert.equal(runtime.proxy.faceIds[0], 0);
|
|
assert.deepEqual([...runtime.proxy.faceRuns], [0, 0, 0, 1, 0]);
|
|
assert.equal(runtime.faceReferenceByRowIndex.get(0)?.id, "face_top");
|
|
});
|
|
|
|
test("uses backend face triangle ranges when they are available", () => {
|
|
const runtime = buildCdslSelectorRuntime({
|
|
references: [
|
|
{ id: "face_000", selectorType: "face", center: [0, 0, 0], normal: [0, 0, 1], frame: { origin_mm: [0, 0, 0], normal: [0, 0, 1] }, triangle_start: 0, triangle_count: 1 },
|
|
{ id: "face_001", selectorType: "face", center: [0, 0, 1], normal: [0, 0, -1], frame: { origin_mm: [0, 0, 1], normal: [0, 0, -1] }, triangle_start: 1, triangle_count: 1 },
|
|
],
|
|
}, {
|
|
vertices: new Float32Array(18),
|
|
indices: new Uint32Array([0, 1, 2, 3, 4, 5]),
|
|
});
|
|
|
|
assert.deepEqual([...runtime.proxy.faceIds], [0, 1]);
|
|
assert.deepEqual([...runtime.proxy.faceRuns], [0, 0, 0, 1, 0, 0, 0, 1, 1, 1]);
|
|
});
|
|
|
|
test("keeps face row lookup separate from edge row lookup", () => {
|
|
const runtime = buildCdslSelectorRuntime({
|
|
references: [
|
|
{ id: "face_000", selectorType: "face", center: [0, 0, 0], normal: [0, 0, 1], frame: { origin_mm: [0, 0, 0], normal: [0, 0, 1] } },
|
|
],
|
|
edges: [{
|
|
record_id: "edge_000",
|
|
geometry: { start_mm: [0, 0, 0], end_mm: [1, 0, 0], center_mm: [0.5, 0, 0], bbox_mm: [0, 0, 0, 1, 0, 0], curve_type: "line" },
|
|
}],
|
|
}, {
|
|
vertices: new Float32Array(9),
|
|
indices: new Uint32Array([0, 1, 2]),
|
|
});
|
|
|
|
assert.equal(runtime.faceReferenceByRowIndex.get(0)?.id, "face_000");
|
|
assert.equal(runtime.edgeReferenceByRowIndex.get(0)?.id, "edge_000");
|
|
assert.deepEqual(runtime.faces.map((reference) => reference.id), ["face_000"]);
|
|
});
|