@faicad/faijs-sketch 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +28 -0
- package/NOTICE +28 -0
- package/dist/bspline.d.ts +58 -0
- package/dist/bspline.d.ts.map +1 -0
- package/dist/bspline.js +93 -0
- package/dist/bspline.js.map +1 -0
- package/dist/canonical.d.ts +205 -0
- package/dist/canonical.d.ts.map +1 -0
- package/dist/canonical.js +12 -0
- package/dist/canonical.js.map +1 -0
- package/dist/contour.d.ts +43 -0
- package/dist/contour.d.ts.map +1 -0
- package/dist/contour.js +132 -0
- package/dist/contour.js.map +1 -0
- package/dist/faces.d.ts +28 -0
- package/dist/faces.d.ts.map +1 -0
- package/dist/faces.js +46 -0
- package/dist/faces.js.map +1 -0
- package/dist/fcstd-types.d.ts +177 -0
- package/dist/fcstd-types.d.ts.map +1 -0
- package/dist/fcstd-types.js +67 -0
- package/dist/fcstd-types.js.map +1 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/namespace.d.ts +51 -0
- package/dist/namespace.d.ts.map +1 -0
- package/dist/namespace.js +67 -0
- package/dist/namespace.js.map +1 -0
- package/dist/node.d.ts +14 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +34 -0
- package/dist/node.js.map +1 -0
- package/dist/op.d.ts +67 -0
- package/dist/op.d.ts.map +1 -0
- package/dist/op.js +104 -0
- package/dist/op.js.map +1 -0
- package/dist/planegcs-backend.d.ts +46 -0
- package/dist/planegcs-backend.d.ts.map +1 -0
- package/dist/planegcs-backend.js +696 -0
- package/dist/planegcs-backend.js.map +1 -0
- package/dist/project.d.ts +115 -0
- package/dist/project.d.ts.map +1 -0
- package/dist/project.js +329 -0
- package/dist/project.js.map +1 -0
- package/dist/solve.d.ts +21 -0
- package/dist/solve.d.ts.map +1 -0
- package/dist/solve.js +102 -0
- package/dist/solve.js.map +1 -0
- package/dist/solver.d.ts +63 -0
- package/dist/solver.d.ts.map +1 -0
- package/dist/solver.js +28 -0
- package/dist/solver.js.map +1 -0
- package/dist/verify.d.ts +53 -0
- package/dist/verify.d.ts.map +1 -0
- package/dist/verify.js +71 -0
- package/dist/verify.js.map +1 -0
- package/package.json +65 -0
package/dist/node.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @faicad/faijs-sketch/node — Node-only entry.
|
|
3
|
+
*
|
|
4
|
+
* Resolves the planegcs WASM binary from the installed package and hands it to
|
|
5
|
+
* the environment-agnostic solver factory. Browser/worker hosts must not import
|
|
6
|
+
* this subpath — they inject wasm bytes through `HostPorts.assets` and call
|
|
7
|
+
* `createPlanegcsSolver({ wasmBytes })` from the main entry instead.
|
|
8
|
+
*/
|
|
9
|
+
import { createRequire } from 'node:module';
|
|
10
|
+
import { dirname, join } from 'node:path';
|
|
11
|
+
import { createPlanegcsSolver } from './planegcs-backend.js';
|
|
12
|
+
const require = createRequire(import.meta.url);
|
|
13
|
+
let wasmPathCache;
|
|
14
|
+
/**
|
|
15
|
+
* Resolve the planegcs WASM binary path from the installed package.
|
|
16
|
+
*
|
|
17
|
+
* @returns the absolute path of `planegcs.wasm` inside `@salusoft89/planegcs`.
|
|
18
|
+
*/
|
|
19
|
+
export function planegcsWasmPath() {
|
|
20
|
+
if (!wasmPathCache) {
|
|
21
|
+
const pkgDir = dirname(require.resolve('@salusoft89/planegcs/package.json'));
|
|
22
|
+
wasmPathCache = join(pkgDir, 'dist', 'planegcs_dist', 'planegcs.wasm');
|
|
23
|
+
}
|
|
24
|
+
return wasmPathCache;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Instantiate the planegcs solver using the installed wasm binary.
|
|
28
|
+
*
|
|
29
|
+
* @returns a `SketchSolver` backed by the planegcs WASM module.
|
|
30
|
+
*/
|
|
31
|
+
export async function createNodePlanegcsSolver() {
|
|
32
|
+
return createPlanegcsSolver({ wasmPath: planegcsWasmPath() });
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=node.js.map
|
package/dist/node.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.js","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAA;AAG5D,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAE9C,IAAI,aAAiC,CAAA;AAErC;;;;GAIG;AACH,MAAM,UAAU,gBAAgB;IAC9B,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,mCAAmC,CAAC,CAAC,CAAA;QAC5E,aAAa,GAAG,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,eAAe,CAAC,CAAA;IACxE,CAAC;IACD,OAAO,aAAa,CAAA;AACtB,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,wBAAwB;IAC5C,OAAO,oBAAoB,CAAC,EAAE,QAAQ,EAAE,gBAAgB,EAAE,EAAE,CAAC,CAAA;AAC/D,CAAC","sourcesContent":["/**\n * @faicad/faijs-sketch/node — Node-only entry.\n *\n * Resolves the planegcs WASM binary from the installed package and hands it to\n * the environment-agnostic solver factory. Browser/worker hosts must not import\n * this subpath — they inject wasm bytes through `HostPorts.assets` and call\n * `createPlanegcsSolver({ wasmBytes })` from the main entry instead.\n */\nimport { createRequire } from 'node:module'\nimport { dirname, join } from 'node:path'\nimport { createPlanegcsSolver } from './planegcs-backend.js'\nimport type { SketchSolver } from './solver.js'\n\nconst require = createRequire(import.meta.url)\n\nlet wasmPathCache: string | undefined\n\n/**\n * Resolve the planegcs WASM binary path from the installed package.\n *\n * @returns the absolute path of `planegcs.wasm` inside `@salusoft89/planegcs`.\n */\nexport function planegcsWasmPath(): string {\n if (!wasmPathCache) {\n const pkgDir = dirname(require.resolve('@salusoft89/planegcs/package.json'))\n wasmPathCache = join(pkgDir, 'dist', 'planegcs_dist', 'planegcs.wasm')\n }\n return wasmPathCache\n}\n\n/**\n * Instantiate the planegcs solver using the installed wasm binary.\n *\n * @returns a `SketchSolver` backed by the planegcs WASM module.\n */\nexport async function createNodePlanegcsSolver(): Promise<SketchSolver> {\n return createPlanegcsSolver({ wasmPath: planegcsWasmPath() })\n}"]}
|
package/dist/op.d.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { Shape } from '@faicad/faijs/mesh/types';
|
|
2
|
+
import type { SketchConstraint, SketchGeom, SolveOutcome } from './canonical.js';
|
|
3
|
+
import type { SketchSolver } from './solver.js';
|
|
4
|
+
/** The op name `cad.sketch`. */
|
|
5
|
+
export declare const SKETCH_OP_NAME: "sketch";
|
|
6
|
+
/**
|
|
7
|
+
* Install the host's planegcs solver factory.
|
|
8
|
+
*
|
|
9
|
+
* Node hosts pass `createNodePlanegcsSolver` from `@faicad/faijs-sketch/node`;
|
|
10
|
+
* browser hosts pass a factory that resolves the wasm bytes through
|
|
11
|
+
* `HostPorts.assets` and calls `createPlanegcsSolver({ wasmBytes })`.
|
|
12
|
+
*
|
|
13
|
+
* @param factory - async factory returning a `SketchSolver`.
|
|
14
|
+
*/
|
|
15
|
+
export declare function installSketchSolver(factory: () => Promise<SketchSolver>): void;
|
|
16
|
+
/** Undo {@link installSketchSolver}. */
|
|
17
|
+
export declare function uninstallSketchSolver(): void;
|
|
18
|
+
/**
|
|
19
|
+
* Install a diagnostics sink for non-`solved` outcomes (§5: allow ≠ silent).
|
|
20
|
+
*
|
|
21
|
+
* Hosts bridge this to their `HostPorts.events` sink / UI. Under-, redundant-
|
|
22
|
+
* and conflicting-constraint sketches still produce geometry, but the
|
|
23
|
+
* diagnostic must reach the host.
|
|
24
|
+
*
|
|
25
|
+
* @param sink - receives every non-`solved` solve outcome; `null` clears it.
|
|
26
|
+
*/
|
|
27
|
+
export declare function setSketchDiagnosticSink(sink: ((outcome: SolveOutcome) => void) | null): void;
|
|
28
|
+
/** `cad.sketch` parameters. */
|
|
29
|
+
export interface SketchParams {
|
|
30
|
+
geoms: SketchGeom[];
|
|
31
|
+
/** Optional — a constraint-free sketch is equivalent to `cad.profile` usage. */
|
|
32
|
+
constraints?: SketchConstraint[];
|
|
33
|
+
/** Product form: `'face'` (default) or `'wire'` (outer wire for sweep spines). */
|
|
34
|
+
as?: 'face' | 'wire';
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Validate `cad.sketch` parameters: `geoms` must be a non-empty array and
|
|
38
|
+
* `constraints`, when present, an array.
|
|
39
|
+
*
|
|
40
|
+
* @param params - the raw sketch operation parameters.
|
|
41
|
+
*/
|
|
42
|
+
export declare function assertSketchParams(params: Record<string, unknown>): void;
|
|
43
|
+
/**
|
|
44
|
+
* Sketch (geometry + constraints) → solve → face / outer wire.
|
|
45
|
+
*
|
|
46
|
+
* brep-only in the first release (D5): the mesh path reports
|
|
47
|
+
* `E_MESH_UNSUPPORTED`, matching `cad.profile` / `cad.extrude`.
|
|
48
|
+
*
|
|
49
|
+
* @group 创建
|
|
50
|
+
* @inputs 0
|
|
51
|
+
* @async true
|
|
52
|
+
* @qual ok
|
|
53
|
+
* @name sketch
|
|
54
|
+
* @returns Shape 平面几何(求解后构面);`as:'wire'` 时返回外环 1D 曲线。
|
|
55
|
+
* @param params.geoms - 草图几何(线段/圆/圆弧)。type:SketchGeom[] required:true
|
|
56
|
+
* @param params.constraints - 草图约束(可空)。type:SketchConstraint[] required:false
|
|
57
|
+
* @param params.as - 产物形态:'face'(默认)构面;'wire' 只交外环 wire。type:'face'|'wire' required:false
|
|
58
|
+
* @example
|
|
59
|
+
* const f = cad.sketch({
|
|
60
|
+
* geoms: [{ tag:'bottom', kind:'line', x1:0, y1:0, x2:80, y2:3 }],
|
|
61
|
+
* constraints: [{ kind:'horizontal', of: { tag:'bottom' } }, { kind:'length', of: { tag:'bottom' }, value: 80 }],
|
|
62
|
+
* })
|
|
63
|
+
*/
|
|
64
|
+
export declare const sketch: ((params: Record<string, unknown>) => Promise<Shape>) & {
|
|
65
|
+
__faijs__dualOp?: import("@faicad/faijs/sdk").DualOpMeta;
|
|
66
|
+
};
|
|
67
|
+
//# sourceMappingURL=op.d.ts.map
|
package/dist/op.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"op.d.ts","sourceRoot":"","sources":["../src/op.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAA;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAEhF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE/C,gCAAgC;AAChC,eAAO,MAAM,cAAc,EAAG,QAAiB,CAAA;AAK/C;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,OAAO,CAAC,YAAY,CAAC,GAAG,IAAI,CAE9E;AAED,wCAAwC;AACxC,wBAAgB,qBAAqB,IAAI,IAAI,CAE5C;AAED;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,CAAC,CAAC,OAAO,EAAE,YAAY,KAAK,IAAI,CAAC,GAAG,IAAI,GAAG,IAAI,CAE5F;AAED,+BAA+B;AAC/B,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,UAAU,EAAE,CAAA;IACnB,gFAAgF;IAChF,WAAW,CAAC,EAAE,gBAAgB,EAAE,CAAA;IAChC,kFAAkF;IAClF,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;CACrB;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAQxE;AASD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,MAAM;;CAgBjB,CAAA"}
|
package/dist/op.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* op — the `cad.sketch` script-face op (sketch geometry + constraints → face).
|
|
3
|
+
*
|
|
4
|
+
* This op is provided by the sketch library, not core: a host merges it into
|
|
5
|
+
* the `cad` namespace (see `./namespace`) only when it wants sketch support.
|
|
6
|
+
* The planegcs solver is host-injected (`installSketchSolver`) because the wasm
|
|
7
|
+
* source differs between Node and browser hosts — the library itself never
|
|
8
|
+
* imports `node:*`.
|
|
9
|
+
*/
|
|
10
|
+
import { defineOp } from '@faicad/faijs/sdk';
|
|
11
|
+
import { sketchFaces } from './faces.js';
|
|
12
|
+
/** The op name `cad.sketch`. */
|
|
13
|
+
export const SKETCH_OP_NAME = 'sketch';
|
|
14
|
+
let solverFactory;
|
|
15
|
+
let diagnosticSink;
|
|
16
|
+
/**
|
|
17
|
+
* Install the host's planegcs solver factory.
|
|
18
|
+
*
|
|
19
|
+
* Node hosts pass `createNodePlanegcsSolver` from `@faicad/faijs-sketch/node`;
|
|
20
|
+
* browser hosts pass a factory that resolves the wasm bytes through
|
|
21
|
+
* `HostPorts.assets` and calls `createPlanegcsSolver({ wasmBytes })`.
|
|
22
|
+
*
|
|
23
|
+
* @param factory - async factory returning a `SketchSolver`.
|
|
24
|
+
*/
|
|
25
|
+
export function installSketchSolver(factory) {
|
|
26
|
+
solverFactory = factory;
|
|
27
|
+
}
|
|
28
|
+
/** Undo {@link installSketchSolver}. */
|
|
29
|
+
export function uninstallSketchSolver() {
|
|
30
|
+
solverFactory = undefined;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Install a diagnostics sink for non-`solved` outcomes (§5: allow ≠ silent).
|
|
34
|
+
*
|
|
35
|
+
* Hosts bridge this to their `HostPorts.events` sink / UI. Under-, redundant-
|
|
36
|
+
* and conflicting-constraint sketches still produce geometry, but the
|
|
37
|
+
* diagnostic must reach the host.
|
|
38
|
+
*
|
|
39
|
+
* @param sink - receives every non-`solved` solve outcome; `null` clears it.
|
|
40
|
+
*/
|
|
41
|
+
export function setSketchDiagnosticSink(sink) {
|
|
42
|
+
diagnosticSink = sink ?? undefined;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Validate `cad.sketch` parameters: `geoms` must be a non-empty array and
|
|
46
|
+
* `constraints`, when present, an array.
|
|
47
|
+
*
|
|
48
|
+
* @param params - the raw sketch operation parameters.
|
|
49
|
+
*/
|
|
50
|
+
export function assertSketchParams(params) {
|
|
51
|
+
const geoms = params.geoms;
|
|
52
|
+
if (!Array.isArray(geoms) || geoms.length === 0) {
|
|
53
|
+
throw new Error('E_SKETCHC_NO_GEOMS: sketch requires at least one geometry');
|
|
54
|
+
}
|
|
55
|
+
if (params.constraints !== undefined && !Array.isArray(params.constraints)) {
|
|
56
|
+
throw new Error('E_SKETCHC_BAD_CONSTRAINTS: constraints must be an array');
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async function resolveSolver() {
|
|
60
|
+
if (!solverFactory) {
|
|
61
|
+
throw new Error('E_SKETCHC_NO_SOLVER: no sketch solver installed (call installSketchSolver)');
|
|
62
|
+
}
|
|
63
|
+
return solverFactory();
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Sketch (geometry + constraints) → solve → face / outer wire.
|
|
67
|
+
*
|
|
68
|
+
* brep-only in the first release (D5): the mesh path reports
|
|
69
|
+
* `E_MESH_UNSUPPORTED`, matching `cad.profile` / `cad.extrude`.
|
|
70
|
+
*
|
|
71
|
+
* @group 创建
|
|
72
|
+
* @inputs 0
|
|
73
|
+
* @async true
|
|
74
|
+
* @qual ok
|
|
75
|
+
* @name sketch
|
|
76
|
+
* @returns Shape 平面几何(求解后构面);`as:'wire'` 时返回外环 1D 曲线。
|
|
77
|
+
* @param params.geoms - 草图几何(线段/圆/圆弧)。type:SketchGeom[] required:true
|
|
78
|
+
* @param params.constraints - 草图约束(可空)。type:SketchConstraint[] required:false
|
|
79
|
+
* @param params.as - 产物形态:'face'(默认)构面;'wire' 只交外环 wire。type:'face'|'wire' required:false
|
|
80
|
+
* @example
|
|
81
|
+
* const f = cad.sketch({
|
|
82
|
+
* geoms: [{ tag:'bottom', kind:'line', x1:0, y1:0, x2:80, y2:3 }],
|
|
83
|
+
* constraints: [{ kind:'horizontal', of: { tag:'bottom' } }, { kind:'length', of: { tag:'bottom' }, value: 80 }],
|
|
84
|
+
* })
|
|
85
|
+
*/
|
|
86
|
+
export const sketch = defineOp({
|
|
87
|
+
name: SKETCH_OP_NAME,
|
|
88
|
+
capabilities: ['directEdit'],
|
|
89
|
+
async brep(params) {
|
|
90
|
+
assertSketchParams(params);
|
|
91
|
+
const solver = await resolveSolver();
|
|
92
|
+
const p = params;
|
|
93
|
+
return sketchFaces(p.geoms, p.constraints ?? [], {
|
|
94
|
+
solver,
|
|
95
|
+
as: p.as,
|
|
96
|
+
onDiagnostic: (outcome) => {
|
|
97
|
+
if (outcome.status !== 'solved')
|
|
98
|
+
diagnosticSink?.(outcome);
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
},
|
|
102
|
+
naming: { kind: 'construct', newFaces: { via: 'explicit', vocab: [] } },
|
|
103
|
+
});
|
|
104
|
+
//# sourceMappingURL=op.js.map
|
package/dist/op.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"op.js","sourceRoot":"","sources":["../src/op.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAI5C,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAGxC,gCAAgC;AAChC,MAAM,CAAC,MAAM,cAAc,GAAG,QAAiB,CAAA;AAE/C,IAAI,aAAwD,CAAA;AAC5D,IAAI,cAA6D,CAAA;AAEjE;;;;;;;;GAQG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAoC;IACtE,aAAa,GAAG,OAAO,CAAA;AACzB,CAAC;AAED,wCAAwC;AACxC,MAAM,UAAU,qBAAqB;IACnC,aAAa,GAAG,SAAS,CAAA;AAC3B,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,uBAAuB,CAAC,IAA8C;IACpF,cAAc,GAAG,IAAI,IAAI,SAAS,CAAA;AACpC,CAAC;AAWD;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,MAA+B;IAChE,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAA;IAC1B,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAChD,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAA;IAC9E,CAAC;IACD,IAAI,MAAM,CAAC,WAAW,KAAK,SAAS,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC;QAC3E,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAA;IAC5E,CAAC;AACH,CAAC;AAED,KAAK,UAAU,aAAa;IAC1B,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,4EAA4E,CAAC,CAAA;IAC/F,CAAC;IACD,OAAO,aAAa,EAAE,CAAA;AACxB,CAAC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,QAAQ,CAAC;IAC7B,IAAI,EAAE,cAAc;IACpB,YAAY,EAAE,CAAC,YAAY,CAAC;IAC5B,KAAK,CAAC,IAAI,CAAC,MAA+B;QACxC,kBAAkB,CAAC,MAAM,CAAC,CAAA;QAC1B,MAAM,MAAM,GAAG,MAAM,aAAa,EAAE,CAAA;QACpC,MAAM,CAAC,GAAG,MAAiC,CAAA;QAC3C,OAAO,WAAW,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,WAAW,IAAI,EAAE,EAAE;YAC/C,MAAM;YACN,EAAE,EAAE,CAAC,CAAC,EAAE;YACR,YAAY,EAAE,CAAC,OAAO,EAAE,EAAE;gBACxB,IAAI,OAAO,CAAC,MAAM,KAAK,QAAQ;oBAAE,cAAc,EAAE,CAAC,OAAO,CAAC,CAAA;YAC5D,CAAC;SACF,CAAC,CAAA;IACJ,CAAC;IACD,MAAM,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,EAAE,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE,EAAE,EAAgB;CACtF,CAAC,CAAA","sourcesContent":["/**\n * op — the `cad.sketch` script-face op (sketch geometry + constraints → face).\n *\n * This op is provided by the sketch library, not core: a host merges it into\n * the `cad` namespace (see `./namespace`) only when it wants sketch support.\n * The planegcs solver is host-injected (`installSketchSolver`) because the wasm\n * source differs between Node and browser hosts — the library itself never\n * imports `node:*`.\n */\nimport { defineOp } from '@faicad/faijs/sdk'\nimport type { Provenance } from '@faicad/faijs/topology/naming'\nimport type { Shape } from '@faicad/faijs/mesh/types'\nimport type { SketchConstraint, SketchGeom, SolveOutcome } from './canonical.js'\nimport { sketchFaces } from './faces.js'\nimport type { SketchSolver } from './solver.js'\n\n/** The op name `cad.sketch`. */\nexport const SKETCH_OP_NAME = 'sketch' as const\n\nlet solverFactory: (() => Promise<SketchSolver>) | undefined\nlet diagnosticSink: ((outcome: SolveOutcome) => void) | undefined\n\n/**\n * Install the host's planegcs solver factory.\n *\n * Node hosts pass `createNodePlanegcsSolver` from `@faicad/faijs-sketch/node`;\n * browser hosts pass a factory that resolves the wasm bytes through\n * `HostPorts.assets` and calls `createPlanegcsSolver({ wasmBytes })`.\n *\n * @param factory - async factory returning a `SketchSolver`.\n */\nexport function installSketchSolver(factory: () => Promise<SketchSolver>): void {\n solverFactory = factory\n}\n\n/** Undo {@link installSketchSolver}. */\nexport function uninstallSketchSolver(): void {\n solverFactory = undefined\n}\n\n/**\n * Install a diagnostics sink for non-`solved` outcomes (§5: allow ≠ silent).\n *\n * Hosts bridge this to their `HostPorts.events` sink / UI. Under-, redundant-\n * and conflicting-constraint sketches still produce geometry, but the\n * diagnostic must reach the host.\n *\n * @param sink - receives every non-`solved` solve outcome; `null` clears it.\n */\nexport function setSketchDiagnosticSink(sink: ((outcome: SolveOutcome) => void) | null): void {\n diagnosticSink = sink ?? undefined\n}\n\n/** `cad.sketch` parameters. */\nexport interface SketchParams {\n geoms: SketchGeom[]\n /** Optional — a constraint-free sketch is equivalent to `cad.profile` usage. */\n constraints?: SketchConstraint[]\n /** Product form: `'face'` (default) or `'wire'` (outer wire for sweep spines). */\n as?: 'face' | 'wire'\n}\n\n/**\n * Validate `cad.sketch` parameters: `geoms` must be a non-empty array and\n * `constraints`, when present, an array.\n *\n * @param params - the raw sketch operation parameters.\n */\nexport function assertSketchParams(params: Record<string, unknown>): void {\n const geoms = params.geoms\n if (!Array.isArray(geoms) || geoms.length === 0) {\n throw new Error('E_SKETCHC_NO_GEOMS: sketch requires at least one geometry')\n }\n if (params.constraints !== undefined && !Array.isArray(params.constraints)) {\n throw new Error('E_SKETCHC_BAD_CONSTRAINTS: constraints must be an array')\n }\n}\n\nasync function resolveSolver(): Promise<SketchSolver> {\n if (!solverFactory) {\n throw new Error('E_SKETCHC_NO_SOLVER: no sketch solver installed (call installSketchSolver)')\n }\n return solverFactory()\n}\n\n/**\n * Sketch (geometry + constraints) → solve → face / outer wire.\n *\n * brep-only in the first release (D5): the mesh path reports\n * `E_MESH_UNSUPPORTED`, matching `cad.profile` / `cad.extrude`.\n *\n * @group 创建\n * @inputs 0\n * @async true\n * @qual ok\n * @name sketch\n * @returns Shape 平面几何(求解后构面);`as:'wire'` 时返回外环 1D 曲线。\n * @param params.geoms - 草图几何(线段/圆/圆弧)。type:SketchGeom[] required:true\n * @param params.constraints - 草图约束(可空)。type:SketchConstraint[] required:false\n * @param params.as - 产物形态:'face'(默认)构面;'wire' 只交外环 wire。type:'face'|'wire' required:false\n * @example\n * const f = cad.sketch({\n * geoms: [{ tag:'bottom', kind:'line', x1:0, y1:0, x2:80, y2:3 }],\n * constraints: [{ kind:'horizontal', of: { tag:'bottom' } }, { kind:'length', of: { tag:'bottom' }, value: 80 }],\n * })\n */\nexport const sketch = defineOp({\n name: SKETCH_OP_NAME,\n capabilities: ['directEdit'],\n async brep(params: Record<string, unknown>): Promise<Shape> {\n assertSketchParams(params)\n const solver = await resolveSolver()\n const p = params as unknown as SketchParams\n return sketchFaces(p.geoms, p.constraints ?? [], {\n solver,\n as: p.as,\n onDiagnostic: (outcome) => {\n if (outcome.status !== 'solved') diagnosticSink?.(outcome)\n },\n })\n },\n naming: { kind: 'construct', newFaces: { via: 'explicit', vocab: [] } } as Provenance,\n})"]}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { GcsWrapper } from '@salusoft89/planegcs';
|
|
2
|
+
import { type Result } from '@faicad/faijs/api/result';
|
|
3
|
+
import type { FcstdSketchGeom, FcstdSketchCon } from './fcstd-types.js';
|
|
4
|
+
import type { FcstdSolveOutcome, SketchSolver } from './solver.js';
|
|
5
|
+
/** Options for instantiating the planegcs WASM solver. */
|
|
6
|
+
export interface PlanegcsSolverOptions {
|
|
7
|
+
/** Absolute filesystem path to `planegcs.wasm` (Node hosts). */
|
|
8
|
+
wasmPath?: string;
|
|
9
|
+
/** Raw wasm bytes (browser/worker hosts, injected via HostPorts.assets). */
|
|
10
|
+
wasmBytes?: Uint8Array | ArrayBuffer;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Instantiate the planegcs WASM solver.
|
|
14
|
+
*
|
|
15
|
+
* Environment-agnostic: the host supplies the wasm source. Node hosts use
|
|
16
|
+
* `createNodePlanegcsSolver()` from `@faicad/faijs-sketch/node`; browser hosts
|
|
17
|
+
* pass bytes resolved through `HostPorts.assets`.
|
|
18
|
+
*
|
|
19
|
+
* @param options - wasm path (Node) or bytes (browser).
|
|
20
|
+
* @returns a `SketchSolver` backed by the planegcs WASM module.
|
|
21
|
+
*/
|
|
22
|
+
export declare function createPlanegcsSolver(options: PlanegcsSolverOptions): Promise<SketchSolver>;
|
|
23
|
+
/**
|
|
24
|
+
* planegcs WASM implementation of the `SketchSolver` interface (M3.2–M3.4):
|
|
25
|
+
* pushes geometry/constraints into the GCS, solves, and pulls the solved
|
|
26
|
+
* parameters back into `FcstdSketchGeom` values.
|
|
27
|
+
*/
|
|
28
|
+
export declare class PlanegcsSolver implements SketchSolver {
|
|
29
|
+
private wrapper;
|
|
30
|
+
constructor(wrapper: GcsWrapper);
|
|
31
|
+
solve(geoms: FcstdSketchGeom[], constraints: FcstdSketchCon[], external?: import('./solver.js').ExternalFixedSeg[]): Promise<Result<FcstdSolveOutcome, never>>;
|
|
32
|
+
/**
|
|
33
|
+
* Remaining degrees of freedom after a successful solve (-1 if unavailable).
|
|
34
|
+
*
|
|
35
|
+
* @returns the DoF count, or -1 if the backend does not report it.
|
|
36
|
+
*/
|
|
37
|
+
getDof(): number;
|
|
38
|
+
private constraintToPrimitives;
|
|
39
|
+
private pullBack;
|
|
40
|
+
/** Read a point's solved coordinates from the sketch index.
|
|
41
|
+
* apply_solution() already pulled every primitive's solved values back into
|
|
42
|
+
* sketch_index (gcs_wrapper.js:104-108), so get_primitive is authoritative. */
|
|
43
|
+
private readPoint;
|
|
44
|
+
private readCircleRadius;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=planegcs-backend.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"planegcs-backend.d.ts","sourceRoot":"","sources":["../src/planegcs-backend.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAM,KAAK,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAExE,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEnE,0DAA0D;AAC1D,MAAM,WAAW,qBAAqB;IACpC,gEAAgE;IAChE,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,4EAA4E;IAC5E,SAAS,CAAC,EAAE,UAAU,GAAG,WAAW,CAAA;CACrC;AAED;;;;;;;;;GASG;AACH,wBAAsB,oBAAoB,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,YAAY,CAAC,CAOhG;AAOD;;;;GAIG;AACH,qBAAa,cAAe,YAAW,YAAY;IACrC,OAAO,CAAC,OAAO;gBAAP,OAAO,EAAE,UAAU;IAEjC,KAAK,CACT,KAAK,EAAE,eAAe,EAAE,EACxB,WAAW,EAAE,cAAc,EAAE,EAC7B,QAAQ,CAAC,EAAE,OAAO,aAAa,EAAE,gBAAgB,EAAE,GAClD,OAAO,CAAC,MAAM,CAAC,iBAAiB,EAAE,KAAK,CAAC,CAAC;IAwQ5C;;;;OAIG;IACH,MAAM,IAAI,MAAM;IAShB,OAAO,CAAC,sBAAsB;IAyR9B,OAAO,CAAC,QAAQ;IA0EhB;;mFAE+E;IAC/E,OAAO,CAAC,SAAS;IAMjB,OAAO,CAAC,gBAAgB;CAIzB"}
|