Update tests for collider and geometry changes
This commit is contained in:
@@ -2,6 +2,7 @@ import { describe, expect, it } from "vitest";
|
||||
|
||||
import { createBoxBrush } from "../../src/document/brushes";
|
||||
import { getBoxBrushBounds, getBoxBrushCornerPositions } from "../../src/geometry/box-brush";
|
||||
import { buildBoxBrushDerivedMeshData, validateBoxBrushGeometry } from "../../src/geometry/box-brush-mesh";
|
||||
|
||||
describe("box brush geometry", () => {
|
||||
it("builds finite bounds and eight corner positions from canonical box data", () => {
|
||||
@@ -67,4 +68,40 @@ describe("box brush geometry", () => {
|
||||
expect(corners).toHaveLength(8);
|
||||
expect(new Set(corners.map((corner) => `${corner.x}:${corner.y}:${corner.z}`)).size).toBe(8);
|
||||
});
|
||||
|
||||
it("triangulates non-planar quad faces deterministically from authored whitebox geometry", () => {
|
||||
const brush = createBoxBrush();
|
||||
brush.geometry.vertices.posX_posY_posZ.z += 0.75;
|
||||
brush.size = {
|
||||
x: 2,
|
||||
y: 2,
|
||||
z: 2.75
|
||||
};
|
||||
|
||||
const diagnostics = validateBoxBrushGeometry(brush);
|
||||
const derivedMesh = buildBoxBrushDerivedMeshData(brush);
|
||||
|
||||
expect(diagnostics).toEqual([]);
|
||||
expect(derivedMesh.faceSurfaces).toHaveLength(6);
|
||||
expect(derivedMesh.faceSurfaces.every((surface) => surface.triangles).flat()).toHaveLength(12);
|
||||
expect(Array.from(derivedMesh.colliderIndices)).toHaveLength(36);
|
||||
});
|
||||
|
||||
it("reports degenerate authored whitebox faces clearly", () => {
|
||||
const brush = createBoxBrush();
|
||||
const collapsedVertex = { x: 1, y: 1, z: 1 };
|
||||
brush.geometry.vertices.negX_posY_posZ = collapsedVertex;
|
||||
brush.geometry.vertices.posX_posY_posZ = collapsedVertex;
|
||||
brush.geometry.vertices.posX_posY_negZ = collapsedVertex;
|
||||
brush.geometry.vertices.negX_posY_negZ = collapsedVertex;
|
||||
|
||||
expect(validateBoxBrushGeometry(brush)).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
code: "degenerate-box-face",
|
||||
faceId: "posY"
|
||||
})
|
||||
])
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user