@bitbybit-dev/base 1.4.0 → 1.5.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/lib/api/GlobalCDNProvider.js +1 -1
  2. package/lib/api/color-space.d.ts +14 -0
  3. package/lib/api/color-space.js +24 -0
  4. package/lib/api/index.d.ts +2 -0
  5. package/lib/api/index.js +2 -0
  6. package/lib/api/inputs/base-inputs.d.ts +382 -5
  7. package/lib/api/inputs/base-inputs.js +0 -3
  8. package/lib/api/inputs/color-inputs.d.ts +1 -1
  9. package/lib/api/inputs/color-inputs.js +0 -1
  10. package/lib/api/inputs/dates-inputs.js +0 -1
  11. package/lib/api/inputs/frame-inputs.d.ts +1 -1
  12. package/lib/api/inputs/inputs.js +0 -1
  13. package/lib/api/inputs/io-inputs.d.ts +1 -1
  14. package/lib/api/inputs/line-inputs.d.ts +1 -1
  15. package/lib/api/inputs/lists-inputs.js +0 -1
  16. package/lib/api/inputs/logic-inputs.d.ts +1 -1
  17. package/lib/api/inputs/logic-inputs.js +0 -1
  18. package/lib/api/inputs/math-inputs.js +0 -1
  19. package/lib/api/inputs/mesh-inputs.d.ts +29 -1
  20. package/lib/api/inputs/mesh-inputs.js +25 -1
  21. package/lib/api/inputs/point-inputs.d.ts +30 -1
  22. package/lib/api/inputs/point-inputs.js +28 -0
  23. package/lib/api/inputs/polyline-inputs.d.ts +1 -1
  24. package/lib/api/inputs/transforms-inputs.d.ts +1 -1
  25. package/lib/api/inputs/vector-inputs.d.ts +1 -1
  26. package/lib/api/kernel-calls/describe-failure.d.ts +3 -2
  27. package/lib/api/kernel-calls/describe-failure.js +9 -17
  28. package/lib/api/kernel-calls/failure-message.d.ts +1 -1
  29. package/lib/api/kernel-calls/hashing.d.ts +14 -0
  30. package/lib/api/kernel-calls/hashing.js +47 -0
  31. package/lib/api/kernel-calls/index.d.ts +3 -0
  32. package/lib/api/kernel-calls/index.js +3 -0
  33. package/lib/api/kernel-calls/input-rules.d.ts +1 -1
  34. package/lib/api/kernel-calls/input-rules.js +10 -5
  35. package/lib/api/kernel-calls/input-validation.d.ts +3 -3
  36. package/lib/api/kernel-calls/input-validation.js +24 -14
  37. package/lib/api/kernel-calls/kernel-steps.d.ts +19 -0
  38. package/lib/api/kernel-calls/kernel-steps.js +19 -0
  39. package/lib/api/kernel-calls/resolve-dto.d.ts +5 -3
  40. package/lib/api/kernel-calls/resolve-dto.js +9 -4
  41. package/lib/api/kernel-calls/unknown-values.d.ts +12 -0
  42. package/lib/api/kernel-calls/unknown-values.js +16 -0
  43. package/lib/api/kernel-calls/with-defaults.d.ts +1 -1
  44. package/lib/api/models/point/hex-grid-data.d.ts +1 -1
  45. package/lib/api/models/text/vector-char-data.d.ts +1 -1
  46. package/lib/api/models/text/vector-text-data.d.ts +1 -1
  47. package/lib/api/recipes/checker-types.d.ts +14 -0
  48. package/lib/api/recipes/checker-types.js +1 -0
  49. package/lib/api/recipes/index.d.ts +4 -0
  50. package/lib/api/recipes/index.js +3 -0
  51. package/lib/api/recipes/limits.constants.d.ts +23 -0
  52. package/lib/api/recipes/limits.constants.js +23 -0
  53. package/lib/api/recipes/recipe-types.d.ts +48 -0
  54. package/lib/api/recipes/recipe-types.js +1 -0
  55. package/lib/api/recipes/sources.d.ts +16 -0
  56. package/lib/api/recipes/sources.js +23 -0
  57. package/lib/api/recipes/surface-mesh.d.ts +16 -0
  58. package/lib/api/recipes/surface-mesh.js +86 -0
  59. package/lib/api/recipes/validate.d.ts +36 -0
  60. package/lib/api/recipes/validate.js +427 -0
  61. package/lib/api/resolved-inputs/index.d.ts +3 -0
  62. package/lib/api/services/color.d.ts +1 -1
  63. package/lib/api/services/frame.d.ts +3 -95
  64. package/lib/api/services/frame.js +24 -135
  65. package/lib/api/services/geometry-helper.d.ts +1 -1
  66. package/lib/api/services/helpers/arcs.d.ts +6 -0
  67. package/lib/api/services/helpers/arcs.js +30 -0
  68. package/lib/api/services/helpers/crc32.d.ts +1 -0
  69. package/lib/api/services/helpers/crc32.js +21 -0
  70. package/lib/api/services/helpers/dxf/dxf-generator.d.ts +0 -83
  71. package/lib/api/services/helpers/dxf/dxf-generator.js +5 -86
  72. package/lib/api/services/helpers/frame-axes.d.ts +9 -1
  73. package/lib/api/services/helpers/frame-axes.js +34 -0
  74. package/lib/api/services/helpers/helper-types.d.ts +34 -0
  75. package/lib/api/services/helpers/helper-types.js +1 -0
  76. package/lib/api/services/helpers/inflate.constants.d.ts +41 -0
  77. package/lib/api/services/helpers/inflate.constants.js +41 -0
  78. package/lib/api/services/helpers/inflate.d.ts +3 -0
  79. package/lib/api/services/helpers/inflate.js +228 -0
  80. package/lib/api/services/helpers/matrices.constants.d.ts +2 -0
  81. package/lib/api/services/helpers/matrices.constants.js +2 -0
  82. package/lib/api/services/helpers/matrices.d.ts +9 -1
  83. package/lib/api/services/helpers/matrices.js +18 -0
  84. package/lib/api/services/helpers/mesh-measures.d.ts +1 -0
  85. package/lib/api/services/helpers/mesh-measures.js +28 -0
  86. package/lib/api/services/helpers/mesh-normals.d.ts +2 -0
  87. package/lib/api/services/helpers/mesh-normals.js +118 -26
  88. package/lib/api/services/helpers/mesh-primitives.constants.d.ts +2 -0
  89. package/lib/api/services/helpers/mesh-primitives.constants.js +12 -0
  90. package/lib/api/services/helpers/mesh-primitives.d.ts +3 -0
  91. package/lib/api/services/helpers/mesh-primitives.js +46 -0
  92. package/lib/api/services/helpers/nurbs.d.ts +7 -0
  93. package/lib/api/services/helpers/nurbs.js +50 -0
  94. package/lib/api/services/helpers/paths.d.ts +8 -0
  95. package/lib/api/services/helpers/paths.js +96 -0
  96. package/lib/api/services/helpers/polygons.d.ts +8 -0
  97. package/lib/api/services/helpers/polygons.js +59 -0
  98. package/lib/api/services/helpers/surface-triangulation.d.ts +6 -0
  99. package/lib/api/services/helpers/surface-triangulation.js +298 -0
  100. package/lib/api/services/helpers/triangulation.d.ts +2 -0
  101. package/lib/api/services/helpers/triangulation.js +295 -0
  102. package/lib/api/services/helpers/vectors.d.ts +18 -0
  103. package/lib/api/services/helpers/vectors.js +17 -0
  104. package/lib/api/services/helpers/zip.constants.d.ts +34 -0
  105. package/lib/api/services/helpers/zip.constants.js +34 -0
  106. package/lib/api/services/helpers/zip.d.ts +4 -0
  107. package/lib/api/services/helpers/zip.js +89 -0
  108. package/lib/api/services/line.d.ts +3 -3
  109. package/lib/api/services/mesh.d.ts +37 -2
  110. package/lib/api/services/mesh.js +60 -3
  111. package/lib/api/services/point.d.ts +22 -10
  112. package/lib/api/services/point.js +42 -13
  113. package/lib/api/services/polyline.d.ts +39 -4
  114. package/lib/api/services/polyline.js +56 -6
  115. package/lib/api/services/text.d.ts +2 -2
  116. package/lib/api/services/text.js +10 -5
  117. package/lib/api/services/transforms.d.ts +3 -9
  118. package/lib/api/services/transforms.js +0 -6
  119. package/lib/api/services/vector.d.ts +2 -2
  120. package/lib/api/services/vector.js +2 -5
  121. package/package.json +1 -1
@@ -0,0 +1,427 @@
1
+ import { InputError } from "../kernel-calls/errors";
2
+ import { isRecord } from "../kernel-calls/unknown-values";
3
+ import { linearDeterminant } from "../services/helpers/matrices";
4
+ import { DEGENERATE_DETERMINANT, FULL_TURN, INT32_HIGHEST, INT32_LOWEST, ISSUES_IN_MESSAGE, MATRIX_SIZE, MAX_BUFFER_LENGTH, MAX_ISSUES, MAX_RECIPE_COORDINATE, MAX_RECIPE_DEPTH, MAX_RECIPE_NODES, MAX_RECIPE_PLACEMENT, MAX_RECIPE_GROUPS, MAX_RECIPE_ROOTS, MAX_REFERENCED_NUMBERS, MIN_INTERSECTED, MIN_LOFT_FRAMES, MIN_POLYGON_NUMBERS, POINT2_SIZE, POINT3_SIZE, RECIPE_FORMAT, RECIPE_VERSION, TRIANGLE_CORNERS, } from "./limits.constants";
5
+ const PROFILE = ["profile"];
6
+ const SOLID = ["solid"];
7
+ const CUTTING_TOOL = ["solid", "halfSpace"];
8
+ const COORDINATE_RANGE = `from -${MAX_RECIPE_COORDINATE} to ${MAX_RECIPE_COORDINATE}`;
9
+ const PLACEMENT_RANGE = `from -${MAX_RECIPE_PLACEMENT} to ${MAX_RECIPE_PLACEMENT}`;
10
+ const UNKNOWN_NODE = { kind: undefined, depth: 0 };
11
+ const TYPED_ARRAY_PROTOTYPE = Object.getPrototypeOf(Int8Array.prototype);
12
+ function typedArrayNameOf(value) {
13
+ return Reflect.get(TYPED_ARRAY_PROTOTYPE, Symbol.toStringTag, value);
14
+ }
15
+ function isFloat64Array(value) {
16
+ return value instanceof Float64Array || typedArrayNameOf(value) === "Float64Array";
17
+ }
18
+ function isInt32Array(value) {
19
+ return value instanceof Int32Array || typedArrayNameOf(value) === "Int32Array";
20
+ }
21
+ function report(issues, path, message) {
22
+ if (issues.length < MAX_ISSUES) {
23
+ issues.push({ path, message });
24
+ }
25
+ }
26
+ function isCoordinate(value, limit = MAX_RECIPE_COORDINATE) {
27
+ return typeof value === "number" && Math.abs(value) <= limit;
28
+ }
29
+ function coordinates(value, size, limit = MAX_RECIPE_COORDINATE) {
30
+ if (!Array.isArray(value) || value.length !== size) {
31
+ return false;
32
+ }
33
+ for (let index = 0; index < size; index++) {
34
+ if (!isCoordinate(value[index], limit)) {
35
+ return false;
36
+ }
37
+ }
38
+ return true;
39
+ }
40
+ function isCount(value) {
41
+ return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
42
+ }
43
+ function positive(issues, value, path) {
44
+ if (typeof value !== "number" || !Number.isFinite(value) || !(value > 0)) {
45
+ report(issues, path, "must be a finite number above zero");
46
+ }
47
+ }
48
+ function extent(issues, value, path) {
49
+ if (!isCoordinate(value) || !(value > 0)) {
50
+ report(issues, path, `must be a number above zero and at most ${MAX_RECIPE_COORDINATE}`);
51
+ }
52
+ }
53
+ function vector(issues, value, path, nonZero) {
54
+ if (!coordinates(value, POINT3_SIZE)) {
55
+ report(issues, path, `must be three numbers, each ${COORDINATE_RANGE}`);
56
+ }
57
+ else if (nonZero && value.every((item) => item === 0)) {
58
+ report(issues, path, "must not be a zero vector");
59
+ }
60
+ }
61
+ function isAffine(matrix) {
62
+ return matrix[3] === 0 && matrix[7] === 0 && matrix[11] === 0 && matrix[15] === 1;
63
+ }
64
+ function checkMatrix(issues, value, path) {
65
+ if (!coordinates(value, MATRIX_SIZE, MAX_RECIPE_PLACEMENT)) {
66
+ report(issues, path, `must be sixteen numbers in column-major order, each ${PLACEMENT_RANGE}`);
67
+ }
68
+ else if (!isAffine(value)) {
69
+ report(issues, path, "must have 0, 0, 0, 1 as its bottom row, at indices 3, 7, 11 and 15: it moves, turns, mirrors and scales, and never projects");
70
+ }
71
+ else if (Math.abs(linearDeterminant(value)) <= DEGENERATE_DETERMINANT) {
72
+ report(issues, path, "flattens what it transforms: its rotation and scale part has no inverse");
73
+ }
74
+ }
75
+ function checkFrames(checker, frames, path) {
76
+ const [start, count] = frames;
77
+ let firstMirrors = false;
78
+ for (let frame = 0; frame < count / MATRIX_SIZE; frame++) {
79
+ const matrix = [...checker.buffers.f64.subarray(start + frame * MATRIX_SIZE, start + (frame + 1) * MATRIX_SIZE)];
80
+ if (!isAffine(matrix)) {
81
+ report(checker.issues, `${path}[${frame}]`, "must have 0, 0, 0, 1 as its bottom row, at numbers 3, 7, 11 and 15 of the frame");
82
+ return;
83
+ }
84
+ const determinant = linearDeterminant(matrix);
85
+ if (Math.abs(determinant) <= DEGENERATE_DETERMINANT) {
86
+ report(checker.issues, `${path}[${frame}]`, "flattens the profile it places: its rotation and scale part has no inverse");
87
+ return;
88
+ }
89
+ if (frame === 0) {
90
+ firstMirrors = determinant < 0;
91
+ }
92
+ else if (determinant < 0 !== firstMirrors) {
93
+ report(checker.issues, `${path}[${frame}]`, "turns the profile over where the first frame does not, or the other way round: a loft's frames all mirror, or none do");
94
+ return;
95
+ }
96
+ }
97
+ }
98
+ function checkRevolve(checker, node, at, path) {
99
+ const { issues } = checker;
100
+ const deepest = reference(checker, node["profile"], at, PROFILE, `${path}.profile`);
101
+ if (!coordinates(node["origin"], POINT2_SIZE)) {
102
+ report(issues, `${path}.origin`, `must be two numbers, each ${COORDINATE_RANGE}`);
103
+ }
104
+ if (!coordinates(node["direction"], POINT2_SIZE)) {
105
+ report(issues, `${path}.direction`, `must be two numbers, each ${COORDINATE_RANGE}`);
106
+ }
107
+ else if (node["direction"].every((item) => item === 0)) {
108
+ report(issues, `${path}.direction`, "must not be a zero vector");
109
+ }
110
+ const angle = node["angle"];
111
+ if (typeof angle !== "number" || !(angle > 0) || !(angle <= FULL_TURN)) {
112
+ report(issues, `${path}.angle`, "must be an angle in radians above zero and at most a whole turn");
113
+ }
114
+ return deepest;
115
+ }
116
+ function checkLoft(checker, node, at, path) {
117
+ const deepest = references(checker, node["profiles"], at, PROFILE, `${path}.profiles`, false);
118
+ const frames = range(checker, node["frames"], checker.buffers.f64.length, MATRIX_SIZE, MIN_LOFT_FRAMES * MATRIX_SIZE, `${path}.frames`);
119
+ if (frames === undefined) {
120
+ return deepest;
121
+ }
122
+ const count = frames[1] / MATRIX_SIZE;
123
+ const profiles = node["profiles"];
124
+ if (Array.isArray(profiles) && profiles.length > 1 && profiles.length !== count) {
125
+ report(checker.issues, `${path}.profiles`, `must hold one profile, or one for each of the ${count} frames`);
126
+ }
127
+ checkFrames(checker, frames, `${path}.frames`);
128
+ return deepest;
129
+ }
130
+ function checkCoordinates(issues, f64) {
131
+ for (let index = 0; index < f64.length; index++) {
132
+ if (!isCoordinate(f64[index])) {
133
+ report(issues, `buffers.f64[${index}]`, `holds ${f64[index]}, where every number must be a coordinate ${COORDINATE_RANGE}`);
134
+ return;
135
+ }
136
+ }
137
+ }
138
+ function range(checker, value, length, multiple, minimum, path) {
139
+ if (!Array.isArray(value) || value.length !== 2 || !isCount(value[0]) || !isCount(value[1])) {
140
+ report(checker.issues, path, "must be a range of two whole numbers, a start and a count");
141
+ return undefined;
142
+ }
143
+ const checked = value;
144
+ const [start, count] = checked;
145
+ if (start + count > length) {
146
+ report(checker.issues, path, `runs past the end of its buffer, which holds ${length} numbers`);
147
+ return undefined;
148
+ }
149
+ if (count % multiple !== 0 || count < minimum) {
150
+ report(checker.issues, path, `must hold a multiple of ${multiple} numbers, at least ${minimum}`);
151
+ return undefined;
152
+ }
153
+ checker.referenced += count;
154
+ return checked;
155
+ }
156
+ function reference(checker, value, at, accepted, path) {
157
+ if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0 || value >= at) {
158
+ report(checker.issues, path, at === 0 ? "must be the index of an earlier node, and none comes before it" : `must be the index of an earlier node, from 0 to ${at - 1}`);
159
+ return 0;
160
+ }
161
+ const kind = checker.kinds[value];
162
+ if (kind !== undefined && !accepted.includes(kind)) {
163
+ report(checker.issues, path, `refers to a ${kind} node where ${accepted.join(" or ")} is needed`);
164
+ }
165
+ return checker.depths[value];
166
+ }
167
+ function references(checker, value, at, accepted, path, allowEmpty) {
168
+ if (!Array.isArray(value) || (!allowEmpty && value.length === 0)) {
169
+ report(checker.issues, path, allowEmpty ? "must be a list of node indices" : "must be a list of at least one node index");
170
+ return 0;
171
+ }
172
+ let deepest = 0;
173
+ for (let index = 0; index < value.length; index++) {
174
+ deepest = Math.max(deepest, reference(checker, value[index], at, accepted, `${path}[${index}]`));
175
+ }
176
+ return deepest;
177
+ }
178
+ function checkCorners(checker, positions, indices, path) {
179
+ const vertices = positions[1] / POINT3_SIZE;
180
+ const [start, count] = indices;
181
+ for (let index = start; index < start + count; index++) {
182
+ const corner = checker.buffers.i32[index];
183
+ if (corner < 0 || corner >= vertices) {
184
+ report(checker.issues, path, `points at position ${corner}, but the node has ${vertices} positions`);
185
+ return;
186
+ }
187
+ }
188
+ }
189
+ function checkTriangles(checker, node, path) {
190
+ const positions = range(checker, node["positions"], checker.buffers.f64.length, POINT3_SIZE, POINT3_SIZE * TRIANGLE_CORNERS, `${path}.positions`);
191
+ const indices = range(checker, node["indices"], checker.buffers.i32.length, TRIANGLE_CORNERS, TRIANGLE_CORNERS, `${path}.indices`);
192
+ if (positions !== undefined && indices !== undefined && checker.referenced <= MAX_REFERENCED_NUMBERS) {
193
+ checkCorners(checker, positions, indices, `${path}.indices`);
194
+ }
195
+ }
196
+ function checkPolygon(checker, node, path) {
197
+ const length = checker.buffers.f64.length;
198
+ range(checker, node["points"], length, POINT2_SIZE, MIN_POLYGON_NUMBERS, `${path}.points`);
199
+ const holes = node["holes"];
200
+ if (!Array.isArray(holes)) {
201
+ report(checker.issues, `${path}.holes`, "must be a list of ranges, empty when there are no holes");
202
+ return;
203
+ }
204
+ for (let index = 0; index < holes.length; index++) {
205
+ range(checker, holes[index], length, POINT2_SIZE, MIN_POLYGON_NUMBERS, `${path}.holes[${index}]`);
206
+ }
207
+ }
208
+ function summary(kind, deepestReference) {
209
+ return { kind, depth: deepestReference + 1 };
210
+ }
211
+ function checkNode(checker, node, at) {
212
+ const path = `nodes[${at}]`;
213
+ const { issues } = checker;
214
+ if (!isRecord(node)) {
215
+ report(issues, path, "must be an object with an op");
216
+ return UNKNOWN_NODE;
217
+ }
218
+ switch (node["op"]) {
219
+ case "polygon":
220
+ checkPolygon(checker, node, path);
221
+ return summary("profile", 0);
222
+ case "circle":
223
+ if (!coordinates(node["center"], POINT2_SIZE)) {
224
+ report(issues, `${path}.center`, `must be two numbers, each ${COORDINATE_RANGE}`);
225
+ }
226
+ extent(issues, node["radius"], `${path}.radius`);
227
+ return summary("profile", 0);
228
+ case "extrude": {
229
+ const deepest = reference(checker, node["profile"], at, PROFILE, `${path}.profile`);
230
+ vector(issues, node["direction"], `${path}.direction`, true);
231
+ if (coordinates(node["direction"], POINT3_SIZE) && node["direction"][2] === 0) {
232
+ report(issues, `${path}.direction`, "lies in the XY plane, so the sweep has no volume");
233
+ }
234
+ extent(issues, node["depth"], `${path}.depth`);
235
+ return summary("solid", deepest);
236
+ }
237
+ case "halfSpace":
238
+ if (!coordinates(node["origin"], POINT3_SIZE, MAX_RECIPE_PLACEMENT)) {
239
+ report(issues, `${path}.origin`, `must be three numbers, each ${PLACEMENT_RANGE}`);
240
+ }
241
+ vector(issues, node["normal"], `${path}.normal`, true);
242
+ return summary("halfSpace", 0);
243
+ case "difference": {
244
+ const deepest = reference(checker, node["of"], at, SOLID, `${path}.of`);
245
+ return summary("solid", Math.max(deepest, references(checker, node["tools"], at, CUTTING_TOOL, `${path}.tools`, false)));
246
+ }
247
+ case "transform": {
248
+ const deepest = reference(checker, node["of"], at, SOLID, `${path}.of`);
249
+ checkMatrix(issues, node["matrix"], `${path}.matrix`);
250
+ return summary("solid", deepest);
251
+ }
252
+ case "voids": {
253
+ const deepest = reference(checker, node["host"], at, SOLID, `${path}.host`);
254
+ return summary("solid", Math.max(deepest, references(checker, node["openings"], at, SOLID, `${path}.openings`, true)));
255
+ }
256
+ case "triangles":
257
+ checkTriangles(checker, node, path);
258
+ return summary("solid", 0);
259
+ case "compound":
260
+ case "union":
261
+ return summary("solid", references(checker, node["of"], at, SOLID, `${path}.of`, false));
262
+ case "intersection":
263
+ if (Array.isArray(node["of"]) && node["of"].length < MIN_INTERSECTED) {
264
+ report(issues, `${path}.of`, `must be a list of at least ${MIN_INTERSECTED} node indices`);
265
+ }
266
+ return summary("solid", references(checker, node["of"], at, SOLID, `${path}.of`, false));
267
+ case "revolve":
268
+ return summary("solid", checkRevolve(checker, node, at, path));
269
+ case "loft":
270
+ return summary("solid", checkLoft(checker, node, at, path));
271
+ default:
272
+ report(issues, `${path}.op`, `'${String(node["op"])}' is not an operation recipes know`);
273
+ return UNKNOWN_NODE;
274
+ }
275
+ }
276
+ function checkNodes(checker, nodes) {
277
+ for (let at = 0; at < nodes.length; at++) {
278
+ const { kind, depth } = checkNode(checker, nodes[at], at);
279
+ checker.kinds.push(kind);
280
+ checker.depths.push(depth);
281
+ if (depth === MAX_RECIPE_DEPTH + 1) {
282
+ report(checker.issues, `nodes[${at}]`, `stands ${depth} steps deep, more than the ${MAX_RECIPE_DEPTH} a recipe may nest`);
283
+ }
284
+ }
285
+ if (checker.referenced > MAX_REFERENCED_NUMBERS) {
286
+ report(checker.issues, "nodes", `refer to ${checker.referenced} numbers of the buffers in all, more than the ${MAX_REFERENCED_NUMBERS} a recipe may build from`);
287
+ }
288
+ }
289
+ function checkGroupIndex(issues, value, groupCount, path, what) {
290
+ if (value !== undefined && !(isCount(value) && value < groupCount)) {
291
+ report(issues, path, groupCount === 0 ? `must be left out, since ${what}` : `must be left out or be the index of ${what}, from 0 to ${groupCount - 1}`);
292
+ }
293
+ }
294
+ function checkRoot(checker, root, path, nodeCount, groupCount) {
295
+ if (!isRecord(root)) {
296
+ report(checker.issues, path, "must be an object with a node, a matrix and a tag");
297
+ return;
298
+ }
299
+ reference(checker, root["node"], nodeCount, SOLID, `${path}.node`);
300
+ checkMatrix(checker.issues, root["matrix"], `${path}.matrix`);
301
+ if (!isRecord(root["tag"])) {
302
+ report(checker.issues, `${path}.tag`, "must be an object");
303
+ }
304
+ checkGroupIndex(checker.issues, root["group"], groupCount, `${path}.group`, groupCount === 0 ? "the recipe has no groups" : "one of the recipe's groups");
305
+ }
306
+ function checkRoots(checker, roots, nodeCount, groupCount) {
307
+ for (let index = 0; index < roots.length; index++) {
308
+ checkRoot(checker, roots[index], `roots[${index}]`, nodeCount, groupCount);
309
+ }
310
+ }
311
+ function checkGroups(issues, groups) {
312
+ for (let index = 0; index < groups.length; index++) {
313
+ const group = groups[index];
314
+ const path = `groups[${index}]`;
315
+ if (!isRecord(group)) {
316
+ report(issues, path, "must be an object with a name and a tag");
317
+ continue;
318
+ }
319
+ if (typeof group["name"] !== "string") {
320
+ report(issues, `${path}.name`, "must be text");
321
+ }
322
+ if (!isRecord(group["tag"])) {
323
+ report(issues, `${path}.tag`, "must be an object");
324
+ }
325
+ checkGroupIndex(issues, group["parent"], index, `${path}.parent`, index === 0 ? "no group comes before the first one" : "an earlier group");
326
+ }
327
+ }
328
+ /**
329
+ * Checks that a value is a recipe an executor can safely run: every index refers to an earlier
330
+ * node of the right kind, every range lies inside its buffer, every coordinate of a profile or an
331
+ * extrusion is finite and between minus and plus one billion, every placement (a matrix or a
332
+ * half-space's origin) between minus and plus ten trillion, every matrix moves, turns, mirrors and
333
+ * scales without flattening, and no list, total or nesting exceeds its limit. A recipe that comes from another thread, a file or a caller is
334
+ * checked before any kernel touches it.
335
+ *
336
+ * Experimental: the recipe format may still change before it is declared stable.
337
+ * @param recipe - The value to check
338
+ * @returns What is wrong with it, at most a hundred issues, empty when nothing is
339
+ * @beta
340
+ */
341
+ export function checkRecipe(recipe) {
342
+ var _a;
343
+ const issues = [];
344
+ if (!isRecord(recipe)) {
345
+ report(issues, "", "a recipe must be an object");
346
+ return issues;
347
+ }
348
+ if (recipe["format"] !== RECIPE_FORMAT || recipe["version"] !== RECIPE_VERSION) {
349
+ report(issues, "format", `must be ${RECIPE_FORMAT} version ${RECIPE_VERSION}`);
350
+ }
351
+ positive(issues, recipe["millimetresPerUnit"], "millimetresPerUnit");
352
+ positive(issues, recipe["tolerance"], "tolerance");
353
+ const buffers = recipe["buffers"];
354
+ const f64 = isRecord(buffers) ? buffers["f64"] : undefined;
355
+ const i32 = isRecord(buffers) ? buffers["i32"] : undefined;
356
+ if (!isFloat64Array(f64) || !isInt32Array(i32)) {
357
+ report(issues, "buffers", "must hold an f64 Float64Array and an i32 Int32Array");
358
+ return issues;
359
+ }
360
+ if (f64.length > MAX_BUFFER_LENGTH || i32.length > MAX_BUFFER_LENGTH) {
361
+ report(issues, "buffers", `must each hold at most ${MAX_BUFFER_LENGTH} numbers`);
362
+ return issues;
363
+ }
364
+ const nodes = recipe["nodes"];
365
+ if (!Array.isArray(nodes) || nodes.length > MAX_RECIPE_NODES) {
366
+ report(issues, "nodes", `must be a list of at most ${MAX_RECIPE_NODES} nodes`);
367
+ return issues;
368
+ }
369
+ const roots = recipe["roots"];
370
+ if (!Array.isArray(roots) || roots.length > MAX_RECIPE_ROOTS) {
371
+ report(issues, "roots", `must be a list of at most ${MAX_RECIPE_ROOTS} roots`);
372
+ return issues;
373
+ }
374
+ const groups = (_a = recipe["groups"]) !== null && _a !== void 0 ? _a : [];
375
+ if (!Array.isArray(groups) || groups.length > MAX_RECIPE_GROUPS) {
376
+ report(issues, "groups", `must be left out or be a list of at most ${MAX_RECIPE_GROUPS} groups`);
377
+ return issues;
378
+ }
379
+ checkCoordinates(issues, f64);
380
+ const checker = { issues, buffers: { f64, i32 }, kinds: [], depths: [], referenced: 0 };
381
+ checkNodes(checker, nodes);
382
+ checkGroups(issues, groups);
383
+ checkRoots(checker, roots, nodes.length, groups.length);
384
+ return issues;
385
+ }
386
+ /**
387
+ * Throws an `InputError` when a value is not a recipe an executor can safely run, naming the first
388
+ * three problems `checkRecipe` finds.
389
+ *
390
+ * Experimental: the recipe format may still change before it is declared stable.
391
+ * @param recipe - The value to check
392
+ * @beta
393
+ */
394
+ export function assertRecipe(recipe) {
395
+ const issues = checkRecipe(recipe);
396
+ if (issues.length) {
397
+ throw new InputError(`The recipe cannot be built: ${issues.slice(0, ISSUES_IN_MESSAGE).map((issue) => `${issue.path ? `${issue.path} ` : ""}${issue.message}`).join("; ")}`, "recipe");
398
+ }
399
+ }
400
+ function isNumberList(value) {
401
+ return Array.isArray(value) && value.every((item) => typeof item === "number");
402
+ }
403
+ function isInt32List(value) {
404
+ return isNumberList(value) && value.every((item) => Number.isInteger(item) && item >= INT32_LOWEST && item <= INT32_HIGHEST);
405
+ }
406
+ /**
407
+ * Reads a value as a recipe an executor can run, taking its buffers as lists of numbers too, as JSON
408
+ * carries them: such lists become the typed arrays the format holds, and the result is checked as
409
+ * `assertRecipe` checks it. The value it is given is left as it was.
410
+ *
411
+ * Experimental: the recipe format may still change before it is declared stable.
412
+ * @param value - The recipe, its buffers typed arrays or lists of numbers
413
+ * @returns The recipe with typed buffers
414
+ * @beta
415
+ */
416
+ export function toRecipe(value) {
417
+ const buffers = isRecord(value) ? value["buffers"] : undefined;
418
+ if (isRecord(value) && isRecord(buffers) && (isNumberList(buffers["f64"]) || isInt32List(buffers["i32"]))) {
419
+ const f64 = buffers["f64"];
420
+ const i32 = buffers["i32"];
421
+ const typed = Object.assign(Object.assign({}, value), { buffers: Object.assign(Object.assign({}, buffers), { f64: isNumberList(f64) ? Float64Array.from(f64) : f64, i32: isInt32List(i32) ? Int32Array.from(i32) : i32 }) });
422
+ assertRecipe(typed);
423
+ return typed;
424
+ }
425
+ assertRecipe(value);
426
+ return value;
427
+ }
@@ -182,7 +182,9 @@ export declare namespace Math {
182
182
  * the way `resolveDto` hands a DTO to the code that reads it.
183
183
  */
184
184
  export declare namespace Mesh {
185
+ type MeshDto = Inputs.Mesh.MeshDto;
185
186
  type MeshMeshToleranceDto = WithDefaults<Inputs.Mesh.MeshMeshToleranceDto, "tolerance">;
187
+ type PolygonWithHolesDto = Inputs.Mesh.PolygonWithHolesDto;
186
188
  type SignedDistanceFromPlaneToPointDto = Inputs.Mesh.SignedDistanceFromPlaneToPointDto;
187
189
  type TriangleDto = Inputs.Mesh.TriangleDto;
188
190
  type TriangleToleranceDto = WithDefaults<Inputs.Mesh.TriangleToleranceDto, "tolerance">;
@@ -193,6 +195,7 @@ export declare namespace Mesh {
193
195
  * the way `resolveDto` hands a DTO to the code that reads it.
194
196
  */
195
197
  export declare namespace Point {
198
+ type ArcThroughThreePointsDto = WithDefaults<Inputs.Point.ArcThroughThreePointsDto, "segments">;
196
199
  type ClosestPointFromPointsDto = Inputs.Point.ClosestPointFromPointsDto;
197
200
  type DrawPointDto<T> = WithDefaults<Inputs.Point.DrawPointDto<T>, "opacity" | "size" | "colours" | "updatable">;
198
201
  type DrawPointsDto<T> = WithDefaults<Inputs.Point.DrawPointsDto<T>, "opacity" | "size" | "colours" | "updatable">;
@@ -1,5 +1,5 @@
1
1
  import * as Inputs from "../inputs";
2
- import { MathBitByBit } from "./math";
2
+ import type { MathBitByBit } from "./math";
3
3
  /**
4
4
  * Colors in the two forms the library uses: a hex text such as `#ff5733`, and an object `{ r, g, b
5
5
  * }` or `{ r, g, b, a }` whose channels run either from 0 to 255 or from 0 to 1. The methods here
@@ -1,7 +1,7 @@
1
1
  import * as Inputs from "../inputs";
2
- import { GeometryHelper } from "./geometry-helper";
3
- import { MathBitByBit } from "./math";
4
- import { Vector } from "./vector";
2
+ import type { GeometryHelper } from "./geometry-helper";
3
+ import type { MathBitByBit } from "./math";
4
+ import type { Vector } from "./vector";
5
5
  /**
6
6
  * Frames: a frame is a point with three axes at right angles, written as its `origin`, its `normal`
7
7
  * (the Z axis) and its `direction` (the X axis), the Y axis following from those two. Frames place
@@ -556,115 +556,23 @@ export declare class Frame {
556
556
  * ```
557
557
  */
558
558
  hexGrid(inputs: Inputs.Frame.HexGridDto): Inputs.Base.Frame[];
559
- /**
560
- * The widest spread's axis, pointing toward the first point, or with its largest component
561
- * positive when the first point lies across it.
562
- * @ignore true
563
- */
564
559
  private alongWidest;
565
- /**
566
- * Where the first point lies from the center, in the fitted plane, or the next point that does
567
- * not sit on the center: the X axis of points that spread evenly every way in their plane.
568
- * @ignore true
569
- */
570
560
  private towardFirstPoint;
571
- /**
572
- * @ignore true
573
- */
574
561
  private translated;
575
- /**
576
- * @ignore true
577
- */
578
562
  private offsetBy;
579
- /**
580
- * The axes turned about one of their own by `angle` radians, through their origin.
581
- * @ignore true
582
- */
583
563
  private turned;
584
- /**
585
- * @ignore true
586
- */
587
564
  private flipped;
588
- /**
589
- * @ignore true
590
- */
591
- private childToWorld;
592
- /**
593
- * @ignore true
594
- */
595
- private childToLocal;
596
- /**
597
- * The vector `u` along `x`, `v` along `y` and `w` along `z` of the axes, from their origin.
598
- * @ignore true
599
- */
600
- private along;
601
- /**
602
- * The same vector read against the axes: its components along `x`, `y` and `z`.
603
- * @ignore true
604
- */
605
- private against;
606
- /**
607
- * `first` scaled by `a` plus `second` scaled by `b`.
608
- * @ignore true
609
- */
610
565
  private combined;
611
- /**
612
- * Flips a unit vector whose largest component is negative, so a sign the data leaves open is
613
- * decided the same way every time. Components within 1e-12 of each other count as equal and the
614
- * first of them decides, so rounding cannot tip the choice; OCCT's frames break the tie the
615
- * same way.
616
- * @ignore true
617
- */
618
566
  private withLargestPositive;
619
- /**
620
- * The column-major matrix carrying the `from` axes onto the `to` axes.
621
- * @ignore true
622
- */
623
567
  private matrixBetween;
624
- /**
625
- * The axes of a frame a caller handed in, squared, or an error naming the input at fault.
626
- * @ignore true
627
- */
628
568
  private axesOf;
629
- /**
630
- * The axes of every frame in a list a caller handed in, or an error naming the list and the
631
- * position at fault.
632
- * @ignore true
633
- */
634
569
  private axesOfEach;
635
- /**
636
- * @ignore true
637
- */
638
570
  private axisOf;
639
- /**
640
- * An origin with a unit normal and a unit X axis square to it, or an error with the message for
641
- * the part that cannot be squared, naming `property`, or that part when none is given.
642
- * @ignore true
643
- */
644
571
  private squared;
645
- /**
646
- * The frame the axes describe, as new arrays.
647
- * @ignore true
648
- */
649
572
  private frameOf;
650
- /**
651
- * @ignore true
652
- */
653
573
  private pointOf;
654
- /**
655
- * @ignore true
656
- */
657
574
  private vectorOf;
658
- /**
659
- * @ignore true
660
- */
661
575
  private pointsOf;
662
- /**
663
- * @ignore true
664
- */
665
576
  private numberOf;
666
- /**
667
- * @ignore true
668
- */
669
577
  private countOf;
670
578
  }