Ship shared projects and CAD reliability updates

This commit is contained in:
Formsmith
2026-07-19 15:58:52 +03:00
parent 3a7db063e7
commit c5ce5a80f0
23 changed files with 999 additions and 83 deletions
+8
View File
@@ -5,6 +5,7 @@ import {
CAD_MODIFIER_RUNTIME_BASE,
cadModifierTimeoutMessage,
edgeModifierSelectionStatus,
isCadModifierWasmMemoryFault,
} from "@/lib/cadModifierRuntime";
describe("CAD modifier runtime state", () => {
@@ -27,4 +28,11 @@ describe("CAD modifier runtime state", () => {
it("does not expose thresholds above the worker's folded edge-angle range", () => {
expect(CAD_MODIFIER_MAX_SHARP_ANGLE).toBe(90);
});
it("recognizes browser-specific WebAssembly memory fault messages", () => {
expect(isCadModifierWasmMemoryFault("toBREP: memory access out of bounds")).toBe(true);
expect(isCadModifierWasmMemoryFault("toBREP: Out of bounds memory access (evaluating 'func(...args)')")).toBe(true);
expect(isCadModifierWasmMemoryFault("Unreachable code reached", "RuntimeError")).toBe(true);
expect(isCadModifierWasmMemoryFault("The selected edges cannot be filleted together", "Error")).toBe(false);
});
});
@@ -0,0 +1,58 @@
import { describe, expect, it } from "vitest";
import manifoldModule from "manifold-3d";
import { findSketchOutlineIntersection } from "@/lib/sketchProfileValidation";
describe("sketch profile validation", () => {
it("rejects a bow-tie profile whose non-adjacent edges cross", () => {
expect(findSketchOutlineIntersection([[
{ x: 0, y: 10 },
{ x: 37, y: 10 },
{ x: 3, y: 0 },
{ x: 34, y: 0 },
]])).toEqual({ outlineA: 0, edgeA: 1, outlineB: 0, edgeB: 3 });
});
it("accepts a normal simple profile", () => {
expect(findSketchOutlineIntersection([[
{ x: 0, y: 10 },
{ x: 37, y: 10 },
{ x: 34, y: 0 },
{ x: 3, y: 0 },
]])).toBeNull();
});
it("allows disjoint and nested profiles", () => {
expect(findSketchOutlineIntersection([
[{ x: 0, y: 0 }, { x: 20, y: 0 }, { x: 20, y: 20 }, { x: 0, y: 20 }],
[{ x: 5, y: 5 }, { x: 15, y: 5 }, { x: 15, y: 15 }, { x: 5, y: 15 }],
[{ x: 30, y: 0 }, { x: 40, y: 0 }, { x: 40, y: 10 }, { x: 30, y: 10 }],
])).toBeNull();
});
it("rejects closed profiles that cross or touch each other", () => {
expect(findSketchOutlineIntersection([
[{ x: 0, y: 0 }, { x: 10, y: 0 }, { x: 10, y: 10 }, { x: 0, y: 10 }],
[{ x: 5, y: -5 }, { x: 15, y: -5 }, { x: 15, y: 5 }, { x: 5, y: 5 }],
])).not.toBeNull();
});
it("resolves a bow-tie into valid even-odd regions that can be extruded", async () => {
const runtime = await manifoldModule();
runtime.setup();
const section = new runtime.CrossSection([[
[-18.5, -5],
[18.5, -5],
[-15.5, 5],
[15.5, 5],
]], "EvenOdd");
const solid = section.extrude(10);
try {
expect(section.toPolygons()).toHaveLength(2);
expect(solid.status()).toBe("NoError");
expect(solid.numTri()).toBeGreaterThan(0);
} finally {
solid.delete();
section.delete();
}
});
});
+8
View File
@@ -6,6 +6,7 @@ import { canonicalizeShape } from "@/lib/workplaneShapes";
import {
exportSkfProject,
importSkfProject,
inspectSkfProjectPackage,
SKF_FORMAT_VERSION,
SKF_SCHEMA_ID,
type SkfProjectDocumentV1,
@@ -96,6 +97,7 @@ describe("SketchForge .skf project packages", () => {
const exported = await exportSkfProject(input(shapes));
const { document } = packageDocument(exported);
const summary = await inspectSkfProjectPackage(exported);
const restored = await importSkfProject(exported);
expect(restored.projectName).toBe("Round trip");
@@ -104,6 +106,12 @@ describe("SketchForge .skf project packages", () => {
expect(restored.workspace).toEqual(DEFAULT_WORKPLANE_WORKSPACE);
expect(restored.snapGrid).toBe(DEFAULT_SNAP_GRID);
expect(restored.placementElevation).toBe(12.5);
expect(summary).toEqual({
projectName: "Round trip",
createdAt: 1_700_000_000_000,
modifiedAt: 1_700_000_100_000,
formatVersion: SKF_FORMAT_VERSION,
});
expect(document.assets.filter((entry) => entry.kind === "derived-mesh")).toHaveLength(0);
});
+12
View File
@@ -5,6 +5,7 @@ import {
cleanNearZero,
cleanRotationDegrees,
fallbackSolidColor,
meshYawDegrees,
mirroredAxisCount,
mirrorSign,
normalizeDegrees,
@@ -50,6 +51,17 @@ describe("workplane shape helpers", () => {
expect(cleanRotationDegrees(12.34)).toBe(12.3);
});
it("preserves the meaningful yaw of low-sided circular primitives", () => {
const triangularPrism = shape({ kind: "cylinder", width: 10, depth: 10, sides: 3 });
expect(meshYawDegrees({ ...triangularPrism, rotation: 30 })).toBeCloseTo(30);
expect(meshYawDegrees({ ...triangularPrism, rotation: 150 })).toBeCloseTo(30);
expect(meshYawDegrees({ ...triangularPrism, rotation: 90 })).toBeCloseTo(-30);
expect(meshYawDegrees({ ...triangularPrism, width: 12, rotation: 150 })).toBe(150);
expect(meshYawDegrees({ ...triangularPrism, kind: "box", rotation: 30 })).toBe(30);
expect(meshYawDegrees({ ...triangularPrism, sides: 96, rotation: 90 })).toBe(0);
});
it("cleans near-zero values and derives dimensions", () => {
const base = shape({ size: 30, width: 18, depth: 24 });
expect(cleanNearZero(0.004)).toBe(0);