@bitbybit-dev/jscad 1.3.2-rc.1 → 1.4.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.
@@ -1,3 +1,5 @@
1
+ import * as Inputs from "../inputs/jscad-inputs";
2
+ import { resolveDto } from "@bitbybit-dev/base";
1
3
  /**
2
4
  * Building JSCAD solids: cubes, cuboids, spheres, ellipsoids, cylinders, a torus and a solid from
3
5
  * raw polygon points, each with a variant that places one copy on every point of a list. The kernel
@@ -24,9 +26,10 @@ export class JSCADShapes {
24
26
  * ```
25
27
  */
26
28
  cube(inputs) {
29
+ const resolved = resolveDto(Inputs.JSCAD.CubeDto, inputs);
27
30
  return this.jscad.primitives.cube({
28
- center: [inputs.center[0], inputs.center[1], inputs.center[2]],
29
- size: inputs.size
31
+ center: [resolved.center[0], resolved.center[1], resolved.center[2]],
32
+ size: resolved.size
30
33
  });
31
34
  }
32
35
  /**
@@ -42,8 +45,9 @@ export class JSCADShapes {
42
45
  * ```
43
46
  */
44
47
  cubesOnCenterPoints(inputs) {
45
- return inputs.centers.map(center => {
46
- return this.cube({ center, size: inputs.size });
48
+ const resolved = resolveDto(Inputs.JSCAD.CubeCentersDto, inputs);
49
+ return resolved.centers.map(center => {
50
+ return this.cube({ center, size: resolved.size });
47
51
  });
48
52
  }
49
53
  /**
@@ -60,9 +64,10 @@ export class JSCADShapes {
60
64
  * ```
61
65
  */
62
66
  cuboid(inputs) {
67
+ const resolved = resolveDto(Inputs.JSCAD.CuboidDto, inputs);
63
68
  return this.jscad.primitives.cuboid({
64
- center: [inputs.center[0], inputs.center[1], inputs.center[2]],
65
- size: [inputs.width, inputs.height, inputs.length]
69
+ center: [resolved.center[0], resolved.center[1], resolved.center[2]],
70
+ size: [resolved.width, resolved.height, resolved.length]
66
71
  });
67
72
  }
68
73
  /**
@@ -79,12 +84,13 @@ export class JSCADShapes {
79
84
  * ```
80
85
  */
81
86
  cuboidsOnCenterPoints(inputs) {
82
- return inputs.centers.map(center => {
87
+ const resolved = resolveDto(Inputs.JSCAD.CuboidCentersDto, inputs);
88
+ return resolved.centers.map(center => {
83
89
  return this.cuboid({
84
90
  center,
85
- width: inputs.width,
86
- length: inputs.length,
87
- height: inputs.height
91
+ width: resolved.width,
92
+ length: resolved.length,
93
+ height: resolved.height
88
94
  });
89
95
  });
90
96
  }
@@ -105,12 +111,13 @@ export class JSCADShapes {
105
111
  * ```
106
112
  */
107
113
  cylinderElliptic(inputs) {
114
+ const resolved = resolveDto(Inputs.JSCAD.CylidnerEllipticDto, inputs);
108
115
  return this.jscad.primitives.cylinderElliptic({
109
- center: [inputs.center[0], inputs.center[1], inputs.center[2]],
110
- height: inputs.height,
111
- startRadius: [inputs.startRadius[0], inputs.startRadius[1]],
112
- endRadius: [inputs.endRadius[0], inputs.endRadius[1]],
113
- segments: inputs.segments,
116
+ center: [resolved.center[0], resolved.center[1], resolved.center[2]],
117
+ height: resolved.height,
118
+ startRadius: [resolved.startRadius[0], resolved.startRadius[1]],
119
+ endRadius: [resolved.endRadius[0], resolved.endRadius[1]],
120
+ segments: resolved.segments,
114
121
  });
115
122
  }
116
123
  /**
@@ -127,13 +134,14 @@ export class JSCADShapes {
127
134
  * ```
128
135
  */
129
136
  cylinderEllipticOnCenterPoints(inputs) {
130
- return inputs.centers.map(center => {
137
+ const resolved = resolveDto(Inputs.JSCAD.CylidnerCentersEllipticDto, inputs);
138
+ return resolved.centers.map(center => {
131
139
  return this.cylinderElliptic({
132
140
  center,
133
- height: inputs.height,
134
- startRadius: inputs.startRadius,
135
- endRadius: inputs.endRadius,
136
- segments: inputs.segments
141
+ height: resolved.height,
142
+ startRadius: resolved.startRadius,
143
+ endRadius: resolved.endRadius,
144
+ segments: resolved.segments
137
145
  });
138
146
  });
139
147
  }
@@ -153,11 +161,12 @@ export class JSCADShapes {
153
161
  * ```
154
162
  */
155
163
  cylinder(inputs) {
164
+ const resolved = resolveDto(Inputs.JSCAD.CylidnerDto, inputs);
156
165
  return this.jscad.primitives.cylinder({
157
- center: [inputs.center[0], inputs.center[1], inputs.center[2]],
158
- height: inputs.height,
159
- radius: inputs.radius,
160
- segments: inputs.segments,
166
+ center: [resolved.center[0], resolved.center[1], resolved.center[2]],
167
+ height: resolved.height,
168
+ radius: resolved.radius,
169
+ segments: resolved.segments,
161
170
  });
162
171
  }
163
172
  /**
@@ -174,12 +183,13 @@ export class JSCADShapes {
174
183
  * ```
175
184
  */
176
185
  cylindersOnCenterPoints(inputs) {
177
- return inputs.centers.map(center => {
186
+ const resolved = resolveDto(Inputs.JSCAD.CylidnerCentersDto, inputs);
187
+ return resolved.centers.map(center => {
178
188
  return this.cylinder({
179
189
  center,
180
- height: inputs.height,
181
- radius: inputs.radius,
182
- segments: inputs.segments
190
+ height: resolved.height,
191
+ radius: resolved.radius,
192
+ segments: resolved.segments
183
193
  });
184
194
  });
185
195
  }
@@ -198,10 +208,11 @@ export class JSCADShapes {
198
208
  * ```
199
209
  */
200
210
  ellipsoid(inputs) {
211
+ const resolved = resolveDto(Inputs.JSCAD.EllipsoidDto, inputs);
201
212
  return this.jscad.primitives.ellipsoid({
202
- center: [inputs.center[0], inputs.center[1], inputs.center[2]],
203
- radius: [inputs.radius[0], inputs.radius[1], inputs.radius[2]],
204
- segments: inputs.segments,
213
+ center: [resolved.center[0], resolved.center[1], resolved.center[2]],
214
+ radius: [resolved.radius[0], resolved.radius[1], resolved.radius[2]],
215
+ segments: resolved.segments,
205
216
  axes: [
206
217
  [-1, 0, 0],
207
218
  [0, -1, 0],
@@ -223,11 +234,12 @@ export class JSCADShapes {
223
234
  * ```
224
235
  */
225
236
  ellipsoidsOnCenterPoints(inputs) {
226
- return inputs.centers.map(center => {
237
+ const resolved = resolveDto(Inputs.JSCAD.EllipsoidCentersDto, inputs);
238
+ return resolved.centers.map(center => {
227
239
  return this.ellipsoid({
228
240
  center,
229
- radius: inputs.radius,
230
- segments: inputs.segments
241
+ radius: resolved.radius,
242
+ segments: resolved.segments
231
243
  });
232
244
  });
233
245
  }
@@ -248,8 +260,9 @@ export class JSCADShapes {
248
260
  * ```
249
261
  */
250
262
  geodesicSphere(inputs) {
251
- let sphere = this.jscad.primitives.geodesicSphere({ radius: inputs.radius, frequency: inputs.frequency });
252
- sphere = this.jscad.transforms.translate([inputs.center[0], inputs.center[1], inputs.center[2]], sphere);
263
+ const resolved = resolveDto(Inputs.JSCAD.GeodesicSphereDto, inputs);
264
+ let sphere = this.jscad.primitives.geodesicSphere({ radius: resolved.radius, frequency: resolved.frequency });
265
+ sphere = this.jscad.transforms.translate([resolved.center[0], resolved.center[1], resolved.center[2]], sphere);
253
266
  return sphere;
254
267
  }
255
268
  /**
@@ -266,11 +279,12 @@ export class JSCADShapes {
266
279
  * ```
267
280
  */
268
281
  geodesicSpheresOnCenterPoints(inputs) {
269
- return inputs.centers.map(center => {
282
+ const resolved = resolveDto(Inputs.JSCAD.GeodesicSphereCentersDto, inputs);
283
+ return resolved.centers.map(center => {
270
284
  return this.geodesicSphere({
271
285
  center,
272
- radius: inputs.radius,
273
- frequency: inputs.frequency
286
+ radius: resolved.radius,
287
+ frequency: resolved.frequency
274
288
  });
275
289
  });
276
290
  }
@@ -291,11 +305,12 @@ export class JSCADShapes {
291
305
  * ```
292
306
  */
293
307
  roundedCuboid(inputs) {
308
+ const resolved = resolveDto(Inputs.JSCAD.RoundedCuboidDto, inputs);
294
309
  return this.jscad.primitives.roundedCuboid({
295
- center: [inputs.center[0], inputs.center[1], inputs.center[2]],
296
- size: [inputs.width, inputs.height, inputs.length],
297
- roundRadius: inputs.roundRadius,
298
- segments: inputs.segments,
310
+ center: [resolved.center[0], resolved.center[1], resolved.center[2]],
311
+ size: [resolved.width, resolved.height, resolved.length],
312
+ roundRadius: resolved.roundRadius,
313
+ segments: resolved.segments,
299
314
  });
300
315
  }
301
316
  /**
@@ -312,14 +327,15 @@ export class JSCADShapes {
312
327
  * ```
313
328
  */
314
329
  roundedCuboidsOnCenterPoints(inputs) {
315
- return inputs.centers.map(center => {
330
+ const resolved = resolveDto(Inputs.JSCAD.RoundedCuboidCentersDto, inputs);
331
+ return resolved.centers.map(center => {
316
332
  return this.roundedCuboid({
317
333
  center,
318
- width: inputs.width,
319
- height: inputs.height,
320
- length: inputs.length,
321
- roundRadius: inputs.roundRadius,
322
- segments: inputs.segments
334
+ width: resolved.width,
335
+ height: resolved.height,
336
+ length: resolved.length,
337
+ roundRadius: resolved.roundRadius,
338
+ segments: resolved.segments
323
339
  });
324
340
  });
325
341
  }
@@ -339,12 +355,13 @@ export class JSCADShapes {
339
355
  * ```
340
356
  */
341
357
  roundedCylinder(inputs) {
358
+ const resolved = resolveDto(Inputs.JSCAD.RoundedCylidnerDto, inputs);
342
359
  return this.jscad.primitives.roundedCylinder({
343
- center: [inputs.center[0], inputs.center[1], inputs.center[2]],
344
- height: inputs.height,
345
- radius: inputs.radius,
346
- roundRadius: inputs.roundRadius,
347
- segments: inputs.segments,
360
+ center: [resolved.center[0], resolved.center[1], resolved.center[2]],
361
+ height: resolved.height,
362
+ radius: resolved.radius,
363
+ roundRadius: resolved.roundRadius,
364
+ segments: resolved.segments,
348
365
  });
349
366
  }
350
367
  /**
@@ -361,13 +378,14 @@ export class JSCADShapes {
361
378
  * ```
362
379
  */
363
380
  roundedCylindersOnCenterPoints(inputs) {
364
- return inputs.centers.map(center => {
381
+ const resolved = resolveDto(Inputs.JSCAD.RoundedCylidnerCentersDto, inputs);
382
+ return resolved.centers.map(center => {
365
383
  return this.roundedCylinder({
366
384
  center,
367
- radius: inputs.radius,
368
- roundRadius: inputs.roundRadius,
369
- segments: inputs.segments,
370
- height: inputs.height,
385
+ radius: resolved.radius,
386
+ roundRadius: resolved.roundRadius,
387
+ segments: resolved.segments,
388
+ height: resolved.height,
371
389
  });
372
390
  });
373
391
  }
@@ -385,10 +403,11 @@ export class JSCADShapes {
385
403
  * ```
386
404
  */
387
405
  sphere(inputs) {
406
+ const resolved = resolveDto(Inputs.JSCAD.SphereDto, inputs);
388
407
  return this.jscad.primitives.sphere({
389
- center: [inputs.center[0], inputs.center[1], inputs.center[2]],
390
- radius: inputs.radius,
391
- segments: inputs.segments
408
+ center: [resolved.center[0], resolved.center[1], resolved.center[2]],
409
+ radius: resolved.radius,
410
+ segments: resolved.segments
392
411
  });
393
412
  }
394
413
  /**
@@ -405,11 +424,12 @@ export class JSCADShapes {
405
424
  * ```
406
425
  */
407
426
  spheresOnCenterPoints(inputs) {
408
- return inputs.centers.map(center => {
427
+ const resolved = resolveDto(Inputs.JSCAD.SphereCentersDto, inputs);
428
+ return resolved.centers.map(center => {
409
429
  return this.sphere({
410
430
  center,
411
- radius: inputs.radius,
412
- segments: inputs.segments,
431
+ radius: resolved.radius,
432
+ segments: resolved.segments,
413
433
  });
414
434
  });
415
435
  }
@@ -431,16 +451,17 @@ export class JSCADShapes {
431
451
  * ```
432
452
  */
433
453
  torus(inputs) {
454
+ const resolved = resolveDto(Inputs.JSCAD.TorusDto, inputs);
434
455
  const torus = this.jscad.primitives.torus({
435
- innerRadius: inputs.innerRadius,
436
- outerRadius: inputs.outerRadius,
437
- innerSegments: inputs.innerSegments,
438
- outerSegments: inputs.outerSegments,
439
- innerRotation: this.math.degToRad({ number: inputs.innerRotation }),
440
- outerRotation: this.math.degToRad({ number: inputs.outerRotation }),
441
- startAngle: this.math.degToRad({ number: inputs.startAngle }),
456
+ innerRadius: resolved.innerRadius,
457
+ outerRadius: resolved.outerRadius,
458
+ innerSegments: resolved.innerSegments,
459
+ outerSegments: resolved.outerSegments,
460
+ innerRotation: this.math.degToRad({ number: resolved.innerRotation }),
461
+ outerRotation: this.math.degToRad({ number: resolved.outerRotation }),
462
+ startAngle: this.math.degToRad({ number: resolved.startAngle }),
442
463
  });
443
- return this.jscad.transforms.translate([inputs.center[0], inputs.center[1], inputs.center[2]], torus);
464
+ return this.jscad.transforms.translate([resolved.center[0], resolved.center[1], resolved.center[2]], torus);
444
465
  }
445
466
  /**
446
467
  * Builds a solid from its faces, each given as a list of points that go around the face.
@@ -1,3 +1,5 @@
1
+ import { resolveDto } from "@bitbybit-dev/base";
2
+ import * as Inputs from "../inputs/jscad-inputs";
1
3
  /**
2
4
  * Writing text with JSCAD's built-in stroke font. `createVectorText` gives the pen strokes of the
3
5
  * text as lists of 2D points in the XY plane; `cylindricalText` and `sphericalText` turn every
@@ -25,15 +27,16 @@ export class JSCADText {
25
27
  * ```
26
28
  */
27
29
  cylindricalText(inputs) {
28
- const text = this.createVectorText(inputs);
30
+ const resolved = resolveDto(Inputs.JSCAD.CylinderTextDto, inputs);
31
+ const text = this.createVectorText(resolved);
29
32
  this.adjustTextToBeOnCenter(text);
30
33
  return text.map(txt => {
31
34
  const cylinders = txt.map(center => {
32
35
  return this.jscad.primitives.cylinder({
33
36
  center: [center[0], center[1], 0],
34
- height: inputs.extrusionHeight,
35
- radius: inputs.extrusionSize,
36
- segments: inputs.segments,
37
+ height: resolved.extrusionHeight,
38
+ radius: resolved.extrusionSize,
39
+ segments: resolved.segments,
37
40
  });
38
41
  });
39
42
  return this.jscad.hulls.hullChain(...cylinders);
@@ -56,14 +59,15 @@ export class JSCADText {
56
59
  * ```
57
60
  */
58
61
  sphericalText(inputs) {
59
- const text = this.createVectorText(inputs);
62
+ const resolved = resolveDto(Inputs.JSCAD.SphereTextDto, inputs);
63
+ const text = this.createVectorText(resolved);
60
64
  this.adjustTextToBeOnCenter(text);
61
65
  return text.map(txt => {
62
66
  const spheres = txt.map(center => {
63
67
  return this.jscad.primitives.sphere({
64
68
  center: [center[0], center[1], 0],
65
- radius: inputs.radius,
66
- segments: inputs.segments,
69
+ radius: resolved.radius,
70
+ segments: resolved.segments,
67
71
  });
68
72
  });
69
73
  return this.jscad.hulls.hullChain(...spheres);
@@ -105,15 +109,16 @@ export class JSCADText {
105
109
  * ```
106
110
  */
107
111
  createVectorText(inputs) {
112
+ const resolved = resolveDto(Inputs.JSCAD.TextDto, inputs);
108
113
  return this.jscad.text.vectorText({
109
- input: inputs.text,
110
- xOffset: inputs.xOffset,
111
- yOffset: inputs.yOffset,
112
- height: inputs.height,
113
- lineSpacing: inputs.lineSpacing,
114
- letterSpacing: inputs.letterSpacing,
115
- align: inputs.align,
116
- extrudeOffset: inputs.extrudeOffset,
114
+ input: resolved.text,
115
+ xOffset: resolved.xOffset,
116
+ yOffset: resolved.yOffset,
117
+ height: resolved.height,
118
+ lineSpacing: resolved.lineSpacing,
119
+ letterSpacing: resolved.letterSpacing,
120
+ align: resolved.align,
121
+ extrudeOffset: resolved.extrudeOffset,
117
122
  });
118
123
  }
119
124
  }
@@ -0,0 +1,11 @@
1
+ import { RuleBook } from "@bitbybit-dev/base";
2
+ /**
3
+ * What the inputs of a JSCAD operation have to satisfy together, beyond what each property accepts
4
+ * on its own, by the DTO the operation takes; rules written for a shared parent apply to both
5
+ * DTOs that extend it. `validateInputs` from the base package runs them.
6
+ *
7
+ * A rounding has to fit: less than half of a box's smallest side, and less than half of a
8
+ * cylinder's height and at most its radius, or JSCAD refuses the shape. A cylinder rounded by
9
+ * exactly its radius is a capsule.
10
+ */
11
+ export declare const jscadDtoRules: RuleBook;
@@ -0,0 +1,17 @@
1
+ import { custom, defineRules, lessThan, ruleBook } from "@bitbybit-dev/base";
2
+ import * as Inputs from "../inputs";
3
+ /**
4
+ * What the inputs of a JSCAD operation have to satisfy together, beyond what each property accepts
5
+ * on its own, by the DTO the operation takes; rules written for a shared parent apply to both
6
+ * DTOs that extend it. `validateInputs` from the base package runs them.
7
+ *
8
+ * A rounding has to fit: less than half of a box's smallest side, and less than half of a
9
+ * cylinder's height and at most its radius, or JSCAD refuses the shape. A cylinder rounded by
10
+ * exactly its radius is a capsule.
11
+ */
12
+ export const jscadDtoRules = ruleBook(defineRules(Inputs.JSCAD.RoundedCuboidSharedDto, [
13
+ lessThan("roundRadius", (inputs) => Math.min(inputs.width, inputs.length, inputs.height) / 2, "must be less than half of the smallest side", ["width", "length", "height"]),
14
+ ]), defineRules(Inputs.JSCAD.RoundedCylinderSharedDto, [
15
+ lessThan("roundRadius", (inputs) => inputs.height / 2, "must be less than half of the height", ["height"]),
16
+ custom("roundRadius", (inputs) => inputs.roundRadius <= inputs.radius, "must not be greater than radius", ["roundRadius", "radius"]),
17
+ ]));
package/lib/index.d.ts CHANGED
@@ -1,2 +1,5 @@
1
1
  export * from "./api/inputs";
2
2
  export * from "./api/jscad-service";
3
+ export * from "./api/dto-registry";
4
+ export * from "./api/validation";
5
+ export * as Resolved from "./api/resolved-inputs";
package/lib/index.js CHANGED
@@ -1,2 +1,5 @@
1
1
  export * from "./api/inputs";
2
2
  export * from "./api/jscad-service";
3
+ export * from "./api/dto-registry";
4
+ export * from "./api/validation";
5
+ export * as Resolved from "./api/resolved-inputs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bitbybit-dev/jscad",
3
- "version": "1.3.2-rc.1",
3
+ "version": "1.4.0-rc.0",
4
4
  "description": "Bit By Bit Developers JSCAD based CAD Library to Program Geometry",
5
5
  "homepage": "https://docs.bitbybit.dev/classes/Bit.JSCAD",
6
6
  "main": "index.js",
@@ -54,7 +54,7 @@
54
54
  "types": "./index.d.ts",
55
55
  "type": "module",
56
56
  "dependencies": {
57
- "@bitbybit-dev/base": "1.3.2-rc.1",
57
+ "@bitbybit-dev/base": "1.4.0-rc.0",
58
58
  "@jscad/io-utils": "2.0.33",
59
59
  "@jscad/modeling": "2.13.0",
60
60
  "@jscad/stl-serializer": "2.1.23",