@faicad/faijs 0.19.0 → 0.22.2

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.
Files changed (140) hide show
  1. package/dist/api/brep-mirror/joinery-brep.d.ts.map +1 -1
  2. package/dist/api/brep-mirror/joinery-brep.js +3 -1
  3. package/dist/api/brep-mirror/joinery-brep.js.map +1 -1
  4. package/dist/api/generated/script-face-manifest.d.ts +4 -0
  5. package/dist/api/generated/script-face-manifest.d.ts.map +1 -1
  6. package/dist/api/generated/script-face-manifest.js.map +1 -1
  7. package/dist/api/knurl.d.ts.map +1 -1
  8. package/dist/api/knurl.js +1 -0
  9. package/dist/api/knurl.js.map +1 -1
  10. package/dist/api/primitives.d.ts +4 -3
  11. package/dist/api/primitives.d.ts.map +1 -1
  12. package/dist/api/primitives.js +9 -3
  13. package/dist/api/primitives.js.map +1 -1
  14. package/dist/api/profile.d.ts +34 -5
  15. package/dist/api/profile.d.ts.map +1 -1
  16. package/dist/api/profile.js +60 -9
  17. package/dist/api/profile.js.map +1 -1
  18. package/dist/api/punch-hole.d.ts +3 -0
  19. package/dist/api/punch-hole.d.ts.map +1 -1
  20. package/dist/api/punch-hole.js.map +1 -1
  21. package/dist/api/sketch-on-plane.d.ts +12 -6
  22. package/dist/api/sketch-on-plane.d.ts.map +1 -1
  23. package/dist/api/sketch-on-plane.js +11 -8
  24. package/dist/api/sketch-on-plane.js.map +1 -1
  25. package/dist/api/surface/arg-spec.d.ts +8 -0
  26. package/dist/api/surface/arg-spec.d.ts.map +1 -1
  27. package/dist/api/surface/arg-spec.js.map +1 -1
  28. package/dist/api/transform.d.ts +5 -5
  29. package/dist/api/transform.d.ts.map +1 -1
  30. package/dist/api/transform.js +12 -10
  31. package/dist/api/transform.js.map +1 -1
  32. package/dist/api/xml-dom.d.ts +27 -0
  33. package/dist/api/xml-dom.d.ts.map +1 -0
  34. package/dist/api/xml-dom.js +45 -0
  35. package/dist/api/xml-dom.js.map +1 -0
  36. package/dist/brep/brep-ops.d.ts +4 -4
  37. package/dist/brep/brep-ops.d.ts.map +1 -1
  38. package/dist/brep/brep-ops.js +8 -6
  39. package/dist/brep/brep-ops.js.map +1 -1
  40. package/dist/brep/brep-topology.d.ts.map +1 -1
  41. package/dist/brep/brep-topology.js +3 -1
  42. package/dist/brep/brep-topology.js.map +1 -1
  43. package/dist/brep/export/export-model.d.ts +79 -0
  44. package/dist/brep/export/export-model.d.ts.map +1 -0
  45. package/dist/brep/export/export-model.js +335 -0
  46. package/dist/brep/export/export-model.js.map +1 -0
  47. package/dist/brep/primitives-brep.d.ts.map +1 -1
  48. package/dist/brep/primitives-brep.js +3 -1
  49. package/dist/brep/primitives-brep.js.map +1 -1
  50. package/dist/brepkit-kernel/brepkitKernel.d.ts.map +1 -1
  51. package/dist/brepkit-kernel/brepkitKernel.js +4 -2
  52. package/dist/brepkit-kernel/brepkitKernel.js.map +1 -1
  53. package/dist/cad-runtime/direct-executor.d.ts +4 -0
  54. package/dist/cad-runtime/direct-executor.d.ts.map +1 -1
  55. package/dist/cad-runtime/direct-executor.js +17 -1
  56. package/dist/cad-runtime/direct-executor.js.map +1 -1
  57. package/dist/cad-runtime/runtime.d.ts +24 -1
  58. package/dist/cad-runtime/runtime.d.ts.map +1 -1
  59. package/dist/cad-runtime/runtime.js +53 -3
  60. package/dist/cad-runtime/runtime.js.map +1 -1
  61. package/dist/define-op.d.ts +22 -0
  62. package/dist/define-op.d.ts.map +1 -1
  63. package/dist/define-op.js +15 -0
  64. package/dist/define-op.js.map +1 -1
  65. package/dist/env-agnostic.d.ts +7 -7
  66. package/dist/env-agnostic.d.ts.map +1 -1
  67. package/dist/env-agnostic.js +3 -3
  68. package/dist/env-agnostic.js.map +1 -1
  69. package/dist/geometry2d/bridge/lift-on-plane.d.ts.map +1 -1
  70. package/dist/geometry2d/bridge/lift-on-plane.js +6 -0
  71. package/dist/geometry2d/bridge/lift-on-plane.js.map +1 -1
  72. package/dist/geometry2d/pen-sketcher.d.ts +25 -0
  73. package/dist/geometry2d/pen-sketcher.d.ts.map +1 -1
  74. package/dist/geometry2d/pen-sketcher.js +43 -0
  75. package/dist/geometry2d/pen-sketcher.js.map +1 -1
  76. package/dist/lang/code-to-args.d.ts +29 -3
  77. package/dist/lang/code-to-args.d.ts.map +1 -1
  78. package/dist/lang/code-to-args.js +41 -2
  79. package/dist/lang/code-to-args.js.map +1 -1
  80. package/dist/lang/codegen.d.ts +45 -1
  81. package/dist/lang/codegen.d.ts.map +1 -1
  82. package/dist/lang/codegen.js +135 -6
  83. package/dist/lang/codegen.js.map +1 -1
  84. package/dist/lang/host-arg.d.ts +6 -0
  85. package/dist/lang/host-arg.d.ts.map +1 -1
  86. package/dist/lang/host-arg.js.map +1 -1
  87. package/dist/lang/metadata-extractor.d.ts +25 -0
  88. package/dist/lang/metadata-extractor.d.ts.map +1 -1
  89. package/dist/lang/metadata-extractor.js +289 -25
  90. package/dist/lang/metadata-extractor.js.map +1 -1
  91. package/dist/lang/parse-error.d.ts +7 -1
  92. package/dist/lang/parse-error.d.ts.map +1 -1
  93. package/dist/lang/parse-error.js.map +1 -1
  94. package/dist/lang/security-scanner.d.ts +9 -1
  95. package/dist/lang/security-scanner.d.ts.map +1 -1
  96. package/dist/lang/security-scanner.js +38 -1
  97. package/dist/lang/security-scanner.js.map +1 -1
  98. package/dist/mesh/io.d.ts +62 -9
  99. package/dist/mesh/io.d.ts.map +1 -1
  100. package/dist/mesh/io.js +124 -17
  101. package/dist/mesh/io.js.map +1 -1
  102. package/dist/mesh/threemf-loader.d.ts +15 -0
  103. package/dist/mesh/threemf-loader.d.ts.map +1 -0
  104. package/dist/mesh/threemf-loader.js +163 -0
  105. package/dist/mesh/threemf-loader.js.map +1 -0
  106. package/dist/mesh/transform.d.ts +2 -2
  107. package/dist/mesh/transform.d.ts.map +1 -1
  108. package/dist/mesh/transform.js +3 -3
  109. package/dist/mesh/transform.js.map +1 -1
  110. package/dist/mesh/types.d.ts +1 -1
  111. package/dist/mesh/types.d.ts.map +1 -1
  112. package/dist/mesh/types.js.map +1 -1
  113. package/dist/node-host/cli.d.ts.map +1 -1
  114. package/dist/node-host/cli.js +53 -26
  115. package/dist/node-host/cli.js.map +1 -1
  116. package/dist/occt-kernel/occtKernel.d.ts.map +1 -1
  117. package/dist/occt-kernel/occtKernel.js +4 -2
  118. package/dist/occt-kernel/occtKernel.js.map +1 -1
  119. package/dist/occt-kernel/topologyExt.d.ts.map +1 -1
  120. package/dist/occt-kernel/topologyExt.js +4 -1
  121. package/dist/occt-kernel/topologyExt.js.map +1 -1
  122. package/dist/runtime-state.d.ts +18 -0
  123. package/dist/runtime-state.d.ts.map +1 -1
  124. package/dist/runtime-state.js +23 -0
  125. package/dist/runtime-state.js.map +1 -1
  126. package/dist/sdk.d.ts +1 -1
  127. package/dist/sdk.d.ts.map +1 -1
  128. package/dist/sdk.js +1 -1
  129. package/dist/sdk.js.map +1 -1
  130. package/dist/tolerance.d.ts +38 -0
  131. package/dist/tolerance.d.ts.map +1 -0
  132. package/dist/tolerance.js +40 -0
  133. package/dist/tolerance.js.map +1 -0
  134. package/dist/topology/naming/score.js +3 -3
  135. package/dist/topology/naming/score.js.map +1 -1
  136. package/dist/units.d.ts +248 -0
  137. package/dist/units.d.ts.map +1 -0
  138. package/dist/units.js +397 -0
  139. package/dist/units.js.map +1 -0
  140. package/package.json +11 -2
@@ -25,15 +25,67 @@ import { curveBounds, evaluateCurve2d } from '../geometry2d/curve2d.js';
25
25
  import { profileSegToCurve } from '../geometry2d/adapt.js';
26
26
  // ── 参数自校验 ──
27
27
  /**
28
- * Validate profile parameters: `contours` must be a non-empty array of loops,
29
- * each with at least one segment.
28
+ * True when a `contours` entry is an already-drawn contour rather than a
29
+ * `ProfileLoop` data record. Discriminated on `curves` vs `segments`, so a
30
+ * `ProfileLoop` can never be mistaken for one.
31
+ * @param v - the candidate value.
32
+ * @returns true when `v` is a `Blueprint`-shaped drawn contour.
33
+ */
34
+ function isDrawnContour(v) {
35
+ return !!v && typeof v === 'object' && !Array.isArray(v) && Array.isArray(v.curves);
36
+ }
37
+ /**
38
+ * Normalize a `contours` argument to `Blueprint[]`.
39
+ *
40
+ * Accepts the segment-loop data form, a single drawn contour, or an array of
41
+ * drawn contours. The two forms are never mixed — a mixed array is a caller bug
42
+ * and is rejected rather than half-interpreted.
43
+ *
44
+ * @param contours - the raw `contours` argument (`ProfileLoop[]` | `Blueprint` | `Blueprint[]`).
45
+ * @returns one `Blueprint` per contour, in input order.
46
+ */
47
+ export function toContourBlueprints(contours) {
48
+ if (isDrawnContour(contours))
49
+ return [contours];
50
+ if (!Array.isArray(contours)) {
51
+ throw new Error('E_PROFILE_NO_CONTOURS: profile requires at least one contour');
52
+ }
53
+ if (contours.length === 0) {
54
+ throw new Error('E_PROFILE_NO_CONTOURS: profile requires at least one contour');
55
+ }
56
+ if (isDrawnContour(contours[0])) {
57
+ for (const [i, c] of contours.entries()) {
58
+ if (!isDrawnContour(c)) {
59
+ throw new Error(`E_PROFILE_MIXED_CONTOURS: contour ${i} is a segment loop, not a drawn contour`);
60
+ }
61
+ }
62
+ return contours;
63
+ }
64
+ return contours.map((loop) => new Blueprint((loop?.segments ?? []).map((s) => profileSegToCurve(s))));
65
+ }
66
+ /**
67
+ * Validate profile parameters: `contours` must be a non-empty contour set —
68
+ * either segment loops (each with at least one segment) or drawn contours.
30
69
  * @param params the raw profile operation parameters.
31
70
  */
32
71
  export function assertProfileParams(params) {
33
72
  const contours = params.contours;
73
+ if (isDrawnContour(contours))
74
+ return;
34
75
  if (!Array.isArray(contours) || contours.length === 0) {
35
76
  throw new Error('E_PROFILE_NO_CONTOURS: profile requires at least one contour');
36
77
  }
78
+ // Discriminate the whole array at once so a mixed set names the real defect
79
+ // (E_PROFILE_MIXED_CONTOURS) instead of falling into the loop-shape branch and
80
+ // reporting a drawn contour as a malformed segment loop.
81
+ const drawn = contours.map((c) => isDrawnContour(c));
82
+ if (drawn.some(Boolean)) {
83
+ if (!drawn.every(Boolean)) {
84
+ const bad = drawn.indexOf(false);
85
+ throw new Error(`E_PROFILE_MIXED_CONTOURS: contour ${bad} is a segment loop while contour ${drawn.indexOf(true)} is a drawn contour — the two forms cannot be mixed`);
86
+ }
87
+ return;
88
+ }
37
89
  for (const loop of contours) {
38
90
  if (!loop || typeof loop !== 'object' || !Array.isArray(loop.segments)) {
39
91
  throw new Error('E_PROFILE_BAD_LOOP: each contour must have a segments array');
@@ -52,21 +104,20 @@ export function assertProfileParams(params) {
52
104
  * (7 面、volume 0)。多岛产物 = compound(每岛一面、各带自己的孔),下游
53
105
  * `cad.extrude` 对 compound 输入逐面挤出(kernel MakePrism 收复合形状)。
54
106
  *
55
- * @param params - 轮廓环集合与产物形态。
107
+ * @param params - 轮廓来源(段环数据或 `cad.draw` 产物)与产物形态。
56
108
  * @returns Shape(单岛为 face;多岛为 face 的 compound;`as:'wire'` 为 1D 曲线)。
57
109
  */
58
110
  export function buildProfileShape(params) {
59
111
  const kernel = getBrepApi();
60
112
  const as = params.as ?? 'face';
61
- const loops = params.contours.map((loop) => ({
62
- loop,
63
- curves: loop.segments.map((s) => profileSegToCurve(s)),
64
- }));
65
113
  // F2(2026-09-27):环分类统一到纯 2D 管线 `organiseBlueprints`
66
114
  // (geometry2d/,brepjs 移植)。「嵌套=孔,不相交=独立岛」语义与既有
67
115
  // `profile-multi-island.test.ts` 断言一致;多岛 → 多个顶层,岛+孔 →
68
116
  // CompoundBlueprint([0]=外环,[1..]=孔)。
69
- const organised = organiseBlueprints(loops.map((l) => new Blueprint(l.curves)));
117
+ //
118
+ // 2026-09-28:段环数据与「已绘制轮廓」(`cad.draw` 产物)在此归一 —— 两条
119
+ // 来源只差一次 `toContourBlueprints`,下游分类/构面完全共享。
120
+ const organised = organiseBlueprints(toContourBlueprints(params.contours));
70
121
  // 'wire' 形态:只挑面积最大的岛的外环 wire(1D 曲线),供扫掠族作 spine。
71
122
  if (as === 'wire') {
72
123
  let best = organised.blueprints[0];
@@ -190,7 +241,7 @@ function blueprintArea(entry) {
190
241
  * @qual ok
191
242
  * @name profile
192
243
  * @returns Shape 平面几何(mesh 三角化 + BREP 句柄);`as:'wire'` 时返回 1D 曲线(kind:'curve')。
193
- * @param params.contours - 有序 2D 轮廓(线段/圆弧;外环 + 孔)。type:ProfileLoop[] required:true
244
+ * @param params.contours - 有序 2D 轮廓(线段/圆弧;外环 + 孔),或已绘制轮廓(`cad.draw` 产物:单个 Blueprint 或其数组)。type:ProfileLoop[]|Blueprint|Blueprint[] required:true
194
245
  * @param params.as - 产物形态:'face'(默认)构面;'wire' 只交外环 wire(1D 曲线)。type:'face'|'wire' required:false
195
246
  * @example
196
247
  * const f = cad.profile({ contours: [{ segments: [{ kind:'line', x1:0,y1:0,x2:10,y2:0 }, ...] }] })
@@ -1 +1 @@
1
- {"version":3,"file":"profile.js","sourceRoot":"","sources":["../../src/api/profile.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAC/C,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAA;AAEjC,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAA;AACpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAC3D,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AACpE,OAAO,EAAE,iBAAiB,EAAuB,MAAM,qBAAqB,CAAA;AAgD5E,cAAc;AAEd;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAA+B;IACjE,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAA;IAChC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,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 用途:faijs 此前没有「从 2D 轮廓构造 planar face」的能力,导致草图轮廓无法喂给\n * extrude/revolve。本 op 接收 2D 轮廓(线段 + 圆弧),在 z=0 平面用 OCCT 构面:\n * makeLineEdge/makeArcEdge → makeWire → makeFace(+ addHolesInFace)。\n *\n * 设计:\n * - 输入:{ contours: ProfileLoop[] },每个 loop = 有序 segments(line / arc,z=0)。\n * - 环语义:嵌套 = 孔,不相交 = 独立岛(多岛 → face 的 compound),见 buildProfileShape。\n * - 圆弧:用起点/中点/终点三点的 makeArcEdge;整圆(sweep≈2π)拆成两段弧。\n * - 输出:Shape(mesh 三角化 + 句柄登记)。brep-only(下游 extrude/revolve 亦 brep-only)。\n *\n * 坐标系:输入 2D 点即 (x, y, 0),法向 +Z;草图在 Body 局部系内的定位由调用方(fcstd 端口)\n * 在轮廓坐标里预先变换,或由下游特征的 Placement 承担。\n */\n\nimport type { Shape } from '../mesh/types'\nimport type { BrepEngineApi } from '../brep/engine/primitives'\nimport { getBrepApi } from '../brep/handle-bridge'\nimport { solidToShape } from '../brep/brep-ops'\nimport { fromBrep, fromBrepCurve } from '../shape'\nimport { defineOp } from '../sdk'\nimport type { Provenance } from '../topology/naming/lineage'\nimport { Blueprint } from '../geometry2d/blueprint'\nimport { CompoundBlueprint } from '../geometry2d/compound-blueprint'\nimport { organiseBlueprints } from '../geometry2d/organise'\nimport { curveBounds, evaluateCurve2d } from '../geometry2d/curve2d'\nimport { profileSegToCurve, type ProfileSegLike } from '../geometry2d/adapt'\n\n// ── 参数形状(与 fcstd Contour 结构相同,避免引擎依赖端口层)──\n\n/** 直线段(2D,z=0;端点为绝对坐标)。 */\nexport interface ProfileLineSeg {\n kind: 'line'\n x1: number\n y1: number\n x2: number\n y2: number\n}\n\n/** 圆弧段(圆心 + 半径 + 起止角,弧度;z=0)。 */\nexport interface ProfileArcSeg {\n kind: 'arc'\n cx: number\n cy: number\n radius: number\n /** 起始角(弧度) */\n startAngle: number\n /** 终止角(弧度) */\n endAngle: number\n ccw: boolean\n x1: number\n y1: number\n x2: number\n y2: number\n}\n\n/** 一条有序 2D 轮廓段(直线或圆弧)。 */\nexport type ProfileSeg = ProfileLineSeg | ProfileArcSeg\n\n/** 单个轮廓环:有序段序列(首尾相接)。 */\nexport interface ProfileLoop {\n segments: ProfileSeg[]\n}\n\n/** `cad.profile` 参数:轮廓环集合。语义见 {@link buildProfileShape}(嵌套=孔,不相交=独立岛)。 */\nexport interface ProfileParams {\n contours: ProfileLoop[]\n /**\n * 产物形态:'face'(默认)构面;'wire' 只交出不带面的最大岛外环 wire(1D 曲线),\n * 供扫掠族(sweep/loft/…)直接作 spine。'wire' 形态丢弃孔环(扫掠脊柱为单闭合轮廓)。\n */\n as?: 'face' | 'wire'\n}\n\n// ── 参数自校验 ──\n\n/**\n * Validate profile parameters: `contours` must be a non-empty array of loops,\n * each with at least one segment.\n * @param params the raw profile operation parameters.\n */\nexport function assertProfileParams(params: Record<string, unknown>): void {\n const contours = params.contours\n if (!Array.isArray(contours) || contours.length === 0) {\n throw new Error('E_PROFILE_NO_CONTOURS: profile requires at least one contour')\n }\n for (const loop of contours) {\n if (!loop || typeof loop !== 'object' || !Array.isArray((loop as ProfileLoop).segments)) {\n throw new Error('E_PROFILE_BAD_LOOP: each contour must have a segments array')\n }\n if ((loop as ProfileLoop).segments.length === 0) {\n throw new Error('E_PROFILE_EMPTY_LOOP: a contour must have at least one segment')\n }\n }\n}\n\n/**\n * BREP 路径:2D 轮廓集合 → planar face 集合。\n *\n * GOTCHA(2026-09-26,Beds part16/39):环语义是「**嵌套 = 孔,不相交 = 独立岛**」\n * (与 FreeCAD 草图一致),不是「面积最大者当外环、其余全当孔」。旧实现把双岛轮廓的\n * 第二个岛判成「洞外面」→ `addHolesInFace` 收到与外环不相交的 wire → 构面退化\n * (7 面、volume 0)。多岛产物 = compound(每岛一面、各带自己的孔),下游\n * `cad.extrude` 对 compound 输入逐面挤出(kernel MakePrism 收复合形状)。\n *\n * @param params - 轮廓环集合与产物形态。\n * @returns Shape(单岛为 face;多岛为 face 的 compound;`as:'wire'` 为 1D 曲线)。\n */\nexport function buildProfileShape(params: ProfileParams): Shape {\n const kernel = getBrepApi()\n const as = params.as ?? 'face'\n\n const loops = params.contours.map((loop) => ({\n loop,\n curves: loop.segments.map((s) => profileSegToCurve(s as ProfileSegLike)),\n }))\n\n // F2(2026-09-27):环分类统一到纯 2D 管线 `organiseBlueprints`\n // (geometry2d/,brepjs 移植)。「嵌套=孔,不相交=独立岛」语义与既有\n // `profile-multi-island.test.ts` 断言一致;多岛 → 多个顶层,岛+孔 →\n // CompoundBlueprint([0]=外环,[1..]=孔)。\n const organised = organiseBlueprints(loops.map((l) => new Blueprint(l.curves)))\n\n // 'wire' 形态:只挑面积最大的岛的外环 wire(1D 曲线),供扫掠族作 spine。\n if (as === 'wire') {\n let best = organised.blueprints[0]!\n for (const entry of organised.blueprints) {\n if (blueprintArea(entry) > blueprintArea(best)) best = entry\n }\n const outerBp = best instanceof CompoundBlueprint ? best.blueprints[0]! : best\n const wire = blueprintToWire(kernel, outerBp)\n return fromBrepCurve(solidToShape(kernel, wire), { solid: wire })\n }\n\n // 每岛一面(岛的外环 + 直接子环为孔)\n const faces: ReturnType<BrepEngineApi['makeFace']>[] = []\n for (const entry of organised.blueprints) {\n if (entry instanceof CompoundBlueprint) {\n const outerWire = blueprintToWire(kernel, entry.blueprints[0]!)\n const face = kernel.makeFace(outerWire)\n const holes = entry.blueprints.slice(1).map((h) => blueprintToWire(kernel, h))\n if (holes.length > 0) {\n const faced = kernel.addHolesInFace(face, holes)\n kernel.release(face)\n faces.push(faced)\n } else {\n faces.push(face)\n }\n } else {\n faces.push(kernel.makeFace(blueprintToWire(kernel, entry)))\n }\n }\n\n if (faces.length === 1) {\n const f = faces[0]!\n return fromBrep(solidToShape(kernel, f), { solid: f })\n }\n const compound = kernel.makeCompound(faces as never)\n return fromBrep(solidToShape(kernel, compound), { solid: compound })\n}\n\n/**\n * Convert a pure-2D Blueprint to a 3D wire (z=0) for planar face construction.\n * @param kernel - the BREP engine handle-bridge.\n * @param bp - the blueprint whose ordered curves become wire edges.\n * @returns the wire handle.\n */\nfunction blueprintToWire(kernel: BrepEngineApi, bp: Blueprint): ReturnType<BrepEngineApi['makeWire']> {\n const edges: ReturnType<BrepEngineApi['makeLineEdge']>[] = []\n const pt3 = ([x, y]: [number, number]): { x: number; y: number; z: number } => ({ x, y, z: 0 })\n for (const c of bp.curves) {\n switch (c.kind2d) {\n case 'line':\n edges.push(kernel.makeLineEdge({ x: c.ox, y: c.oy, z: 0 }, { x: c.ox + c.dx * c.len, y: c.oy + c.dy * c.len, z: 0 }))\n break\n case 'bezier':\n edges.push(kernel.makeBezierEdge(c.poles.map(pt3)))\n break\n case 'circle': {\n // 完整圆:拆两段半圆 makeArcEdge(避免三点退化)。\n edges.push(kernel.makeArcEdge(pt3(evaluateCurve2d(c, 0)), pt3(evaluateCurve2d(c, Math.PI / 2)), pt3(evaluateCurve2d(c, Math.PI))))\n edges.push(kernel.makeArcEdge(pt3(evaluateCurve2d(c, Math.PI)), pt3(evaluateCurve2d(c, (3 * Math.PI) / 2)), pt3(evaluateCurve2d(c, 2 * Math.PI))))\n break\n }\n case 'trimmed': {\n if (c.basis.kind2d === 'circle') {\n // 圆弧:以 start/mid/end 三点构真实 makeArcEdge(保留光滑柱面,勿拆成折线段)\n edges.push(kernel.makeArcEdge(pt3(evaluateCurve2d(c, 0)), pt3(evaluateCurve2d(c, 0.5)), pt3(evaluateCurve2d(c, 1))))\n break\n }\n const b = curveBounds(c)\n const pts: Array<{ x: number; y: number; z: number }> = []\n for (let k = 0; k <= 32; k++) {\n const t = b.first + ((b.last - b.first) * k) / 32\n pts.push(pt3(evaluateCurve2d(c, t)))\n }\n for (let k = 0; k < pts.length - 1; k++) edges.push(kernel.makeLineEdge(pts[k]!, pts[k + 1]!))\n break\n }\n case 'ellipse':\n case 'bspline': {\n const b = curveBounds(c)\n const n = 32\n const pts: Array<{ x: number; y: number; z: number }> = []\n for (let k = 0; k <= n; k++) {\n const t = b.first + ((b.last - b.first) * k) / n\n pts.push(pt3(evaluateCurve2d(c, t)))\n }\n for (let k = 0; k < pts.length - 1; k++) edges.push(kernel.makeLineEdge(pts[k]!, pts[k + 1]!))\n break\n }\n }\n }\n return kernel.makeWire(edges)\n}\n\n/** 顶层 Blueprint/CompoundBlueprint 的近似有符号面积(用于 wire 最大岛选择)。 */\nfunction blueprintArea(entry: Blueprint | CompoundBlueprint): number {\n const bp = entry instanceof CompoundBlueprint ? entry.blueprints[0]! : entry\n let a = 0\n for (const c of bp.curves) {\n if (c.kind2d === 'line') {\n a += (c.ox * (c.oy + c.dy * c.len) - (c.ox + c.dx * c.len) * c.oy) / 2\n continue\n }\n const b = curveBounds(c)\n const nSamples = 32\n for (let k = 0; k < nSamples; k++) {\n const t0 = b.first + ((b.last - b.first) * k) / nSamples\n const t1 = b.first + ((b.last - b.first) * (k + 1)) / nSamples\n const [x0, y0] = evaluateCurve2d(c, t0)\n const [x1, y1] = evaluateCurve2d(c, t1)\n a += (x0 * y1 - x1 * y0) / 2\n }\n }\n return a\n}\n\n/**\n * 从 2D 轮廓构造平面(creator,无输入)。仅 BREP 可用。\n * @group 创建\n * @inputs 0\n * @async false\n * @qual ok\n * @name profile\n * @returns Shape 平面几何(mesh 三角化 + BREP 句柄);`as:'wire'` 时返回 1D 曲线(kind:'curve')。\n * @param params.contours - 有序 2D 轮廓(线段/圆弧;外环 + 孔)。type:ProfileLoop[] required:true\n * @param params.as - 产物形态:'face'(默认)构面;'wire' 只交外环 wire(1D 曲线)。type:'face'|'wire' required:false\n * @example\n * const f = cad.profile({ contours: [{ segments: [{ kind:'line', x1:0,y1:0,x2:10,y2:0 }, ...] }] })\n * const w = cad.profile({ contours: [{ segments: [{ kind:'line', x1:0,y1:0,x2:10,y2:0 }, ...] }], as: 'wire' })\n */\nexport const profile = defineOp({\n capabilities: ['directEdit'],\n brep(params: Record<string, unknown>) {\n assertProfileParams(params)\n return buildProfileShape(params as unknown as ProfileParams)\n },\n naming: { kind: 'construct', newFaces: { via: 'explicit', vocab: [] } } as Provenance,\n})"]}
1
+ {"version":3,"file":"profile.js","sourceRoot":"","sources":["../../src/api/profile.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAC/C,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAA;AAEjC,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAA;AACpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAC3D,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AACpE,OAAO,EAAE,iBAAiB,EAAuB,MAAM,qBAAqB,CAAA;AAkE5E,cAAc;AAEd;;;;;;GAMG;AACH,SAAS,cAAc,CAAC,CAAU;IAChC,OAAO,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,OAAO,CAAE,CAAe,CAAC,MAAM,CAAC,CAAA;AACpG,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,mBAAmB,CAAC,QAAiB;IACnD,IAAI,cAAc,CAAC,QAAQ,CAAC;QAAE,OAAO,CAAC,QAAQ,CAAC,CAAA;IAC/C,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CAAC,8DAA8D,CAAC,CAAA;IACjF,CAAC;IACD,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC1B,MAA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AAG,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAA;YACxD,MAAM,EAAE,GAAG,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAA;YAC9D,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,eAAe,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;YACvC,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,eAAe,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;YACvC,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAA;QAC9B,CAAC;IACH,CAAC;IACD,OAAO,CAAC,CAAA;AACV,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAAC;IAC9B,YAAY,EAAE,CAAC,YAAY,CAAC;IAC5B,IAAI,CAAC,MAA+B;QAClC,mBAAmB,CAAC,MAAM,CAAC,CAAA;QAC3B,OAAO,iBAAiB,CAAC,MAAkC,CAAC,CAAA;IAC9D,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 * stdlib profile — 从 2D 轮廓构面(creator 函数,无输入,brep-only)。\n *\n * 用途:faijs 此前没有「从 2D 轮廓构造 planar face」的能力,导致草图轮廓无法喂给\n * extrude/revolve。本 op 接收 2D 轮廓(线段 + 圆弧),在 z=0 平面用 OCCT 构面:\n * makeLineEdge/makeArcEdge → makeWire → makeFace(+ addHolesInFace)。\n *\n * 设计:\n * - 输入:{ contours: ProfileLoop[] },每个 loop = 有序 segments(line / arc,z=0)。\n * - 环语义:嵌套 = 孔,不相交 = 独立岛(多岛 → face 的 compound),见 buildProfileShape。\n * - 圆弧:用起点/中点/终点三点的 makeArcEdge;整圆(sweep≈2π)拆成两段弧。\n * - 输出:Shape(mesh 三角化 + 句柄登记)。brep-only(下游 extrude/revolve 亦 brep-only)。\n *\n * 坐标系:输入 2D 点即 (x, y, 0),法向 +Z;草图在 Body 局部系内的定位由调用方(fcstd 端口)\n * 在轮廓坐标里预先变换,或由下游特征的 Placement 承担。\n */\n\nimport type { Shape } from '../mesh/types'\nimport type { BrepEngineApi } from '../brep/engine/primitives'\nimport { getBrepApi } from '../brep/handle-bridge'\nimport { solidToShape } from '../brep/brep-ops'\nimport { fromBrep, fromBrepCurve } from '../shape'\nimport { defineOp } from '../sdk'\nimport type { Provenance } from '../topology/naming/lineage'\nimport { Blueprint } from '../geometry2d/blueprint'\nimport { CompoundBlueprint } from '../geometry2d/compound-blueprint'\nimport { organiseBlueprints } from '../geometry2d/organise'\nimport { curveBounds, evaluateCurve2d } from '../geometry2d/curve2d'\nimport { profileSegToCurve, type ProfileSegLike } from '../geometry2d/adapt'\n\n// ── 参数形状(与 fcstd Contour 结构相同,避免引擎依赖端口层)──\n\n/** 直线段(2D,z=0;端点为绝对坐标)。 */\nexport interface ProfileLineSeg {\n kind: 'line'\n x1: number\n y1: number\n x2: number\n y2: number\n}\n\n/** 圆弧段(圆心 + 半径 + 起止角,弧度;z=0)。 */\nexport interface ProfileArcSeg {\n kind: 'arc'\n cx: number\n cy: number\n radius: number\n /** 起始角(弧度) */\n startAngle: number\n /** 终止角(弧度) */\n endAngle: number\n ccw: boolean\n x1: number\n y1: number\n x2: number\n y2: number\n}\n\n/** 一条有序 2D 轮廓段(直线或圆弧)。 */\nexport type ProfileSeg = ProfileLineSeg | ProfileArcSeg\n\n/** 单个轮廓环:有序段序列(首尾相接)。 */\nexport interface ProfileLoop {\n segments: ProfileSeg[]\n}\n\n/**\n * A 2D contour that is already DRAWN — i.e. `cad.draw`'s product (a\n * `Blueprint`), or an array of them (one per contour).\n *\n * Why the 2D entries accept this: `cad.draw` returns a pure-data contour with no\n * OCCT handle, and without this path NO op can turn it into a Shape. Measured\n * 2026-09-28 — feeding a `cad.draw` product straight to `cad.extrude` fails with\n * `E_BREP_INPUT: argument carries no BREP handle`, and to `cad.sweep` with\n * `INVALID_SHAPE_ID`. The plan's \"draw → `sketchOnPlane` → `extrude`\" pipeline\n * therefore needs this bridge; `cad.profile` takes it too, because both entries\n * share {@link toContourBlueprints} and a split acceptance rule would be a trap.\n */\nexport type DrawnContours = Blueprint | Blueprint[]\n\n/** `cad.profile` 参数:轮廓环集合。语义见 {@link buildProfileShape}(嵌套=孔,不相交=独立岛)。 */\nexport interface ProfileParams {\n /**\n * 轮廓来源,两种等价形态:段环数据(`{segments: […]}`)或已绘制轮廓\n * (`cad.draw` 产物 / 其数组)。\n */\n contours: ProfileLoop[] | DrawnContours\n /**\n * 产物形态:'face'(默认)构面;'wire' 只交出不带面的最大岛外环 wire(1D 曲线),\n * 供扫掠族(sweep/loft/…)直接作 spine。'wire' 形态丢弃孔环(扫掠脊柱为单闭合轮廓)。\n */\n as?: 'face' | 'wire'\n}\n\n// ── 参数自校验 ──\n\n/**\n * True when a `contours` entry is an already-drawn contour rather than a\n * `ProfileLoop` data record. Discriminated on `curves` vs `segments`, so a\n * `ProfileLoop` can never be mistaken for one.\n * @param v - the candidate value.\n * @returns true when `v` is a `Blueprint`-shaped drawn contour.\n */\nfunction isDrawnContour(v: unknown): v is Blueprint {\n return !!v && typeof v === 'object' && !Array.isArray(v) && Array.isArray((v as Blueprint).curves)\n}\n\n/**\n * Normalize a `contours` argument to `Blueprint[]`.\n *\n * Accepts the segment-loop data form, a single drawn contour, or an array of\n * drawn contours. The two forms are never mixed — a mixed array is a caller bug\n * and is rejected rather than half-interpreted.\n *\n * @param contours - the raw `contours` argument (`ProfileLoop[]` | `Blueprint` | `Blueprint[]`).\n * @returns one `Blueprint` per contour, in input order.\n */\nexport function toContourBlueprints(contours: unknown): Blueprint[] {\n if (isDrawnContour(contours)) return [contours]\n if (!Array.isArray(contours)) {\n throw new Error('E_PROFILE_NO_CONTOURS: profile requires at least one contour')\n }\n if (contours.length === 0) {\n throw new Error('E_PROFILE_NO_CONTOURS: profile requires at least one contour')\n }\n if (isDrawnContour(contours[0])) {\n for (const [i, c] of contours.entries()) {\n if (!isDrawnContour(c)) {\n throw new Error(`E_PROFILE_MIXED_CONTOURS: contour ${i} is a segment loop, not a drawn contour`)\n }\n }\n return contours as Blueprint[]\n }\n return (contours as ProfileLoop[]).map(\n (loop) =>\n new Blueprint(\n (loop?.segments ?? []).map((s) => profileSegToCurve(s as ProfileSegLike)),\n ),\n )\n}\n\n/**\n * Validate profile parameters: `contours` must be a non-empty contour set —\n * either segment loops (each with at least one segment) or drawn contours.\n * @param params the raw profile operation parameters.\n */\nexport function assertProfileParams(params: Record<string, unknown>): void {\n const contours = params.contours\n if (isDrawnContour(contours)) return\n if (!Array.isArray(contours) || contours.length === 0) {\n throw new Error('E_PROFILE_NO_CONTOURS: profile requires at least one contour')\n }\n // Discriminate the whole array at once so a mixed set names the real defect\n // (E_PROFILE_MIXED_CONTOURS) instead of falling into the loop-shape branch and\n // reporting a drawn contour as a malformed segment loop.\n const drawn = contours.map((c) => isDrawnContour(c))\n if (drawn.some(Boolean)) {\n if (!drawn.every(Boolean)) {\n const bad = drawn.indexOf(false)\n throw new Error(\n `E_PROFILE_MIXED_CONTOURS: contour ${bad} is a segment loop while contour ${drawn.indexOf(true)} is a drawn contour — the two forms cannot be mixed`,\n )\n }\n return\n }\n for (const loop of contours) {\n if (!loop || typeof loop !== 'object' || !Array.isArray((loop as ProfileLoop).segments)) {\n throw new Error('E_PROFILE_BAD_LOOP: each contour must have a segments array')\n }\n if ((loop as ProfileLoop).segments.length === 0) {\n throw new Error('E_PROFILE_EMPTY_LOOP: a contour must have at least one segment')\n }\n }\n}\n\n/**\n * BREP 路径:2D 轮廓集合 → planar face 集合。\n *\n * GOTCHA(2026-09-26,Beds part16/39):环语义是「**嵌套 = 孔,不相交 = 独立岛**」\n * (与 FreeCAD 草图一致),不是「面积最大者当外环、其余全当孔」。旧实现把双岛轮廓的\n * 第二个岛判成「洞外面」→ `addHolesInFace` 收到与外环不相交的 wire → 构面退化\n * (7 面、volume 0)。多岛产物 = compound(每岛一面、各带自己的孔),下游\n * `cad.extrude` 对 compound 输入逐面挤出(kernel MakePrism 收复合形状)。\n *\n * @param params - 轮廓来源(段环数据或 `cad.draw` 产物)与产物形态。\n * @returns Shape(单岛为 face;多岛为 face 的 compound;`as:'wire'` 为 1D 曲线)。\n */\nexport function buildProfileShape(params: ProfileParams): Shape {\n const kernel = getBrepApi()\n const as = params.as ?? 'face'\n\n // F2(2026-09-27):环分类统一到纯 2D 管线 `organiseBlueprints`\n // (geometry2d/,brepjs 移植)。「嵌套=孔,不相交=独立岛」语义与既有\n // `profile-multi-island.test.ts` 断言一致;多岛 → 多个顶层,岛+孔 →\n // CompoundBlueprint([0]=外环,[1..]=孔)。\n //\n // 2026-09-28:段环数据与「已绘制轮廓」(`cad.draw` 产物)在此归一 —— 两条\n // 来源只差一次 `toContourBlueprints`,下游分类/构面完全共享。\n const organised = organiseBlueprints(toContourBlueprints(params.contours))\n\n // 'wire' 形态:只挑面积最大的岛的外环 wire(1D 曲线),供扫掠族作 spine。\n if (as === 'wire') {\n let best = organised.blueprints[0]!\n for (const entry of organised.blueprints) {\n if (blueprintArea(entry) > blueprintArea(best)) best = entry\n }\n const outerBp = best instanceof CompoundBlueprint ? best.blueprints[0]! : best\n const wire = blueprintToWire(kernel, outerBp)\n return fromBrepCurve(solidToShape(kernel, wire), { solid: wire })\n }\n\n // 每岛一面(岛的外环 + 直接子环为孔)\n const faces: ReturnType<BrepEngineApi['makeFace']>[] = []\n for (const entry of organised.blueprints) {\n if (entry instanceof CompoundBlueprint) {\n const outerWire = blueprintToWire(kernel, entry.blueprints[0]!)\n const face = kernel.makeFace(outerWire)\n const holes = entry.blueprints.slice(1).map((h) => blueprintToWire(kernel, h))\n if (holes.length > 0) {\n const faced = kernel.addHolesInFace(face, holes)\n kernel.release(face)\n faces.push(faced)\n } else {\n faces.push(face)\n }\n } else {\n faces.push(kernel.makeFace(blueprintToWire(kernel, entry)))\n }\n }\n\n if (faces.length === 1) {\n const f = faces[0]!\n return fromBrep(solidToShape(kernel, f), { solid: f })\n }\n const compound = kernel.makeCompound(faces as never)\n return fromBrep(solidToShape(kernel, compound), { solid: compound })\n}\n\n/**\n * Convert a pure-2D Blueprint to a 3D wire (z=0) for planar face construction.\n * @param kernel - the BREP engine handle-bridge.\n * @param bp - the blueprint whose ordered curves become wire edges.\n * @returns the wire handle.\n */\nfunction blueprintToWire(kernel: BrepEngineApi, bp: Blueprint): ReturnType<BrepEngineApi['makeWire']> {\n const edges: ReturnType<BrepEngineApi['makeLineEdge']>[] = []\n const pt3 = ([x, y]: [number, number]): { x: number; y: number; z: number } => ({ x, y, z: 0 })\n for (const c of bp.curves) {\n switch (c.kind2d) {\n case 'line':\n edges.push(kernel.makeLineEdge({ x: c.ox, y: c.oy, z: 0 }, { x: c.ox + c.dx * c.len, y: c.oy + c.dy * c.len, z: 0 }))\n break\n case 'bezier':\n edges.push(kernel.makeBezierEdge(c.poles.map(pt3)))\n break\n case 'circle': {\n // 完整圆:拆两段半圆 makeArcEdge(避免三点退化)。\n edges.push(kernel.makeArcEdge(pt3(evaluateCurve2d(c, 0)), pt3(evaluateCurve2d(c, Math.PI / 2)), pt3(evaluateCurve2d(c, Math.PI))))\n edges.push(kernel.makeArcEdge(pt3(evaluateCurve2d(c, Math.PI)), pt3(evaluateCurve2d(c, (3 * Math.PI) / 2)), pt3(evaluateCurve2d(c, 2 * Math.PI))))\n break\n }\n case 'trimmed': {\n if (c.basis.kind2d === 'circle') {\n // 圆弧:以 start/mid/end 三点构真实 makeArcEdge(保留光滑柱面,勿拆成折线段)\n edges.push(kernel.makeArcEdge(pt3(evaluateCurve2d(c, 0)), pt3(evaluateCurve2d(c, 0.5)), pt3(evaluateCurve2d(c, 1))))\n break\n }\n const b = curveBounds(c)\n const pts: Array<{ x: number; y: number; z: number }> = []\n for (let k = 0; k <= 32; k++) {\n const t = b.first + ((b.last - b.first) * k) / 32\n pts.push(pt3(evaluateCurve2d(c, t)))\n }\n for (let k = 0; k < pts.length - 1; k++) edges.push(kernel.makeLineEdge(pts[k]!, pts[k + 1]!))\n break\n }\n case 'ellipse':\n case 'bspline': {\n const b = curveBounds(c)\n const n = 32\n const pts: Array<{ x: number; y: number; z: number }> = []\n for (let k = 0; k <= n; k++) {\n const t = b.first + ((b.last - b.first) * k) / n\n pts.push(pt3(evaluateCurve2d(c, t)))\n }\n for (let k = 0; k < pts.length - 1; k++) edges.push(kernel.makeLineEdge(pts[k]!, pts[k + 1]!))\n break\n }\n }\n }\n return kernel.makeWire(edges)\n}\n\n/** 顶层 Blueprint/CompoundBlueprint 的近似有符号面积(用于 wire 最大岛选择)。 */\nfunction blueprintArea(entry: Blueprint | CompoundBlueprint): number {\n const bp = entry instanceof CompoundBlueprint ? entry.blueprints[0]! : entry\n let a = 0\n for (const c of bp.curves) {\n if (c.kind2d === 'line') {\n a += (c.ox * (c.oy + c.dy * c.len) - (c.ox + c.dx * c.len) * c.oy) / 2\n continue\n }\n const b = curveBounds(c)\n const nSamples = 32\n for (let k = 0; k < nSamples; k++) {\n const t0 = b.first + ((b.last - b.first) * k) / nSamples\n const t1 = b.first + ((b.last - b.first) * (k + 1)) / nSamples\n const [x0, y0] = evaluateCurve2d(c, t0)\n const [x1, y1] = evaluateCurve2d(c, t1)\n a += (x0 * y1 - x1 * y0) / 2\n }\n }\n return a\n}\n\n/**\n * 从 2D 轮廓构造平面(creator,无输入)。仅 BREP 可用。\n * @group 创建\n * @inputs 0\n * @async false\n * @qual ok\n * @name profile\n * @returns Shape 平面几何(mesh 三角化 + BREP 句柄);`as:'wire'` 时返回 1D 曲线(kind:'curve')。\n * @param params.contours - 有序 2D 轮廓(线段/圆弧;外环 + 孔),或已绘制轮廓(`cad.draw` 产物:单个 Blueprint 或其数组)。type:ProfileLoop[]|Blueprint|Blueprint[] required:true\n * @param params.as - 产物形态:'face'(默认)构面;'wire' 只交外环 wire(1D 曲线)。type:'face'|'wire' required:false\n * @example\n * const f = cad.profile({ contours: [{ segments: [{ kind:'line', x1:0,y1:0,x2:10,y2:0 }, ...] }] })\n * const w = cad.profile({ contours: [{ segments: [{ kind:'line', x1:0,y1:0,x2:10,y2:0 }, ...] }], as: 'wire' })\n */\nexport const profile = defineOp({\n capabilities: ['directEdit'],\n brep(params: Record<string, unknown>) {\n assertProfileParams(params)\n return buildProfileShape(params as unknown as ProfileParams)\n },\n naming: { kind: 'construct', newFaces: { via: 'explicit', vocab: [] } } as Provenance,\n})"]}
@@ -1,4 +1,7 @@
1
1
  /**
2
+ * @platform occt — 本文件 import occt-kernel(getOcctKernel:draft-angle punch
3
+ * 的 frustum loft 走原生 occt `loft`,适配器层无此能力)。
4
+ *
2
5
  * `cad.punchHole`: cut a face-placed 2D profile out of a solid (E4 pocket/through
3
6
  * hole with optional taper).
4
7
  *
@@ -1 +1 @@
1
- {"version":3,"file":"punch-hole.d.ts","sourceRoot":"","sources":["../../src/api/punch-hole.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAC9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAQtD,OAAO,EAAqB,KAAK,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAIvE,OAAO,EAAuB,KAAK,WAAW,EAAE,MAAM,WAAW,CAAA;AAEjE,sCAAsC;AACtC,MAAM,WAAW,eAAe;IAC9B,8FAA8F;IAC9F,QAAQ,EAAE,WAAW,EAAE,CAAA;IACvB,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AAA;IACzD,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,YAAY,CAAC,yBAAyB,EAAE,MAAM,EAAE,0CAA0C,CAAC,CAAA;IACvG,CAAC;IACD,MAAM,KAAK,GAAG,YAAY,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAA;IACjD,OAAO,QAAQ,CAAC,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAA;AAChE,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,QAAQ,CAAC;IAChC,YAAY,EAAE,CAAC,YAAY,CAAC;IAC5B,OAAO,EAAE,CAAC,MAAM,CAAC;IACjB,IAAI,CAAC,MAA+B;QAClC,mBAAmB,CAAC,MAAM,CAAC,CAAA;QAC3B,OAAO,cAAc,CAAC,UAAU,EAAE,EAAE,MAAoC,CAAC,CAAA;IAC3E,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 * `cad.punchHole`: cut a face-placed 2D profile out of a solid (E4 pocket/through\n * hole with optional taper).\n *\n * The hole profile is a set of closed 2D contours placed on a target face of the\n * solid (the same placement step as `cad.sketchOnFace`). Each placed contour is\n * extruded from the face *into* the part along the face inward normal, and the\n * resulting prism is the \"punch\" tool; a Boolean `cut` removes it from the host —\n * a profile-based pocket (`height` given) or through-hole (`height: null`).\n *\n * v1 scope: the punch is a straight linear prism, or — when `draftAngle > 0` — a\n * **tapered frustum** whose walls recede by `draftAngle` over the punch depth\n * (built as an occt `loft` between a mouth wire in the host plane and an inset\n * end wire at depth `depth·tan(draftAngle)`). The op is a composition over the\n * E3 on-surface placement + `kernel.extrude`/occt `loft` + `kernel.cut` and\n * declares `engines: ['occt']` (surface sampling + Boolean cut + draft loft need\n * the BREP platform).\n * @module\n */\nimport type { Shape } from '../mesh/types'\nimport type { BrepEngineApi } from '../brep/engine/primitives'\nimport type { BrepHandle } from '../brep/engine/types'\nimport { getBrepApi } from '../brep/handle-bridge'\nimport { solidToShape } from '../brep/brep-ops'\nimport { fromBrep, brepOf } from '../shape'\nimport { getOcctKernel } from '../occt-kernel/occtKernel'\nimport { defineOp } from '../sdk'\nimport type { Provenance } from '../topology/naming/lineage'\nimport { TopoRefError } from '../topology/naming'\nimport { resolveFaceHandle, type FaceSelector } from './sketch-on-face'\nimport { makeUvMap, curves2dBounds, type UvMap } from '../geometry2d/bridge/on-surface'\nimport { evaluateCurve2d } from '../geometry2d/curve2d'\nimport { profileSegToCurve } from '../geometry2d/adapt'\nimport { assertProfileParams, type ProfileLoop } from './profile'\n\n/** Parameters for `cad.punchHole`. */\nexport interface PunchHoleParams {\n /** Ordered 2D closed contour(s) describing the hole profile (same shape as `cad.profile`). */\n contours: ProfileLoop[]\n /** The target solid on which the hole is punched. */\n on: Shape\n /** The host face: a 1-based ordinal or a `cad.faceRef(on, n)` result. */\n face: FaceSelector\n /** Removal depth along the face inward normal. `null`/absent = through hole. */\n height?: number | null\n /** Taper on the hole walls (degrees; default 0 = straight wall). Built as a frustum via occt loft. */\n draftAngle?: number\n /** UV mapping mode for contour placement (default `'original'`). */\n scaleMode?: 'original' | 'bounds' | 'native'\n}\n\n/** Extra length past the host extent so a through-hole clears the opposite side. */\nconst THROUGH_MARGIN = 10\n\n/**\n * Depth of the punch extrusion: the explicit `height`, or the host's bounding-box\n * diagonal (+ margin) for a through hole.\n * @param kernel - the BREP engine surface.\n * @param solid - the host solid handle.\n * @param height - the blind depth, or null for through.\n * @returns the positive extrude length.\n */\nfunction punchDepth(kernel: BrepEngineApi, solid: BrepHandle, height: number | null | undefined): number {\n if (height !== null && height !== undefined) return height\n const box = kernel.getBoundingBox(solid)\n const diag = Math.hypot(box.xmax - box.xmin, box.ymax - box.ymin, box.zmax - box.zmin)\n return diag + THROUGH_MARGIN\n}\n\n/**\n * Map a contour's sampled 2D points onto the host face's UV space, evaluate the\n * surface there, and return a clean, coplanar polygon (sample points projected\n * onto the host's plane through its normal). Rebuilding a straight-edged planar\n * face is deliberate: extruding the on-surface bridge's wire-derived face (a\n * near-coplanar shell, z varies by ~1e-7) collapses its OCCT volume to ~0 — see\n * GOTCHA `punch-hole` (E4).\n * @param kernel - the BREP engine surface.\n * @param host - the host face handle.\n * @param mode - the face scale mode.\n * @param uv - the UV mapping for this contour.\n * @param anchor - an in-plane point of the host face (for the projection plane).\n * @param n - the host face outward normal (unit).\n * @param contour - the 2D contour to punch.\n * @returns a flat polygon of 3D points (each approximately in the host plane).\n */\nfunction buildPolygon3d(\n kernel: BrepEngineApi,\n host: BrepHandle,\n uv: UvMap,\n anchor: { x: number; y: number; z: number },\n n: { x: number; y: number; z: number },\n contour: ProfileLoop,\n): { x: number; y: number; z: number }[] {\n const pts: { x: number; y: number; z: number }[] = []\n // Dedupe consecutive coincident samples across the contour.\n const push = (p: { x: number; y: number; z: number }) => {\n const last = pts[pts.length - 1]\n if (last && Math.abs(last.x - p.x) < 1e-7 && Math.abs(last.y - p.y) < 1e-7 && Math.abs(last.z - p.z) < 1e-7) return\n pts.push(p)\n }\n for (const seg of contour.segments) {\n const c = profileSegToCurve(seg as never)\n for (let k = 0; k <= 12; k++) {\n const [x, y] = evaluateCurve2d(c, k / 12)\n const [u, v] = uv(x, y)\n const raw = kernel.pointOnSurface(host, u, v)\n // Project onto the host face plane (through `anchor` + `n`) for exact coplanarity.\n const d = (raw.x - anchor.x) * n.x + (raw.y - anchor.y) * n.y + (raw.z - anchor.z) * n.z\n push({ x: raw.x - n.x * d, y: raw.y - n.y * d, z: raw.z - n.z * d })\n }\n }\n // Close the loop: drop a trailing point equal to the first.\n if (pts.length > 1) {\n const a = pts[0]!\n const b = pts[pts.length - 1]!\n if (Math.abs(a.x - b.x) < 1e-7 && Math.abs(a.y - b.y) < 1e-7 && Math.abs(a.z - b.z) < 1e-7) pts.pop()\n }\n return pts\n}\n\n/**\n * Build and cut the punch solid for every placed profile on the host face and\n * Boolean-cut it from `solid`, returning the holed solid handle.\n * @param kernel - the BREP engine surface.\n * @param solid - the host solid handle.\n * @param params - the punch parameters.\n * @returns the holed solid handle.\n */\nexport function punchSolidOf(kernel: BrepEngineApi, solid: BrepHandle, params: PunchHoleParams): BrepHandle {\n const host = resolveFaceHandle(kernel, params.on, params.face)\n const mode = params.scaleMode ?? 'original'\n const depth = punchDepth(kernel, solid, params.height ?? null)\n\n const draft = params.draftAngle ?? 0\n const draftRad = (draft * Math.PI) / 180\n\n // Punch inward = opposite the host face outward normal.\n const n0 = kernel.surfaceNormal(host, 0, 0)\n const nlen = Math.hypot(n0.x, n0.y, n0.z) || 1\n const n = { x: n0.x / nlen, y: n0.y / nlen, z: n0.z / nlen }\n\n // In-plane anchor via the host face's UV center.\n const ub = kernel.uvBounds(host)\n const uMid = (ub.uMin + ub.uMax) / 2\n const vMid = (ub.vMin + ub.vMax) / 2\n const anchor = kernel.pointOnSurface(host, uMid, vMid)\n\n const bounds = ub\n let result = solid\n for (const contour of params.contours) {\n const curves = contour.segments.map((s) => profileSegToCurve(s as never))\n const uv = makeUvMap(mode, curves2dBounds(curves), bounds)\n const mouth = buildPolygon3d(kernel, host, uv, anchor, n, contour)\n if (mouth.length < 3) throw new Error('punchHole: contour is degenerate (fewer than 3 distinct points)')\n\n // Mouth wire on the host plane.\n const mouthEdges = [] as BrepHandle[]\n for (let i = 0; i < mouth.length; i++) {\n const a = mouth[i]!\n const b = mouth[(i + 1) % mouth.length]!\n mouthEdges.push(kernel.makeLineEdge(a, b) as never)\n }\n\n let punch: BrepHandle\n if (draft !== 0) {\n // Drafted hole = a tapered frustum: the mouth wire at the host plane and an\n // end wire (recessed by `depth*tan(draftAngle)` toward the contour centre)\n // at the punch depth, lofted together via occt. Verified: occt `loft` of two\n // parallel-planar rect wires reproduces the analytic frustum volume exactly.\n const inset = depth * Math.tan(draftRad)\n // Uniform wall recess: each wall recedes by `inset` = depth·tan(draftAngle)\n // measured *perpendicular* to that wall. For a homothetic scale about the\n // centroid by factor s, the perpendicular recess of an edge at distance h\n // from the centroid is h·(1−s); so choose s = 1 − inset/h̄ with h̄ the mean\n // centroid→edge distance (h̄ = the half-side for a square/rect ⇒ walls land\n // at exactly draftAngle).\n const cx = mouth.reduce((s, p) => s + p.x, 0) / mouth.length\n const cy = mouth.reduce((s, p) => s + p.y, 0) / mouth.length\n const cz = mouth.reduce((s, p) => s + p.z, 0) / mouth.length\n let edgeSum = 0\n for (let i = 0; i < mouth.length; i++) {\n const a = mouth[i]!\n const b = mouth[(i + 1) % mouth.length]!\n // centroid → edge midpoint projection in the host plane\n const mx = (a.x + b.x) / 2 - cx\n const my = (a.y + b.y) / 2 - cy\n const mz = (a.z + b.z) / 2 - cz\n edgeSum += Math.hypot(mx, my, mz)\n }\n const hBar = edgeSum / mouth.length\n if (!Number.isFinite(hBar) || hBar <= 1e-9 || inset >= hBar * 0.999) {\n throw new Error(\n `E_PUNCH_DRAFT_OVER_TAPER: draftAngle ${draft}° inset ${inset.toFixed(3)} must be < half-width ${hBar.toFixed(3)} at depth ${depth}`,\n )\n }\n const s = 1 - inset / hBar\n const endPoints = mouth.map((p) => ({\n x: cx + (p.x - cx) * s - n.x * depth,\n y: cy + (p.y - cy) * s - n.y * depth,\n z: cz + (p.z - cz) * s - n.z * depth,\n }))\n const endEdges = endPoints.map((p, i) => {\n const a = endPoints[i]!\n const b = endPoints[(i + 1) % endPoints.length]!\n return kernel.makeLineEdge(a, b) as never\n }) as BrepHandle[]\n const k = getOcctKernel()\n punch = k.loft(\n [kernel.makeWire(mouthEdges), kernel.makeWire(endEdges)] as unknown as never[],\n true,\n true,\n ) as unknown as BrepHandle\n } else {\n const prismFace = kernel.makeFace(kernel.makeWire(mouthEdges))\n punch = kernel.extrude(prismFace, -n.x * depth, -n.y * depth, -n.z * depth)\n }\n try {\n result = kernel.cut(result, punch)\n } finally {\n kernel.release(punch)\n }\n }\n return result\n}\n\n/**\n * Build a Shape: the host solid with the profile(s) punched out of `params.on`.\n * @param kernel - the BREP engine surface.\n * @param params - the punch parameters.\n * @returns the holed Shape.\n */\nexport function buildPunchHole(kernel: BrepEngineApi, params: PunchHoleParams): Shape {\n const solid = brepOf(params.on) as BrepHandle | undefined\n if (!solid) {\n throw new TopoRefError('E_TOPO_MESH_UNSUPPORTED', 'face', 'punchHole: target `on` has no BREP solid')\n }\n const holed = punchSolidOf(kernel, solid, params)\n return fromBrep(solidToShape(kernel, holed), { solid: holed })\n}\n\n/**\n * `cad.punchHole`: cut a face-placed 2D profile out of a solid.\n * @group 创建\n * @inputs 1\n * @async false\n * @qual ok\n * @name punchHole\n * @returns Shape with the profile punched out of `on`.\n * @param params.contours - ordered 2D closed contours (the hole profile).type:any[] required:true\n * @param params.on - the target solid to punch.type:Shape required:true\n * @param params.face - host face: 1-based ordinal or `cad.faceRef(on, n)`.type:any required:true\n * @param params.height - blind depth along the face inward normal (null/absent = through).type:number|object required:false\n * @param params.draftAngle - wall taper in degrees (default 0 = straight; built as an occt loft frustum).type:number required:false\n * @param params.scaleMode - UV mapping: 'original' | 'bounds' | 'native'.type:string required:false\n */\nexport const punchHole = defineOp({\n capabilities: ['directEdit'],\n engines: ['occt'],\n brep(params: Record<string, unknown>) {\n assertProfileParams(params)\n return buildPunchHole(getBrepApi(), params as unknown as PunchHoleParams)\n },\n naming: { kind: 'construct', newFaces: { via: 'explicit', vocab: [] } } as Provenance,\n})"]}
1
+ {"version":3,"file":"punch-hole.js","sourceRoot":"","sources":["../../src/api/punch-hole.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,MA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EAAE,EAAE,EAAE,EAAgB;CACtF,CAAC,CAAA","sourcesContent":["/**\n * @platform occt — 本文件 import occt-kernel(getOcctKernel:draft-angle punch\n * 的 frustum loft 走原生 occt `loft`,适配器层无此能力)。\n *\n * `cad.punchHole`: cut a face-placed 2D profile out of a solid (E4 pocket/through\n * hole with optional taper).\n *\n * The hole profile is a set of closed 2D contours placed on a target face of the\n * solid (the same placement step as `cad.sketchOnFace`). Each placed contour is\n * extruded from the face *into* the part along the face inward normal, and the\n * resulting prism is the \"punch\" tool; a Boolean `cut` removes it from the host —\n * a profile-based pocket (`height` given) or through-hole (`height: null`).\n *\n * v1 scope: the punch is a straight linear prism, or — when `draftAngle > 0` — a\n * **tapered frustum** whose walls recede by `draftAngle` over the punch depth\n * (built as an occt `loft` between a mouth wire in the host plane and an inset\n * end wire at depth `depth·tan(draftAngle)`). The op is a composition over the\n * E3 on-surface placement + `kernel.extrude`/occt `loft` + `kernel.cut` and\n * declares `engines: ['occt']` (surface sampling + Boolean cut + draft loft need\n * the BREP platform).\n * @module\n */\nimport type { Shape } from '../mesh/types'\nimport type { BrepEngineApi } from '../brep/engine/primitives'\nimport type { BrepHandle } from '../brep/engine/types'\nimport { getBrepApi } from '../brep/handle-bridge'\nimport { solidToShape } from '../brep/brep-ops'\nimport { fromBrep, brepOf } from '../shape'\nimport { getOcctKernel } from '../occt-kernel/occtKernel'\nimport { defineOp } from '../sdk'\nimport type { Provenance } from '../topology/naming/lineage'\nimport { TopoRefError } from '../topology/naming'\nimport { resolveFaceHandle, type FaceSelector } from './sketch-on-face'\nimport { makeUvMap, curves2dBounds, type UvMap } from '../geometry2d/bridge/on-surface'\nimport { evaluateCurve2d } from '../geometry2d/curve2d'\nimport { profileSegToCurve } from '../geometry2d/adapt'\nimport { assertProfileParams, type ProfileLoop } from './profile'\n\n/** Parameters for `cad.punchHole`. */\nexport interface PunchHoleParams {\n /** Ordered 2D closed contour(s) describing the hole profile (same shape as `cad.profile`). */\n contours: ProfileLoop[]\n /** The target solid on which the hole is punched. */\n on: Shape\n /** The host face: a 1-based ordinal or a `cad.faceRef(on, n)` result. */\n face: FaceSelector\n /** Removal depth along the face inward normal. `null`/absent = through hole. */\n height?: number | null\n /** Taper on the hole walls (degrees; default 0 = straight wall). Built as a frustum via occt loft. */\n draftAngle?: number\n /** UV mapping mode for contour placement (default `'original'`). */\n scaleMode?: 'original' | 'bounds' | 'native'\n}\n\n/** Extra length past the host extent so a through-hole clears the opposite side. */\nconst THROUGH_MARGIN = 10\n\n/**\n * Depth of the punch extrusion: the explicit `height`, or the host's bounding-box\n * diagonal (+ margin) for a through hole.\n * @param kernel - the BREP engine surface.\n * @param solid - the host solid handle.\n * @param height - the blind depth, or null for through.\n * @returns the positive extrude length.\n */\nfunction punchDepth(kernel: BrepEngineApi, solid: BrepHandle, height: number | null | undefined): number {\n if (height !== null && height !== undefined) return height\n const box = kernel.getBoundingBox(solid)\n const diag = Math.hypot(box.xmax - box.xmin, box.ymax - box.ymin, box.zmax - box.zmin)\n return diag + THROUGH_MARGIN\n}\n\n/**\n * Map a contour's sampled 2D points onto the host face's UV space, evaluate the\n * surface there, and return a clean, coplanar polygon (sample points projected\n * onto the host's plane through its normal). Rebuilding a straight-edged planar\n * face is deliberate: extruding the on-surface bridge's wire-derived face (a\n * near-coplanar shell, z varies by ~1e-7) collapses its OCCT volume to ~0 — see\n * GOTCHA `punch-hole` (E4).\n * @param kernel - the BREP engine surface.\n * @param host - the host face handle.\n * @param mode - the face scale mode.\n * @param uv - the UV mapping for this contour.\n * @param anchor - an in-plane point of the host face (for the projection plane).\n * @param n - the host face outward normal (unit).\n * @param contour - the 2D contour to punch.\n * @returns a flat polygon of 3D points (each approximately in the host plane).\n */\nfunction buildPolygon3d(\n kernel: BrepEngineApi,\n host: BrepHandle,\n uv: UvMap,\n anchor: { x: number; y: number; z: number },\n n: { x: number; y: number; z: number },\n contour: ProfileLoop,\n): { x: number; y: number; z: number }[] {\n const pts: { x: number; y: number; z: number }[] = []\n // Dedupe consecutive coincident samples across the contour.\n const push = (p: { x: number; y: number; z: number }) => {\n const last = pts[pts.length - 1]\n if (last && Math.abs(last.x - p.x) < 1e-7 && Math.abs(last.y - p.y) < 1e-7 && Math.abs(last.z - p.z) < 1e-7) return\n pts.push(p)\n }\n for (const seg of contour.segments) {\n const c = profileSegToCurve(seg as never)\n for (let k = 0; k <= 12; k++) {\n const [x, y] = evaluateCurve2d(c, k / 12)\n const [u, v] = uv(x, y)\n const raw = kernel.pointOnSurface(host, u, v)\n // Project onto the host face plane (through `anchor` + `n`) for exact coplanarity.\n const d = (raw.x - anchor.x) * n.x + (raw.y - anchor.y) * n.y + (raw.z - anchor.z) * n.z\n push({ x: raw.x - n.x * d, y: raw.y - n.y * d, z: raw.z - n.z * d })\n }\n }\n // Close the loop: drop a trailing point equal to the first.\n if (pts.length > 1) {\n const a = pts[0]!\n const b = pts[pts.length - 1]!\n if (Math.abs(a.x - b.x) < 1e-7 && Math.abs(a.y - b.y) < 1e-7 && Math.abs(a.z - b.z) < 1e-7) pts.pop()\n }\n return pts\n}\n\n/**\n * Build and cut the punch solid for every placed profile on the host face and\n * Boolean-cut it from `solid`, returning the holed solid handle.\n * @param kernel - the BREP engine surface.\n * @param solid - the host solid handle.\n * @param params - the punch parameters.\n * @returns the holed solid handle.\n */\nexport function punchSolidOf(kernel: BrepEngineApi, solid: BrepHandle, params: PunchHoleParams): BrepHandle {\n const host = resolveFaceHandle(kernel, params.on, params.face)\n const mode = params.scaleMode ?? 'original'\n const depth = punchDepth(kernel, solid, params.height ?? null)\n\n const draft = params.draftAngle ?? 0\n const draftRad = (draft * Math.PI) / 180\n\n // Punch inward = opposite the host face outward normal.\n const n0 = kernel.surfaceNormal(host, 0, 0)\n const nlen = Math.hypot(n0.x, n0.y, n0.z) || 1\n const n = { x: n0.x / nlen, y: n0.y / nlen, z: n0.z / nlen }\n\n // In-plane anchor via the host face's UV center.\n const ub = kernel.uvBounds(host)\n const uMid = (ub.uMin + ub.uMax) / 2\n const vMid = (ub.vMin + ub.vMax) / 2\n const anchor = kernel.pointOnSurface(host, uMid, vMid)\n\n const bounds = ub\n let result = solid\n for (const contour of params.contours) {\n const curves = contour.segments.map((s) => profileSegToCurve(s as never))\n const uv = makeUvMap(mode, curves2dBounds(curves), bounds)\n const mouth = buildPolygon3d(kernel, host, uv, anchor, n, contour)\n if (mouth.length < 3) throw new Error('punchHole: contour is degenerate (fewer than 3 distinct points)')\n\n // Mouth wire on the host plane.\n const mouthEdges = [] as BrepHandle[]\n for (let i = 0; i < mouth.length; i++) {\n const a = mouth[i]!\n const b = mouth[(i + 1) % mouth.length]!\n mouthEdges.push(kernel.makeLineEdge(a, b) as never)\n }\n\n let punch: BrepHandle\n if (draft !== 0) {\n // Drafted hole = a tapered frustum: the mouth wire at the host plane and an\n // end wire (recessed by `depth*tan(draftAngle)` toward the contour centre)\n // at the punch depth, lofted together via occt. Verified: occt `loft` of two\n // parallel-planar rect wires reproduces the analytic frustum volume exactly.\n const inset = depth * Math.tan(draftRad)\n // Uniform wall recess: each wall recedes by `inset` = depth·tan(draftAngle)\n // measured *perpendicular* to that wall. For a homothetic scale about the\n // centroid by factor s, the perpendicular recess of an edge at distance h\n // from the centroid is h·(1−s); so choose s = 1 − inset/h̄ with h̄ the mean\n // centroid→edge distance (h̄ = the half-side for a square/rect ⇒ walls land\n // at exactly draftAngle).\n const cx = mouth.reduce((s, p) => s + p.x, 0) / mouth.length\n const cy = mouth.reduce((s, p) => s + p.y, 0) / mouth.length\n const cz = mouth.reduce((s, p) => s + p.z, 0) / mouth.length\n let edgeSum = 0\n for (let i = 0; i < mouth.length; i++) {\n const a = mouth[i]!\n const b = mouth[(i + 1) % mouth.length]!\n // centroid → edge midpoint projection in the host plane\n const mx = (a.x + b.x) / 2 - cx\n const my = (a.y + b.y) / 2 - cy\n const mz = (a.z + b.z) / 2 - cz\n edgeSum += Math.hypot(mx, my, mz)\n }\n const hBar = edgeSum / mouth.length\n if (!Number.isFinite(hBar) || hBar <= 1e-9 || inset >= hBar * 0.999) {\n throw new Error(\n `E_PUNCH_DRAFT_OVER_TAPER: draftAngle ${draft}° inset ${inset.toFixed(3)} must be < half-width ${hBar.toFixed(3)} at depth ${depth}`,\n )\n }\n const s = 1 - inset / hBar\n const endPoints = mouth.map((p) => ({\n x: cx + (p.x - cx) * s - n.x * depth,\n y: cy + (p.y - cy) * s - n.y * depth,\n z: cz + (p.z - cz) * s - n.z * depth,\n }))\n const endEdges = endPoints.map((p, i) => {\n const a = endPoints[i]!\n const b = endPoints[(i + 1) % endPoints.length]!\n return kernel.makeLineEdge(a, b) as never\n }) as BrepHandle[]\n const k = getOcctKernel()\n punch = k.loft(\n [kernel.makeWire(mouthEdges), kernel.makeWire(endEdges)] as unknown as never[],\n true,\n true,\n ) as unknown as BrepHandle\n } else {\n const prismFace = kernel.makeFace(kernel.makeWire(mouthEdges))\n punch = kernel.extrude(prismFace, -n.x * depth, -n.y * depth, -n.z * depth)\n }\n try {\n result = kernel.cut(result, punch)\n } finally {\n kernel.release(punch)\n }\n }\n return result\n}\n\n/**\n * Build a Shape: the host solid with the profile(s) punched out of `params.on`.\n * @param kernel - the BREP engine surface.\n * @param params - the punch parameters.\n * @returns the holed Shape.\n */\nexport function buildPunchHole(kernel: BrepEngineApi, params: PunchHoleParams): Shape {\n const solid = brepOf(params.on) as BrepHandle | undefined\n if (!solid) {\n throw new TopoRefError('E_TOPO_MESH_UNSUPPORTED', 'face', 'punchHole: target `on` has no BREP solid')\n }\n const holed = punchSolidOf(kernel, solid, params)\n return fromBrep(solidToShape(kernel, holed), { solid: holed })\n}\n\n/**\n * `cad.punchHole`: cut a face-placed 2D profile out of a solid.\n * @group 创建\n * @inputs 1\n * @async false\n * @qual ok\n * @name punchHole\n * @returns Shape with the profile punched out of `on`.\n * @param params.contours - ordered 2D closed contours (the hole profile).type:any[] required:true\n * @param params.on - the target solid to punch.type:Shape required:true\n * @param params.face - host face: 1-based ordinal or `cad.faceRef(on, n)`.type:any required:true\n * @param params.height - blind depth along the face inward normal (null/absent = through).type:number|object required:false\n * @param params.draftAngle - wall taper in degrees (default 0 = straight; built as an occt loft frustum).type:number required:false\n * @param params.scaleMode - UV mapping: 'original' | 'bounds' | 'native'.type:string required:false\n */\nexport const punchHole = defineOp({\n capabilities: ['directEdit'],\n engines: ['occt'],\n brep(params: Record<string, unknown>) {\n assertProfileParams(params)\n return buildPunchHole(getBrepApi(), params as unknown as PunchHoleParams)\n },\n naming: { kind: 'construct', newFaces: { via: 'explicit', vocab: [] } } as Provenance,\n})"]}
@@ -13,7 +13,7 @@ import type { Shape } from '../mesh/types.js';
13
13
  import type { BrepEngineApi } from '../brep/engine/primitives.js';
14
14
  import { Blueprint } from '../geometry2d/blueprint.js';
15
15
  import { type Plane, type Vec3Input } from '../geometry2d/bridge/plane.js';
16
- import { type ProfileLoop } from './profile.js';
16
+ import { type DrawnContours, type ProfileLoop } from './profile.js';
17
17
  /** A plane given by a named plane and/or an explicit frame (coords accept both array and `{x,y,z}`). */
18
18
  export interface PlaneSpec {
19
19
  /** Named plane (`'XY'` / `'XZ'` / `'YZ'` / `'front'` / `'back'` / `'left'` / …). */
@@ -27,7 +27,12 @@ export interface PlaneSpec {
27
27
  }
28
28
  /** Contour loops + a target plane (+ the result mode) for `cad.sketchOnPlane`. */
29
29
  export interface SketchOnPlaneParams {
30
- contours: ProfileLoop[];
30
+ /**
31
+ * Contour source: segment loops (`{segments: […]}`) or already-drawn contours
32
+ * (a `cad.draw` product, or an array of them). The drawn form is what makes the
33
+ * "draw → place → extrude" pipeline real — see {@link DrawnContours}.
34
+ */
35
+ contours: ProfileLoop[] | DrawnContours;
31
36
  /** Named plane or explicit `{ origin, normal, xAxis }` frame. */
32
37
  plane: PlaneSpec;
33
38
  /** Result shape: 'face' (default) builds a planar face; 'wire' returns the outer-loop wire only. */
@@ -56,10 +61,11 @@ export declare function resolvePlane(planeSpec: PlaneSpec, fallbackOrigin?: Vec3
56
61
  */
57
62
  export declare function buildShapeFromBlueprints(kernel: BrepEngineApi, plane: Plane, blueprints: Blueprint[], as?: 'face' | 'wire'): Shape;
58
63
  /**
59
- * Build the 2D→3D placement: convert contour loops to a classified Blueprint
60
- * set, assemble a wire on the plane, then wrap as a face (or the outer wire).
64
+ * Build the 2D→3D placement: normalize the contour source (segment loops or a
65
+ * drawn contour) to a classified Blueprint set, assemble a wire on the plane,
66
+ * then wrap as a face (or the outer wire).
61
67
  * @param kernel - the BREP engine surface.
62
- * @param params - contour loops + plane + mode.
68
+ * @param params - contour source + plane + mode.
63
69
  * @returns Shape on the target plane (face, or a wire curve when `as:'wire'`).
64
70
  */
65
71
  export declare function buildSketchOnPlaneWith(kernel: BrepEngineApi, params: SketchOnPlaneParams): Shape;
@@ -71,7 +77,7 @@ export declare function buildSketchOnPlaneWith(kernel: BrepEngineApi, params: Sk
71
77
  * @qual ok
72
78
  * @name sketchOnPlane
73
79
  * @returns Shape on the target plane (face, or a wire curve when `as:'wire'`).
74
- * @param params.contours - ordered 2D contours (same shape as `cad.profile`).type:any[] required:true
80
+ * @param params.contours - ordered 2D contours (same shape as `cad.profile`: segment loops, or a `cad.draw` product).type:any required:true
75
81
  * @param params.plane - named plane (`'XY'` / `'XZ'`…) or `{ origin, normal, xAxis }`.type:any required:true
76
82
  * @param params.as - `'face'` (default) or `'wire'` (outer loop only).type:string required:false
77
83
  */
@@ -1 +1 @@
1
- {"version":3,"file":"sketch-on-plane.d.ts","sourceRoot":"","sources":["../../src/api/sketch-on-plane.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAM9D,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAGnD,OAAO,EAAiC,KAAK,KAAK,EAAE,KAAK,SAAS,EAAE,MAAM,4BAA4B,CAAA;AAGtG,OAAO,EAAuB,KAAK,WAAW,EAAE,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EAAE,MAAM,4BAA4B,CAAA;AAEtG,OAAO,EAA4C,KAAK,aAAa,EAAE,KAAK,WAAW,EAAE,MAAM,WAAW,CAAA;AAE1G,wGAAwG;AACxG,MAAM,WAAW,SAAS;IACxB,oFAAoF;IACpF,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,wEAAwE;IACxE,MAAM,CAAC,EAAE,SAAS,CAAA;IAClB,yEAAyE;IACzE,MAAM,CAAC,EAAE,SAAS,CAAA;IAClB,gFAAgF;IAChF,KAAK,CAAC,EAAE,SAAS,CAAA;CAClB;AAED,kFAAkF;AAClF,MAAM,WAAW,mBAAmB;IAClC;;;;OAIG;IACH,QAAQ,EAAE,WAAW,EAAE,GAAG,aAAa,CAAA;IACvC,iEAAiE;IACjE,KAAK,EAAE,SAAS,CAAA;IAChB,oGAAoG;IACpG,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;CACrB;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,SAAS,EAAE,cAAc,GAAE,SAAqB,GAAG,KAAK,CAK/F;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,aAAa,EACrB,KAAK,EAAE,KAAK,EACZ,UAAU,EAAE,SAAS,EAAE,EACvB,EAAE,GAAE,MAAM,GAAG,MAAe,GAC3B,KAAK,CAgCP;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,mBAAmB,GAAG,KAAK,CAQhG;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,aAAa;;CAQxB,CAAA"}
@@ -2,13 +2,11 @@ import { getBrepApi } from '../brep/handle-bridge.js';
2
2
  import { solidToShape } from '../brep/brep-ops.js';
3
3
  import { fromBrep, fromBrepCurve } from '../shape.js';
4
4
  import { defineOp } from '../sdk.js';
5
- import { Blueprint } from '../geometry2d/blueprint.js';
6
5
  import { CompoundBlueprint } from '../geometry2d/compound-blueprint.js';
7
6
  import { organiseBlueprints } from '../geometry2d/organise.js';
8
7
  import { namedPlane, makePlane, toVec3 } from '../geometry2d/bridge/plane.js';
9
8
  import { assembleWire } from '../geometry2d/bridge/lift-on-plane.js';
10
- import { profileSegToCurve } from '../geometry2d/adapt.js';
11
- import { assertProfileParams } from './profile.js';
9
+ import { assertProfileParams, toContourBlueprints } from './profile.js';
12
10
  /**
13
11
  * Resolve a `PlaneSpec` to a plane frame. A named plane wins over an explicit
14
12
  * frame; with neither, the XY plane is used.
@@ -68,15 +66,20 @@ export function buildShapeFromBlueprints(kernel, plane, blueprints, as = 'face')
68
66
  return fromBrep(solidToShape(kernel, compound), { solid: compound });
69
67
  }
70
68
  /**
71
- * Build the 2D→3D placement: convert contour loops to a classified Blueprint
72
- * set, assemble a wire on the plane, then wrap as a face (or the outer wire).
69
+ * Build the 2D→3D placement: normalize the contour source (segment loops or a
70
+ * drawn contour) to a classified Blueprint set, assemble a wire on the plane,
71
+ * then wrap as a face (or the outer wire).
73
72
  * @param kernel - the BREP engine surface.
74
- * @param params - contour loops + plane + mode.
73
+ * @param params - contour source + plane + mode.
75
74
  * @returns Shape on the target plane (face, or a wire curve when `as:'wire'`).
76
75
  */
77
76
  export function buildSketchOnPlaneWith(kernel, params) {
78
77
  const plane = resolvePlane(params.plane);
79
- const blueprints = params.contours.map((loop) => new Blueprint(loop.segments.map((s) => profileSegToCurve(s))));
78
+ // 2026-09-28:段环数据与「已绘制轮廓」(`cad.draw` 产物)在此归一。少了这一步,
79
+ // 计划 A4 的「draw → sketchOnPlane → extrude」就断了 —— `cad.draw` 的 Blueprint
80
+ // 没有 OCCT 句柄,实测喂 `cad.extrude` 报 `argument carries no BREP handle`、
81
+ // 喂 `cad.sweep` 报 `INVALID_SHAPE_ID`,全仓没有第二个能把它变成 Shape 的通道。
82
+ const blueprints = toContourBlueprints(params.contours);
80
83
  return buildShapeFromBlueprints(kernel, plane, blueprints, params.as ?? 'face');
81
84
  }
82
85
  /**
@@ -87,7 +90,7 @@ export function buildSketchOnPlaneWith(kernel, params) {
87
90
  * @qual ok
88
91
  * @name sketchOnPlane
89
92
  * @returns Shape on the target plane (face, or a wire curve when `as:'wire'`).
90
- * @param params.contours - ordered 2D contours (same shape as `cad.profile`).type:any[] required:true
93
+ * @param params.contours - ordered 2D contours (same shape as `cad.profile`: segment loops, or a `cad.draw` product).type:any required:true
91
94
  * @param params.plane - named plane (`'XY'` / `'XZ'`…) or `{ origin, normal, xAxis }`.type:any required:true
92
95
  * @param params.as - `'face'` (default) or `'wire'` (outer loop only).type:string required:false
93
96
  */
@@ -1 +1 @@
1
- {"version":3,"file":"sketch-on-plane.js","sourceRoot":"","sources":["../../src/api/sketch-on-plane.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAC/C,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAA;AAEjC,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAA;AACpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAC3D,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAA8B,MAAM,4BAA4B,CAAA;AACtG,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAA;AACjE,OAAO,EAAE,iBAAiB,EAAuB,MAAM,qBAAqB,CAAA;AAC5E,OAAO,EAAE,mBAAmB,EAAoB,MAAM,WAAW,CAAA;AAuBjE;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,SAAoB,EAAE,iBAA4B,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IACtF,MAAM,CAAC,GAAG,SAAS,CAAC,MAAM,IAA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AAC,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,CAAmB,CAAC,CAAC,CAAC,CAC1F,CAAA;IACD,OAAO,wBAAwB,CAAC,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,IAAI,MAAM,CAAC,CAAA;AACjF,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,QAAQ,CAAC;IACpC,YAAY,EAAE,CAAC,YAAY,CAAC;IAC5B,OAAO,EAAE,CAAC,MAAM,CAAC;IACjB,IAAI,CAAC,MAA+B;QAClC,mBAAmB,CAAC,MAAM,CAAC,CAAA;QAC3B,OAAO,sBAAsB,CAAC,UAAU,EAAE,EAAE,MAAwC,CAAC,CAAA;IACvF,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 * `cad.sketchOnPlane`: lift 2D contours onto an arbitrary plane (E2 placement).\n *\n * This is the shared \"placement\" step of the plan's unified 3D pipeline: any 2D\n * profile source (profile / draw / sketch) that describes contours as\n * `ProfileLoop`s can be placed here, then extruded along the plane normal. The\n * plane is a named plane (`'XY'` / `'XZ'` / `'top'` …) or an explicit frame\n * `{ origin, normal, xAxis }`. The plane lift runs on the occt platform surface\n * via the geometry2d bridge; the op declares `engines: ['occt']`.\n * @module\n */\nimport type { Shape } from '../mesh/types'\nimport type { BrepEngineApi } from '../brep/engine/primitives'\nimport { getBrepApi } from '../brep/handle-bridge'\nimport { solidToShape } from '../brep/brep-ops'\nimport { fromBrep, fromBrepCurve } from '../shape'\nimport { defineOp } from '../sdk'\nimport type { Provenance } from '../topology/naming/lineage'\nimport { Blueprint } from '../geometry2d/blueprint'\nimport { CompoundBlueprint } from '../geometry2d/compound-blueprint'\nimport { organiseBlueprints } from '../geometry2d/organise'\nimport { namedPlane, makePlane, toVec3, type Plane, type Vec3Input } from '../geometry2d/bridge/plane'\nimport { assembleWire } from '../geometry2d/bridge/lift-on-plane'\nimport { profileSegToCurve, type ProfileSegLike } from '../geometry2d/adapt'\nimport { assertProfileParams, type ProfileLoop } from './profile'\n\n/** A plane given by a named plane and/or an explicit frame (coords accept both array and `{x,y,z}`). */\nexport interface PlaneSpec {\n /** Named plane (`'XY'` / `'XZ'` / `'YZ'` / `'front'` / `'back'` / `'left'` / …). */\n name?: string\n /** The plane origin (default [0,0,0]; array `[x,y,z]` or `{x,y,z}`). */\n origin?: Vec3Input\n /** Explicit normal (used with an explicit frame; array or `{x,y,z}`). */\n normal?: Vec3Input\n /** Explicit in-plane X axis (auto-derived when omitted; array or `{x,y,z}`). */\n xAxis?: Vec3Input\n}\n\n/** Contour loops + a target plane (+ the result mode) for `cad.sketchOnPlane`. */\nexport interface SketchOnPlaneParams {\n contours: ProfileLoop[]\n /** Named plane or explicit `{ origin, normal, xAxis }` frame. */\n plane: PlaneSpec\n /** Result shape: 'face' (default) builds a planar face; 'wire' returns the outer-loop wire only. */\n as?: 'face' | 'wire'\n}\n\n/**\n * Resolve a `PlaneSpec` to a plane frame. A named plane wins over an explicit\n * frame; with neither, the XY plane is used.\n * @param planeSpec - the user-facing plane spec (named plane and/or explicit frame).\n * @param fallbackOrigin - the origin used when `planeSpec.origin` is absent (default [0,0,0]).\n * @returns the resolved plane frame.\n */\nexport function resolvePlane(planeSpec: PlaneSpec, fallbackOrigin: Vec3Input = [0, 0, 0]): Plane {\n const o = planeSpec.origin ?? toVec3(fallbackOrigin)\n if (planeSpec.name) return namedPlane(planeSpec.name, o)\n if (planeSpec.normal) return makePlane(o, planeSpec.normal, planeSpec.xAxis)\n return namedPlane('XY', o)\n}\n\n/**\n * Build a 3D Shape (planar face, or outer-loop wire when `as:'wire'`) from a set\n * of classified `Blueprint` contours on a plane. This is the shared placement\n * core for every 2D profile source (`cad.profile` / `cad.draw` / sketch): it\n * organises the closed contours (holes vs islands), assembles edge wires on the\n * plane via the geometry2d bridge, and wraps them as a BREP face — ready to be\n * extruded along the plane normal.\n * @param kernel - the BREP engine surface.\n * @param plane - the resolved target plane frame.\n * @param blueprints - ordered closed contours as `Blueprint`s (draw output).\n * @param as - `'face'` (default) or `'wire'` (outer loop only).\n * @returns Shape on the target plane (face, or a wire curve when `as:'wire'`).\n */\nexport function buildShapeFromBlueprints(\n kernel: BrepEngineApi,\n plane: Plane,\n blueprints: Blueprint[],\n as: 'face' | 'wire' = 'face',\n): Shape {\n const organised = organiseBlueprints(blueprints)\n\n if (as === 'wire') {\n const outerBp =\n organised.blueprints[0] instanceof CompoundBlueprint\n ? organised.blueprints[0].blueprints[0]!\n : (organised.blueprints[0] as Blueprint)\n const wire = assembleWire(kernel, plane, outerBp)\n return fromBrepCurve(solidToShape(kernel, wire), { solid: wire })\n }\n\n const faces: ReturnType<BrepEngineApi['makeFace']>[] = []\n for (const entry of organised.blueprints) {\n if (entry instanceof CompoundBlueprint) {\n let face = kernel.makeFace(assembleWire(kernel, plane, entry.blueprints[0]!))\n const holes = entry.blueprints.slice(1).map((h) => assembleWire(kernel, plane, h) as never)\n if (holes.length > 0) {\n face = kernel.addHolesInFace(face, holes)\n }\n faces.push(face)\n } else {\n faces.push(kernel.makeFace(assembleWire(kernel, plane, entry)))\n }\n }\n\n if (faces.length === 1) {\n const f = faces[0]!\n return fromBrep(solidToShape(kernel, f), { solid: f })\n }\n const compound = kernel.makeCompound(faces)\n return fromBrep(solidToShape(kernel, compound), { solid: compound })\n}\n\n/**\n * Build the 2D→3D placement: convert contour loops to a classified Blueprint\n * set, assemble a wire on the plane, then wrap as a face (or the outer wire).\n * @param kernel - the BREP engine surface.\n * @param params - contour loops + plane + mode.\n * @returns Shape on the target plane (face, or a wire curve when `as:'wire'`).\n */\nexport function buildSketchOnPlaneWith(kernel: BrepEngineApi, params: SketchOnPlaneParams): Shape {\n const plane = resolvePlane(params.plane)\n const blueprints = params.contours.map(\n (loop) => new Blueprint(loop.segments.map((s) => profileSegToCurve(s as ProfileSegLike))),\n )\n return buildShapeFromBlueprints(kernel, plane, blueprints, params.as ?? 'face')\n}\n\n/**\n * `cad.sketchOnPlane`: place 2D contours on a plane and construct a Shape.\n * @group 创建\n * @inputs 0\n * @async false\n * @qual ok\n * @name sketchOnPlane\n * @returns Shape on the target plane (face, or a wire curve when `as:'wire'`).\n * @param params.contours - ordered 2D contours (same shape as `cad.profile`).type:any[] required:true\n * @param params.plane - named plane (`'XY'` / `'XZ'`…) or `{ origin, normal, xAxis }`.type:any required:true\n * @param params.as - `'face'` (default) or `'wire'` (outer loop only).type:string required:false\n */\nexport const sketchOnPlane = defineOp({\n capabilities: ['directEdit'],\n engines: ['occt'],\n brep(params: Record<string, unknown>) {\n assertProfileParams(params)\n return buildSketchOnPlaneWith(getBrepApi(), params as unknown as SketchOnPlaneParams)\n },\n naming: { kind: 'construct', newFaces: { via: 'explicit', vocab: [] } } as Provenance,\n})"]}
1
+ {"version":3,"file":"sketch-on-plane.js","sourceRoot":"","sources":["../../src/api/sketch-on-plane.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAC/C,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAA;AAGjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAA;AACpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAC3D,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAA8B,MAAM,4BAA4B,CAAA;AACtG,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAA;AACjE,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAwC,MAAM,WAAW,CAAA;AA4B1G;;;;;;GAMG;AACH,MAAM,UAA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AAuE;IACvE,oEAAoE;IACpE,6DAA6D;IAC7D,MAAM,UAAU,GAAG,mBAAmB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;IACvD,OAAO,wBAAwB,CAAC,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,IAAI,MAAM,CAAC,CAAA;AACjF,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,QAAQ,CAAC;IACpC,YAAY,EAAE,CAAC,YAAY,CAAC;IAC5B,OAAO,EAAE,CAAC,MAAM,CAAC;IACjB,IAAI,CAAC,MAA+B;QAClC,mBAAmB,CAAC,MAAM,CAAC,CAAA;QAC3B,OAAO,sBAAsB,CAAC,UAAU,EAAE,EAAE,MAAwC,CAAC,CAAA;IACvF,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 * `cad.sketchOnPlane`: lift 2D contours onto an arbitrary plane (E2 placement).\n *\n * This is the shared \"placement\" step of the plan's unified 3D pipeline: any 2D\n * profile source (profile / draw / sketch) that describes contours as\n * `ProfileLoop`s can be placed here, then extruded along the plane normal. The\n * plane is a named plane (`'XY'` / `'XZ'` / `'top'` …) or an explicit frame\n * `{ origin, normal, xAxis }`. The plane lift runs on the occt platform surface\n * via the geometry2d bridge; the op declares `engines: ['occt']`.\n * @module\n */\nimport type { Shape } from '../mesh/types'\nimport type { BrepEngineApi } from '../brep/engine/primitives'\nimport { getBrepApi } from '../brep/handle-bridge'\nimport { solidToShape } from '../brep/brep-ops'\nimport { fromBrep, fromBrepCurve } from '../shape'\nimport { defineOp } from '../sdk'\nimport type { Provenance } from '../topology/naming/lineage'\nimport { Blueprint } from '../geometry2d/blueprint'\nimport { CompoundBlueprint } from '../geometry2d/compound-blueprint'\nimport { organiseBlueprints } from '../geometry2d/organise'\nimport { namedPlane, makePlane, toVec3, type Plane, type Vec3Input } from '../geometry2d/bridge/plane'\nimport { assembleWire } from '../geometry2d/bridge/lift-on-plane'\nimport { assertProfileParams, toContourBlueprints, type DrawnContours, type ProfileLoop } from './profile'\n\n/** A plane given by a named plane and/or an explicit frame (coords accept both array and `{x,y,z}`). */\nexport interface PlaneSpec {\n /** Named plane (`'XY'` / `'XZ'` / `'YZ'` / `'front'` / `'back'` / `'left'` / …). */\n name?: string\n /** The plane origin (default [0,0,0]; array `[x,y,z]` or `{x,y,z}`). */\n origin?: Vec3Input\n /** Explicit normal (used with an explicit frame; array or `{x,y,z}`). */\n normal?: Vec3Input\n /** Explicit in-plane X axis (auto-derived when omitted; array or `{x,y,z}`). */\n xAxis?: Vec3Input\n}\n\n/** Contour loops + a target plane (+ the result mode) for `cad.sketchOnPlane`. */\nexport interface SketchOnPlaneParams {\n /**\n * Contour source: segment loops (`{segments: […]}`) or already-drawn contours\n * (a `cad.draw` product, or an array of them). The drawn form is what makes the\n * \"draw → place → extrude\" pipeline real — see {@link DrawnContours}.\n */\n contours: ProfileLoop[] | DrawnContours\n /** Named plane or explicit `{ origin, normal, xAxis }` frame. */\n plane: PlaneSpec\n /** Result shape: 'face' (default) builds a planar face; 'wire' returns the outer-loop wire only. */\n as?: 'face' | 'wire'\n}\n\n/**\n * Resolve a `PlaneSpec` to a plane frame. A named plane wins over an explicit\n * frame; with neither, the XY plane is used.\n * @param planeSpec - the user-facing plane spec (named plane and/or explicit frame).\n * @param fallbackOrigin - the origin used when `planeSpec.origin` is absent (default [0,0,0]).\n * @returns the resolved plane frame.\n */\nexport function resolvePlane(planeSpec: PlaneSpec, fallbackOrigin: Vec3Input = [0, 0, 0]): Plane {\n const o = planeSpec.origin ?? toVec3(fallbackOrigin)\n if (planeSpec.name) return namedPlane(planeSpec.name, o)\n if (planeSpec.normal) return makePlane(o, planeSpec.normal, planeSpec.xAxis)\n return namedPlane('XY', o)\n}\n\n/**\n * Build a 3D Shape (planar face, or outer-loop wire when `as:'wire'`) from a set\n * of classified `Blueprint` contours on a plane. This is the shared placement\n * core for every 2D profile source (`cad.profile` / `cad.draw` / sketch): it\n * organises the closed contours (holes vs islands), assembles edge wires on the\n * plane via the geometry2d bridge, and wraps them as a BREP face — ready to be\n * extruded along the plane normal.\n * @param kernel - the BREP engine surface.\n * @param plane - the resolved target plane frame.\n * @param blueprints - ordered closed contours as `Blueprint`s (draw output).\n * @param as - `'face'` (default) or `'wire'` (outer loop only).\n * @returns Shape on the target plane (face, or a wire curve when `as:'wire'`).\n */\nexport function buildShapeFromBlueprints(\n kernel: BrepEngineApi,\n plane: Plane,\n blueprints: Blueprint[],\n as: 'face' | 'wire' = 'face',\n): Shape {\n const organised = organiseBlueprints(blueprints)\n\n if (as === 'wire') {\n const outerBp =\n organised.blueprints[0] instanceof CompoundBlueprint\n ? organised.blueprints[0].blueprints[0]!\n : (organised.blueprints[0] as Blueprint)\n const wire = assembleWire(kernel, plane, outerBp)\n return fromBrepCurve(solidToShape(kernel, wire), { solid: wire })\n }\n\n const faces: ReturnType<BrepEngineApi['makeFace']>[] = []\n for (const entry of organised.blueprints) {\n if (entry instanceof CompoundBlueprint) {\n let face = kernel.makeFace(assembleWire(kernel, plane, entry.blueprints[0]!))\n const holes = entry.blueprints.slice(1).map((h) => assembleWire(kernel, plane, h) as never)\n if (holes.length > 0) {\n face = kernel.addHolesInFace(face, holes)\n }\n faces.push(face)\n } else {\n faces.push(kernel.makeFace(assembleWire(kernel, plane, entry)))\n }\n }\n\n if (faces.length === 1) {\n const f = faces[0]!\n return fromBrep(solidToShape(kernel, f), { solid: f })\n }\n const compound = kernel.makeCompound(faces)\n return fromBrep(solidToShape(kernel, compound), { solid: compound })\n}\n\n/**\n * Build the 2D→3D placement: normalize the contour source (segment loops or a\n * drawn contour) to a classified Blueprint set, assemble a wire on the plane,\n * then wrap as a face (or the outer wire).\n * @param kernel - the BREP engine surface.\n * @param params - contour source + plane + mode.\n * @returns Shape on the target plane (face, or a wire curve when `as:'wire'`).\n */\nexport function buildSketchOnPlaneWith(kernel: BrepEngineApi, params: SketchOnPlaneParams): Shape {\n const plane = resolvePlane(params.plane)\n // 2026-09-28:段环数据与「已绘制轮廓」(`cad.draw` 产物)在此归一。少了这一步,\n // 计划 A4 的「draw → sketchOnPlane → extrude」就断了 —— `cad.draw` 的 Blueprint\n // 没有 OCCT 句柄,实测喂 `cad.extrude` 报 `argument carries no BREP handle`、\n // 喂 `cad.sweep` 报 `INVALID_SHAPE_ID`,全仓没有第二个能把它变成 Shape 的通道。\n const blueprints = toContourBlueprints(params.contours)\n return buildShapeFromBlueprints(kernel, plane, blueprints, params.as ?? 'face')\n}\n\n/**\n * `cad.sketchOnPlane`: place 2D contours on a plane and construct a Shape.\n * @group 创建\n * @inputs 0\n * @async false\n * @qual ok\n * @name sketchOnPlane\n * @returns Shape on the target plane (face, or a wire curve when `as:'wire'`).\n * @param params.contours - ordered 2D contours (same shape as `cad.profile`: segment loops, or a `cad.draw` product).type:any required:true\n * @param params.plane - named plane (`'XY'` / `'XZ'`…) or `{ origin, normal, xAxis }`.type:any required:true\n * @param params.as - `'face'` (default) or `'wire'` (outer loop only).type:string required:false\n */\nexport const sketchOnPlane = defineOp({\n capabilities: ['directEdit'],\n engines: ['occt'],\n brep(params: Record<string, unknown>) {\n assertProfileParams(params)\n return buildSketchOnPlaneWith(getBrepApi(), params as unknown as SketchOnPlaneParams)\n },\n naming: { kind: 'construct', newFaces: { via: 'explicit', vocab: [] } } as Provenance,\n})"]}
@@ -140,6 +140,14 @@ export interface ArgSpecEntry {
140
140
  schema?: Record<string, string>;
141
141
  /** D11 slot-map 声明(positional→object 装箱表)。 */
142
142
  slotMap?: import('../../api/internal/dual-form-args.js').SlotMap;
143
+ /**
144
+ * P26 (unit-system D8): 脚本面参数量纲声明——`参数名 → DimName`。缺省该键的
145
+ * 参数视为无量纲、不参与静态 dimension 检查(10 裸数字会被拒、10*mm 通过)。
146
+ * 生成器透传给 defineOp 的 `paramDims`,并写进 script-face-manifest 供宿主读取。
147
+ */
148
+ paramDims?: Record<string, import('../../units.js').DimName>;
149
+ /** P26 (unit-system D8): 返回值量纲声明(函数调用结果携带的量纲)。 */
150
+ retDim?: import('../../units.js').DimName;
143
151
  }
144
152
  /**
145
153
  * 首批机制验证样本(P13a)。每个样本都选了 faijs 无同名、brepjs 有完整实现的符号,
@@ -1 +1 @@
1
- {"version":3,"file":"arg-spec.d.ts","sourceRoot":"","sources":["../../../src/api/surface/arg-spec.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,kBAAkB;AAClB,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAA;AAErF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAA;AAC/D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAC3D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAA;AAE5E,YAAY,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAA;AAE/D,uDAAuD;AAEvD;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAA;IACZ,8CAA8C;IAC9C,IAAI,EAAE,MAAM,CAAA;IACZ,iDAAiD;IACjD,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,kBAAkB;IAClB,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AAED;;;;;;GAMG;AACH,MAAM,MAAM,SAAS,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,CAAA;AAEzC;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,cAAc,CAAA;IACpB,6BAA6B;IAC7B,MAAM,CAAC,EAAE,MAAM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