@snaptrude/plugin-core 0.9.13 → 0.9.14

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 (65) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/api-manifest.json +778 -32
  3. package/dist/api/core/geom/create/index.d.ts +935 -100
  4. package/dist/api/core/geom/create/index.d.ts.map +1 -1
  5. package/dist/api/core/geom/query/brep.d.ts +59 -2
  6. package/dist/api/core/geom/query/brep.d.ts.map +1 -1
  7. package/dist/api/core/geom/query/curve.d.ts +59 -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/contour.d.ts +2 -0
  13. package/dist/api/core/geom/update/contour.d.ts.map +1 -1
  14. package/dist/api/core/geom/update/curve.d.ts +5 -5
  15. package/dist/api/core/geom/update/profile.d.ts +3 -1
  16. package/dist/api/core/geom/update/profile.d.ts.map +1 -1
  17. package/dist/api/core/handles/index.d.ts +4 -2
  18. package/dist/api/core/handles/index.d.ts.map +1 -1
  19. package/dist/api/design/create/grids.d.ts +1 -1
  20. package/dist/api/design/family.d.ts +67 -10
  21. package/dist/api/design/family.d.ts.map +1 -1
  22. package/dist/api/design/query/geometry/index.d.ts +33 -5
  23. package/dist/api/design/query/geometry/index.d.ts.map +1 -1
  24. package/dist/api/design/query/grids.d.ts +3 -3
  25. package/dist/api/design/query/index.d.ts +47 -0
  26. package/dist/api/design/query/index.d.ts.map +1 -1
  27. package/dist/api/design/query/spaces.d.ts +5 -5
  28. package/dist/api/design/update/index.d.ts +99 -0
  29. package/dist/api/design/update/index.d.ts.map +1 -1
  30. package/dist/api/entity/referenceLine.d.ts +1 -1
  31. package/dist/api/entity/space.d.ts +4 -4
  32. package/dist/api/entity/story.d.ts +4 -4
  33. package/dist/api/program/site.d.ts +4 -4
  34. package/dist/api/program/spreadsheet.d.ts +4 -4
  35. package/dist/handles.d.ts +13 -3
  36. package/dist/handles.d.ts.map +1 -1
  37. package/dist/index.cjs +3417 -2946
  38. package/dist/index.cjs.map +1 -1
  39. package/dist/index.d.ts +2 -0
  40. package/dist/index.d.ts.map +1 -1
  41. package/dist/index.js +3370 -2946
  42. package/dist/index.js.map +1 -1
  43. package/dist/massParameters.d.ts +287 -0
  44. package/dist/massParameters.d.ts.map +1 -0
  45. package/dist/massParameters.ops.d.ts +138 -0
  46. package/dist/massParameters.ops.d.ts.map +1 -0
  47. package/package.json +2 -1
  48. package/scripts/check-dist-fresh.mjs +22 -0
  49. package/src/api/core/geom/create/index.ts +1030 -101
  50. package/src/api/core/geom/query/brep.ts +60 -2
  51. package/src/api/core/geom/query/curve.ts +26 -2
  52. package/src/api/core/geom/query/edge.ts +2 -2
  53. package/src/api/core/geom/query/face.ts +109 -4
  54. package/src/api/core/geom/update/contour.ts +2 -0
  55. package/src/api/core/geom/update/profile.ts +2 -0
  56. package/src/api/core/handles/index.ts +3 -2
  57. package/src/api/design/family.ts +68 -10
  58. package/src/api/design/query/geometry/index.ts +35 -4
  59. package/src/api/design/query/index.ts +50 -0
  60. package/src/api/design/update/index.ts +106 -0
  61. package/src/handles.ts +18 -3
  62. package/src/index.ts +2 -0
  63. package/src/massParameters.ops.ts +246 -0
  64. package/src/massParameters.ts +427 -0
  65. package/test/massParameters.test.mjs +952 -0
@@ -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,
@@ -1040,6 +1041,55 @@ export abstract class PluginDesignQueryApi {
1040
1041
  staircase: ComponentHandle,
1041
1042
  ): PluginApiReturn<PluginStaircaseParams | null>
1042
1043
 
1044
+ /**
1045
+ * Read a mass's creation-parameter record — the recipe it was built from
1046
+ * (`kind` plus the values that constructor was called with). Present on
1047
+ * masses committed from a `core.geom.create` brep constructor that carries a
1048
+ * recipe: {@linkcode MassParametersRecord} covers the four primitives
1049
+ * (sphere, cylinder, cone, torus), extrusions, revolutions, lofts and sweeps.
1050
+ *
1051
+ * A fillet, chamfer, shell or offset of a recorded solid keeps the record
1052
+ * too: `kind` stays the base constructor and the operation is appended to the
1053
+ * record's `operations` list. Edit any of it with `design.update.parameters`.
1054
+ *
1055
+ * `null` for everything else — drawn masses, imported geometry, booleans,
1056
+ * split parts, `brepFromFaces` / `brepFromMesh`, and results built on a
1057
+ * source that carried no record — and for a mass whose record no longer
1058
+ * matches what is on
1059
+ * screen (a later free-form edit dropped the recipe, or the mass carries a
1060
+ * baked scale). `null` too when the recipe was not recordable: the record
1061
+ * schema has its own caps (a sweep path of at most 512 points, a loft of at
1062
+ * most 32 sections, at most 8 chained `operations`, at most 256 curves in one
1063
+ * profile loop and 64 holes in one contour), and a mass built past one of
1064
+ * them — through a route that does not enforce the matching creator cap —
1065
+ * commits as ordinary geometry carrying no record. The `operations` cap is
1066
+ * the one an agent can walk into by accident: a 9th chained
1067
+ * fillet/chamfer/shell/offset drops the record silently, so the result
1068
+ * commits as ordinary geometry and reads back `null` here. A record is never
1069
+ * reported unless it is still the truth.
1070
+ *
1071
+ * Points and axes come back in **world** coordinates. Pure read — nothing is
1072
+ * created or modified.
1073
+ *
1074
+ * @param component - the mass's {@linkcode ComponentHandle}
1075
+ * @returns the {@linkcode MassParametersRecord}, or `null`
1076
+ *
1077
+ * @examplePrompt What radius is this sphere?
1078
+ * @examplePrompt Is this mass parametric?
1079
+ * @examplePrompt Read back the dome's creation parameters
1080
+ * @examplePrompt How tall was this cylinder made?
1081
+ *
1082
+ * # Example
1083
+ * ```ts
1084
+ * const [mass] = await snaptrude.design.query.listMasses({ isSelected: true })
1085
+ * const params = await snaptrude.design.query.getParameters(mass)
1086
+ * if (params?.kind === "sphere") console.log("radius:", params.values.radius)
1087
+ * ```
1088
+ */
1089
+ public abstract getParameters(
1090
+ component: ComponentHandle,
1091
+ ): PluginApiReturn<MassParametersRecord | null>
1092
+
1043
1093
  /**
1044
1094
  * Get the **union** axis-aligned bounding box enclosing a set of entities.
1045
1095
  *
@@ -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,
@@ -137,6 +138,22 @@ export type PluginDesignUpdateStaircaseArgs = z.infer<
137
138
  typeof PluginDesignUpdateStaircaseArgs
138
139
  >
139
140
 
141
+ /**
142
+ * Arguments for {@linkcode PluginDesignUpdateApi.parameters}.
143
+ *
144
+ * | Property | Type | Description |
145
+ * |---|---|---|
146
+ * | `component` | {@linkcode ComponentHandle} | The parametric mass to edit |
147
+ * | `patch` | {@linkcode MassParametersPatch} | Partial `values` (+ optional `operations`), or the full edited record |
148
+ */
149
+ export const PluginDesignUpdateParametersArgs = z.object({
150
+ component: ComponentHandle,
151
+ patch: MassParametersPatch,
152
+ })
153
+ export type PluginDesignUpdateParametersArgs = z.infer<
154
+ typeof PluginDesignUpdateParametersArgs
155
+ >
156
+
140
157
  /**
141
158
  * Sparse edits for a wall (all optional; at least one required). Only the
142
159
  * fields you provide change. Dimensions are in **engine units** (the same
@@ -462,6 +479,95 @@ export abstract class PluginDesignUpdateApi {
462
479
  params: PluginStaircaseParamUpdates,
463
480
  ): PluginApiReturn<PluginDesignChangeResult>
464
481
 
482
+ /**
483
+ * Edit a parametric mass by patching its creation recipe and rebuilding the
484
+ * solid in place — the mass keeps its id, storey, materials, position and
485
+ * linked copies; only the geometry changes. Read the current record with
486
+ * `design.query.getParameters` first.
487
+ *
488
+ * `patch` is a partial of `record.values` — or the whole record you read
489
+ * back, edited. A key you leave out is unchanged (that includes
490
+ * `operations`). Each key you send replaces that value whole — a scalar, a
491
+ * point, a list or a record (`contour`, `profile`, `sections`, `path`,
492
+ * `options`, `operations`) alike — so send the complete value you read,
493
+ * edited (a partial `options` drops the switches it leaves out);
494
+ * `{ operations: [] }` drops every operation. An optional key
495
+ * the record does not carry yet may be patched in when the kind allows it:
496
+ * a straight extrusion acquires `twistInDegrees` or `topScale`, an
497
+ * options-less loft or sweep acquires `options` (`levels` is not one — send
498
+ * the angle, not the section count). A patch that changes nothing
499
+ * returns the current record and records no edit (no undo step). `kind` and
500
+ * `version` are immutable: to change the kind, build a new mass. Keys are the
501
+ * record's `values` keys for its `kind` (sphere: `centre`, `radius`;
502
+ * cylinder: `base`, `axis`, `radius`, `height`; torus: `centre`, `axis`,
503
+ * `majorRadius`, `minorRadius`; …) plus `operations`. To change a fillet
504
+ * radius, edit `operations[i].radius` in the record you read and send
505
+ * `{ operations }` back. Points and axes are WORLD coordinates in internal
506
+ * units, exactly as `getParameters` reports them.
507
+ *
508
+ * Rebuilds in memory first, then swaps onto the SAME component; every linked
509
+ * copy regenerates together. One undo step; saves and syncs to collaborators
510
+ * like any geometry edit. Kernel kinds (revolution, sweep, loft, primitives,
511
+ * any `operations`) run on OpenCascade — expect a short pause.
512
+ *
513
+ * @param component - a mass whose `getParameters` is non-null
514
+ * @param patch - partial `values` (+ optional `operations`), or the full edited record
515
+ * @returns the complete post-edit record, world coordinates (what
516
+ * `getParameters` now returns)
517
+ * @throws PRECONDITION_FAILED when the component is not a mass (a family
518
+ * instance: use `design.family.setParameters`).
519
+ * Also PRECONDITION_FAILED when the mass carries no live recipe — built
520
+ * from a boolean, split, `brepFromFaces`/`brepFromMesh` or drawn; edited
521
+ * free-form since (push/pull, move face, boolean); or scaled with the
522
+ * transform tool. `getParameters` returns `null` for exactly these.
523
+ * Do not retry — rebuild it with a recipe constructor and say so.
524
+ * A scaled mass is the exception: undo the scale and call again.
525
+ * Also PRECONDITION_FAILED when the mass (or a linked copy) is **locked**
526
+ * (the message says so). Locking is invisible to `getParameters` — a
527
+ * locked parametric mass still reads back a full record. Unlock it (and
528
+ * every linked copy) and call again; never rebuild it, the recipe is intact.
529
+ * Also PRECONDITION_FAILED when an `operations` entry's edge/face selectors
530
+ * no longer resolve on the rebuilt base (the message names the operation
531
+ * and edge): re-select the edges on the new shape and re-apply that
532
+ * operation.
533
+ * Also PRECONDITION_FAILED when the edit is the first twist or taper — or
534
+ * the straightening — of an extrusion that carries a shell, fillet or
535
+ * chamfer (the kernel numbers its faces differently): send the twist/taper
536
+ * keys with `operations: []` first (the message names them), re-select on
537
+ * the new shape, then send `{ operations }` back.
538
+ * @throws VALIDATION for a key the kind does not have (the message lists the
539
+ * kind's keys), `kind` or `version` in a partial patch, or a value outside
540
+ * the constructor's own rules (torus tube ≥ ring, revolution angle ∉
541
+ * (0, 360], a profile crossing its axis, a spline with fewer than
542
+ * degree + 1 poles).
543
+ * @throws OPERATION_FAILED when the kernel cannot build the edited recipe;
544
+ * the model is left unchanged.
545
+ *
546
+ * @examplePrompt Make the dome's radius 8 metres
547
+ * @examplePrompt Raise the podium to 5 m
548
+ * @examplePrompt Widen the vase — move its profile points 20 cm outward
549
+ * @examplePrompt Change the fillet on the rounded column to 300 mm
550
+ *
551
+ * # Example
552
+ * ```ts
553
+ * // { kind: "sphere", values: { centre, radius: 19.685 }, … }
554
+ * const before = await snaptrude.design.query.getParameters(dome)
555
+ * const after = await snaptrude.design.update.parameters(dome, { radius: 31.496 }) // 8 m in internal units
556
+ *
557
+ * // Fillet radius on a recorded result: read → edit → send the array back
558
+ * const rec = await snaptrude.design.query.getParameters(column)
559
+ * const operations = rec?.operations ?? []
560
+ * if (operations[0]?.op === "fillet") {
561
+ * operations[0].radius = 1.181
562
+ * await snaptrude.design.update.parameters(column, { operations })
563
+ * }
564
+ * ```
565
+ */
566
+ public abstract parameters(
567
+ component: ComponentHandle,
568
+ patch: MassParametersPatch,
569
+ ): PluginApiReturn<MassParametersRecord>
570
+
465
571
  /**
466
572
  * Edit a **wall** — its thickness and/or height (the same command the
467
573
  * properties panel's Thickness/Height fields drive) and/or its **wall type**
package/src/handles.ts CHANGED
@@ -145,8 +145,17 @@ export type Vec3Handle = Handle<"vec3">
145
145
  export type QuatHandle = Handle<"quat">
146
146
  export type LineHandle = Handle<"line">
147
147
  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
148
+ /**
149
+ * A NURBS curve value handle (open B-spline curve). Minted by
150
+ * `core.geom.create.splineFromPoints` / `splineFromControlPoints`, and returned by
151
+ * `edge.getCurve`, `profile.listCurves` and `update.curve.reverse` for a spline run;
152
+ * accepted everywhere a {@linkcode CurveHandle} is (profileFromCurves, query.curve.*).
153
+ * Closed spline loops never exist as a single handle — a closed run is built
154
+ * directly as a profile via `core.geom.create.profileFromSplinePoints`.
155
+ */
156
+ export type SplineHandle = Handle<"spline">
157
+ /** A curve is a line, an arc, or a spline — its handle is one of those kinds. */
158
+ export type CurveHandle = LineHandle | ArcHandle | SplineHandle
150
159
  /**
151
160
  * A circle value handle. A circle is a CLOSED curve — it deliberately does NOT
152
161
  * join {@linkcode CurveHandle} (it has no stable start/end and would break the
@@ -262,7 +271,13 @@ export const Vec3Handle = handleSchema("vec3")
262
271
  export const QuatHandle = handleSchema("quat")
263
272
  export const LineHandle = handleSchema("line")
264
273
  export const ArcHandle = handleSchema("arc")
265
- export const CurveHandle = z.union([LineHandle, ArcHandle])
274
+ export const SplineHandle = handleSchema("spline")
275
+ // Explicitly typed (rather than inferred): the inferred union type prints its
276
+ // three fully-expanded member schemas into handles.d.ts, which is served to
277
+ // agents whole and has a size budget. ZodUnion (not ZodType) keeps `.options`.
278
+ export const CurveHandle: z.ZodUnion<
279
+ readonly [typeof LineHandle, typeof ArcHandle, typeof SplineHandle]
280
+ > = z.union([LineHandle, ArcHandle, SplineHandle])
266
281
  export const CircleHandle = handleSchema("circle")
267
282
 
268
283
  // 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,246 @@
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` so that each file stays under the size limit
21
+ * at which the agent runtime still serves a type module in ONE whole read (the
22
+ * record module alone had grown past it). Do not merge the two back. It is
23
+ * re-exported from there and from the package root, so every import path keeps
24
+ * working.
25
+ *
26
+ * Everything here is **pure JSON** by construction, exactly as in
27
+ * {@linkcode MassParametersRecord}: plain objects, numbers and arrays only, one
28
+ * `{x, y, z}` point shape, no class instances.
29
+ */
30
+
31
+ /** Maximum kernel operations chained onto one recipe. */
32
+ export const MAX_OPERATIONS = 8
33
+ /** Maximum edges one fillet/chamfer operation may select. */
34
+ export const MAX_OPERATION_EDGES = 64
35
+ /** Maximum faces one shell operation may open. */
36
+ export const MAX_OPERATION_FACES = 32
37
+ /** Maximum rows in a variable-fillet radius law. */
38
+ export const MAX_FILLET_LAW_SAMPLES = 32
39
+
40
+ // `XYZ` and the record schemas below are resolved through `z.lazy`: this module
41
+ // and `massParameters.ts` re-export each other, and this one is evaluated first,
42
+ // so their consts are not yet initialised while these schemas are built. The
43
+ // closures run at parse time, when both modules are live.
44
+ const At: z.ZodType<XYZ, XYZ> = z.lazy(() => XYZ)
45
+
46
+ /**
47
+ * Which EDGE of the input solid an operation used: its index in
48
+ * `core.geom.query.brep.listEdges` order at authoring time, the indices of the
49
+ * two faces it lies between, and its curve kind. This is topology, not
50
+ * coordinates — it survives a scalar edit of the base recipe (which moves every
51
+ * edge) and trips on a reorder or a topology change. Read-only: to blend a
52
+ * different edge, re-select it on the new shape and re-apply the operation.
53
+ */
54
+ export type EdgeSelector = {
55
+ index: number
56
+ faces: [number, number]
57
+ curve: CurveKind
58
+ /** Where the edge sits INSIDE its solid: its midpoint in the record's own
59
+ * frame, divided by the solid's bounding-box extent — a ratio per axis,
60
+ * never a length, so it survives a scalar edit that scales the whole shape.
61
+ * Written only when the discriminators above cannot tell two edges apart. A
62
+ * tiebreak, never a coordinate fingerprint: a replay checks it within 0.02 of
63
+ * the solid's own box and refuses on a miss — it never searches for a better
64
+ * candidate. */
65
+ at?: XYZ
66
+ }
67
+
68
+ /**
69
+ * Which FACE of the input solid an operation used: its index in
70
+ * `core.geom.query.brep.listFaces` order, its surface kind, and the number of
71
+ * edges in its outer loop. Read-only, like {@linkcode EdgeSelector}.
72
+ */
73
+ export type FaceSelector = {
74
+ index: number
75
+ kind: SurfaceKind
76
+ edgeCount: number
77
+ /** The face's centroid under the same normalisation and the same tiebreak
78
+ * rule as {@linkcode EdgeSelector}'s `at` — written only where the
79
+ * discriminators above cannot separate two faces, which on a freeform solid
80
+ * (every face answers `"spline"`) is the common case. */
81
+ at?: XYZ
82
+ }
83
+
84
+ /** The input solid's topology at authoring time — the counts a replay checks first. */
85
+ export type TopologyCounts = { faceCount: number; edgeCount: number }
86
+
87
+ /**
88
+ * One kernel operation applied to the base recipe's solid, in order. `input`
89
+ * pins the topology the operation was authored against, so a base edit that
90
+ * changes the topology is refused rather than mis-applied.
91
+ *
92
+ * Edit one by patching the whole list back:
93
+ * `design.update.parameters(mass, { operations })`.
94
+ */
95
+ export type OperationRecord =
96
+ | {
97
+ op: "fillet"
98
+ edges: EdgeSelector[]
99
+ radius: number
100
+ /** Radius at the far end of the blend contour, internal length units — a
101
+ * linear variable blend from `radius`. One edge, and never with `radii`. */
102
+ endRadius?: number
103
+ /** The blend's radius law instead: `position` is normalised arc length
104
+ * along the blend contour (a ratio 0..1, never converted), `radius` is
105
+ * internal length units. 2..32 rows, strictly increasing `position`.
106
+ * One edge, and never with `endRadius`. */
107
+ radii?: { position: number; radius: number }[]
108
+ input: TopologyCounts
109
+ }
110
+ | { op: "chamfer"; edges: EdgeSelector[]; distance: number; input: TopologyCounts }
111
+ | { op: "shell"; openFaces: FaceSelector[]; thickness: number; input: TopologyCounts }
112
+ | { op: "offset"; distance: number; input: TopologyCounts }
113
+
114
+ /**
115
+ * One value of a `MassParametersPatch` — whatever a record's `values` key (or
116
+ * `operations`) may hold. Each key you send replaces that value whole — a
117
+ * scalar, a point, a list or a record (`contour`, `profile`, `sections`,
118
+ * `path`, `options`, `operations`) alike — so send the complete value you read.
119
+ */
120
+ export type ParameterPatchValue =
121
+ | number
122
+ | XYZ
123
+ | XYZ[]
124
+ | ContourRecord
125
+ | ContourRecord[]
126
+ | CurveRecord[]
127
+ | LoftOptions
128
+ | SweepOptions
129
+ | SweepAlongCurveRecordOptions
130
+ | OperationRecord[]
131
+
132
+ const FaceIndex = z.number().int().nonnegative()
133
+
134
+ /** See {@linkcode EdgeSelector}. */
135
+ export const EdgeSelector: z.ZodType<EdgeSelector, EdgeSelector> = z.strictObject({
136
+ index: FaceIndex,
137
+ faces: z.tuple([FaceIndex, FaceIndex]),
138
+ curve: z.enum(["line", "arc", "circle", "spline"]),
139
+ at: At.optional(),
140
+ })
141
+
142
+ /** See {@linkcode FaceSelector}. */
143
+ export const FaceSelector: z.ZodType<FaceSelector, FaceSelector> = z.strictObject({
144
+ index: FaceIndex,
145
+ kind: z.enum(["plane", "cylinder", "cone", "sphere", "torus", "spline"]),
146
+ edgeCount: z.number().int().positive(),
147
+ at: At.optional(),
148
+ })
149
+
150
+ /** See {@linkcode TopologyCounts}. */
151
+ export const TopologyCounts: z.ZodType<TopologyCounts, TopologyCounts> = z.strictObject({
152
+ faceCount: z.number().int().positive(),
153
+ edgeCount: z.number().int().positive(),
154
+ })
155
+
156
+ /** One row of a variable fillet's radius law. See {@linkcode OperationRecord}. */
157
+ const FilletLawRow = z.strictObject({
158
+ position: z.number().finite().min(0).max(1),
159
+ radius: z.number().finite().positive(),
160
+ })
161
+
162
+ /**
163
+ * See {@linkcode OperationRecord}.
164
+ *
165
+ * A variable fillet — `endRadius` or `radii` — names ONE edge: the law is a
166
+ * property of the blend contour that edge belongs to, and `position` is measured
167
+ * from that edge's start, so a second edge would have no origin. The two forms
168
+ * are mutually exclusive and `radii` rows run strictly forward.
169
+ */
170
+ export const OperationRecord: z.ZodType<OperationRecord, OperationRecord> = z
171
+ .discriminatedUnion("op", [
172
+ z.strictObject({
173
+ op: z.literal("fillet"),
174
+ edges: z.array(EdgeSelector).min(1).max(MAX_OPERATION_EDGES),
175
+ radius: z.number().finite().positive(),
176
+ endRadius: z.number().finite().positive().optional(),
177
+ radii: z.array(FilletLawRow).min(2).max(MAX_FILLET_LAW_SAMPLES).optional(),
178
+ input: TopologyCounts,
179
+ }),
180
+ z.strictObject({
181
+ op: z.literal("chamfer"),
182
+ edges: z.array(EdgeSelector).min(1).max(MAX_OPERATION_EDGES),
183
+ distance: z.number().finite().positive(),
184
+ input: TopologyCounts,
185
+ }),
186
+ z.strictObject({
187
+ op: z.literal("shell"),
188
+ openFaces: z.array(FaceSelector).min(1).max(MAX_OPERATION_FACES),
189
+ thickness: z.number().finite().positive(),
190
+ input: TopologyCounts,
191
+ }),
192
+ z.strictObject({
193
+ op: z.literal("offset"),
194
+ distance: z
195
+ .number()
196
+ .finite()
197
+ .refine((value) => value !== 0, { message: "distance must be non-zero" }),
198
+ input: TopologyCounts,
199
+ }),
200
+ ])
201
+ .superRefine((operation, ctx) => {
202
+ if (operation.op !== "fillet") return
203
+ const { edges, endRadius, radii } = operation
204
+ if (endRadius === undefined && radii === undefined) return
205
+ if (endRadius !== undefined && radii !== undefined) {
206
+ ctx.addIssue({
207
+ code: "custom",
208
+ message: "endRadius is mutually exclusive with radii",
209
+ })
210
+ }
211
+ if (edges.length !== 1) {
212
+ ctx.addIssue({
213
+ code: "custom",
214
+ message: "a variable fillet names exactly one edge — the blend contour it runs along",
215
+ })
216
+ }
217
+ if (radii?.some((row, i) => i > 0 && row.position <= radii[i - 1].position)) {
218
+ ctx.addIssue({
219
+ code: "custom",
220
+ message: "radii positions must strictly increase",
221
+ })
222
+ }
223
+ })
224
+
225
+ /**
226
+ * One value of a parameter patch. See {@linkcode ParameterPatchValue}.
227
+ *
228
+ * Deliberately a CLOSED union of the shapes a record's `values` actually hold —
229
+ * no `z.unknown()`, nothing recursive: an unrecognised value is a VALIDATION at
230
+ * the wire, not a silent write of nonsense onto a mass. It only ever widens, so
231
+ * every value it accepted before it still accepts.
232
+ */
233
+ export const ParameterPatchValue: z.ZodType<ParameterPatchValue, ParameterPatchValue> = z.lazy(() =>
234
+ z.union([
235
+ z.number().finite(),
236
+ XYZ,
237
+ z.array(XYZ).max(MAX_SWEEP_PATH_POINTS),
238
+ ContourRecord,
239
+ z.array(ContourRecord).max(MAX_LOFT_SECTIONS),
240
+ z.array(CurveRecord).max(MAX_PATH_CURVES),
241
+ LoftOptions,
242
+ SweepOptions,
243
+ SweepAlongCurveRecordOptions,
244
+ z.array(OperationRecord).max(MAX_OPERATIONS),
245
+ ]),
246
+ )