@jwc/jscad-utils 4.9.0 → 5.0.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.
package/dist/compat.js CHANGED
@@ -43,187 +43,6 @@ function initJscadutils(_CSG, options = {}) {
43
43
  var jscadUtils = (function (exports, jsCadCSG, scadApi) {
44
44
  'use strict';
45
45
 
46
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
47
-
48
- var jsCadCSG__default = /*#__PURE__*/_interopDefaultLegacy(jsCadCSG);
49
- var scadApi__default = /*#__PURE__*/_interopDefaultLegacy(scadApi);
50
-
51
- var util = /*#__PURE__*/Object.freeze({
52
- __proto__: null,
53
- get NOZZEL_SIZE () { return NOZZEL_SIZE; },
54
- get nearest () { return nearest; },
55
- get identity () { return identity; },
56
- get result () { return result; },
57
- get defaults () { return defaults; },
58
- get isEmpty () { return isEmpty; },
59
- get isNegative () { return isNegative; },
60
- get print () { return print; },
61
- get jscadToString () { return jscadToString; },
62
- get error () { return error; },
63
- get depreciated () { return depreciated; },
64
- get inch () { return inch; },
65
- get cm () { return cm; },
66
- get label () { return label; },
67
- get text () { return text; },
68
- get unitCube () { return unitCube; },
69
- get unitAxis () { return unitAxis; },
70
- get toArray () { return toArray; },
71
- get ifArray () { return ifArray; },
72
- get segment () { return segment; },
73
- get zipObject () { return zipObject; },
74
- get map () { return map; },
75
- get mapValues () { return mapValues; },
76
- get pick () { return pick; },
77
- get mapPick () { return mapPick; },
78
- get divA () { return divA; },
79
- get divxyz () { return divxyz; },
80
- get div () { return div; },
81
- get mulxyz () { return mulxyz; },
82
- get mul () { return mul; },
83
- get xyz2array () { return xyz2array; },
84
- get rotationAxes () { return rotationAxes; },
85
- get size () { return size; },
86
- get scale () { return scale; },
87
- get center () { return center; },
88
- get centerY () { return centerY; },
89
- get centerX () { return centerX; },
90
- get enlarge () { return enlarge; },
91
- get fit () { return fit; },
92
- get shift () { return shift; },
93
- get zero () { return zero; },
94
- get mirrored4 () { return mirrored4; },
95
- get flushSide () { return flushSide; },
96
- get calcFlush () { return calcFlush; },
97
- get calcSnap () { return calcSnap; },
98
- get snap () { return snap; },
99
- get flush () { return flush; },
100
- get axisApply () { return axisApply; },
101
- get axis2array () { return axis2array; },
102
- get centroid () { return centroid; },
103
- get calcmidlineTo () { return calcmidlineTo; },
104
- get midlineTo () { return midlineTo; },
105
- get translator () { return translator; },
106
- get calcCenterWith () { return calcCenterWith; },
107
- get centerWith () { return centerWith; },
108
- get getDelta () { return getDelta; },
109
- get bisect () { return bisect; },
110
- get slice () { return slice; },
111
- get wedge () { return wedge; },
112
- get stretch () { return stretch; },
113
- get poly2solid () { return poly2solid; },
114
- get slices2poly () { return slices2poly; },
115
- get normalVector () { return normalVector; },
116
- get sliceParams () { return sliceParams; },
117
- get reShape () { return reShape; },
118
- get chamfer () { return chamfer; },
119
- get fillet () { return fillet; },
120
- get calcRotate () { return calcRotate; },
121
- get rotateAround () { return rotateAround; },
122
- get clone () { return clone; },
123
- get addConnector () { return addConnector; }
124
- });
125
-
126
- function _arrayLikeToArray(r, a) {
127
- (null == a || a > r.length) && (a = r.length);
128
- for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
129
- return n;
130
- }
131
- function _arrayWithHoles(r) {
132
- if (Array.isArray(r)) return r;
133
- }
134
- function _defineProperty(e, r, t) {
135
- return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
136
- value: t,
137
- enumerable: !0,
138
- configurable: !0,
139
- writable: !0
140
- }) : e[r] = t, e;
141
- }
142
- function _iterableToArrayLimit(r, l) {
143
- var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
144
- if (null != t) {
145
- var e,
146
- n,
147
- i,
148
- u,
149
- a = [],
150
- f = !0,
151
- o = !1;
152
- try {
153
- if (i = (t = t.call(r)).next, 0 === l) {
154
- if (Object(t) !== t) return;
155
- f = !1;
156
- } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
157
- } catch (r) {
158
- o = !0, n = r;
159
- } finally {
160
- try {
161
- if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
162
- } finally {
163
- if (o) throw n;
164
- }
165
- }
166
- return a;
167
- }
168
- }
169
- function _nonIterableRest() {
170
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
171
- }
172
- function ownKeys(e, r) {
173
- var t = Object.keys(e);
174
- if (Object.getOwnPropertySymbols) {
175
- var o = Object.getOwnPropertySymbols(e);
176
- r && (o = o.filter(function (r) {
177
- return Object.getOwnPropertyDescriptor(e, r).enumerable;
178
- })), t.push.apply(t, o);
179
- }
180
- return t;
181
- }
182
- function _objectSpread2(e) {
183
- for (var r = 1; r < arguments.length; r++) {
184
- var t = null != arguments[r] ? arguments[r] : {};
185
- r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
186
- _defineProperty(e, r, t[r]);
187
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
188
- Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
189
- });
190
- }
191
- return e;
192
- }
193
- function _slicedToArray(r, e) {
194
- return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
195
- }
196
- function _toPrimitive(t, r) {
197
- if ("object" != typeof t || !t) return t;
198
- var e = t[Symbol.toPrimitive];
199
- if (void 0 !== e) {
200
- var i = e.call(t, r || "default");
201
- if ("object" != typeof i) return i;
202
- throw new TypeError("@@toPrimitive must return a primitive value.");
203
- }
204
- return ("string" === r ? String : Number)(t);
205
- }
206
- function _toPropertyKey(t) {
207
- var i = _toPrimitive(t, "string");
208
- return "symbol" == typeof i ? i : i + "";
209
- }
210
- function _typeof(o) {
211
- "@babel/helpers - typeof";
212
-
213
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
214
- return typeof o;
215
- } : function (o) {
216
- return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
217
- }, _typeof(o);
218
- }
219
- function _unsupportedIterableToArray(r, a) {
220
- if (r) {
221
- if ("string" == typeof r) return _arrayLikeToArray(r, a);
222
- var t = {}.toString.call(r).slice(8, -1);
223
- return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
224
- }
225
- }
226
-
227
46
  /** @module triangle */
228
47
 
229
48
  /**
@@ -231,7 +50,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
231
50
  * @param {Number} deg value in degrees
232
51
  * @return {Number} value in radians
233
52
  */
234
- var toRadians = function toRadians(deg) {
53
+ const toRadians = function toRadians(deg) {
235
54
  return deg / 180 * Math.PI;
236
55
  };
237
56
 
@@ -240,7 +59,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
240
59
  * @param {Number} rad value in radians
241
60
  * @return {Number} value in degrees
242
61
  */
243
- var toDegrees = function toDegrees(rad) {
62
+ const toDegrees = function toDegrees(rad) {
244
63
  return rad * (180 / Math.PI);
245
64
  };
246
65
 
@@ -252,7 +71,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
252
71
  * @param {Number} p2.y Point 2 y coordinate
253
72
  * @return {Object} A triangle object {A,B,C,a,b,c}
254
73
  */
255
- var solve = function solve(p1, p2) {
74
+ const solve = function (p1, p2) {
256
75
  var r = {
257
76
  c: 90,
258
77
  A: Math.abs(p2.x - p1.x),
@@ -294,7 +113,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
294
113
  * @param {Number} r.c Length of side `c`
295
114
  * @return {Object} A solved triangle object {A,B,C,a,b,c}
296
115
  */
297
- var solve90SA = function solve90SA(r) {
116
+ const solve90SA = function (r) {
298
117
  r = Object.assign(r, {
299
118
  C: 90
300
119
  });
@@ -315,7 +134,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
315
134
  r.b = r.b || r.a / Math.tan(arad);
316
135
  return r;
317
136
  };
318
- var solve90ac = function solve90ac(r) {
137
+ const solve90ac = function (r) {
319
138
  r = Object.assign(r, {
320
139
  C: 90
321
140
  });
@@ -372,12 +191,12 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
372
191
 
373
192
  var triUtils = /*#__PURE__*/Object.freeze({
374
193
  __proto__: null,
375
- toRadians: toRadians,
376
- toDegrees: toDegrees,
377
194
  solve: solve,
378
195
  solve90SA: solve90SA,
379
196
  solve90ac: solve90ac,
380
- solveab: solveab
197
+ solveab: solveab,
198
+ toDegrees: toDegrees,
199
+ toRadians: toRadians
381
200
  });
382
201
 
383
202
  /**
@@ -392,7 +211,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
392
211
  * @param {Number} f
393
212
  * @memberof! array
394
213
  */
395
- var div$1 = function div(a, f) {
214
+ const div$1 = function (a, f) {
396
215
  return a.map(function (e) {
397
216
  return e / f;
398
217
  });
@@ -405,7 +224,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
405
224
  * @param {Number} f A value to add to each element of the original array.
406
225
  * @return {Array} A new array with the values added together.
407
226
  */
408
- var addValue = function addValue(a, f) {
227
+ const addValue = function (a, f) {
409
228
  return a.map(function (e) {
410
229
  return e + f;
411
230
  });
@@ -419,7 +238,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
419
238
  * @param {Array} f Another array of numbers, if
420
239
  * @return {Array} A new array with the two values added together.
421
240
  */
422
- var addArray = function addArray(a, f) {
241
+ const addArray = function (a, f) {
423
242
  return a.map(function (e, i) {
424
243
  return e + f[i];
425
244
  });
@@ -431,7 +250,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
431
250
  * @param {Array} a An array of numbers .
432
251
  * @return {Array} A new array with the two values added together.
433
252
  */
434
- var add = function add(a) {
253
+ const add = function (a) {
435
254
  return Array.prototype.slice.call(arguments, 1).reduce(function (result, arg) {
436
255
  if (Array.isArray(arg)) {
437
256
  result = addArray(result, arg);
@@ -448,10 +267,10 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
448
267
  * @function fromxyz
449
268
  * @param {Object|Array} object
450
269
  */
451
- var fromxyz = function fromxyz(object) {
270
+ const fromxyz = function (object) {
452
271
  return Array.isArray(object) ? object : [object.x, object.y, object.z];
453
272
  };
454
- var toxyz = function toxyz(a) {
273
+ const toxyz = function (a) {
455
274
  return {
456
275
  x: a[0],
457
276
  y: a[1],
@@ -465,7 +284,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
465
284
  * @param {Array} a An array of numbers.
466
285
  * @return {Number} The value of the first element of the array or undefined.
467
286
  */
468
- var first = function first(a) {
287
+ const first = function (a) {
469
288
  return a ? a[0] : undefined;
470
289
  };
471
290
 
@@ -474,7 +293,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
474
293
  * @param {Array} a An array of numbers.
475
294
  * @return {Number} The value of the last element of the array or undefined.
476
295
  */
477
- var last = function last(a) {
296
+ const last = function (a) {
478
297
  return a && a.length > 0 ? a[a.length - 1] : undefined;
479
298
  };
480
299
 
@@ -484,7 +303,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
484
303
  * @param {Array} a An array of numbers.
485
304
  * @return {Number} The minimum value in an array of numbers.
486
305
  */
487
- var min = function min(a) {
306
+ const min = function (a) {
488
307
  return a.reduce(function (result, value) {
489
308
  return value < result ? value : result;
490
309
  }, Number.MAX_VALUE);
@@ -497,7 +316,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
497
316
  * @param {Number} b The ending value.
498
317
  * @return {Array} An array of values from `a` to `b`.
499
318
  */
500
- var range = function range(a, b) {
319
+ const range = function (a, b) {
501
320
  var result = [];
502
321
  for (var i = a; i < b; i++) {
503
322
  result.push(i);
@@ -507,22 +326,22 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
507
326
 
508
327
  var array = /*#__PURE__*/Object.freeze({
509
328
  __proto__: null,
510
- div: div$1,
511
- addValue: addValue,
512
- addArray: addArray,
513
329
  add: add,
514
- fromxyz: fromxyz,
515
- toxyz: toxyz,
330
+ addArray: addArray,
331
+ addValue: addValue,
332
+ div: div$1,
516
333
  first: first,
334
+ fromxyz: fromxyz,
517
335
  last: last,
518
336
  min: min,
519
- range: range
337
+ range: range,
338
+ toxyz: toxyz
520
339
  });
521
340
 
522
341
  /* globals jscadUtilsDebug */
523
342
 
524
- var debugColors = ['#e41a1c', '#377eb8', '#4daf4a', '#984ea3', '#ff7f00', '#ffff33', '#a65628', '#f781bf', '#999999'];
525
- var termColors = ['\\033[0;34m', '\\033[0;32m', '\\033[0;36m', '\\033[0;31m', '\\033[0;35m', '\\033[0;33m', '\\033[1;33m', '\\033[0;30m', '\\033[1;34m'];
343
+ const debugColors = ['#e41a1c', '#377eb8', '#4daf4a', '#984ea3', '#ff7f00', '#ffff33', '#a65628', '#f781bf', '#999999'];
344
+ const termColors = ['\\033[0;34m', '\\033[0;32m', '\\033[0;36m', '\\033[0;31m', '\\033[0;35m', '\\033[0;33m', '\\033[1;33m', '\\033[0;30m', '\\033[1;34m'];
526
345
  var debugCount = 0;
527
346
 
528
347
  /**
@@ -543,7 +362,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
543
362
  * @param {String} name The name of the debug function.
544
363
  * @return {Function} A debug function if enabled otherwise an empty function.
545
364
  */
546
- var Debug = function Debug(name) {
365
+ const Debug = function (name) {
547
366
  var checks = Object.assign({
548
367
  enabled: [],
549
368
  disabled: [],
@@ -551,31 +370,25 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
551
370
  browser: true
552
371
  }
553
372
  }, jscadUtilsDebug || {});
554
- var style = checks.options.browser ? "color:".concat(debugColors[debugCount++ % debugColors.length]) : "".concat(termColors[debugCount++ % termColors.length]);
373
+ var style = checks.options.browser ? `color:${debugColors[debugCount++ % debugColors.length]}` : `${termColors[debugCount++ % termColors.length]}`;
555
374
  var enabled = checks.enabled.some(function checkEnabled(check) {
556
375
  return check.test(name);
557
376
  }) && !checks.disabled.some(function checkEnabled(check) {
558
377
  return check.test(name);
559
378
  });
560
- var logger = enabled ? checks.options.browser ? function () {
561
- var _console;
562
- for (var _len = arguments.length, msg = new Array(_len), _key = 0; _key < _len; _key++) {
563
- msg[_key] = arguments[_key];
564
- }
565
- (_console = console).log.apply(_console, ['%c%s', style, name].concat(msg));
566
- } : function () {
567
- var _console2;
568
- for (var _len2 = arguments.length, msg = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
569
- msg[_key2] = arguments[_key2];
570
- }
571
- (_console2 = console).log.apply(_console2, ["".concat(name)].concat(msg));
572
- } : function () {
573
- return undefined;
574
- };
379
+ var logger = enabled ? checks.options.browser ? (...msg) => {
380
+ console.log('%c%s', style, name, ...msg);
381
+ } : (...msg) => {
382
+ console.log(`${name}`, ...msg);
383
+ } : () => undefined;
575
384
  logger.enabled = enabled;
576
385
  return logger;
577
386
  };
578
387
 
388
+ /** @typedef { import('@jscad/csg').CSG } CSG */
389
+
390
+ /** @typedef {"aliceblue"|"antiquewhite"|"aqua"|"aquamarine"|"azure"|"beige"|"bisque"|"black"|"blanchedalmond"|"blue"|"blueviolet"|"brown"|"burlywood"|"cadetblue"|"chartreuse"|"chocolate"|"coral"|"cornflowerblue"|"cornsilk"|"crimson"|"cyan"|"darkblue"|"darkcyan"|"darkgoldenrod"|"darkgray"|"darkgrey"|"darkgreen"|"darkkhaki"|"darkmagenta"|"darkolivegreen"|"darkorange"|"darkorchid"|"darkred"|"darksalmon"|"darkseagreen"|"darkslateblue"|"darkslategray"|"darkslategrey"|"darkturquoise"|"darkviolet"|"deeppink"|"deepskyblue"|"dimgray"|"dimgrey"|"dodgerblue"|"firebrick"|"floralwhite"|"forestgreen"|"fuchsia"|"gainsboro"|"ghostwhite"|"gold"|"goldenrod"|"gray"|"grey"|"green"|"greenyellow"|"honeydew"|"hotpink"|"indianred"|"indigo"|"ivory"|"khaki"|"lavender"|"lavenderblush"|"lawngreen"|"lemonchiffon"|"lightblue"|"lightcoral"|"lightcyan"|"lightgoldenrodyellow"|"lightgray"|"lightgrey"|"lightgreen"|"lightpink"|"lightsalmon"|"lightseagreen"|"lightskyblue"|"lightslategray"|"lightslategrey"|"lightsteelblue"|"lightyellow"|"lime"|"limegreen"|"linen"|"magenta"|"maroon"|"mediumaquamarine"|"mediumblue"|"mediumorchid"|"mediumpurple"|"mediumseagreen"|"mediumslateblue"|"mediumspringgreen"|"mediumturquoise"|"mediumvioletred"|"midnightblue"|"mintcream"|"mistyrose"|"moccasin"|"navajowhite"|"navy"|"oldlace"|"olive"|"olivedrab"|"orange"|"orangered"|"orchid"|"palegoldenrod"|"palegreen"|"paleturquoise"|"palevioletred"|"papayawhip"|"peachpuff"|"peru"|"pink"|"plum"|"powderblue"|"purple"|"red"|"rosybrown"|"royalblue"|"saddlebrown"|"salmon"|"sandybrown"|"seagreen"|"seashell"|"sienna"|"silver"|"skyblue"|"slateblue"|"slategray"|"slategrey"|"snow"|"springgreen"|"steelblue"|"tan"|"teal"|"thistle"|"tomato"|"turquoise"|"violet"|"wheat"|"white"|"whitesmoke"|"yellow"|"yellowgreen"} ColorName */
391
+
579
392
  /**
580
393
  * Color utilities for jscad. Makes setting colors easier using css color names. Using `.init()` adds a `.color()` function to the CSG object.
581
394
  * > You must use `Colors.init(CSG)` in the `main()` function. The `CSG` class is not available before
@@ -588,9 +401,9 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
588
401
  * // draws a purple cube
589
402
  * return CSG.cube({radius: [10, 10, 10]}).color('purple');
590
403
  *}
591
- * @type {Object}
404
+ * @type {Record<ColorName, string>}
592
405
  */
593
- var nameArray = {
406
+ const nameArray = {
594
407
  aliceblue: '#f0f8ff',
595
408
  antiquewhite: '#faebd7',
596
409
  aqua: '#00ffff',
@@ -739,87 +552,158 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
739
552
  yellow: '#ffff00',
740
553
  yellowgreen: '#9acd32'
741
554
  };
555
+
556
+ /**
557
+ * Converts a css color name to a hex string.
558
+ * @param {ColorName} n A css color name
559
+ * @returns {string}
560
+ */
742
561
  function name2hex(n) {
743
- n = n.toLowerCase();
562
+ n = /** @type {ColorName} */n.toLowerCase();
744
563
  if (!nameArray[n]) return 'Invalid Color Name';
745
564
  return nameArray[n];
746
565
  }
566
+
567
+ /**
568
+ * Converts a hex color string to an rgb array.
569
+ * @param {string} h
570
+ * @returns {number[]}
571
+ */
747
572
  function hex2rgb(h) {
748
573
  h = h.replace(/^\#/, '');
749
574
  if (h.length === 6) {
750
575
  return [parseInt(h.substr(0, 2), 16), parseInt(h.substr(2, 2), 16), parseInt(h.substr(4, 2), 16)];
576
+ } else {
577
+ return [0, 0, 0];
751
578
  }
752
579
  }
753
- var _name2rgb = {};
580
+
581
+ /**
582
+ * @type {Record<ColorName, number[]>}
583
+ */
584
+ const _name2rgb = {};
585
+
586
+ /**
587
+ * Converts a css color name to an rgb array.
588
+ * @param {ColorName} n A css color name
589
+ * @returns {number[]}
590
+ */
754
591
  function name2rgb(n) {
755
592
  if (!_name2rgb[n]) _name2rgb[n] = hex2rgb(name2hex(n));
756
593
  return _name2rgb[n];
757
594
  }
595
+
596
+ /**
597
+ *
598
+ * @param {CSG} o
599
+ * @param {number|string} r The red channel value (0.0 - 1.0) or a css color name
600
+ * @param {number} [g] The green channel value (0.0 - 1.0) or the alpha channel when used with a css color string
601
+ * @param {number} [b] The blue channel value (0.0 - 1.0)
602
+ * @param {number} [a] The alpha channel value (0.0 - 1.0)
603
+ * @returns {CSG} Returns a `CSG` object set to the desired color.
604
+ */
758
605
  function color(o, r, g, b, a) {
759
606
  if (typeof r !== 'string') return o.setColor(r, g, b, a);
760
607
  if (r === '') return o; // shortcut for no color
761
- var c = name2rgb(r).map(function (x) {
608
+ var c = name2rgb(/** @type {ColorName} */r).map(function (x) {
762
609
  return x / 255;
763
610
  });
764
611
  c[3] = g || 1.0;
765
612
  return o.setColor(c);
766
613
  }
767
614
 
768
- /**
769
- * Initialize the Color utility. This adds a `.color()` prototype to the `CSG` object.
770
- * @param {CSG} CSG The global `CSG` object
771
- * @memberof module:jscad-utils-color
772
- * @augments CSG
773
- */
774
- // init: function init(proto) {
775
- // // if (proto.setColor) {
776
- // var _setColor = proto.setColor; // eslint-disable-line no-unused-vars
777
-
778
- // /**
779
- // * Set the color of a CSG object using a css color name. Also accepts the normal `setColor()` values.
780
- // * @example
781
- // * // creates a red cube
782
- // * var redcube = CSG.cube({radius: [1, 1, 1]}).color('red');
783
- // *
784
- // * // creates a blue cube with the alpha channel at 50%
785
- // * var bluecube = CSG.cube({radius: [1, 1, 1]}).color('blue', 0.5);
786
- // *
787
- // * // creates a green cube with the alpha channel at 25%
788
- // * // this is the same as the standard setColor
789
- // * var greencube = proto.cube({radius: [1, 1, 1]}).color(0, 1, 0, 0.25);
790
- // * @param {(String | Number)} [red or css name] - Css color name or the red color channel value (0.0 - 1.0)
791
- // * @param {Number} [green or alpha] - green color channel value (0.0 - 1.0) or the alpha channel when used with a css color string
792
- // * @param {Number} [blue] - blue color channel value (0.0 - 1.0)
793
- // * @param {Number} [alpha] - alpha channel value (0.0 - 1.0)
794
- // * @return {CSG} Returns a `CSG` object set to the desired color.
795
- // * @memberof module:CSG
796
- // * @alias color
797
- // * @chainable
798
- // * @augments CSG
799
- // */
800
- // proto.prototype.color = function(r, g, b, a) {
801
- // if (!r) return this; // shortcut empty color values to do nothing.
802
- // return Colors.color(this, r, g, b, a);
803
- // };
804
- // // } else {
805
- // // console.error(
806
- // // `"${proto}" does not have a setColor function to add the Colors prototype to. Make sure the object your trying to decorate with '.color' is correct.`
807
- // // );
808
- // // }
809
- // }
615
+ /** @typedef {object} ExtendedCSG
616
+ * @property {object} prototype
617
+ * @property {function} prototype.color
618
+ * @property {function} prototype.flush
619
+ * @property {function} prototype.snap
620
+ * @property {function} prototype.calcSnap
621
+ * @property {function} prototype.midlineTo
622
+ * @property {function} prototype.calcmidlineTo
623
+ * @property {function} prototype.centerWith
624
+ * @property {function} prototype.calcCenter
625
+ * @property {function} prototype.align
626
+ * @property {function} prototype.calcAlign
627
+ * @property {function} prototype.enlarge
628
+ * @property {function} prototype.fit
629
+ * @property {function} prototype.size
630
+ * @property {function} prototype.centroid
631
+ * @property {function} prototype.Zero
632
+ * @property {function} prototype.Center
633
+ * @property {function} prototype.fillet
634
+ * @property {function} prototype.chamfer
635
+ * @property {function} prototype.bisect
636
+ * @property {function} prototype.slice
637
+ * @property {function} prototype.wedge
638
+ * @property {function} prototype.stretch
639
+ * @property {function} prototype.unionIf
640
+ * @property {function} prototype.subtractIf
641
+ * @property {function} prototype.translate
642
+ * @property {function} prototype.addConnector
643
+ * @property {function} prototype.connect
644
+ * @property {function} prototype.connectTo
645
+ * @property {object} Vector2D
646
+ * @property {function} Vector2D.prototype.map
647
+ * @property {boolean} prototype._jscadutilsinit
648
+ * @property {function} result
649
+ * @property {function} array.addArray
650
+ * @property {function} unitCube
651
+ * @property {function} depreciated
652
+ * @property {function} error
653
+ * @property {function} size
654
+ * @property {function} centroid
655
+ * @property {function} zero
656
+ * @property {function} calcCenterWith
657
+ * @property {function} fillet
658
+ * @property {function} chamfer
659
+ * @property {function} bisect
660
+ * @property {function} slice
661
+ * @property {function} wedge
662
+ * @property {function} stretch
663
+ * @property {function} addConnector
664
+ * @property {function} echo
665
+ * @property {function} log
666
+ * @property {function} warn
667
+ * @property {function} info
668
+ * @property {function} debug
669
+ * @property {function} table
670
+ * @property {function} dir
671
+ * @property {function} dirxml
672
+ * @property {function} trace
673
+ * @property {function} group
674
+ * @property {function} clear
675
+ * @property {function} count
676
+ * @property {function} countReset
677
+ * @property {function} time
678
+ * @property {function} timeLog
679
+ * @property {function} timeEnd
680
+ * @property {function} assert
681
+ * @property {function} profile
682
+ * @property {function} profileEnd
683
+ * @property {function} timeStamp
684
+ * @property {function} stackTrace
685
+ * @property {function} getConnector
686
+ */
687
+
810
688
 
811
689
  /**
812
690
  * Initialize `jscad-utils` and add utilities to the `proto` object.
813
- * @param {proto} proto The global `proto` object
814
- * @augments proto
691
+ * @param {CSG} proto The global `proto` object
815
692
  */
816
693
  function init(proto) {
817
694
  /**
818
- * Short circut out if the prototypes have alrady been added.
695
+ * Short circuit out if the prototypes have already been added.
819
696
  */
820
697
  if (proto.prototype._jscadutilsinit) return;
821
698
 
822
- // Colors.init(proto);
699
+ /**
700
+ *
701
+ * @param {ColorName | number} r The red channel value (0.0 - 1.0) or a css color name
702
+ * @param {number} [g] The green channel value (0.0 - 1.0) or the alpha channel when used with a css color string
703
+ * @param {number} [b] The blue channel value (0.0 - 1.0)
704
+ * @param {number} [a] The alpha channel value (0.0 - 1.0)
705
+ * @returns {CSG} The colored object
706
+ */
823
707
  proto.prototype.color = function (r, g, b, a) {
824
708
  if (!r) return this; // shortcut empty color values to do nothing.
825
709
  return color(this, r, g, b, a);
@@ -845,14 +729,12 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
845
729
  };
846
730
  if (proto.center) echo('proto already has .center');
847
731
  proto.prototype.center = function center(axis) {
848
- // console.log('center', axis, this.getBounds());
849
732
  return centerWith(this, axis || 'xyz', unitCube());
850
733
  };
851
734
  proto.prototype.calcCenter = function centerWith(axis) {
852
735
  return calcCenterWith(this, axis || 'xyz', unitCube(), 0);
853
736
  };
854
737
  proto.prototype.align = function align(to, axis) {
855
- // console.log('align', to.getBounds(), axis);
856
738
  return centerWith(this, axis, to);
857
739
  };
858
740
  proto.prototype.calcAlign = function calcAlign(to, axis, delta) {
@@ -886,23 +768,14 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
886
768
  proto.prototype.chamfer = function chamfer$1(radius, orientation, options) {
887
769
  return chamfer(this, radius, orientation, options);
888
770
  };
889
- proto.prototype.bisect = function bisect$1() {
890
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
891
- args[_key] = arguments[_key];
892
- }
893
- return bisect.apply(util, [this].concat(args));
771
+ proto.prototype.bisect = function bisect$1(...args) {
772
+ return bisect(this, ...args);
894
773
  };
895
- proto.prototype.slice = function slice$1() {
896
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
897
- args[_key2] = arguments[_key2];
898
- }
899
- return slice.apply(util, [this].concat(args));
774
+ proto.prototype.slice = function slice$1(...args) {
775
+ return slice(this, ...args);
900
776
  };
901
- proto.prototype.wedge = function wedge$1() {
902
- for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
903
- args[_key3] = arguments[_key3];
904
- }
905
- return wedge.apply(util, [this].concat(args));
777
+ proto.prototype.wedge = function wedge$1(...args) {
778
+ return wedge(this, ...args);
906
779
  };
907
780
  proto.prototype.stretch = function stretch$1(axis, distance, offset) {
908
781
  return stretch(this, axis, distance, offset);
@@ -919,7 +792,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
919
792
  * This modifies the normal `proto.translate` method to accept
920
793
  * multiple translations, adding the translations together.
921
794
  * The original translate is available on `proto._translate` and
922
- * a short circut is applied when only one parameter is given.
795
+ * a short circuit is applied when only one parameter is given.
923
796
  * @return {proto} The resulting object.
924
797
  */
925
798
  proto.prototype.translate = function translate() {
@@ -928,7 +801,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
928
801
  } else {
929
802
  var t = Array.prototype.slice.call(arguments, 0).reduce(function (result, arg) {
930
803
  // console.log('arg', arg);
931
- result = undefined(result, arg);
804
+ result = undefined.addArray(result, arg);
932
805
  return result;
933
806
  }, [0, 0, 0]);
934
807
 
@@ -939,10 +812,8 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
939
812
  proto.prototype.addConnector = function addConnector$1(name, point, axis, normal) {
940
813
  return addConnector(this, name, point, axis, normal);
941
814
  };
942
- proto.prototype.connect = function connectTo(myConnectorName, otherConnector) {
943
- var mirror = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
944
- var normalrotation = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
945
- var myConnector = myConnectorName.split('.').reduce(function (a, v) {
815
+ proto.prototype.connect = function connectTo(myConnectorName, otherConnector, mirror = false, normalrotation = 0) {
816
+ var myConnector = myConnectorName.split('.').reduce((a, v) => {
946
817
  return a[v];
947
818
  }, this.properties);
948
819
 
@@ -950,7 +821,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
950
821
  * Check for missing property.
951
822
  */
952
823
  if (!myConnector) {
953
- error("The connector '".concat(myConnectorName, "' does not exist on the object [").concat(Object.keys(this.properties).join(','), "]"), 'Missing connector property');
824
+ error(`The connector '${myConnectorName}' does not exist on the object [${Object.keys(this.properties).join(',')}]`, 'Missing connector property');
954
825
  }
955
826
  return this.connectTo(myConnector, otherConnector, mirror, normalrotation);
956
827
  };
@@ -961,19 +832,26 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
961
832
 
962
833
  var init$1 = /*#__PURE__*/Object.freeze({
963
834
  __proto__: null,
964
- 'default': init
835
+ default: init
965
836
  });
966
837
 
967
- var CSG = jsCadCSG__default["default"].CSG,
968
- CAG = jsCadCSG__default["default"].CAG;
969
- var rectangular_extrude = scadApi__default["default"].extrusions.rectangular_extrude;
970
- var _scadApi$text = scadApi__default["default"].text,
971
- vector_text = _scadApi$text.vector_text,
972
- vector_char = _scadApi$text.vector_char;
973
- var union = scadApi__default["default"].booleanOps.union;
838
+ const {
839
+ CSG,
840
+ CAG
841
+ } = jsCadCSG;
842
+ const {
843
+ rectangular_extrude
844
+ } = scadApi.extrusions;
845
+ const {
846
+ vector_text,
847
+ vector_char
848
+ } = scadApi.text;
849
+ const {
850
+ union
851
+ } = scadApi.booleanOps;
974
852
  init(CSG);
975
853
 
976
- var debug$3 = Debug('jscadUtils:group');
854
+ const debug$3 = Debug('jscadUtils:group');
977
855
 
978
856
  /**
979
857
  * @function JsCadUtilsGroup
@@ -982,10 +860,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
982
860
  * @param {CSG[]} holes An array of CSG objects that will be subtracted after combination.
983
861
  * @namespace JsCadUtilsGroup
984
862
  */
985
- function JsCadUtilsGroup() {
986
- var names = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
987
- var parts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
988
- var holes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
863
+ function JsCadUtilsGroup(names = [], parts = {}, holes = []) {
989
864
  this.name = '';
990
865
  this.names = names;
991
866
  this.parts = parts;
@@ -1033,11 +908,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
1033
908
  * @param {Function} map A function that is run before unioning the parts together.
1034
909
  * @return {CSG} A single `CSG` object of the unioned parts.
1035
910
  */
1036
- JsCadUtilsGroup.prototype.combine = function (pieces) {
1037
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1038
- var map = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function (x) {
1039
- return x;
1040
- };
911
+ JsCadUtilsGroup.prototype.combine = function (pieces, options = {}, map = x => x) {
1041
912
  try {
1042
913
  var self = this;
1043
914
  options = Object.assign({
@@ -1045,7 +916,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
1045
916
  }, options);
1046
917
  pieces = pieces ? pieces.split(',') : self.names;
1047
918
  if (pieces.length === 0) {
1048
- throw new Error("no pieces found in ".concat(self.name, " pieces: ").concat(pieces, " parts: ").concat(Object.keys(self.parts), " names: ").concat(self.names));
919
+ throw new Error(`no pieces found in ${self.name} pieces: ${pieces} parts: ${Object.keys(self.parts)} names: ${self.names}`);
1049
920
  }
1050
921
  debug$3('combine', self.names, self.parts);
1051
922
  var g = union(mapPick(self.parts, pieces, function (value, key, index, object) {
@@ -1055,7 +926,12 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
1055
926
  return g.subtractIf(self.holes && Array.isArray(self.holes) ? union(self.holes) : self.holes, self.holes && !options.noholes);
1056
927
  } catch (err) {
1057
928
  debug$3('combine error', this, pieces, options, err);
1058
- throw error("group::combine error \"".concat(err.message || err.toString(), "\"\nthis: ").concat(this, "\npieces: \"").concat(pieces, "\"\noptions: ").concat(JSON.stringify(options, null, 2), "\nstack: ").concat(err.stack, "\n"), 'JSCAD_UTILS_GROUP_ERROR');
929
+ throw error(`group::combine error "${err.message || err.toString()}"
930
+ this: ${this}
931
+ pieces: "${pieces}"
932
+ options: ${JSON.stringify(options, null, 2)}
933
+ stack: ${err.stack}
934
+ `, 'JSCAD_UTILS_GROUP_ERROR');
1059
935
  }
1060
936
  };
1061
937
 
@@ -1068,9 +944,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
1068
944
  */
1069
945
  JsCadUtilsGroup.prototype.map = function (cb) {
1070
946
  var self = this;
1071
- self.parts = Object.keys(self.parts).filter(function (k) {
1072
- return k !== 'holes';
1073
- }).reduce(function (result, key) {
947
+ self.parts = Object.keys(self.parts).filter(k => k !== 'holes').reduce(function (result, key) {
1074
948
  result[key] = cb(self.parts[key], key);
1075
949
  return result;
1076
950
  }, {});
@@ -1094,7 +968,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
1094
968
  * @return {JsCadUtilsGroup} The new group.
1095
969
  */
1096
970
  JsCadUtilsGroup.prototype.clone = function (name, map) {
1097
- debug$3('clone', name, _typeof(name), map);
971
+ debug$3('clone', name, typeof name, map);
1098
972
  var self = this;
1099
973
  /**
1100
974
  * For backwards compatibility
@@ -1181,7 +1055,15 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
1181
1055
  return self;
1182
1056
  } catch (err) {
1183
1057
  debug$3('snap error', this, part, to, axis, delta, err);
1184
- throw error("group::snap error \"".concat(err.message || err.toString(), "\"\nthis: ").concat(this, "\npart: \"").concat(part, "\"\nto: ").concat(to, "\naxis: \"").concat(axis, "\"\norientation: \"").concat(orientation, "\"\ndelta: \"").concat(delta, "\"\nstack: ").concat(err.stack, "\n"), 'JSCAD_UTILS_GROUP_ERROR');
1058
+ throw error(`group::snap error "${err.message || err.toString()}"
1059
+ this: ${this}
1060
+ part: "${part}"
1061
+ to: ${to}
1062
+ axis: "${axis}"
1063
+ orientation: "${orientation}"
1064
+ delta: "${delta}"
1065
+ stack: ${err.stack}
1066
+ `, 'JSCAD_UTILS_GROUP_ERROR');
1185
1067
  }
1186
1068
  };
1187
1069
 
@@ -1213,7 +1095,14 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
1213
1095
  return self;
1214
1096
  } catch (err) {
1215
1097
  debug$3('align error', this, part, to, axis, delta, err);
1216
- throw error("group::align error \"".concat(err.message || err.toString(), "\"\nthis: ").concat(this, "\npart: \"").concat(part, "\"\nto: ").concat(to, "\naxis: \"").concat(axis, "\"\ndelta: \"").concat(delta, "\"\nstack: ").concat(err.stack, "\n"), 'JSCAD_UTILS_GROUP_ERROR');
1098
+ throw error(`group::align error "${err.message || err.toString()}"
1099
+ this: ${this}
1100
+ part: "${part}"
1101
+ to: ${to}
1102
+ axis: "${axis}"
1103
+ delta: "${delta}"
1104
+ stack: ${err.stack}
1105
+ `, 'JSCAD_UTILS_GROUP_ERROR');
1217
1106
  }
1218
1107
  };
1219
1108
  JsCadUtilsGroup.prototype.center = function center(part) {
@@ -1225,23 +1114,21 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
1225
1114
  var bounds = self.parts[part].getBounds();
1226
1115
  return self.translate([0, 0, -bounds[0].z]);
1227
1116
  };
1228
- JsCadUtilsGroup.prototype.connectTo = function connectTo(partName, connectorName, to, toConnectorName) {
1229
- var mirror = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
1230
- var normalrotation = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 0;
1117
+ JsCadUtilsGroup.prototype.connectTo = function connectTo(partName, connectorName, to, toConnectorName, mirror = true, normalrotation = 0) {
1231
1118
  debug$3('connectTo', {
1232
- partName: partName,
1233
- connectorName: connectorName,
1234
- to: to,
1235
- toConnectorName: toConnectorName,
1236
- mirror: mirror,
1237
- normalrotation: normalrotation
1119
+ partName,
1120
+ connectorName,
1121
+ to,
1122
+ toConnectorName,
1123
+ mirror,
1124
+ normalrotation
1238
1125
  });
1239
1126
  var self = this;
1240
- var myConnector = connectorName.split('.').reduce(function (a, v) {
1127
+ var myConnector = connectorName.split('.').reduce((a, v) => {
1241
1128
  return a[v];
1242
1129
  }, self.parts[partName].properties);
1243
1130
  debug$3('toConnector', to instanceof CSG.Connector);
1244
- var toConnector = toConnectorName.split('.').reduce(function (a, v) {
1131
+ var toConnector = toConnectorName.split('.').reduce((a, v) => {
1245
1132
  return a[v];
1246
1133
  }, to.properties);
1247
1134
  var matrix = myConnector.getTransformationTo(toConnector, mirror, normalrotation);
@@ -1329,16 +1216,18 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
1329
1216
  * @return {Array} An array of `CSG` objects
1330
1217
  */
1331
1218
  JsCadUtilsGroup.prototype.array = function (parts, map) {
1332
- var _this = this;
1333
1219
  var self = this;
1334
1220
  // try {
1335
1221
  var p = parts && parts.length > 0 && parts.split(',') || self.names;
1336
1222
  if (!map) map = identity;
1337
1223
  var a = [];
1338
- p.forEach(function (name) {
1224
+ p.forEach(name => {
1339
1225
  if (!self.parts[name]) {
1340
- debug$3('array error', _this, parts);
1341
- throw error("group::array error \"".concat(name, "\" not found.\nthis: ").concat(_this, "\nparts: \"").concat(parts, "\"\n"), 'JSCAD_UTILS_GROUP_ERROR');
1226
+ debug$3('array error', this, parts);
1227
+ throw error(`group::array error "${name}" not found.
1228
+ this: ${this}
1229
+ parts: "${parts}"
1230
+ `, 'JSCAD_UTILS_GROUP_ERROR');
1342
1231
  }
1343
1232
  a.push(map(CSG.fromPolygons(self.parts[name].toPolygons()), name));
1344
1233
  });
@@ -1368,12 +1257,17 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
1368
1257
  var self = this;
1369
1258
  var piecesArray = pieces ? pieces.split(',') : self.names;
1370
1259
  return piecesArray.map(function (piece) {
1371
- if (!self.parts[piece]) console.error("Cannot find ".concat(piece, " in ").concat(self.names));
1260
+ if (!self.parts[piece]) console.error(`Cannot find ${piece} in ${self.names}`);
1372
1261
  return self.parts[piece];
1373
1262
  });
1374
1263
  };
1375
1264
  JsCadUtilsGroup.prototype.toString = function () {
1376
- return "{\n name: \"".concat(this.name, "\",\n names: \"").concat(this.names.join(','), "\", \n parts: \"").concat(Object.keys(this.parts), "\",\n holes: ").concat(Array.isArray(this.holes) ? this.holes.length : this.holes ? 1 : 0, "\n}");
1265
+ return `{
1266
+ name: "${this.name}",
1267
+ names: "${this.names.join(',')}",
1268
+ parts: "${Object.keys(this.parts)}",
1269
+ holes: ${Array.isArray(this.holes) ? this.holes.length : this.holes ? 1 : 0}
1270
+ }`;
1377
1271
  };
1378
1272
  JsCadUtilsGroup.prototype.setName = function (name) {
1379
1273
  this.name = name;
@@ -1422,9 +1316,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
1422
1316
  self.name = objectNames;
1423
1317
  } else {
1424
1318
  var objects = objectNames; // eslint-disable-line no-redeclare
1425
- self.names = Object.keys(objects).filter(function (k) {
1426
- return k !== 'holes';
1427
- });
1319
+ self.names = Object.keys(objects).filter(k => k !== 'holes');
1428
1320
  self.parts = Object.assign({}, objects);
1429
1321
  self.holes = objects.holes;
1430
1322
  }
@@ -1433,45 +1325,43 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
1433
1325
  return new JsCadUtilsGroup(self.names, self.parts, self.holes);
1434
1326
  }
1435
1327
 
1436
- var debug$2 = Debug('jscadUtils:util');
1328
+ /** @typedef { import('@jscad/csg').CSG } CSG */
1329
+
1330
+ const debug$2 = Debug('jscadUtils:util');
1437
1331
  // import utilInit from '../src/add-prototype';
1438
1332
  // utilInit(CSG);
1439
1333
  // console.trace('CSG', CSG.prototype);
1440
1334
 
1441
1335
  var NOZZEL_SIZE = 0.4;
1442
- var nearest = {
1336
+ const nearest = {
1443
1337
  /**
1444
1338
  * Return the largest number that is a multiple of the
1445
1339
  * nozzel size.
1446
1340
  * @param {Number} desired Desired value
1447
- * @param {Number} [nozzel=NOZZEL_SIZE] Nozel size, defaults to `NOZZEL_SIZE`
1341
+ * @param {Number} [nozzel=NOZZEL_SIZE] Nozzel size, defaults to `NOZZEL_SIZE`
1448
1342
  * @param {Number} [nozzie=0] Number of nozzel sizes to add to the value
1449
1343
  * @return {Number} Multiple of nozzel size
1450
1344
  */
1451
- under: function under(desired) {
1452
- var nozzel = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : NOZZEL_SIZE;
1453
- var nozzie = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
1345
+ under: function (desired, nozzel = NOZZEL_SIZE, nozzie = 0) {
1454
1346
  return (Math.floor(desired / nozzel) + nozzie) * nozzel;
1455
1347
  },
1456
1348
  /**
1457
- * Returns the largest number that is a multipel of the
1349
+ * Returns the largest number that is a multiple of the
1458
1350
  * nozzel size, just over the desired value.
1459
1351
  * @param {Number} desired Desired value
1460
- * @param {Number} [nozzel=NOZZEL_SIZE] Nozel size, defaults to `NOZZEL_SIZE`
1352
+ * @param {Number} [nozzel=NOZZEL_SIZE] Nozzel size, defaults to `NOZZEL_SIZE`
1461
1353
  * @param {Number} [nozzie=0] Number of nozzel sizes to add to the value
1462
1354
  * @return {Number} Multiple of nozzel size
1463
1355
  */
1464
- over: function over(desired) {
1465
- var nozzel = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : NOZZEL_SIZE;
1466
- var nozzie = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
1356
+ over: function (desired, nozzel = NOZZEL_SIZE, nozzie = 0) {
1467
1357
  return (Math.ceil(desired / nozzel) + nozzie) * nozzel;
1468
1358
  }
1469
1359
  };
1470
1360
 
1471
1361
  /**
1472
- * A function that reutrns the first argument. Useful when
1362
+ * A function that returns the first argument. Useful when
1473
1363
  * passing in a callback to modify something, and you want a
1474
- * default functiont hat does nothing.
1364
+ * default function hat does nothing.
1475
1365
  * @param {object} solid an object that will be returned
1476
1366
  * @return {object} the first parameter passed into the function.
1477
1367
  * @function identity
@@ -1481,13 +1371,13 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
1481
1371
  }
1482
1372
 
1483
1373
  /**
1484
- * If `f` is a funciton, it is executed with `object` as the
1374
+ * If `f` is a function, it is executed with `object` as the
1485
1375
  * parameter. This is used in `CSG.unionIf` and `CSG.subtractIf`,
1486
1376
  * allowing you to pass a function instead of an object. Since the
1487
- * function isn't exeuted until called, the object to `union` or
1377
+ * function isn't executed until called, the object to `union` or
1488
1378
  * `subtract` can be assembled only if the conditional is true.
1489
1379
  * @param {object} object the context to run the function with.
1490
- * @param {function|object} f if a funciton it is executed, othewise the object is returned.
1380
+ * @param {function|object} f if a function it is executed, otherwise the object is returned.
1491
1381
  * @return {object} the result of the function or the object.
1492
1382
  * @function result
1493
1383
  */
@@ -1502,10 +1392,10 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
1502
1392
  /**
1503
1393
  * Returns target object with default values assigned. If values already exist, they are not set.
1504
1394
  * @param {object} target The target object to return.
1505
- * @param {object} defaults Defalut values to add to the object if they don't already exist.
1395
+ * @param {object} defaults Default values to add to the object if they don't already exist.
1506
1396
  * @return {object} Target object with default values assigned.
1507
1397
  * @function defaults
1508
- * @depricated
1398
+ * @deprecated
1509
1399
  */
1510
1400
  function defaults(target, defaults) {
1511
1401
  depreciated('defaults', true, 'use Object.assign instead');
@@ -1519,20 +1409,24 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
1519
1409
  }
1520
1410
 
1521
1411
  /**
1522
- * Print a message and CSG object bounds and size to the conosle.
1412
+ * Print a message and CSG object bounds and size to the console.
1523
1413
  * @param {String} msg Message to print
1524
1414
  * @param {CSG} o A CSG object to print the bounds and size of.
1525
1415
  * @function
1526
- * @depricated use Debug instead
1416
+ * @deprecated use Debug instead
1527
1417
  */
1528
1418
  function print(msg, o) {
1529
1419
  debug$2(msg, JSON.stringify(o.getBounds()), JSON.stringify(this.size(o.getBounds())));
1530
1420
  }
1531
1421
  function jscadToString(o) {
1532
- if (_typeof(o) == 'object') {
1422
+ if (typeof o == 'object') {
1533
1423
  if (o.polygons) {
1534
1424
  // is this CSG like?
1535
- return "{\npolygons: ".concat(o.polygons.length, ",\nproperties: \"").concat(Object.keys(o.properties), "\"\n}\n");
1425
+ return `{
1426
+ polygons: ${o.polygons.length},
1427
+ properties: "${Object.keys(o.properties)}"
1428
+ }
1429
+ `;
1536
1430
  }
1537
1431
  } else {
1538
1432
  return o.toString();
@@ -1548,11 +1442,11 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
1548
1442
 
1549
1443
  /**
1550
1444
  * Shows a warning or error message. Used to indicate a method
1551
- * has been depricated and what to use instead.
1445
+ * has been deprecated and what to use instead.
1552
1446
  * @function depreciated
1553
- * @param {string} method The name of the method being depricated.
1447
+ * @param {string} method The name of the method being deprecated.
1554
1448
  * @param {boolean} [error] Throws an error if called when true.
1555
- * @param {string} [message] Instructions on what to use instead of the depricated method.
1449
+ * @param {string} [message] Instructions on what to use instead of the deprecated method.
1556
1450
  */
1557
1451
  function depreciated(method, error, message) {
1558
1452
  var msg = method + ' is depreciated.' + (' ' + message || '');
@@ -1601,13 +1495,13 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
1601
1495
  }
1602
1496
  function text(text) {
1603
1497
  var l = vector_char(0, 0, text); // l contains a list of polylines to draw
1604
- var _char = l.segments.reduce(function (result, segment) {
1498
+ var char = l.segments.reduce(function (result, segment) {
1605
1499
  var path = new CSG.Path2D(segment);
1606
1500
  var cag = path.expandToCAG(2);
1607
1501
  // debug('reduce', result, segment, path, cag);
1608
1502
  return result ? result.union(cag) : cag;
1609
1503
  }, undefined);
1610
- return _char;
1504
+ return char;
1611
1505
  }
1612
1506
  function unitCube(length, radius) {
1613
1507
  radius = radius || 0.5;
@@ -1634,7 +1528,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
1634
1528
  * Returns an array of positions along an object on a given axis.
1635
1529
  * @param {CSG} object The object to calculate the segments on.
1636
1530
  * @param {number} segments The number of segments to create.
1637
- * @param {string} axis Axis to create the sgements on.
1531
+ * @param {string} axis Axis to create the segments on.
1638
1532
  * @return {Array} An array of segment positions.
1639
1533
  * @function segment
1640
1534
  */
@@ -1680,7 +1574,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
1680
1574
  function mapPick(o, names, f, options) {
1681
1575
  return names.reduce(function (result, name, index) {
1682
1576
  if (!o[name]) {
1683
- throw new Error("".concat(name, " not found in ").concat(options.name, ": ").concat(Object.keys(o).join(',')));
1577
+ throw new Error(`${name} not found in ${options.name}: ${Object.keys(o).join(',')}`);
1684
1578
  }
1685
1579
  result.push(f ? f(o[name], name, index, o) : o[name]);
1686
1580
  return result;
@@ -1712,7 +1606,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
1712
1606
  function xyz2array(size) {
1713
1607
  return [size.x, size.y, size.z];
1714
1608
  }
1715
- var rotationAxes = {
1609
+ const rotationAxes = {
1716
1610
  x: [1, 0, 0],
1717
1611
  y: [0, 1, 0],
1718
1612
  z: [0, 0, 1]
@@ -1833,7 +1727,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
1833
1727
  function mirrored4(x) {
1834
1728
  return x.union([x.mirroredY(90), x.mirroredX(90), x.mirroredY(90).mirroredX(90)]);
1835
1729
  }
1836
- var flushSide = {
1730
+ const flushSide = {
1837
1731
  'above-outside': [1, 0],
1838
1732
  'above-inside': [1, 1],
1839
1733
  'below-outside': [0, 1],
@@ -1866,8 +1760,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
1866
1760
  return w[side[0]][axis] - m[side[1]][axis];
1867
1761
  });
1868
1762
  }
1869
- function calcSnap(moveobj, withobj, axes, orientation) {
1870
- var delta = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
1763
+ function calcSnap(moveobj, withobj, axes, orientation, delta = 0) {
1871
1764
  var side = flushSide[orientation];
1872
1765
  if (!side) {
1873
1766
  var fix = {
@@ -1945,7 +1838,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
1945
1838
  objectSize = objectSize || size(bounds);
1946
1839
  return bounds[0].plus(objectSize.dividedBy(2));
1947
1840
  } catch (err) {
1948
- error("centroid error o:".concat(jscadToString(o), " objectSize: ").concat(objectSize), undefined, err);
1841
+ error(`centroid error o:${jscadToString(o)} objectSize: ${objectSize}`, undefined, err);
1949
1842
  }
1950
1843
  }
1951
1844
 
@@ -1957,7 +1850,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
1957
1850
  * @param {CSG} o A CSG object.
1958
1851
  * @param {String} axis A string with the axis to operate on.
1959
1852
  * @param {Number} to Value to move the midline of the object to.
1960
- * @return {Number[]} The tranform array needed to move the object.
1853
+ * @return {Number[]} The transform array needed to move the object.
1961
1854
  */
1962
1855
  function calcmidlineTo(o, axis, to) {
1963
1856
  var bounds = o.getBounds();
@@ -1978,8 +1871,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
1978
1871
  });
1979
1872
  return t;
1980
1873
  }
1981
- function calcCenterWith(o, axes, withObj) {
1982
- var delta = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
1874
+ function calcCenterWith(o, axes, withObj, delta = 0) {
1983
1875
  var objectCentroid = centroid(o);
1984
1876
  var withCentroid = centroid(withObj);
1985
1877
  var t = axisApply(axes, function (i, axis) {
@@ -1996,7 +1888,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
1996
1888
  * along the axis will be returned. If no `offset`
1997
1889
  * is given, then the midway point on the axis is returned.
1998
1890
  * When the `offset` is positive, a point `offset` from the
1999
- * mininum axis is returned. When the `offset` is negative,
1891
+ * minimum axis is returned. When the `offset` is negative,
2000
1892
  * the `offset` is subtracted from the axis maximum.
2001
1893
  * @param {Size} size Size array of the object
2002
1894
  * @param {Bounds} bounds Bounds of the object
@@ -2041,12 +1933,9 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
2041
1933
  * @param {CSG.Vector3D} [options.rotationCenter]
2042
1934
  * @return {JsCadUtilsGroup} Returns a group object with a parts object.
2043
1935
  */
2044
- function bisect() {
2045
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
2046
- args[_key] = arguments[_key];
2047
- }
1936
+ function bisect(...args) {
2048
1937
  if (args.length < 2) {
2049
- error('bisect requries an object and an axis', 'JSCAD_UTILS_INVALID_ARGS');
1938
+ error('bisect requires an object and an axis', 'JSCAD_UTILS_INVALID_ARGS');
2050
1939
  }
2051
1940
  var object = args[0];
2052
1941
  var axis = args[1];
@@ -2114,16 +2003,16 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
2114
2003
  var theRotationAxis = rotationAxes[rotateaxis];
2115
2004
  var cutplane = CSG.OrthoNormalBasis.GetCartesian(info.orthoNormalCartesian[0], info.orthoNormalCartesian[1]).translate(cutDelta).rotate(rotationCenter, theRotationAxis, angle);
2116
2005
  debug$2('bisect', debug$2.enabled && {
2117
- axis: axis,
2118
- offset: offset,
2119
- angle: angle,
2120
- rotateaxis: rotateaxis,
2121
- cutDelta: cutDelta,
2122
- rotateOffsetAxis: rotateOffsetAxis,
2123
- rotationCenter: rotationCenter,
2124
- theRotationAxis: theRotationAxis,
2125
- cutplane: cutplane,
2126
- options: options
2006
+ axis,
2007
+ offset,
2008
+ angle,
2009
+ rotateaxis,
2010
+ cutDelta,
2011
+ rotateOffsetAxis,
2012
+ rotationCenter,
2013
+ theRotationAxis,
2014
+ cutplane,
2015
+ options
2127
2016
  });
2128
2017
  var g = Group('negative,positive', [object.cutByPlane(cutplane.plane).color(options.color && 'red'), object.cutByPlane(cutplane.plane.flipped()).color(options.color && 'blue')]);
2129
2018
  if (options.addRotationCenter) g.add(unitAxis(objectSize.length() + 10, 0.1, rotationCenter), 'rotationCenter');
@@ -2141,14 +2030,10 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
2141
2030
  * @param {CSG.Vector3D} [options.rotationCenter] The location of the rotation center, defaults to [0,0,0].
2142
2031
  * @return {JsCadUtilsGroup} A group with a positive and negative CSG object.
2143
2032
  */
2144
- function slice(object) {
2145
- var angle = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 15;
2146
- var axis = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'x';
2147
- var rotateaxis = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'z';
2148
- var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {
2149
- color: true,
2150
- addRotationCenter: true
2151
- };
2033
+ function slice(object, angle = 15, axis = 'x', rotateaxis = 'z', options = {
2034
+ color: true,
2035
+ addRotationCenter: true
2036
+ }) {
2152
2037
  var info = normalVector(axis);
2153
2038
  var rotationCenter = options.rotationCenter || new CSG.Vector3D(0, 0, 0);
2154
2039
  var theRotationAxis = rotationAxes[rotateaxis];
@@ -2208,7 +2093,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
2208
2093
  * Wraps the `stretchAtPlane` call using the same
2209
2094
  * logic as `bisect`.
2210
2095
  * @param {CSG} object Object to stretch
2211
- * @param {String} axis Axis to streatch along
2096
+ * @param {String} axis Axis to stretch along
2212
2097
  * @param {Number} distance Distance to stretch
2213
2098
  * @param {Number} offset Offset along the axis to cut the object
2214
2099
  * @return {CSG} The stretched object.
@@ -2298,7 +2183,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
2298
2183
  flipped: up
2299
2184
  }));
2300
2185
 
2301
- // rotate with quick short circut
2186
+ // rotate with quick short circuit
2302
2187
  var rotate = twistangle === 0 ? function rotateZero(v) {
2303
2188
  return v;
2304
2189
  } : function rotate(v, angle, percent) {
@@ -2389,7 +2274,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
2389
2274
  var absoluteRadius = Math.abs(radius);
2390
2275
  var si = sliceParams(orientation, radius, b);
2391
2276
  debug$2('reShape', absoluteRadius, si);
2392
- if (si.axis !== 'z') throw new Error('reShape error: CAG._toPlanePolytons only uses the "z" axis. You must use the "z" axis for now.');
2277
+ if (si.axis !== 'z') throw new Error('reShape error: CAG._toPlanePolygons only uses the "z" axis. You must use the "z" axis for now.');
2393
2278
  var cutplane = CSG.OrthoNormalBasis.GetCartesian(si.orthoNormalCartesian[0], si.orthoNormalCartesian[1]).translate(si.cutDelta);
2394
2279
  var slice = object.sectionCut(cutplane);
2395
2280
  var first = axisApply(si.axis, function () {
@@ -2445,21 +2330,19 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
2445
2330
  var rotationCenter = solid.centroid();
2446
2331
  var rotationAxis = axes[axis];
2447
2332
  return {
2448
- rotationCenter: rotationCenter,
2449
- rotationAxis: rotationAxis
2333
+ rotationCenter,
2334
+ rotationAxis
2450
2335
  };
2451
2336
  }
2452
2337
  function rotateAround(part, solid, axis, angle) {
2453
- var _calcRotate = calcRotate(part, solid, axis),
2454
- rotationCenter = _calcRotate.rotationCenter,
2455
- rotationAxis = _calcRotate.rotationAxis;
2338
+ var {
2339
+ rotationCenter,
2340
+ rotationAxis
2341
+ } = calcRotate(part, solid, axis);
2456
2342
  return part.rotate(rotationCenter, rotationAxis, angle);
2457
2343
  }
2458
- function cloneProperties(from, to) {
2459
- return Object.entries(from).reduce(function (props, _ref) {
2460
- var _ref2 = _slicedToArray(_ref, 2),
2461
- key = _ref2[0],
2462
- value = _ref2[1];
2344
+ function cloneProperties(from, to, depth = 0) {
2345
+ return Object.entries(from).reduce((props, [key, value]) => {
2463
2346
  props[key] = value;
2464
2347
  return props;
2465
2348
  }, to);
@@ -2480,21 +2363,93 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
2480
2363
  * @param {Array} point=[0,0,0] a 3 axis array direction vector somewhat perpendicular to axis; this defines the “12 o'clock” orientation of the connection.
2481
2364
  * @return {CSG} The CSG object with the new connector added.
2482
2365
  */
2483
- function addConnector(object, name) {
2484
- var point = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [0, 0, 0];
2485
- var axis = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [1, 0, 0];
2486
- var normal = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [0, 0, 1];
2366
+ function addConnector(object, name, point = [0, 0, 0], axis = [1, 0, 0], normal = [0, 0, 1]) {
2487
2367
  object.properties[name] = new CSG.Connector(point, axis, normal);
2488
2368
  return object;
2489
2369
  }
2490
2370
 
2491
- var debug$1 = Debug('jscadUtils:parts');
2371
+ var util = /*#__PURE__*/Object.freeze({
2372
+ __proto__: null,
2373
+ NOZZEL_SIZE: NOZZEL_SIZE,
2374
+ addConnector: addConnector,
2375
+ axis2array: axis2array,
2376
+ axisApply: axisApply,
2377
+ bisect: bisect,
2378
+ calcCenterWith: calcCenterWith,
2379
+ calcFlush: calcFlush,
2380
+ calcRotate: calcRotate,
2381
+ calcSnap: calcSnap,
2382
+ calcmidlineTo: calcmidlineTo,
2383
+ center: center,
2384
+ centerWith: centerWith,
2385
+ centerX: centerX,
2386
+ centerY: centerY,
2387
+ centroid: centroid,
2388
+ chamfer: chamfer,
2389
+ clone: clone,
2390
+ cm: cm,
2391
+ defaults: defaults,
2392
+ depreciated: depreciated,
2393
+ div: div,
2394
+ divA: divA,
2395
+ divxyz: divxyz,
2396
+ enlarge: enlarge,
2397
+ error: error,
2398
+ fillet: fillet,
2399
+ fit: fit,
2400
+ flush: flush,
2401
+ flushSide: flushSide,
2402
+ getDelta: getDelta,
2403
+ identity: identity,
2404
+ ifArray: ifArray,
2405
+ inch: inch,
2406
+ isEmpty: isEmpty,
2407
+ isNegative: isNegative,
2408
+ jscadToString: jscadToString,
2409
+ label: label,
2410
+ map: map,
2411
+ mapPick: mapPick,
2412
+ mapValues: mapValues,
2413
+ midlineTo: midlineTo,
2414
+ mirrored4: mirrored4,
2415
+ mul: mul,
2416
+ mulxyz: mulxyz,
2417
+ nearest: nearest,
2418
+ normalVector: normalVector,
2419
+ pick: pick,
2420
+ poly2solid: poly2solid,
2421
+ print: print,
2422
+ reShape: reShape,
2423
+ result: result,
2424
+ rotateAround: rotateAround,
2425
+ rotationAxes: rotationAxes,
2426
+ scale: scale,
2427
+ segment: segment,
2428
+ shift: shift,
2429
+ size: size,
2430
+ slice: slice,
2431
+ sliceParams: sliceParams,
2432
+ slices2poly: slices2poly,
2433
+ snap: snap,
2434
+ stretch: stretch,
2435
+ text: text,
2436
+ toArray: toArray,
2437
+ translator: translator,
2438
+ unitAxis: unitAxis,
2439
+ unitCube: unitCube,
2440
+ wedge: wedge,
2441
+ xyz2array: xyz2array,
2442
+ zero: zero,
2443
+ zipObject: zipObject
2444
+ });
2445
+
2446
+ const debug$1 = Debug('jscadUtils:parts');
2492
2447
  var parts = {
2493
2448
  BBox: BBox$1,
2494
- Cube: Cube,
2495
- RoundedCube: RoundedCube,
2496
- Cylinder: Cylinder,
2497
- Cone: Cone
2449
+ Cube,
2450
+ RoundedCube,
2451
+ Cylinder,
2452
+ Cone
2498
2453
  };
2499
2454
 
2500
2455
  /**
@@ -2504,16 +2459,13 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
2504
2459
  * @param {CSG} ...objects Any number of CSG objects to create a bounding box for.
2505
2460
  * @return {CSG} A box with the size of the extents of all of the passed in objects
2506
2461
  */
2507
- function BBox$1() {
2462
+ function BBox$1(...objects) {
2508
2463
  function box(object) {
2509
2464
  return CSG.cube({
2510
2465
  center: object.centroid(),
2511
2466
  radius: object.size().dividedBy(2)
2512
2467
  });
2513
2468
  }
2514
- for (var _len = arguments.length, objects = new Array(_len), _key = 0; _key < _len; _key++) {
2515
- objects[_key] = arguments[_key];
2516
- }
2517
2469
  return objects.reduce(function (bbox, part) {
2518
2470
  var object = bbox ? union([bbox, box(part)]) : part;
2519
2471
  return box(object);
@@ -2573,8 +2525,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
2573
2525
  * @param {number} [options.resolution] The number of segments to create in 360 degrees of rotation.
2574
2526
  * @return {CSG} A CSG Cylinder
2575
2527
  */
2576
- function Cylinder(diameter, height) {
2577
- var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
2528
+ function Cylinder(diameter, height, options = {}) {
2578
2529
  debug$1('parts.Cylinder', diameter, height, options);
2579
2530
  options = Object.assign({
2580
2531
  start: [0, 0, 0],
@@ -2594,8 +2545,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
2594
2545
  * @param {Object} options Additional options passed to `CSG.cylinder`.
2595
2546
  * @return {CSG} A CSG cone object.
2596
2547
  */
2597
- function Cone(diameter1, diameter2, height) {
2598
- var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
2548
+ function Cone(diameter1, diameter2, height, options = {}) {
2599
2549
  debug$1('parts.Cone', diameter1, diameter2, height, options);
2600
2550
  return CSG.cylinder(Object.assign({
2601
2551
  start: [0, 0, 0],
@@ -2656,14 +2606,12 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
2656
2606
  * @param {Number} width
2657
2607
  * @param {Number} height
2658
2608
  */
2659
- function Anchor() {
2660
- var width = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 10;
2661
- var height = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10;
2609
+ function Anchor(width = 10, height = 10) {
2662
2610
  var hole = Cylinder(width, height).Center().color('red');
2663
2611
  var post = Cylinder(height / 2, width * 0.66).rotateX(90).align(hole, 'xz').snap(hole, 'y', 'inside-').translate([0, 0, -height / 6]).color('purple');
2664
2612
  return Group({
2665
- post: post,
2666
- hole: hole
2613
+ post,
2614
+ hole
2667
2615
  });
2668
2616
  }
2669
2617
  function Board(width, height, corner_radius, thickness) {
@@ -2678,7 +2626,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
2678
2626
  });
2679
2627
  return board;
2680
2628
  }
2681
- var Hardware = {
2629
+ const Hardware = {
2682
2630
  Orientation: {
2683
2631
  up: {
2684
2632
  head: 'outside-',
@@ -2689,7 +2637,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
2689
2637
  clear: 'inside-'
2690
2638
  }
2691
2639
  },
2692
- Screw: function Screw(head, thread, headClearSpace, options) {
2640
+ Screw: function (head, thread, headClearSpace, options) {
2693
2641
  depreciated('Screw', false, 'Use the jscad-hardware screw methods instead');
2694
2642
  options = Object.assign(options, {
2695
2643
  orientation: 'up',
@@ -2714,7 +2662,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
2714
2662
  * @param {number} clearLength Length of the clearance section of the head.
2715
2663
  * @param {object} options Screw options include orientation and clerance scale.
2716
2664
  */
2717
- PanHeadScrew: function PanHeadScrew(headDiameter, headLength, diameter, length, clearLength, options) {
2665
+ PanHeadScrew: function (headDiameter, headLength, diameter, length, clearLength, options) {
2718
2666
  depreciated('PanHeadScrew', false, 'Use the jscad-hardware screw methods instead');
2719
2667
  var head = Cylinder(headDiameter, headLength);
2720
2668
  var thread = Cylinder(diameter, length);
@@ -2732,7 +2680,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
2732
2680
  * @param {number} clearLength Length of the clearance section of the head.
2733
2681
  * @param {object} options Screw options include orientation and clerance scale.
2734
2682
  */
2735
- HexHeadScrew: function HexHeadScrew(headDiameter, headLength, diameter, length, clearLength, options) {
2683
+ HexHeadScrew: function (headDiameter, headLength, diameter, length, clearLength, options) {
2736
2684
  depreciated('HexHeadScrew', false, 'Use the jscad-hardware screw methods instead');
2737
2685
  var head = Hexagon(headDiameter, headLength);
2738
2686
  var thread = Cylinder(diameter, length);
@@ -2750,7 +2698,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
2750
2698
  * @param {number} clearLength clearance length
2751
2699
  * @param {object} options options
2752
2700
  */
2753
- FlatHeadScrew: function FlatHeadScrew(headDiameter, headLength, diameter, length, clearLength, options) {
2701
+ FlatHeadScrew: function (headDiameter, headLength, diameter, length, clearLength, options) {
2754
2702
  depreciated('FlatHeadScrew', false, 'Use the jscad-hardware screw methods instead');
2755
2703
  var head = Cone(headDiameter, diameter, headLength);
2756
2704
  // var head = Cylinder(headDiameter, headLength);
@@ -2764,21 +2712,21 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
2764
2712
 
2765
2713
  var parts$1 = /*#__PURE__*/Object.freeze({
2766
2714
  __proto__: null,
2767
- 'default': parts,
2715
+ Anchor: Anchor,
2768
2716
  BBox: BBox$1,
2717
+ Board: Board,
2718
+ Cone: Cone,
2769
2719
  Cube: Cube,
2770
- RoundedCube: RoundedCube,
2771
2720
  Cylinder: Cylinder,
2772
- Cone: Cone,
2721
+ Hardware: Hardware,
2773
2722
  Hexagon: Hexagon,
2723
+ RoundedCube: RoundedCube,
2774
2724
  Triangle: Triangle,
2775
2725
  Tube: Tube,
2776
- Anchor: Anchor,
2777
- Board: Board,
2778
- Hardware: Hardware
2726
+ default: parts
2779
2727
  });
2780
2728
 
2781
- var debug = Debug('jscadUtils:boxes');
2729
+ const debug = Debug('jscadUtils:boxes');
2782
2730
 
2783
2731
  /** @typedef {import("./group").JsCadUtilsGroup} JsCadUtilsGroup */
2784
2732
 
@@ -2850,8 +2798,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
2850
2798
  * @param {Number} face Size of the join face.
2851
2799
  * @return {JsCadUtilsGroup} A group object with `positive`, `negative` parts.
2852
2800
  */
2853
- function Rabett(box, thickness, gap, height, face) {
2854
- var options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
2801
+ function Rabett(box, thickness, gap, height, face, options = {}) {
2855
2802
  debug('Rabett', 'thickness', thickness, 'gap', gap, 'height', height, 'face', face);
2856
2803
  gap = gap || 0.25;
2857
2804
  var inside = thickness - gap;
@@ -2860,16 +2807,18 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
2860
2807
  debug('inside', inside, 'outside', outside);
2861
2808
  var group = Group();
2862
2809
  // debug('Rabbet top height:', height, 'options:', options);
2863
- var _box$bisect$parts = box.bisect('z', height, options).parts,
2864
- top = _box$bisect$parts.positive,
2865
- lower2_3rd = _box$bisect$parts.negative;
2810
+ var {
2811
+ positive: top,
2812
+ negative: lower2_3rd
2813
+ } = box.bisect('z', height, options).parts;
2866
2814
 
2867
2815
  // debug('face', face, 'height', height);
2868
2816
  var lowerBisectHeight = Math.sign(height) < 0 ? face * Math.sign(height) : height - face;
2869
2817
  // debug('Rabbet bottom height:', lowerBisectHeight, 'options:', options);
2870
- var _lower2_3rd$bisect$pa = lower2_3rd.bisect('z', lowerBisectHeight, options).parts,
2871
- middle = _lower2_3rd$bisect$pa.positive,
2872
- bottom = _lower2_3rd$bisect$pa.negative;
2818
+ var {
2819
+ positive: middle,
2820
+ negative: bottom
2821
+ } = lower2_3rd.bisect('z', lowerBisectHeight, options).parts;
2873
2822
  var middleTop = middle.color('yellow').subtract(middle.color('darkred').enlarge([outside, outside, 0]));
2874
2823
  group.add(top
2875
2824
  // .color('blue')
@@ -2913,9 +2862,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
2913
2862
  * @return {JsCadUtilsGroup} An A hollow version of the original object..
2914
2863
  * @memberof module:Boxes
2915
2864
  */
2916
- var RabettTopBottom = function rabbetTMB(box, thickness) {
2917
- var gap = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0.25;
2918
- var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
2865
+ const RabettTopBottom = function rabbetTMB(box, thickness, gap = 0.25, options = {}) {
2919
2866
  options = Object.assign({
2920
2867
  removableTop: true,
2921
2868
  removableBottom: true,
@@ -2948,7 +2895,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
2948
2895
  }
2949
2896
  return group;
2950
2897
  };
2951
- var CutOut = function cutOut(o, h, box, plug, gap) {
2898
+ const CutOut = function cutOut(o, h, box, plug, gap) {
2952
2899
  gap = gap || 0.25;
2953
2900
  // console.log('cutOut', o.size(), h, b.size());
2954
2901
  // var r = getRadius(o);
@@ -2968,7 +2915,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
2968
2915
  insert: union([o, top]).intersect(box).subtract(o).enlarge([-gap, 0, 0]).union(clip.subtract(plug).enlarge(-gap, -gap, 0)).color('blue')
2969
2916
  });
2970
2917
  };
2971
- var Rectangle = function Rectangle(size, thickness, cb) {
2918
+ const Rectangle = function (size, thickness, cb) {
2972
2919
  thickness = thickness || 2;
2973
2920
  var s = div$1(xyz2array(size), 2);
2974
2921
  var r = add(s, thickness);
@@ -2999,7 +2946,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
2999
2946
  * @return {CSG} An A hollow version of the original object..
3000
2947
  * @memberof module:Boxes
3001
2948
  */
3002
- var Hollow = function Hollow(object, thickness, interiorcb, exteriorcb) {
2949
+ const Hollow = function (object, thickness, interiorcb, exteriorcb) {
3003
2950
  thickness = thickness || 2;
3004
2951
  var size = -thickness * 2;
3005
2952
  interiorcb = interiorcb || identity;
@@ -3015,7 +2962,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
3015
2962
  * @deprecated use parts.BBox
3016
2963
  * @memberof module:Boxes
3017
2964
  */
3018
- var BBox = function BBox(o) {
2965
+ const BBox = function (o) {
3019
2966
  depreciated('BBox', true, "Use 'parts.BBox' instead");
3020
2967
  var s = div$1(xyz2array(o.size()), 2);
3021
2968
  return CSG.cube({
@@ -3026,8 +2973,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
3026
2973
  function getRadius(o) {
3027
2974
  return div$1(xyz2array(o.size()), 2);
3028
2975
  }
3029
- function rabbetJoin(box, thickness) {
3030
- var gap = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0.25;
2976
+ function rabbetJoin(box, thickness, gap = 0.25) {
3031
2977
  var r = add(getRadius(box), -thickness / 2);
3032
2978
  r[2] = thickness / 2;
3033
2979
  var cutter = CSG.cube({
@@ -3046,25 +2992,30 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
3046
2992
 
3047
2993
  var Boxes = /*#__PURE__*/Object.freeze({
3048
2994
  __proto__: null,
2995
+ BBox: BBox,
2996
+ CutOut: CutOut,
2997
+ Hollow: Hollow,
3049
2998
  RabbetJoin: RabbetJoin,
3050
- topMiddleBottom: topMiddleBottom,
3051
2999
  Rabett: Rabett,
3052
3000
  RabettTopBottom: RabettTopBottom,
3053
- CutOut: CutOut,
3054
3001
  Rectangle: Rectangle,
3055
- Hollow: Hollow,
3056
- BBox: BBox
3002
+ topMiddleBottom: topMiddleBottom
3057
3003
  });
3058
3004
 
3059
- var compatV1 = _objectSpread2(_objectSpread2({}, util), {}, {
3005
+ /**
3006
+ * JsCad Utilities es6
3007
+ */
3008
+
3009
+ const compatV1 = {
3010
+ ...util,
3060
3011
  group: Group,
3061
3012
  init: init$1,
3062
3013
  triangle: triUtils,
3063
- array: array,
3014
+ array,
3064
3015
  parts: parts$1,
3065
- Boxes: Boxes,
3066
- Debug: Debug
3067
- });
3016
+ Boxes,
3017
+ Debug
3018
+ };
3068
3019
 
3069
3020
  exports.Boxes = Boxes;
3070
3021
  exports.Debug = Debug;
@@ -3076,8 +3027,6 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
3076
3027
  exports.triUtils = triUtils;
3077
3028
  exports.util = util;
3078
3029
 
3079
- Object.defineProperty(exports, '__esModule', { value: true });
3080
-
3081
3030
  return exports;
3082
3031
 
3083
3032
  })({}, jsCadCSG, scadApi);