@snaptrude/plugin-core 0.0.0-dev-20260911064951 → 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 (79) hide show
  1. package/CHANGELOG.md +0 -25
  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/core/io/import/index.d.ts +1 -3
  15. package/dist/api/core/io/import/index.d.ts.map +1 -1
  16. package/dist/api/design/create/index.d.ts +22 -310
  17. package/dist/api/design/create/index.d.ts.map +1 -1
  18. package/dist/api/design/delete/index.d.ts +0 -4
  19. package/dist/api/design/delete/index.d.ts.map +1 -1
  20. package/dist/api/design/doors/index.d.ts +13 -20
  21. package/dist/api/design/doors/index.d.ts.map +1 -1
  22. package/dist/api/design/index.d.ts +0 -5
  23. package/dist/api/design/index.d.ts.map +1 -1
  24. package/dist/api/design/query/geometry/index.d.ts +27 -1
  25. package/dist/api/design/query/geometry/index.d.ts.map +1 -1
  26. package/dist/api/design/query/index.d.ts +47 -0
  27. package/dist/api/design/query/index.d.ts.map +1 -1
  28. package/dist/api/design/query/spaces.d.ts +5 -5
  29. package/dist/api/design/update/index.d.ts +87 -0
  30. package/dist/api/design/update/index.d.ts.map +1 -1
  31. package/dist/api/entity/referenceLine.d.ts +2 -2
  32. package/dist/api/entity/referenceLine.d.ts.map +1 -1
  33. package/dist/api/entity/space.d.ts +5 -4
  34. package/dist/api/entity/space.d.ts.map +1 -1
  35. package/dist/api/entity/story.d.ts +4 -4
  36. package/dist/api/presentation/annotate.d.ts +2 -2
  37. package/dist/api/presentation/shapes.d.ts +2 -2
  38. package/dist/api/program/site.d.ts +4 -4
  39. package/dist/api/program/spreadsheet.d.ts +4 -4
  40. package/dist/handles.d.ts +12 -22
  41. package/dist/handles.d.ts.map +1 -1
  42. package/dist/index.cjs +2773 -2445
  43. package/dist/index.cjs.map +1 -1
  44. package/dist/index.d.ts +2 -0
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/index.js +2726 -2422
  47. package/dist/index.js.map +1 -1
  48. package/dist/massParameters.d.ts +280 -0
  49. package/dist/massParameters.d.ts.map +1 -0
  50. package/dist/massParameters.ops.d.ts +135 -0
  51. package/dist/massParameters.ops.d.ts.map +1 -0
  52. package/package.json +1 -1
  53. package/src/api/core/geom/create/index.ts +1011 -94
  54. package/src/api/core/geom/query/brep.ts +51 -0
  55. package/src/api/core/geom/query/curve.ts +25 -2
  56. package/src/api/core/geom/query/edge.ts +2 -2
  57. package/src/api/core/geom/query/face.ts +109 -4
  58. package/src/api/core/io/import/index.ts +3 -11
  59. package/src/api/design/create/index.ts +38 -335
  60. package/src/api/design/delete/index.ts +0 -4
  61. package/src/api/design/doors/index.ts +13 -20
  62. package/src/api/design/index.ts +0 -5
  63. package/src/api/design/query/geometry/index.ts +29 -0
  64. package/src/api/design/query/index.ts +50 -0
  65. package/src/api/design/update/index.ts +94 -0
  66. package/src/handles.ts +15 -27
  67. package/src/index.ts +2 -0
  68. package/src/massParameters.ops.ts +243 -0
  69. package/src/massParameters.ts +418 -0
  70. package/test/massParameters.test.mjs +936 -0
  71. package/dist/api/design/create/bulk-items.d.ts +0 -185
  72. package/dist/api/design/create/bulk-items.d.ts.map +0 -1
  73. package/dist/api/design/create/opening-fields.d.ts +0 -37
  74. package/dist/api/design/create/opening-fields.d.ts.map +0 -1
  75. package/dist/api/design/dimensions.d.ts +0 -427
  76. package/dist/api/design/dimensions.d.ts.map +0 -1
  77. package/src/api/design/create/bulk-items.ts +0 -186
  78. package/src/api/design/create/opening-fields.ts +0 -37
  79. package/src/api/design/dimensions.ts +0 -453
@@ -14,7 +14,6 @@ import { PluginDesignTransformApi } from "./transform"
14
14
  import { PluginDesignEditApi } from "./edit"
15
15
  import { PluginDesignUpdateApi } from "./update"
16
16
  import { PluginDesignVisibilityApi } from "./visibility"
17
- import { PluginDesignDimensionsApi } from "./dimensions"
18
17
  import { PluginDesignTypesApi } from "./types"
19
18
  import { PluginDesignFamilyApi } from "./family"
20
19
  import { PluginDesignChangeResult } from "./lock"
@@ -32,7 +31,6 @@ import { PluginDesignChangeResult } from "./lock"
32
31
  * - {@linkcode PluginDesignApi.erase} — plan-level adjacency-edge erase (NOT hard delete)
33
32
  * - {@linkcode PluginDesignApi.delete} — hard entity removal
34
33
  * - {@linkcode PluginDesignApi.visibility} — hide / isolate / reveal entities
35
- * - {@linkcode PluginDesignApi.dimensions} — dimension lines (Measuring Tape): create / list / delete / hide
36
34
  * - {@linkcode PluginDesignApi.types} — read-only building type / assembly reference
37
35
  * - {@linkcode PluginDesignApi.family} — author parametric families from a JSON spec
38
36
  * - {@linkcode PluginDesignApi.lock} / {@linkcode PluginDesignApi.unlock} / {@linkcode PluginDesignApi.isLocked} / {@linkcode PluginDesignApi.listLocked} — lock state (top-level design verbs, §2A.1)
@@ -69,8 +67,6 @@ export abstract class PluginDesignApi {
69
67
  public abstract update: PluginDesignUpdateApi
70
68
  /** Hide / isolate / reveal entities. See {@linkcode PluginDesignVisibilityApi}. */
71
69
  public abstract visibility: PluginDesignVisibilityApi
72
- /** Dimension lines (Measuring Tape). See {@linkcode PluginDesignDimensionsApi}. */
73
- public abstract dimensions: PluginDesignDimensionsApi
74
70
  /** Read-only building type / assembly reference. See {@linkcode PluginDesignTypesApi}. */
75
71
  public abstract types: PluginDesignTypesApi
76
72
  /** Author parametric families from a JSON spec. See {@linkcode PluginDesignFamilyApi}. */
@@ -264,6 +260,5 @@ export * from "./transform"
264
260
  export * from "./edit"
265
261
  export * from "./update"
266
262
  export * from "./visibility"
267
- export * from "./dimensions"
268
263
  export * from "./types"
269
264
  export * from "./family"
@@ -34,10 +34,25 @@ export abstract class PluginDesignQueryGeometryApi {
34
34
  * scene entity, as a reusable {@linkcode BrepHandle} for the
35
35
  * `core.geom.query.brep.*` reads.
36
36
  *
37
+ * **Frame.** By default the brep comes back in the component's own LOCAL frame
38
+ * (its vertices are relative to the mesh origin, exactly as stored) — the
39
+ * behaviour every 0.9.x caller relies on. Pass `{ frame: "world" }` to get the
40
+ * same solid placed where it sits in the scene (world coordinates, like
41
+ * `getBottomContour` / `getTriangulatedMeshes` and every `design.query.measure`
42
+ * read). Use `"world"` whenever the handle will be COMBINED with other scene
43
+ * geometry or committed back beside its source: booleans between two scene
44
+ * masses, `brepFromFillet` / `brepFromShell` / `brepFromOffset` /
45
+ * `brepFromChamfer` on a scene mass followed by `massFromBrep`, or comparing
46
+ * its vertices with a bounding box. A world-frame handle from a parametrically
47
+ * live mass also carries that mass's recipe, so an operation result keeps an
48
+ * editable record.
49
+ *
37
50
  * @param component - The scene component to read
51
+ * @param options - `frame`: `"local"` (default, mesh-local coordinates) or `"world"` (scene coordinates)
38
52
  * @returns The brep as a {@linkcode BrepHandle}, or `null` if the component has no brep geometry
39
53
  *
40
54
  * @examplePrompt Get the 3D solid geometry of the selected wall
55
+ * @examplePrompt Round the top rim of this column and put it back where it is
41
56
  * @examplePrompt How many faces does this mass have?
42
57
  * @examplePrompt Inspect the mesh of this slab so I can look at its faces and edges
43
58
  * @examplePrompt Read the vertices of the selected column's geometry
@@ -48,10 +63,16 @@ export abstract class PluginDesignQueryGeometryApi {
48
63
  * if (brep) {
49
64
  * const faces = await snaptrude.core.geom.query.brep.listFaces(brep)
50
65
  * }
66
+ *
67
+ * // Operate on a scene mass and commit the result where the mass sits:
68
+ * const placed = await snaptrude.design.query.geometry.getBrep(mass, { frame: "world" })
69
+ * const rounded = await snaptrude.core.geom.create.brepFromFillet(placed, edges, 0.2)
70
+ * await snaptrude.design.create.massFromBrep(rounded, "Rounded")
51
71
  * ```
52
72
  */
53
73
  public abstract getBrep(
54
74
  component: ComponentHandle,
75
+ options?: PluginDesignQueryGeometryGetBrepOptions,
55
76
  ): PluginApiReturn<BrepHandle | null>
56
77
 
57
78
  /**
@@ -189,8 +210,16 @@ export abstract class PluginDesignQueryGeometryApi {
189
210
  * |---|---|---|
190
211
  * | `component` | {@linkcode ComponentHandle} | The scene component to read |
191
212
  */
213
+ /** Options for {@linkcode PluginDesignQueryGeometryApi.getBrep}: `frame` defaults to `"local"`. */
214
+ export type PluginDesignQueryGeometryGetBrepOptions = { frame?: "local" | "world" }
215
+ export const PluginDesignQueryGeometryGetBrepOptions: z.ZodType<
216
+ PluginDesignQueryGeometryGetBrepOptions,
217
+ PluginDesignQueryGeometryGetBrepOptions
218
+ > = z.object({ frame: z.enum(["local", "world"]).optional() })
219
+
192
220
  export const PluginDesignQueryGeometryGetBrepArgs = z.object({
193
221
  component: ComponentHandle,
222
+ options: PluginDesignQueryGeometryGetBrepOptions.optional(),
194
223
  })
195
224
 
196
225
  export type PluginDesignQueryGeometryGetBrepArgs = z.infer<
@@ -1,6 +1,7 @@
1
1
  import * as z from "zod"
2
2
  import { PluginApiReturn } from "../../../types"
3
3
  import { ComponentHandle, BBoxComponents } from "../../../handles"
4
+ import type { MassParametersRecord } from "../../../massParameters"
4
5
  import {
5
6
  PluginSpaceType,
6
7
  PluginMassType,
@@ -1014,6 +1015,55 @@ export abstract class PluginDesignQueryApi {
1014
1015
  staircase: ComponentHandle,
1015
1016
  ): PluginApiReturn<PluginStaircaseParams | null>
1016
1017
 
1018
+ /**
1019
+ * Read a mass's creation-parameter record — the recipe it was built from
1020
+ * (`kind` plus the values that constructor was called with). Present on
1021
+ * masses committed from a `core.geom.create` brep constructor that carries a
1022
+ * recipe: {@linkcode MassParametersRecord} covers the four primitives
1023
+ * (sphere, cylinder, cone, torus), extrusions, revolutions, lofts and sweeps.
1024
+ *
1025
+ * A fillet, chamfer, shell or offset of a recorded solid keeps the record
1026
+ * too: `kind` stays the base constructor and the operation is appended to the
1027
+ * record's `operations` list. Edit any of it with `design.update.parameters`.
1028
+ *
1029
+ * `null` for everything else — drawn masses, imported geometry, booleans,
1030
+ * split parts, `brepFromFaces` / `brepFromMesh`, and results built on a
1031
+ * source that carried no record — and for a mass whose record no longer
1032
+ * matches what is on
1033
+ * screen (a later free-form edit dropped the recipe, or the mass carries a
1034
+ * baked scale). `null` too when the recipe was not recordable: the record
1035
+ * schema has its own caps (a sweep path of at most 512 points, a loft of at
1036
+ * most 32 sections, at most 8 chained `operations`, at most 256 curves in one
1037
+ * profile loop and 64 holes in one contour), and a mass built past one of
1038
+ * them — through a route that does not enforce the matching creator cap —
1039
+ * commits as ordinary geometry carrying no record. The `operations` cap is
1040
+ * the one an agent can walk into by accident: a 9th chained
1041
+ * fillet/chamfer/shell/offset drops the record silently, so the result
1042
+ * commits as ordinary geometry and reads back `null` here. A record is never
1043
+ * reported unless it is still the truth.
1044
+ *
1045
+ * Points and axes come back in **world** coordinates. Pure read — nothing is
1046
+ * created or modified.
1047
+ *
1048
+ * @param component - the mass's {@linkcode ComponentHandle}
1049
+ * @returns the {@linkcode MassParametersRecord}, or `null`
1050
+ *
1051
+ * @examplePrompt What radius is this sphere?
1052
+ * @examplePrompt Is this mass parametric?
1053
+ * @examplePrompt Read back the dome's creation parameters
1054
+ * @examplePrompt How tall was this cylinder made?
1055
+ *
1056
+ * # Example
1057
+ * ```ts
1058
+ * const [mass] = await snaptrude.design.query.listMasses({ isSelected: true })
1059
+ * const params = await snaptrude.design.query.getParameters(mass)
1060
+ * if (params?.kind === "sphere") console.log("radius:", params.values.radius)
1061
+ * ```
1062
+ */
1063
+ public abstract getParameters(
1064
+ component: ComponentHandle,
1065
+ ): PluginApiReturn<MassParametersRecord | null>
1066
+
1017
1067
  /**
1018
1068
  * Get the **union** axis-aligned bounding box enclosing a set of entities.
1019
1069
  *
@@ -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**
package/src/handles.ts CHANGED
@@ -115,19 +115,6 @@ export type UnderlayHandle = EntityId<"underlay">
115
115
  */
116
116
  export type TerrainHandle = EntityId<"terrain">
117
117
 
118
- /**
119
- * A **dimension line** — one measurement annotation left behind by the Measuring
120
- * Tape tool (NOT a width/height/depth property; see `design.dimensions`).
121
- * Entity-style: the token IS the raw engine dimension id (`dim_…`), resolved live
122
- * host-side from the dimension-line registry (`getDimensionLineMap()`) — not via
123
- * `ComponentUtility.FindComponentById`, which does not index dimension lines (a
124
- * dimension line is not a Component). No arena, no quota, stable across
125
- * undo/redo and across reloads (the record persists with the project). Returned
126
- * by `design.dimensions.create` and consumed by every other
127
- * `design.dimensions.*` method.
128
- */
129
- export type DimensionHandle = EntityId<"dimension">
130
-
131
118
  /**
132
119
  * A handle to an **asynchronous import job** (today: a DWG → Forge conversion, which
133
120
  * can take minutes). Returned immediately by `core.io.import.dwg`; poll it via
@@ -145,8 +132,16 @@ export type Vec3Handle = Handle<"vec3">
145
132
  export type QuatHandle = Handle<"quat">
146
133
  export type LineHandle = Handle<"line">
147
134
  export type ArcHandle = Handle<"arc">
148
- /** A curve is a line or an arc — its handle is one of those kinds. */
149
- 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
150
145
  /**
151
146
  * A circle value handle. A circle is a CLOSED curve — it deliberately does NOT
152
147
  * join {@linkcode CurveHandle} (it has no stable start/end and would break the
@@ -246,23 +241,16 @@ export const ImportJobHandle = z
246
241
  .min(1)
247
242
  .transform((s) => s as ImportJobHandle)
248
243
 
249
- /**
250
- * {@linkcode DimensionHandle} is an entity-style handle — the raw `dim_…` engine
251
- * id, validated only as a non-empty string (no `"<kind>_"` prefix enforcement),
252
- * resolved live host-side against the dimension-line registry (existence
253
- * enforced there, as `HANDLE_INVALID`).
254
- */
255
- export const DimensionHandle = z
256
- .string()
257
- .min(1)
258
- .transform((s) => s as DimensionHandle)
259
-
260
244
  // Value-kind handle schemas (all-handle model, §11).
261
245
  export const Vec3Handle = handleSchema("vec3")
262
246
  export const QuatHandle = handleSchema("quat")
263
247
  export const LineHandle = handleSchema("line")
264
248
  export const ArcHandle = handleSchema("arc")
265
- 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])
266
254
  export const CircleHandle = handleSchema("circle")
267
255
 
268
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
+ )