@snaptrude/plugin-core 0.0.0-dev-20260908074328 → 0.0.0-surfaces-20260921090636

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 (73) hide show
  1. package/CHANGELOG.md +0 -23
  2. package/api-manifest.json +151 -12
  3. package/dist/api/core/geom/create/index.d.ts +918 -93
  4. package/dist/api/core/geom/create/index.d.ts.map +1 -1
  5. package/dist/api/core/geom/query/brep.d.ts +50 -0
  6. package/dist/api/core/geom/query/brep.d.ts.map +1 -1
  7. package/dist/api/core/geom/query/curve.d.ts +58 -35
  8. package/dist/api/core/geom/query/curve.d.ts.map +1 -1
  9. package/dist/api/core/geom/query/edge.d.ts +2 -2
  10. package/dist/api/core/geom/query/face.d.ts +105 -0
  11. package/dist/api/core/geom/query/face.d.ts.map +1 -1
  12. package/dist/api/core/geom/update/curve.d.ts +5 -5
  13. package/dist/api/core/geom/update/profile.d.ts +1 -1
  14. package/dist/api/design/create/index.d.ts +6 -29
  15. package/dist/api/design/create/index.d.ts.map +1 -1
  16. package/dist/api/design/delete/index.d.ts +2 -20
  17. package/dist/api/design/delete/index.d.ts.map +1 -1
  18. package/dist/api/design/query/geometry/index.d.ts +27 -1
  19. package/dist/api/design/query/geometry/index.d.ts.map +1 -1
  20. package/dist/api/design/query/index.d.ts +47 -2
  21. package/dist/api/design/query/index.d.ts.map +1 -1
  22. package/dist/api/design/query/spaces.d.ts +5 -66
  23. package/dist/api/design/query/spaces.d.ts.map +1 -1
  24. package/dist/api/design/update/index.d.ts +87 -0
  25. package/dist/api/design/update/index.d.ts.map +1 -1
  26. package/dist/api/entity/referenceLine.d.ts +2 -2
  27. package/dist/api/entity/referenceLine.d.ts.map +1 -1
  28. package/dist/api/entity/space.d.ts +5 -7
  29. package/dist/api/entity/space.d.ts.map +1 -1
  30. package/dist/api/entity/story.d.ts +4 -4
  31. package/dist/api/presentation/placedViews.d.ts +1 -35
  32. package/dist/api/presentation/placedViews.d.ts.map +1 -1
  33. package/dist/api/presentation/sheets.d.ts +2 -20
  34. package/dist/api/presentation/sheets.d.ts.map +1 -1
  35. package/dist/api/program/site.d.ts +4 -4
  36. package/dist/api/program/spreadsheet.d.ts +4 -4
  37. package/dist/errors/codes.d.ts +3 -8
  38. package/dist/errors/codes.d.ts.map +1 -1
  39. package/dist/handles.d.ts +12 -3
  40. package/dist/handles.d.ts.map +1 -1
  41. package/dist/index.cjs +3188 -2769
  42. package/dist/index.cjs.map +1 -1
  43. package/dist/index.d.ts +2 -0
  44. package/dist/index.d.ts.map +1 -1
  45. package/dist/index.js +3141 -2764
  46. package/dist/index.js.map +1 -1
  47. package/dist/massParameters.d.ts +280 -0
  48. package/dist/massParameters.d.ts.map +1 -0
  49. package/dist/massParameters.ops.d.ts +135 -0
  50. package/dist/massParameters.ops.d.ts.map +1 -0
  51. package/package.json +1 -1
  52. package/src/api/core/geom/create/index.ts +1011 -94
  53. package/src/api/core/geom/query/brep.ts +51 -0
  54. package/src/api/core/geom/query/curve.ts +25 -2
  55. package/src/api/core/geom/query/edge.ts +2 -2
  56. package/src/api/core/geom/query/face.ts +109 -4
  57. package/src/api/design/create/index.ts +8 -34
  58. package/src/api/design/delete/index.ts +1 -20
  59. package/src/api/design/query/geometry/index.ts +29 -0
  60. package/src/api/design/query/index.ts +50 -2
  61. package/src/api/design/query/spaces.ts +0 -68
  62. package/src/api/design/update/index.ts +94 -0
  63. package/src/api/entity/space.ts +0 -2
  64. package/src/api/presentation/placedViews.ts +1 -29
  65. package/src/api/presentation/sheets.ts +3 -19
  66. package/src/errors/codes.ts +2 -30
  67. package/src/handles.ts +15 -3
  68. package/src/index.ts +2 -0
  69. package/src/massParameters.ops.ts +243 -0
  70. package/src/massParameters.ts +418 -0
  71. package/test/errors.test.mjs +0 -4
  72. package/test/massParameters.test.mjs +936 -0
  73. package/snaptrude-plugin-core-0.11.0.tgz +0 -0
@@ -9,6 +9,7 @@ import {
9
9
  PluginSpaceUpdateResult,
10
10
  } from "../../entity/space"
11
11
  import { PluginDesignChangeResult } from "../lock"
12
+ import { MassParametersPatch, type MassParametersRecord } from "../../../massParameters"
12
13
  import {
13
14
  PluginBuildableEnvelopePolygonVertex,
14
15
  PluginBuildableEnvelopeSetbackTier,
@@ -136,6 +137,22 @@ export type PluginDesignUpdateStaircaseArgs = z.infer<
136
137
  typeof PluginDesignUpdateStaircaseArgs
137
138
  >
138
139
 
140
+ /**
141
+ * Arguments for {@linkcode PluginDesignUpdateApi.parameters}.
142
+ *
143
+ * | Property | Type | Description |
144
+ * |---|---|---|
145
+ * | `component` | {@linkcode ComponentHandle} | The parametric mass to edit |
146
+ * | `patch` | {@linkcode MassParametersPatch} | Partial `values` (+ optional `operations`), or the full edited record |
147
+ */
148
+ export const PluginDesignUpdateParametersArgs = z.object({
149
+ component: ComponentHandle,
150
+ patch: MassParametersPatch,
151
+ })
152
+ export type PluginDesignUpdateParametersArgs = z.infer<
153
+ typeof PluginDesignUpdateParametersArgs
154
+ >
155
+
139
156
  /**
140
157
  * Sparse edits for a wall (all optional; at least one required). Only the
141
158
  * fields you provide change. Dimensions are in **engine units** (the same
@@ -409,6 +426,83 @@ export abstract class PluginDesignUpdateApi {
409
426
  params: PluginStaircaseParamUpdates,
410
427
  ): PluginApiReturn<PluginDesignChangeResult>
411
428
 
429
+ /**
430
+ * Edit a parametric mass by patching its creation recipe and rebuilding the
431
+ * solid in place — the mass keeps its id, storey, materials, position and
432
+ * linked copies; only the geometry changes. Read the current record with
433
+ * `design.query.getParameters` first.
434
+ *
435
+ * `patch` is a partial of `record.values` — or the whole record you read
436
+ * back, edited. A key you leave out is unchanged (that includes
437
+ * `operations`). Scalars and points MERGE by key (`{ radius: 8 }` changes
438
+ * only the radius); arrays (`contour`, `sections`, `path`, `profile`,
439
+ * `operations`) REPLACE WHOLE when present — send the complete new list;
440
+ * `{ operations: [] }` drops every operation. A patch that changes nothing
441
+ * returns the current record and records no edit (no undo step). `kind` and
442
+ * `version` are immutable: to change the kind, build a new mass. Keys are the
443
+ * record's `values` keys for its `kind` (sphere: `centre`, `radius`;
444
+ * cylinder: `base`, `axis`, `radius`, `height`; torus: `centre`, `axis`,
445
+ * `majorRadius`, `minorRadius`; …) plus `operations`. To change a fillet
446
+ * radius, edit `operations[i].radius` in the record you read and send
447
+ * `{ operations }` back. Points and axes are WORLD coordinates in internal
448
+ * units, exactly as `getParameters` reports them.
449
+ *
450
+ * Rebuilds in memory first, then swaps onto the SAME component; every linked
451
+ * copy regenerates together. One undo step; saves and syncs to collaborators
452
+ * like any geometry edit. Kernel kinds (revolution, sweep, loft, primitives,
453
+ * any `operations`) run on OpenCascade — expect a short pause.
454
+ *
455
+ * @param component - a mass whose `getParameters` is non-null
456
+ * @param patch - partial `values` (+ optional `operations`), or the full edited record
457
+ * @returns the complete post-edit record, world coordinates (what
458
+ * `getParameters` now returns)
459
+ * @throws PRECONDITION_FAILED when the mass carries no live recipe — built
460
+ * from a boolean, split, `brepFromFaces`/`brepFromMesh` or drawn; edited
461
+ * free-form since (push/pull, move face, boolean); or scaled with the
462
+ * transform tool. `getParameters` returns `null` for exactly these.
463
+ * Do not retry — rebuild it with a recipe constructor and say so.
464
+ * Also PRECONDITION_FAILED when the mass is **locked** (the message says
465
+ * so). Locking is invisible to `getParameters` — a locked parametric mass
466
+ * still reads back a full record — so this is the one PRECONDITION_FAILED
467
+ * the read cannot predict. Unlock the mass and call again; never rebuild
468
+ * it, the recipe is intact.
469
+ * Also PRECONDITION_FAILED when an `operations` entry's edge/face selectors
470
+ * no longer resolve on the rebuilt base (the message names the operation
471
+ * and edge): re-select the edges on the new shape and re-apply that
472
+ * operation.
473
+ * @throws VALIDATION for a key the kind does not have (the message lists the
474
+ * kind's keys), `kind` or `version` in a partial patch, or a value outside
475
+ * the constructor's own rules (torus tube ≥ ring, revolution angle ∉
476
+ * (0, 360], a profile crossing its axis, a spline with fewer than
477
+ * degree + 1 poles).
478
+ * @throws OPERATION_FAILED when the kernel cannot build the edited recipe;
479
+ * the model is left unchanged.
480
+ *
481
+ * @examplePrompt Make the dome's radius 8 metres
482
+ * @examplePrompt Raise the podium to 5 m
483
+ * @examplePrompt Widen the vase — move its profile points 20 cm outward
484
+ * @examplePrompt Change the fillet on the rounded column to 300 mm
485
+ *
486
+ * # Example
487
+ * ```ts
488
+ * // { kind: "sphere", values: { centre, radius: 19.685 }, … }
489
+ * const before = await snaptrude.design.query.getParameters(dome)
490
+ * const after = await snaptrude.design.update.parameters(dome, { radius: 31.496 }) // 8 m in internal units
491
+ *
492
+ * // Fillet radius on a recorded result: read → edit → send the array back
493
+ * const rec = await snaptrude.design.query.getParameters(column)
494
+ * const operations = rec?.operations ?? []
495
+ * if (operations[0]?.op === "fillet") {
496
+ * operations[0].radius = 1.181
497
+ * await snaptrude.design.update.parameters(column, { operations })
498
+ * }
499
+ * ```
500
+ */
501
+ public abstract parameters(
502
+ component: ComponentHandle,
503
+ patch: MassParametersPatch,
504
+ ): PluginApiReturn<MassParametersRecord>
505
+
412
506
  /**
413
507
  * Edit a **wall** — its thickness and/or height (the same command the
414
508
  * properties panel's Thickness/Height fields drive) and/or its **wall type**
@@ -434,7 +434,6 @@ export type PluginSpaceUpdateArgs = z.infer<typeof PluginSpaceUpdateArgs>
434
434
  * | `massType` | `string?` | Updated mass type (if changed) |
435
435
  * | `spaceType` | `string?` | Updated space type (if changed) |
436
436
  * | `departmentId` | `string \| null?` | Updated department ID (if changed) |
437
- * | `rebuilt` | `boolean?` | `true` when a geometry update rebuilt the space's derived BIM — hosted children were re-created and the previous derived handles are retired (re-query them) |
438
437
  */
439
438
  export const PluginSpaceUpdateResult = z.object({
440
439
  spaceId: z.string(),
@@ -443,7 +442,6 @@ export const PluginSpaceUpdateResult = z.object({
443
442
  spaceType: z.string().optional(),
444
443
  areaClass: PluginAreaClass.optional(),
445
444
  departmentId: z.string().nullable().optional(),
446
- rebuilt: z.boolean().optional(),
447
445
  })
448
446
 
449
447
  export type PluginSpaceUpdateResult = z.infer<typeof PluginSpaceUpdateResult>
@@ -1,6 +1,6 @@
1
1
  import * as z from "zod"
2
2
  import { PluginApiReturn } from "../../types"
3
- import { PluginSheetPosition, PluginViewLod } from "./sheets"
3
+ import { PluginSheetPosition } from "./sheets"
4
4
 
5
5
  /**
6
6
  * Placed views — the view shapes already laid out on the Present canvas.
@@ -613,23 +613,6 @@ export abstract class PluginPresentationPlacedViewsApi {
613
613
  shapeId: string,
614
614
  enabled: boolean,
615
615
  ): PluginApiReturn<void>
616
-
617
- /**
618
- * Set the level of detail a placed view renders at — `"design"` (the
619
- * Design-mode massing representation) or `"bim"` (the detailed BIM
620
- * representation). Views only. Undoable. Requires Present mode to be open.
621
- *
622
- * @param shapeId - The placed view shape.
623
- * @param lod - Target level of detail.
624
- * @throws If Present mode is not open or `shapeId` is not a placed view.
625
- *
626
- * @examplePrompt Switch this placed view to the BIM level of detail
627
- * @examplePrompt Show the massing version of the placed plan
628
- */
629
- public abstract setLod(
630
- shapeId: string,
631
- lod: PluginViewLod,
632
- ): PluginApiReturn<void>
633
616
  }
634
617
 
635
618
  /** A point in crop space — fractions (0–1) of the uncropped view. */
@@ -674,8 +657,6 @@ export type PluginPlacedViewCrop = z.infer<typeof PluginPlacedViewCrop>
674
657
  * | `rotation` | `number` | Rotation in radians, `[0, 2π)` (nonzero only for 3D views — 2D views cannot rotate; set with `setRotation`) |
675
658
  * | `crop` | {@linkcode PluginPlacedViewCrop}` \| null` | Crop window (`null` when uncropped) |
676
659
  * | `isUnlinked` | `boolean` | Whether the source proposal was removed (an unlinked view no longer refreshes) |
677
- * | `lod` | {@linkcode PluginViewLod}? | Level of detail the view renders at (`"design"` massing / `"bim"` detail); absent on views that predate LOD variants (set with `setLod`) |
678
- * | `inactiveBuildingMask` | `boolean`? | Whether inactive proposal buildings are masked (the `setMask` toggle); absent when never set (masked by default) |
679
660
  */
680
661
  export const PluginPlacedView = z.object({
681
662
  shapeId: z.string(),
@@ -689,8 +670,6 @@ export const PluginPlacedView = z.object({
689
670
  rotation: z.number(),
690
671
  crop: PluginPlacedViewCrop.nullable(),
691
672
  isUnlinked: z.boolean(),
692
- lod: PluginViewLod.optional(),
693
- inactiveBuildingMask: z.boolean().optional(),
694
673
  })
695
674
  export type PluginPlacedView = z.infer<typeof PluginPlacedView>
696
675
 
@@ -1139,10 +1118,3 @@ export const PluginPlacedViewsSetMaskArgs = z.object({
1139
1118
  enabled: z.boolean(),
1140
1119
  })
1141
1120
  export type PluginPlacedViewsSetMaskArgs = z.infer<typeof PluginPlacedViewsSetMaskArgs>
1142
-
1143
- /** Arguments for {@link PluginPresentationPlacedViewsApi.setLod}. */
1144
- export const PluginPlacedViewsSetLodArgs = z.object({
1145
- shapeId: z.string().min(1),
1146
- lod: PluginViewLod,
1147
- })
1148
- export type PluginPlacedViewsSetLodArgs = z.infer<typeof PluginPlacedViewsSetLodArgs>
@@ -172,10 +172,9 @@ export abstract class PluginPresentationSheetsApi {
172
172
  * @param sheetId - The id of the sheet to place onto.
173
173
  * @param viewId - The id of the saved view to place.
174
174
  * @param options - Optional `position` ({@linkcode PluginSheetPosition}) —
175
- * where to place it (sheet centre when omitted) — `scale` — a standard
175
+ * where to place it (sheet centre when omitted) — and `scale` — a standard
176
176
  * scale value for the project's unit system (2D/site-plan views only;
177
- * auto-fit when omitted) — and `lod` ({@linkcode PluginViewLod}) — the LOD
178
- * of the placed view (default: the product's Design default).
177
+ * auto-fit when omitted).
179
178
  * @returns A {@linkcode PluginPresentationSheetsPlaceResult} with the created
180
179
  * `shapeId`.
181
180
  * @throws If Present mode is not open, the sheet/view id is invalid, `scale`
@@ -198,11 +197,7 @@ export abstract class PluginPresentationSheetsApi {
198
197
  public abstract place(
199
198
  sheetId: string,
200
199
  viewId: string,
201
- options?: {
202
- position?: PluginSheetPosition
203
- scale?: number
204
- lod?: PluginViewLod
205
- },
200
+ options?: { position?: PluginSheetPosition; scale?: number },
206
201
  ): PluginApiReturn<PluginPresentationSheetsPlaceResult>
207
202
 
208
203
  /**
@@ -413,15 +408,6 @@ export const PluginSheetPosition = z.object({
413
408
  })
414
409
  export type PluginSheetPosition = z.infer<typeof PluginSheetPosition>
415
410
 
416
- /**
417
- * The level of detail a placed view renders at: `"design"` (the Design-mode
418
- * massing representation) or `"bim"` (the detailed BIM representation).
419
- * Shared by `sheets.place` and `placedViews.*` (defined here because
420
- * `placedViews` already imports from this module).
421
- */
422
- export const PluginViewLod = z.enum(["design", "bim"])
423
- export type PluginViewLod = z.infer<typeof PluginViewLod>
424
-
425
411
  /** Result of {@linkcode PluginPresentationSheetsApi.list}. */
426
412
  export const PluginPresentationSheetsListResult = z.object({
427
413
  sheets: z.array(PluginPresentationSheet),
@@ -483,14 +469,12 @@ export type PluginPresentationSheetsSetMarginArgs = z.infer<
483
469
  * | `viewId` | `string` | The saved view to place |
484
470
  * | `position` | {@linkcode PluginSheetPosition}` \| undefined` | Where to place it (sheet centre when omitted) |
485
471
  * | `scale` | `number \| undefined` | Standard scale value for the project's unit system (2D/site-plan views only; auto-fit to the closest standard scale when omitted) |
486
- * | `lod` | {@linkcode PluginViewLod}` \| undefined` | LOD of the placed view (default: the product's Design default) |
487
472
  */
488
473
  export const PluginPresentationSheetsPlaceArgs = z.object({
489
474
  sheetId: z.string(),
490
475
  viewId: z.string(),
491
476
  position: PluginSheetPosition.optional(),
492
477
  scale: z.number().positive().optional(),
493
- lod: PluginViewLod.optional(),
494
478
  })
495
479
  export type PluginPresentationSheetsPlaceArgs = z.infer<
496
480
  typeof PluginPresentationSheetsPlaceArgs
@@ -5,13 +5,8 @@
5
5
  * APPEND-ONLY: codes are a published contract; never rename or remove one.
6
6
  * Handle-resolution failures deliberately collapse to ONE code
7
7
  * (`HANDLE_INVALID`) so error responses cannot be used as an existence /
8
- * ownership oracle (PLUGIN_HANDLE_MIGRATION_HLD §6) — with one deliberate
9
- * exception: `HANDLE_STALE` marks a handle the caller legitimately held that a
10
- * parametric resolution (merge / split / rebuild) has since retired — a
11
- * lifetime fact about the caller's own write-scoped handle, not an oracle
12
- * (forged / never-issued ids still collapse to `HANDLE_INVALID`).
13
- * `HANDLE_KIND_MISMATCH` stays distinct because the kind is information the
14
- * caller already holds.
8
+ * ownership oracle (PLUGIN_HANDLE_MIGRATION_HLD §6). `HANDLE_KIND_MISMATCH`
9
+ * stays distinct because the kind is information the caller already holds.
15
10
  */
16
11
  export const PLUGIN_ERROR_CODES = [
17
12
  "VALIDATION",
@@ -37,10 +32,6 @@ export const PLUGIN_ERROR_CODES = [
37
32
  "NO_ACTIVE_STRUCTURE",
38
33
  "NO_ELIGIBLE_ELEMENTS",
39
34
  "PROPOSAL_SWITCH_BLOCKED",
40
- "HANDLE_STALE",
41
- "KIND_HIDDEN_IN_MODE",
42
- "MERGED_INTO_EXISTING",
43
- "BLOCKED_IN_BIM",
44
35
  "INTERNAL",
45
36
  "UNKNOWN",
46
37
  ] as const
@@ -132,25 +123,6 @@ export const CODE_META: Record<PluginErrorCode, CodeMeta> = {
132
123
  category: "execution",
133
124
  hintTemplate: "Wait for the in-canvas agent run to finish, then retry.",
134
125
  },
135
- HANDLE_STALE: {
136
- category: "handle",
137
- hintTemplate:
138
- "The entity was retired by a parametric resolution (merge/split/rebuild); re-query for its successor.",
139
- },
140
- KIND_HIDDEN_IN_MODE: {
141
- category: "execution",
142
- hintTemplate:
143
- "This entity kind has no representation in the current mode/LOD; switch mode or target a visible kind.",
144
- },
145
- MERGED_INTO_EXISTING: {
146
- category: "execution",
147
- hintTemplate:
148
- "The created geometry merged into an existing entity; use the surviving handles from details.",
149
- },
150
- BLOCKED_IN_BIM: {
151
- category: "execution",
152
- hintTemplate: "This operation is unavailable in BIM mode; switch to Design and retry.",
153
- },
154
126
  INTERNAL: {
155
127
  category: "internal",
156
128
  hintTemplate: "Host-side fault. Report with errorId.",
package/src/handles.ts CHANGED
@@ -132,8 +132,16 @@ export type Vec3Handle = Handle<"vec3">
132
132
  export type QuatHandle = Handle<"quat">
133
133
  export type LineHandle = Handle<"line">
134
134
  export type ArcHandle = Handle<"arc">
135
- /** A curve is a line or an arc — its handle is one of those kinds. */
136
- export type CurveHandle = LineHandle | ArcHandle
135
+ /**
136
+ * A NURBS curve value handle (open B-spline curve). Minted by
137
+ * `core.geom.create.splineFromPoints` / `splineFromControlPoints`, accepted everywhere a
138
+ * {@linkcode CurveHandle} is (profileFromCurves, query.curve.*).
139
+ * Closed spline loops never exist as a single handle — a closed run is built
140
+ * directly as a profile via `core.geom.create.profileFromSplinePoints`.
141
+ */
142
+ export type SplineHandle = Handle<"spline">
143
+ /** A curve is a line, an arc, or a spline — its handle is one of those kinds. */
144
+ export type CurveHandle = LineHandle | ArcHandle | SplineHandle
137
145
  /**
138
146
  * A circle value handle. A circle is a CLOSED curve — it deliberately does NOT
139
147
  * join {@linkcode CurveHandle} (it has no stable start/end and would break the
@@ -238,7 +246,11 @@ export const Vec3Handle = handleSchema("vec3")
238
246
  export const QuatHandle = handleSchema("quat")
239
247
  export const LineHandle = handleSchema("line")
240
248
  export const ArcHandle = handleSchema("arc")
241
- export const CurveHandle = z.union([LineHandle, ArcHandle])
249
+ export const SplineHandle = handleSchema("spline")
250
+ // Explicitly typed (rather than inferred): the inferred union type prints its
251
+ // three fully-expanded member schemas into handles.d.ts, which is served to
252
+ // agents whole and has a size budget.
253
+ export const CurveHandle: z.ZodType<CurveHandle> = z.union([LineHandle, ArcHandle, SplineHandle])
242
254
  export const CircleHandle = handleSchema("circle")
243
255
 
244
256
  // BREP topology handle schemas (§2A.2.1). Prefix-shape validation only; existence,
package/src/index.ts CHANGED
@@ -2,4 +2,6 @@ export * from "./api"
2
2
  export * from "./types"
3
3
  export * from "./host-utils"
4
4
  export * from "./handles"
5
+ export * from "./massParameters"
6
+ export * from "./massParameters.ops"
5
7
  export * from "./errors"
@@ -0,0 +1,243 @@
1
+ import * as z from "zod"
2
+ import {
3
+ ContourRecord,
4
+ CurveRecord,
5
+ LoftOptions,
6
+ MAX_LOFT_SECTIONS,
7
+ MAX_PATH_CURVES,
8
+ MAX_SWEEP_PATH_POINTS,
9
+ SweepAlongCurveRecordOptions,
10
+ SweepOptions,
11
+ XYZ,
12
+ } from "./massParameters"
13
+ import type { CurveKind, SurfaceKind } from "./massParameters"
14
+
15
+ /**
16
+ * The **operation half** of a mass creation-parameter record: which edge or
17
+ * face of the recipe's solid a kernel step used, the step itself, and the
18
+ * values a `design.update.parameters` patch may carry.
19
+ *
20
+ * Split out of `massParameters.ts` — same contract, same repos, one module each
21
+ * so either can be read whole — and re-exported from it and from the package
22
+ * root, so every import path keeps working.
23
+ *
24
+ * Everything here is **pure JSON** by construction, exactly as in
25
+ * {@linkcode MassParametersRecord}: plain objects, numbers and arrays only, one
26
+ * `{x, y, z}` point shape, no class instances.
27
+ */
28
+
29
+ /** Maximum kernel operations chained onto one recipe. */
30
+ export const MAX_OPERATIONS = 8
31
+ /** Maximum edges one fillet/chamfer operation may select. */
32
+ export const MAX_OPERATION_EDGES = 64
33
+ /** Maximum faces one shell operation may open. */
34
+ export const MAX_OPERATION_FACES = 32
35
+ /** Maximum rows in a variable-fillet radius law. */
36
+ export const MAX_FILLET_LAW_SAMPLES = 32
37
+
38
+ // `XYZ` and the record schemas below are resolved through `z.lazy`: this module
39
+ // and `massParameters.ts` re-export each other, and this one is evaluated first,
40
+ // so their consts are not yet initialised while these schemas are built. The
41
+ // closures run at parse time, when both modules are live.
42
+ const At: z.ZodType<XYZ, XYZ> = z.lazy(() => XYZ)
43
+
44
+ /**
45
+ * Which EDGE of the input solid an operation used: its index in
46
+ * `core.geom.query.brep.listEdges` order at authoring time, the indices of the
47
+ * two faces it lies between, and its curve kind. This is topology, not
48
+ * coordinates — it survives a scalar edit of the base recipe (which moves every
49
+ * edge) and trips on a reorder or a topology change. Read-only: to blend a
50
+ * different edge, re-select it on the new shape and re-apply the operation.
51
+ */
52
+ export type EdgeSelector = {
53
+ index: number
54
+ faces: [number, number]
55
+ curve: CurveKind
56
+ /** Where the edge sits INSIDE its solid: its midpoint in the record's own
57
+ * frame, divided by the solid's bounding-box extent — a ratio per axis,
58
+ * never a length, so it survives a scalar edit that scales the whole shape.
59
+ * Written only when the discriminators above cannot tell two edges apart. A
60
+ * tiebreak, never a coordinate fingerprint: a replay checks it within 0.02 of
61
+ * the solid's own box and refuses on a miss — it never searches for a better
62
+ * candidate. */
63
+ at?: XYZ
64
+ }
65
+
66
+ /**
67
+ * Which FACE of the input solid an operation used: its index in
68
+ * `core.geom.query.brep.listFaces` order, its surface kind, and the number of
69
+ * edges in its outer loop. Read-only, like {@linkcode EdgeSelector}.
70
+ */
71
+ export type FaceSelector = {
72
+ index: number
73
+ kind: SurfaceKind
74
+ edgeCount: number
75
+ /** The face's centroid under the same normalisation and the same tiebreak
76
+ * rule as {@linkcode EdgeSelector}'s `at` — written only where the
77
+ * discriminators above cannot separate two faces, which on a freeform solid
78
+ * (every face answers `"spline"`) is the common case. */
79
+ at?: XYZ
80
+ }
81
+
82
+ /** The input solid's topology at authoring time — the counts a replay checks first. */
83
+ export type TopologyCounts = { faceCount: number; edgeCount: number }
84
+
85
+ /**
86
+ * One kernel operation applied to the base recipe's solid, in order. `input`
87
+ * pins the topology the operation was authored against, so a base edit that
88
+ * changes the topology is refused rather than mis-applied.
89
+ *
90
+ * Edit one by patching the whole list back:
91
+ * `design.update.parameters(mass, { operations })`.
92
+ */
93
+ export type OperationRecord =
94
+ | {
95
+ op: "fillet"
96
+ edges: EdgeSelector[]
97
+ radius: number
98
+ /** Radius at the far end of the blend contour, internal length units — a
99
+ * linear variable blend from `radius`. One edge, and never with `radii`. */
100
+ endRadius?: number
101
+ /** The blend's radius law instead: `position` is normalised arc length
102
+ * along the blend contour (a ratio 0..1, never converted), `radius` is
103
+ * internal length units. 2..32 rows, strictly increasing `position`.
104
+ * One edge, and never with `endRadius`. */
105
+ radii?: { position: number; radius: number }[]
106
+ input: TopologyCounts
107
+ }
108
+ | { op: "chamfer"; edges: EdgeSelector[]; distance: number; input: TopologyCounts }
109
+ | { op: "shell"; openFaces: FaceSelector[]; thickness: number; input: TopologyCounts }
110
+ | { op: "offset"; distance: number; input: TopologyCounts }
111
+
112
+ /**
113
+ * One value of a `MassParametersPatch` — whatever a record's `values` key (or
114
+ * `operations`) may hold. Scalars and points merge by key; every array form
115
+ * replaces the list whole.
116
+ */
117
+ export type ParameterPatchValue =
118
+ | number
119
+ | XYZ
120
+ | XYZ[]
121
+ | ContourRecord
122
+ | ContourRecord[]
123
+ | CurveRecord[]
124
+ | LoftOptions
125
+ | SweepOptions
126
+ | SweepAlongCurveRecordOptions
127
+ | OperationRecord[]
128
+
129
+ const FaceIndex = z.number().int().nonnegative()
130
+
131
+ /** See {@linkcode EdgeSelector}. */
132
+ export const EdgeSelector: z.ZodType<EdgeSelector, EdgeSelector> = z.strictObject({
133
+ index: FaceIndex,
134
+ faces: z.tuple([FaceIndex, FaceIndex]),
135
+ curve: z.enum(["line", "arc", "circle", "spline"]),
136
+ at: At.optional(),
137
+ })
138
+
139
+ /** See {@linkcode FaceSelector}. */
140
+ export const FaceSelector: z.ZodType<FaceSelector, FaceSelector> = z.strictObject({
141
+ index: FaceIndex,
142
+ kind: z.enum(["plane", "cylinder", "cone", "sphere", "torus", "spline"]),
143
+ edgeCount: z.number().int().positive(),
144
+ at: At.optional(),
145
+ })
146
+
147
+ /** See {@linkcode TopologyCounts}. */
148
+ export const TopologyCounts: z.ZodType<TopologyCounts, TopologyCounts> = z.strictObject({
149
+ faceCount: z.number().int().positive(),
150
+ edgeCount: z.number().int().positive(),
151
+ })
152
+
153
+ /** One row of a variable fillet's radius law. See {@linkcode OperationRecord}. */
154
+ const FilletLawRow = z.strictObject({
155
+ position: z.number().finite().min(0).max(1),
156
+ radius: z.number().finite().positive(),
157
+ })
158
+
159
+ /**
160
+ * See {@linkcode OperationRecord}.
161
+ *
162
+ * A variable fillet — `endRadius` or `radii` — names ONE edge: the law is a
163
+ * property of the blend contour that edge belongs to, and `position` is measured
164
+ * from that edge's start, so a second edge would have no origin. The two forms
165
+ * are mutually exclusive and `radii` rows run strictly forward.
166
+ */
167
+ export const OperationRecord: z.ZodType<OperationRecord, OperationRecord> = z
168
+ .discriminatedUnion("op", [
169
+ z.strictObject({
170
+ op: z.literal("fillet"),
171
+ edges: z.array(EdgeSelector).min(1).max(MAX_OPERATION_EDGES),
172
+ radius: z.number().finite().positive(),
173
+ endRadius: z.number().finite().positive().optional(),
174
+ radii: z.array(FilletLawRow).min(2).max(MAX_FILLET_LAW_SAMPLES).optional(),
175
+ input: TopologyCounts,
176
+ }),
177
+ z.strictObject({
178
+ op: z.literal("chamfer"),
179
+ edges: z.array(EdgeSelector).min(1).max(MAX_OPERATION_EDGES),
180
+ distance: z.number().finite().positive(),
181
+ input: TopologyCounts,
182
+ }),
183
+ z.strictObject({
184
+ op: z.literal("shell"),
185
+ openFaces: z.array(FaceSelector).min(1).max(MAX_OPERATION_FACES),
186
+ thickness: z.number().finite().positive(),
187
+ input: TopologyCounts,
188
+ }),
189
+ z.strictObject({
190
+ op: z.literal("offset"),
191
+ distance: z
192
+ .number()
193
+ .finite()
194
+ .refine((value) => value !== 0, { message: "distance must be non-zero" }),
195
+ input: TopologyCounts,
196
+ }),
197
+ ])
198
+ .superRefine((operation, ctx) => {
199
+ if (operation.op !== "fillet") return
200
+ const { edges, endRadius, radii } = operation
201
+ if (endRadius === undefined && radii === undefined) return
202
+ if (endRadius !== undefined && radii !== undefined) {
203
+ ctx.addIssue({
204
+ code: "custom",
205
+ message: "endRadius is mutually exclusive with radii",
206
+ })
207
+ }
208
+ if (edges.length !== 1) {
209
+ ctx.addIssue({
210
+ code: "custom",
211
+ message: "a variable fillet names exactly one edge — the blend contour it runs along",
212
+ })
213
+ }
214
+ if (radii?.some((row, i) => i > 0 && row.position <= radii[i - 1].position)) {
215
+ ctx.addIssue({
216
+ code: "custom",
217
+ message: "radii positions must strictly increase",
218
+ })
219
+ }
220
+ })
221
+
222
+ /**
223
+ * One value of a parameter patch. See {@linkcode ParameterPatchValue}.
224
+ *
225
+ * Deliberately a CLOSED union of the shapes a record's `values` actually hold —
226
+ * no `z.unknown()`, nothing recursive: an unrecognised value is a VALIDATION at
227
+ * the wire, not a silent write of nonsense onto a mass. It only ever widens, so
228
+ * every value it accepted before it still accepts.
229
+ */
230
+ export const ParameterPatchValue: z.ZodType<ParameterPatchValue, ParameterPatchValue> = z.lazy(() =>
231
+ z.union([
232
+ z.number().finite(),
233
+ XYZ,
234
+ z.array(XYZ).max(MAX_SWEEP_PATH_POINTS),
235
+ ContourRecord,
236
+ z.array(ContourRecord).max(MAX_LOFT_SECTIONS),
237
+ z.array(CurveRecord).max(MAX_PATH_CURVES),
238
+ LoftOptions,
239
+ SweepOptions,
240
+ SweepAlongCurveRecordOptions,
241
+ z.array(OperationRecord).max(MAX_OPERATIONS),
242
+ ]),
243
+ )