@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 +430 -481
- package/dist/examples/bisect.jscad +201 -512
- package/dist/examples/boxes.jscad +201 -512
- package/dist/examples/chamfer.jscad +201 -512
- package/dist/examples/fillet.jscad +201 -512
- package/dist/examples/fit.jscad +201 -512
- package/dist/examples/groups.jscad +201 -512
- package/dist/examples/midlineTo.jscad +201 -512
- package/dist/examples/parts-hexagon.jscad +201 -512
- package/dist/examples/rabett-tb.jscad +201 -512
- package/dist/examples/rabett.jscad +201 -512
- package/dist/examples/rabett2.jscad +201 -512
- package/dist/examples/retraction-test.jscad +201 -512
- package/dist/examples/size.jscad +201 -512
- package/dist/examples/snap.jscad +201 -512
- package/dist/examples/text.jscad +201 -512
- package/dist/examples/wedge.jscad +201 -512
- package/dist/index.js +430 -481
- package/package.json +15 -43
- package/src/add-prototype.js +87 -7
- package/src/color.js +36 -46
- package/src/util.js +24 -22
package/dist/index.js
CHANGED
|
@@ -1,187 +1,6 @@
|
|
|
1
1
|
var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
5
|
-
|
|
6
|
-
var jsCadCSG__default = /*#__PURE__*/_interopDefaultLegacy(jsCadCSG);
|
|
7
|
-
var scadApi__default = /*#__PURE__*/_interopDefaultLegacy(scadApi);
|
|
8
|
-
|
|
9
|
-
var util = /*#__PURE__*/Object.freeze({
|
|
10
|
-
__proto__: null,
|
|
11
|
-
get NOZZEL_SIZE () { return NOZZEL_SIZE; },
|
|
12
|
-
get nearest () { return nearest; },
|
|
13
|
-
get identity () { return identity; },
|
|
14
|
-
get result () { return result; },
|
|
15
|
-
get defaults () { return defaults; },
|
|
16
|
-
get isEmpty () { return isEmpty; },
|
|
17
|
-
get isNegative () { return isNegative; },
|
|
18
|
-
get print () { return print; },
|
|
19
|
-
get jscadToString () { return jscadToString; },
|
|
20
|
-
get error () { return error; },
|
|
21
|
-
get depreciated () { return depreciated; },
|
|
22
|
-
get inch () { return inch; },
|
|
23
|
-
get cm () { return cm; },
|
|
24
|
-
get label () { return label; },
|
|
25
|
-
get text () { return text; },
|
|
26
|
-
get unitCube () { return unitCube; },
|
|
27
|
-
get unitAxis () { return unitAxis; },
|
|
28
|
-
get toArray () { return toArray; },
|
|
29
|
-
get ifArray () { return ifArray; },
|
|
30
|
-
get segment () { return segment; },
|
|
31
|
-
get zipObject () { return zipObject; },
|
|
32
|
-
get map () { return map; },
|
|
33
|
-
get mapValues () { return mapValues; },
|
|
34
|
-
get pick () { return pick; },
|
|
35
|
-
get mapPick () { return mapPick; },
|
|
36
|
-
get divA () { return divA; },
|
|
37
|
-
get divxyz () { return divxyz; },
|
|
38
|
-
get div () { return div; },
|
|
39
|
-
get mulxyz () { return mulxyz; },
|
|
40
|
-
get mul () { return mul; },
|
|
41
|
-
get xyz2array () { return xyz2array; },
|
|
42
|
-
get rotationAxes () { return rotationAxes; },
|
|
43
|
-
get size () { return size; },
|
|
44
|
-
get scale () { return scale; },
|
|
45
|
-
get center () { return center; },
|
|
46
|
-
get centerY () { return centerY; },
|
|
47
|
-
get centerX () { return centerX; },
|
|
48
|
-
get enlarge () { return enlarge; },
|
|
49
|
-
get fit () { return fit; },
|
|
50
|
-
get shift () { return shift; },
|
|
51
|
-
get zero () { return zero; },
|
|
52
|
-
get mirrored4 () { return mirrored4; },
|
|
53
|
-
get flushSide () { return flushSide; },
|
|
54
|
-
get calcFlush () { return calcFlush; },
|
|
55
|
-
get calcSnap () { return calcSnap; },
|
|
56
|
-
get snap () { return snap; },
|
|
57
|
-
get flush () { return flush; },
|
|
58
|
-
get axisApply () { return axisApply; },
|
|
59
|
-
get axis2array () { return axis2array; },
|
|
60
|
-
get centroid () { return centroid; },
|
|
61
|
-
get calcmidlineTo () { return calcmidlineTo; },
|
|
62
|
-
get midlineTo () { return midlineTo; },
|
|
63
|
-
get translator () { return translator; },
|
|
64
|
-
get calcCenterWith () { return calcCenterWith; },
|
|
65
|
-
get centerWith () { return centerWith; },
|
|
66
|
-
get getDelta () { return getDelta; },
|
|
67
|
-
get bisect () { return bisect; },
|
|
68
|
-
get slice () { return slice; },
|
|
69
|
-
get wedge () { return wedge; },
|
|
70
|
-
get stretch () { return stretch; },
|
|
71
|
-
get poly2solid () { return poly2solid; },
|
|
72
|
-
get slices2poly () { return slices2poly; },
|
|
73
|
-
get normalVector () { return normalVector; },
|
|
74
|
-
get sliceParams () { return sliceParams; },
|
|
75
|
-
get reShape () { return reShape; },
|
|
76
|
-
get chamfer () { return chamfer; },
|
|
77
|
-
get fillet () { return fillet; },
|
|
78
|
-
get calcRotate () { return calcRotate; },
|
|
79
|
-
get rotateAround () { return rotateAround; },
|
|
80
|
-
get clone () { return clone; },
|
|
81
|
-
get addConnector () { return addConnector; }
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
function _arrayLikeToArray(r, a) {
|
|
85
|
-
(null == a || a > r.length) && (a = r.length);
|
|
86
|
-
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
87
|
-
return n;
|
|
88
|
-
}
|
|
89
|
-
function _arrayWithHoles(r) {
|
|
90
|
-
if (Array.isArray(r)) return r;
|
|
91
|
-
}
|
|
92
|
-
function _defineProperty(e, r, t) {
|
|
93
|
-
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
94
|
-
value: t,
|
|
95
|
-
enumerable: !0,
|
|
96
|
-
configurable: !0,
|
|
97
|
-
writable: !0
|
|
98
|
-
}) : e[r] = t, e;
|
|
99
|
-
}
|
|
100
|
-
function _iterableToArrayLimit(r, l) {
|
|
101
|
-
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
102
|
-
if (null != t) {
|
|
103
|
-
var e,
|
|
104
|
-
n,
|
|
105
|
-
i,
|
|
106
|
-
u,
|
|
107
|
-
a = [],
|
|
108
|
-
f = !0,
|
|
109
|
-
o = !1;
|
|
110
|
-
try {
|
|
111
|
-
if (i = (t = t.call(r)).next, 0 === l) {
|
|
112
|
-
if (Object(t) !== t) return;
|
|
113
|
-
f = !1;
|
|
114
|
-
} else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
|
|
115
|
-
} catch (r) {
|
|
116
|
-
o = !0, n = r;
|
|
117
|
-
} finally {
|
|
118
|
-
try {
|
|
119
|
-
if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
|
|
120
|
-
} finally {
|
|
121
|
-
if (o) throw n;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
return a;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
function _nonIterableRest() {
|
|
128
|
-
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
129
|
-
}
|
|
130
|
-
function ownKeys(e, r) {
|
|
131
|
-
var t = Object.keys(e);
|
|
132
|
-
if (Object.getOwnPropertySymbols) {
|
|
133
|
-
var o = Object.getOwnPropertySymbols(e);
|
|
134
|
-
r && (o = o.filter(function (r) {
|
|
135
|
-
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
136
|
-
})), t.push.apply(t, o);
|
|
137
|
-
}
|
|
138
|
-
return t;
|
|
139
|
-
}
|
|
140
|
-
function _objectSpread2(e) {
|
|
141
|
-
for (var r = 1; r < arguments.length; r++) {
|
|
142
|
-
var t = null != arguments[r] ? arguments[r] : {};
|
|
143
|
-
r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
|
|
144
|
-
_defineProperty(e, r, t[r]);
|
|
145
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
|
|
146
|
-
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
return e;
|
|
150
|
-
}
|
|
151
|
-
function _slicedToArray(r, e) {
|
|
152
|
-
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
|
|
153
|
-
}
|
|
154
|
-
function _toPrimitive(t, r) {
|
|
155
|
-
if ("object" != typeof t || !t) return t;
|
|
156
|
-
var e = t[Symbol.toPrimitive];
|
|
157
|
-
if (void 0 !== e) {
|
|
158
|
-
var i = e.call(t, r || "default");
|
|
159
|
-
if ("object" != typeof i) return i;
|
|
160
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
161
|
-
}
|
|
162
|
-
return ("string" === r ? String : Number)(t);
|
|
163
|
-
}
|
|
164
|
-
function _toPropertyKey(t) {
|
|
165
|
-
var i = _toPrimitive(t, "string");
|
|
166
|
-
return "symbol" == typeof i ? i : i + "";
|
|
167
|
-
}
|
|
168
|
-
function _typeof(o) {
|
|
169
|
-
"@babel/helpers - typeof";
|
|
170
|
-
|
|
171
|
-
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
|
|
172
|
-
return typeof o;
|
|
173
|
-
} : function (o) {
|
|
174
|
-
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
175
|
-
}, _typeof(o);
|
|
176
|
-
}
|
|
177
|
-
function _unsupportedIterableToArray(r, a) {
|
|
178
|
-
if (r) {
|
|
179
|
-
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
180
|
-
var t = {}.toString.call(r).slice(8, -1);
|
|
181
|
-
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;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
4
|
/** @module triangle */
|
|
186
5
|
|
|
187
6
|
/**
|
|
@@ -189,7 +8,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
189
8
|
* @param {Number} deg value in degrees
|
|
190
9
|
* @return {Number} value in radians
|
|
191
10
|
*/
|
|
192
|
-
|
|
11
|
+
const toRadians = function toRadians(deg) {
|
|
193
12
|
return deg / 180 * Math.PI;
|
|
194
13
|
};
|
|
195
14
|
|
|
@@ -198,7 +17,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
198
17
|
* @param {Number} rad value in radians
|
|
199
18
|
* @return {Number} value in degrees
|
|
200
19
|
*/
|
|
201
|
-
|
|
20
|
+
const toDegrees = function toDegrees(rad) {
|
|
202
21
|
return rad * (180 / Math.PI);
|
|
203
22
|
};
|
|
204
23
|
|
|
@@ -210,7 +29,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
210
29
|
* @param {Number} p2.y Point 2 y coordinate
|
|
211
30
|
* @return {Object} A triangle object {A,B,C,a,b,c}
|
|
212
31
|
*/
|
|
213
|
-
|
|
32
|
+
const solve = function (p1, p2) {
|
|
214
33
|
var r = {
|
|
215
34
|
c: 90,
|
|
216
35
|
A: Math.abs(p2.x - p1.x),
|
|
@@ -252,7 +71,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
252
71
|
* @param {Number} r.c Length of side `c`
|
|
253
72
|
* @return {Object} A solved triangle object {A,B,C,a,b,c}
|
|
254
73
|
*/
|
|
255
|
-
|
|
74
|
+
const solve90SA = function (r) {
|
|
256
75
|
r = Object.assign(r, {
|
|
257
76
|
C: 90
|
|
258
77
|
});
|
|
@@ -273,7 +92,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
273
92
|
r.b = r.b || r.a / Math.tan(arad);
|
|
274
93
|
return r;
|
|
275
94
|
};
|
|
276
|
-
|
|
95
|
+
const solve90ac = function (r) {
|
|
277
96
|
r = Object.assign(r, {
|
|
278
97
|
C: 90
|
|
279
98
|
});
|
|
@@ -330,12 +149,12 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
330
149
|
|
|
331
150
|
var triUtils = /*#__PURE__*/Object.freeze({
|
|
332
151
|
__proto__: null,
|
|
333
|
-
toRadians: toRadians,
|
|
334
|
-
toDegrees: toDegrees,
|
|
335
152
|
solve: solve,
|
|
336
153
|
solve90SA: solve90SA,
|
|
337
154
|
solve90ac: solve90ac,
|
|
338
|
-
solveab: solveab
|
|
155
|
+
solveab: solveab,
|
|
156
|
+
toDegrees: toDegrees,
|
|
157
|
+
toRadians: toRadians
|
|
339
158
|
});
|
|
340
159
|
|
|
341
160
|
/**
|
|
@@ -350,7 +169,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
350
169
|
* @param {Number} f
|
|
351
170
|
* @memberof! array
|
|
352
171
|
*/
|
|
353
|
-
|
|
172
|
+
const div$1 = function (a, f) {
|
|
354
173
|
return a.map(function (e) {
|
|
355
174
|
return e / f;
|
|
356
175
|
});
|
|
@@ -363,7 +182,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
363
182
|
* @param {Number} f A value to add to each element of the original array.
|
|
364
183
|
* @return {Array} A new array with the values added together.
|
|
365
184
|
*/
|
|
366
|
-
|
|
185
|
+
const addValue = function (a, f) {
|
|
367
186
|
return a.map(function (e) {
|
|
368
187
|
return e + f;
|
|
369
188
|
});
|
|
@@ -377,7 +196,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
377
196
|
* @param {Array} f Another array of numbers, if
|
|
378
197
|
* @return {Array} A new array with the two values added together.
|
|
379
198
|
*/
|
|
380
|
-
|
|
199
|
+
const addArray = function (a, f) {
|
|
381
200
|
return a.map(function (e, i) {
|
|
382
201
|
return e + f[i];
|
|
383
202
|
});
|
|
@@ -389,7 +208,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
389
208
|
* @param {Array} a An array of numbers .
|
|
390
209
|
* @return {Array} A new array with the two values added together.
|
|
391
210
|
*/
|
|
392
|
-
|
|
211
|
+
const add = function (a) {
|
|
393
212
|
return Array.prototype.slice.call(arguments, 1).reduce(function (result, arg) {
|
|
394
213
|
if (Array.isArray(arg)) {
|
|
395
214
|
result = addArray(result, arg);
|
|
@@ -406,10 +225,10 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
406
225
|
* @function fromxyz
|
|
407
226
|
* @param {Object|Array} object
|
|
408
227
|
*/
|
|
409
|
-
|
|
228
|
+
const fromxyz = function (object) {
|
|
410
229
|
return Array.isArray(object) ? object : [object.x, object.y, object.z];
|
|
411
230
|
};
|
|
412
|
-
|
|
231
|
+
const toxyz = function (a) {
|
|
413
232
|
return {
|
|
414
233
|
x: a[0],
|
|
415
234
|
y: a[1],
|
|
@@ -423,7 +242,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
423
242
|
* @param {Array} a An array of numbers.
|
|
424
243
|
* @return {Number} The value of the first element of the array or undefined.
|
|
425
244
|
*/
|
|
426
|
-
|
|
245
|
+
const first = function (a) {
|
|
427
246
|
return a ? a[0] : undefined;
|
|
428
247
|
};
|
|
429
248
|
|
|
@@ -432,7 +251,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
432
251
|
* @param {Array} a An array of numbers.
|
|
433
252
|
* @return {Number} The value of the last element of the array or undefined.
|
|
434
253
|
*/
|
|
435
|
-
|
|
254
|
+
const last = function (a) {
|
|
436
255
|
return a && a.length > 0 ? a[a.length - 1] : undefined;
|
|
437
256
|
};
|
|
438
257
|
|
|
@@ -442,7 +261,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
442
261
|
* @param {Array} a An array of numbers.
|
|
443
262
|
* @return {Number} The minimum value in an array of numbers.
|
|
444
263
|
*/
|
|
445
|
-
|
|
264
|
+
const min = function (a) {
|
|
446
265
|
return a.reduce(function (result, value) {
|
|
447
266
|
return value < result ? value : result;
|
|
448
267
|
}, Number.MAX_VALUE);
|
|
@@ -455,7 +274,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
455
274
|
* @param {Number} b The ending value.
|
|
456
275
|
* @return {Array} An array of values from `a` to `b`.
|
|
457
276
|
*/
|
|
458
|
-
|
|
277
|
+
const range = function (a, b) {
|
|
459
278
|
var result = [];
|
|
460
279
|
for (var i = a; i < b; i++) {
|
|
461
280
|
result.push(i);
|
|
@@ -465,22 +284,22 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
465
284
|
|
|
466
285
|
var array = /*#__PURE__*/Object.freeze({
|
|
467
286
|
__proto__: null,
|
|
468
|
-
div: div$1,
|
|
469
|
-
addValue: addValue,
|
|
470
|
-
addArray: addArray,
|
|
471
287
|
add: add,
|
|
472
|
-
|
|
473
|
-
|
|
288
|
+
addArray: addArray,
|
|
289
|
+
addValue: addValue,
|
|
290
|
+
div: div$1,
|
|
474
291
|
first: first,
|
|
292
|
+
fromxyz: fromxyz,
|
|
475
293
|
last: last,
|
|
476
294
|
min: min,
|
|
477
|
-
range: range
|
|
295
|
+
range: range,
|
|
296
|
+
toxyz: toxyz
|
|
478
297
|
});
|
|
479
298
|
|
|
480
299
|
/* globals jscadUtilsDebug */
|
|
481
300
|
|
|
482
|
-
|
|
483
|
-
|
|
301
|
+
const debugColors = ['#e41a1c', '#377eb8', '#4daf4a', '#984ea3', '#ff7f00', '#ffff33', '#a65628', '#f781bf', '#999999'];
|
|
302
|
+
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'];
|
|
484
303
|
var debugCount = 0;
|
|
485
304
|
|
|
486
305
|
/**
|
|
@@ -501,7 +320,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
501
320
|
* @param {String} name The name of the debug function.
|
|
502
321
|
* @return {Function} A debug function if enabled otherwise an empty function.
|
|
503
322
|
*/
|
|
504
|
-
|
|
323
|
+
const Debug = function (name) {
|
|
505
324
|
var checks = Object.assign({
|
|
506
325
|
enabled: [],
|
|
507
326
|
disabled: [],
|
|
@@ -509,31 +328,25 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
509
328
|
browser: true
|
|
510
329
|
}
|
|
511
330
|
}, jscadUtilsDebug || {});
|
|
512
|
-
var style = checks.options.browser ?
|
|
331
|
+
var style = checks.options.browser ? `color:${debugColors[debugCount++ % debugColors.length]}` : `${termColors[debugCount++ % termColors.length]}`;
|
|
513
332
|
var enabled = checks.enabled.some(function checkEnabled(check) {
|
|
514
333
|
return check.test(name);
|
|
515
334
|
}) && !checks.disabled.some(function checkEnabled(check) {
|
|
516
335
|
return check.test(name);
|
|
517
336
|
});
|
|
518
|
-
var logger = enabled ? checks.options.browser ?
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
(_console = console).log.apply(_console, ['%c%s', style, name].concat(msg));
|
|
524
|
-
} : function () {
|
|
525
|
-
var _console2;
|
|
526
|
-
for (var _len2 = arguments.length, msg = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
527
|
-
msg[_key2] = arguments[_key2];
|
|
528
|
-
}
|
|
529
|
-
(_console2 = console).log.apply(_console2, ["".concat(name)].concat(msg));
|
|
530
|
-
} : function () {
|
|
531
|
-
return undefined;
|
|
532
|
-
};
|
|
337
|
+
var logger = enabled ? checks.options.browser ? (...msg) => {
|
|
338
|
+
console.log('%c%s', style, name, ...msg);
|
|
339
|
+
} : (...msg) => {
|
|
340
|
+
console.log(`${name}`, ...msg);
|
|
341
|
+
} : () => undefined;
|
|
533
342
|
logger.enabled = enabled;
|
|
534
343
|
return logger;
|
|
535
344
|
};
|
|
536
345
|
|
|
346
|
+
/** @typedef { import('@jscad/csg').CSG } CSG */
|
|
347
|
+
|
|
348
|
+
/** @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 */
|
|
349
|
+
|
|
537
350
|
/**
|
|
538
351
|
* Color utilities for jscad. Makes setting colors easier using css color names. Using `.init()` adds a `.color()` function to the CSG object.
|
|
539
352
|
* > You must use `Colors.init(CSG)` in the `main()` function. The `CSG` class is not available before
|
|
@@ -546,9 +359,9 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
546
359
|
* // draws a purple cube
|
|
547
360
|
* return CSG.cube({radius: [10, 10, 10]}).color('purple');
|
|
548
361
|
*}
|
|
549
|
-
* @type {
|
|
362
|
+
* @type {Record<ColorName, string>}
|
|
550
363
|
*/
|
|
551
|
-
|
|
364
|
+
const nameArray = {
|
|
552
365
|
aliceblue: '#f0f8ff',
|
|
553
366
|
antiquewhite: '#faebd7',
|
|
554
367
|
aqua: '#00ffff',
|
|
@@ -697,87 +510,158 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
697
510
|
yellow: '#ffff00',
|
|
698
511
|
yellowgreen: '#9acd32'
|
|
699
512
|
};
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* Converts a css color name to a hex string.
|
|
516
|
+
* @param {ColorName} n A css color name
|
|
517
|
+
* @returns {string}
|
|
518
|
+
*/
|
|
700
519
|
function name2hex(n) {
|
|
701
|
-
n = n.toLowerCase();
|
|
520
|
+
n = /** @type {ColorName} */n.toLowerCase();
|
|
702
521
|
if (!nameArray[n]) return 'Invalid Color Name';
|
|
703
522
|
return nameArray[n];
|
|
704
523
|
}
|
|
524
|
+
|
|
525
|
+
/**
|
|
526
|
+
* Converts a hex color string to an rgb array.
|
|
527
|
+
* @param {string} h
|
|
528
|
+
* @returns {number[]}
|
|
529
|
+
*/
|
|
705
530
|
function hex2rgb(h) {
|
|
706
531
|
h = h.replace(/^\#/, '');
|
|
707
532
|
if (h.length === 6) {
|
|
708
533
|
return [parseInt(h.substr(0, 2), 16), parseInt(h.substr(2, 2), 16), parseInt(h.substr(4, 2), 16)];
|
|
534
|
+
} else {
|
|
535
|
+
return [0, 0, 0];
|
|
709
536
|
}
|
|
710
537
|
}
|
|
711
|
-
|
|
538
|
+
|
|
539
|
+
/**
|
|
540
|
+
* @type {Record<ColorName, number[]>}
|
|
541
|
+
*/
|
|
542
|
+
const _name2rgb = {};
|
|
543
|
+
|
|
544
|
+
/**
|
|
545
|
+
* Converts a css color name to an rgb array.
|
|
546
|
+
* @param {ColorName} n A css color name
|
|
547
|
+
* @returns {number[]}
|
|
548
|
+
*/
|
|
712
549
|
function name2rgb(n) {
|
|
713
550
|
if (!_name2rgb[n]) _name2rgb[n] = hex2rgb(name2hex(n));
|
|
714
551
|
return _name2rgb[n];
|
|
715
552
|
}
|
|
553
|
+
|
|
554
|
+
/**
|
|
555
|
+
*
|
|
556
|
+
* @param {CSG} o
|
|
557
|
+
* @param {number|string} r The red channel value (0.0 - 1.0) or a css color name
|
|
558
|
+
* @param {number} [g] The green channel value (0.0 - 1.0) or the alpha channel when used with a css color string
|
|
559
|
+
* @param {number} [b] The blue channel value (0.0 - 1.0)
|
|
560
|
+
* @param {number} [a] The alpha channel value (0.0 - 1.0)
|
|
561
|
+
* @returns {CSG} Returns a `CSG` object set to the desired color.
|
|
562
|
+
*/
|
|
716
563
|
function color(o, r, g, b, a) {
|
|
717
564
|
if (typeof r !== 'string') return o.setColor(r, g, b, a);
|
|
718
565
|
if (r === '') return o; // shortcut for no color
|
|
719
|
-
var c = name2rgb(r).map(function (x) {
|
|
566
|
+
var c = name2rgb(/** @type {ColorName} */r).map(function (x) {
|
|
720
567
|
return x / 255;
|
|
721
568
|
});
|
|
722
569
|
c[3] = g || 1.0;
|
|
723
570
|
return o.setColor(c);
|
|
724
571
|
}
|
|
725
572
|
|
|
726
|
-
/**
|
|
727
|
-
*
|
|
728
|
-
* @
|
|
729
|
-
* @
|
|
730
|
-
* @
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
573
|
+
/** @typedef {object} ExtendedCSG
|
|
574
|
+
* @property {object} prototype
|
|
575
|
+
* @property {function} prototype.color
|
|
576
|
+
* @property {function} prototype.flush
|
|
577
|
+
* @property {function} prototype.snap
|
|
578
|
+
* @property {function} prototype.calcSnap
|
|
579
|
+
* @property {function} prototype.midlineTo
|
|
580
|
+
* @property {function} prototype.calcmidlineTo
|
|
581
|
+
* @property {function} prototype.centerWith
|
|
582
|
+
* @property {function} prototype.calcCenter
|
|
583
|
+
* @property {function} prototype.align
|
|
584
|
+
* @property {function} prototype.calcAlign
|
|
585
|
+
* @property {function} prototype.enlarge
|
|
586
|
+
* @property {function} prototype.fit
|
|
587
|
+
* @property {function} prototype.size
|
|
588
|
+
* @property {function} prototype.centroid
|
|
589
|
+
* @property {function} prototype.Zero
|
|
590
|
+
* @property {function} prototype.Center
|
|
591
|
+
* @property {function} prototype.fillet
|
|
592
|
+
* @property {function} prototype.chamfer
|
|
593
|
+
* @property {function} prototype.bisect
|
|
594
|
+
* @property {function} prototype.slice
|
|
595
|
+
* @property {function} prototype.wedge
|
|
596
|
+
* @property {function} prototype.stretch
|
|
597
|
+
* @property {function} prototype.unionIf
|
|
598
|
+
* @property {function} prototype.subtractIf
|
|
599
|
+
* @property {function} prototype.translate
|
|
600
|
+
* @property {function} prototype.addConnector
|
|
601
|
+
* @property {function} prototype.connect
|
|
602
|
+
* @property {function} prototype.connectTo
|
|
603
|
+
* @property {object} Vector2D
|
|
604
|
+
* @property {function} Vector2D.prototype.map
|
|
605
|
+
* @property {boolean} prototype._jscadutilsinit
|
|
606
|
+
* @property {function} result
|
|
607
|
+
* @property {function} array.addArray
|
|
608
|
+
* @property {function} unitCube
|
|
609
|
+
* @property {function} depreciated
|
|
610
|
+
* @property {function} error
|
|
611
|
+
* @property {function} size
|
|
612
|
+
* @property {function} centroid
|
|
613
|
+
* @property {function} zero
|
|
614
|
+
* @property {function} calcCenterWith
|
|
615
|
+
* @property {function} fillet
|
|
616
|
+
* @property {function} chamfer
|
|
617
|
+
* @property {function} bisect
|
|
618
|
+
* @property {function} slice
|
|
619
|
+
* @property {function} wedge
|
|
620
|
+
* @property {function} stretch
|
|
621
|
+
* @property {function} addConnector
|
|
622
|
+
* @property {function} echo
|
|
623
|
+
* @property {function} log
|
|
624
|
+
* @property {function} warn
|
|
625
|
+
* @property {function} info
|
|
626
|
+
* @property {function} debug
|
|
627
|
+
* @property {function} table
|
|
628
|
+
* @property {function} dir
|
|
629
|
+
* @property {function} dirxml
|
|
630
|
+
* @property {function} trace
|
|
631
|
+
* @property {function} group
|
|
632
|
+
* @property {function} clear
|
|
633
|
+
* @property {function} count
|
|
634
|
+
* @property {function} countReset
|
|
635
|
+
* @property {function} time
|
|
636
|
+
* @property {function} timeLog
|
|
637
|
+
* @property {function} timeEnd
|
|
638
|
+
* @property {function} assert
|
|
639
|
+
* @property {function} profile
|
|
640
|
+
* @property {function} profileEnd
|
|
641
|
+
* @property {function} timeStamp
|
|
642
|
+
* @property {function} stackTrace
|
|
643
|
+
* @property {function} getConnector
|
|
644
|
+
*/
|
|
645
|
+
|
|
768
646
|
|
|
769
647
|
/**
|
|
770
648
|
* Initialize `jscad-utils` and add utilities to the `proto` object.
|
|
771
|
-
* @param {
|
|
772
|
-
* @augments proto
|
|
649
|
+
* @param {CSG} proto The global `proto` object
|
|
773
650
|
*/
|
|
774
651
|
function init(proto) {
|
|
775
652
|
/**
|
|
776
|
-
* Short
|
|
653
|
+
* Short circuit out if the prototypes have already been added.
|
|
777
654
|
*/
|
|
778
655
|
if (proto.prototype._jscadutilsinit) return;
|
|
779
656
|
|
|
780
|
-
|
|
657
|
+
/**
|
|
658
|
+
*
|
|
659
|
+
* @param {ColorName | number} r The red channel value (0.0 - 1.0) or a css color name
|
|
660
|
+
* @param {number} [g] The green channel value (0.0 - 1.0) or the alpha channel when used with a css color string
|
|
661
|
+
* @param {number} [b] The blue channel value (0.0 - 1.0)
|
|
662
|
+
* @param {number} [a] The alpha channel value (0.0 - 1.0)
|
|
663
|
+
* @returns {CSG} The colored object
|
|
664
|
+
*/
|
|
781
665
|
proto.prototype.color = function (r, g, b, a) {
|
|
782
666
|
if (!r) return this; // shortcut empty color values to do nothing.
|
|
783
667
|
return color(this, r, g, b, a);
|
|
@@ -803,14 +687,12 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
803
687
|
};
|
|
804
688
|
if (proto.center) echo('proto already has .center');
|
|
805
689
|
proto.prototype.center = function center(axis) {
|
|
806
|
-
// console.log('center', axis, this.getBounds());
|
|
807
690
|
return centerWith(this, axis || 'xyz', unitCube());
|
|
808
691
|
};
|
|
809
692
|
proto.prototype.calcCenter = function centerWith(axis) {
|
|
810
693
|
return calcCenterWith(this, axis || 'xyz', unitCube(), 0);
|
|
811
694
|
};
|
|
812
695
|
proto.prototype.align = function align(to, axis) {
|
|
813
|
-
// console.log('align', to.getBounds(), axis);
|
|
814
696
|
return centerWith(this, axis, to);
|
|
815
697
|
};
|
|
816
698
|
proto.prototype.calcAlign = function calcAlign(to, axis, delta) {
|
|
@@ -844,23 +726,14 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
844
726
|
proto.prototype.chamfer = function chamfer$1(radius, orientation, options) {
|
|
845
727
|
return chamfer(this, radius, orientation, options);
|
|
846
728
|
};
|
|
847
|
-
proto.prototype.bisect = function bisect$1() {
|
|
848
|
-
|
|
849
|
-
args[_key] = arguments[_key];
|
|
850
|
-
}
|
|
851
|
-
return bisect.apply(util, [this].concat(args));
|
|
729
|
+
proto.prototype.bisect = function bisect$1(...args) {
|
|
730
|
+
return bisect(this, ...args);
|
|
852
731
|
};
|
|
853
|
-
proto.prototype.slice = function slice$1() {
|
|
854
|
-
|
|
855
|
-
args[_key2] = arguments[_key2];
|
|
856
|
-
}
|
|
857
|
-
return slice.apply(util, [this].concat(args));
|
|
732
|
+
proto.prototype.slice = function slice$1(...args) {
|
|
733
|
+
return slice(this, ...args);
|
|
858
734
|
};
|
|
859
|
-
proto.prototype.wedge = function wedge$1() {
|
|
860
|
-
|
|
861
|
-
args[_key3] = arguments[_key3];
|
|
862
|
-
}
|
|
863
|
-
return wedge.apply(util, [this].concat(args));
|
|
735
|
+
proto.prototype.wedge = function wedge$1(...args) {
|
|
736
|
+
return wedge(this, ...args);
|
|
864
737
|
};
|
|
865
738
|
proto.prototype.stretch = function stretch$1(axis, distance, offset) {
|
|
866
739
|
return stretch(this, axis, distance, offset);
|
|
@@ -877,7 +750,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
877
750
|
* This modifies the normal `proto.translate` method to accept
|
|
878
751
|
* multiple translations, adding the translations together.
|
|
879
752
|
* The original translate is available on `proto._translate` and
|
|
880
|
-
* a short
|
|
753
|
+
* a short circuit is applied when only one parameter is given.
|
|
881
754
|
* @return {proto} The resulting object.
|
|
882
755
|
*/
|
|
883
756
|
proto.prototype.translate = function translate() {
|
|
@@ -886,7 +759,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
886
759
|
} else {
|
|
887
760
|
var t = Array.prototype.slice.call(arguments, 0).reduce(function (result, arg) {
|
|
888
761
|
// console.log('arg', arg);
|
|
889
|
-
result = undefined(result, arg);
|
|
762
|
+
result = undefined.addArray(result, arg);
|
|
890
763
|
return result;
|
|
891
764
|
}, [0, 0, 0]);
|
|
892
765
|
|
|
@@ -897,10 +770,8 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
897
770
|
proto.prototype.addConnector = function addConnector$1(name, point, axis, normal) {
|
|
898
771
|
return addConnector(this, name, point, axis, normal);
|
|
899
772
|
};
|
|
900
|
-
proto.prototype.connect = function connectTo(myConnectorName, otherConnector) {
|
|
901
|
-
var
|
|
902
|
-
var normalrotation = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
903
|
-
var myConnector = myConnectorName.split('.').reduce(function (a, v) {
|
|
773
|
+
proto.prototype.connect = function connectTo(myConnectorName, otherConnector, mirror = false, normalrotation = 0) {
|
|
774
|
+
var myConnector = myConnectorName.split('.').reduce((a, v) => {
|
|
904
775
|
return a[v];
|
|
905
776
|
}, this.properties);
|
|
906
777
|
|
|
@@ -908,7 +779,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
908
779
|
* Check for missing property.
|
|
909
780
|
*/
|
|
910
781
|
if (!myConnector) {
|
|
911
|
-
error(
|
|
782
|
+
error(`The connector '${myConnectorName}' does not exist on the object [${Object.keys(this.properties).join(',')}]`, 'Missing connector property');
|
|
912
783
|
}
|
|
913
784
|
return this.connectTo(myConnector, otherConnector, mirror, normalrotation);
|
|
914
785
|
};
|
|
@@ -919,19 +790,26 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
919
790
|
|
|
920
791
|
var init$1 = /*#__PURE__*/Object.freeze({
|
|
921
792
|
__proto__: null,
|
|
922
|
-
|
|
793
|
+
default: init
|
|
923
794
|
});
|
|
924
795
|
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
796
|
+
const {
|
|
797
|
+
CSG,
|
|
798
|
+
CAG
|
|
799
|
+
} = jsCadCSG;
|
|
800
|
+
const {
|
|
801
|
+
rectangular_extrude
|
|
802
|
+
} = scadApi.extrusions;
|
|
803
|
+
const {
|
|
804
|
+
vector_text,
|
|
805
|
+
vector_char
|
|
806
|
+
} = scadApi.text;
|
|
807
|
+
const {
|
|
808
|
+
union
|
|
809
|
+
} = scadApi.booleanOps;
|
|
932
810
|
init(CSG);
|
|
933
811
|
|
|
934
|
-
|
|
812
|
+
const debug$3 = Debug('jscadUtils:group');
|
|
935
813
|
|
|
936
814
|
/**
|
|
937
815
|
* @function JsCadUtilsGroup
|
|
@@ -940,10 +818,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
940
818
|
* @param {CSG[]} holes An array of CSG objects that will be subtracted after combination.
|
|
941
819
|
* @namespace JsCadUtilsGroup
|
|
942
820
|
*/
|
|
943
|
-
function JsCadUtilsGroup() {
|
|
944
|
-
var names = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
945
|
-
var parts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
946
|
-
var holes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
821
|
+
function JsCadUtilsGroup(names = [], parts = {}, holes = []) {
|
|
947
822
|
this.name = '';
|
|
948
823
|
this.names = names;
|
|
949
824
|
this.parts = parts;
|
|
@@ -991,11 +866,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
991
866
|
* @param {Function} map A function that is run before unioning the parts together.
|
|
992
867
|
* @return {CSG} A single `CSG` object of the unioned parts.
|
|
993
868
|
*/
|
|
994
|
-
JsCadUtilsGroup.prototype.combine = function (pieces) {
|
|
995
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
996
|
-
var map = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function (x) {
|
|
997
|
-
return x;
|
|
998
|
-
};
|
|
869
|
+
JsCadUtilsGroup.prototype.combine = function (pieces, options = {}, map = x => x) {
|
|
999
870
|
try {
|
|
1000
871
|
var self = this;
|
|
1001
872
|
options = Object.assign({
|
|
@@ -1003,7 +874,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1003
874
|
}, options);
|
|
1004
875
|
pieces = pieces ? pieces.split(',') : self.names;
|
|
1005
876
|
if (pieces.length === 0) {
|
|
1006
|
-
throw new Error(
|
|
877
|
+
throw new Error(`no pieces found in ${self.name} pieces: ${pieces} parts: ${Object.keys(self.parts)} names: ${self.names}`);
|
|
1007
878
|
}
|
|
1008
879
|
debug$3('combine', self.names, self.parts);
|
|
1009
880
|
var g = union(mapPick(self.parts, pieces, function (value, key, index, object) {
|
|
@@ -1013,7 +884,12 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1013
884
|
return g.subtractIf(self.holes && Array.isArray(self.holes) ? union(self.holes) : self.holes, self.holes && !options.noholes);
|
|
1014
885
|
} catch (err) {
|
|
1015
886
|
debug$3('combine error', this, pieces, options, err);
|
|
1016
|
-
throw error(
|
|
887
|
+
throw error(`group::combine error "${err.message || err.toString()}"
|
|
888
|
+
this: ${this}
|
|
889
|
+
pieces: "${pieces}"
|
|
890
|
+
options: ${JSON.stringify(options, null, 2)}
|
|
891
|
+
stack: ${err.stack}
|
|
892
|
+
`, 'JSCAD_UTILS_GROUP_ERROR');
|
|
1017
893
|
}
|
|
1018
894
|
};
|
|
1019
895
|
|
|
@@ -1026,9 +902,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1026
902
|
*/
|
|
1027
903
|
JsCadUtilsGroup.prototype.map = function (cb) {
|
|
1028
904
|
var self = this;
|
|
1029
|
-
self.parts = Object.keys(self.parts).filter(function (
|
|
1030
|
-
return k !== 'holes';
|
|
1031
|
-
}).reduce(function (result, key) {
|
|
905
|
+
self.parts = Object.keys(self.parts).filter(k => k !== 'holes').reduce(function (result, key) {
|
|
1032
906
|
result[key] = cb(self.parts[key], key);
|
|
1033
907
|
return result;
|
|
1034
908
|
}, {});
|
|
@@ -1052,7 +926,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1052
926
|
* @return {JsCadUtilsGroup} The new group.
|
|
1053
927
|
*/
|
|
1054
928
|
JsCadUtilsGroup.prototype.clone = function (name, map) {
|
|
1055
|
-
debug$3('clone', name,
|
|
929
|
+
debug$3('clone', name, typeof name, map);
|
|
1056
930
|
var self = this;
|
|
1057
931
|
/**
|
|
1058
932
|
* For backwards compatibility
|
|
@@ -1139,7 +1013,15 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1139
1013
|
return self;
|
|
1140
1014
|
} catch (err) {
|
|
1141
1015
|
debug$3('snap error', this, part, to, axis, delta, err);
|
|
1142
|
-
throw error(
|
|
1016
|
+
throw error(`group::snap error "${err.message || err.toString()}"
|
|
1017
|
+
this: ${this}
|
|
1018
|
+
part: "${part}"
|
|
1019
|
+
to: ${to}
|
|
1020
|
+
axis: "${axis}"
|
|
1021
|
+
orientation: "${orientation}"
|
|
1022
|
+
delta: "${delta}"
|
|
1023
|
+
stack: ${err.stack}
|
|
1024
|
+
`, 'JSCAD_UTILS_GROUP_ERROR');
|
|
1143
1025
|
}
|
|
1144
1026
|
};
|
|
1145
1027
|
|
|
@@ -1171,7 +1053,14 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1171
1053
|
return self;
|
|
1172
1054
|
} catch (err) {
|
|
1173
1055
|
debug$3('align error', this, part, to, axis, delta, err);
|
|
1174
|
-
throw error(
|
|
1056
|
+
throw error(`group::align error "${err.message || err.toString()}"
|
|
1057
|
+
this: ${this}
|
|
1058
|
+
part: "${part}"
|
|
1059
|
+
to: ${to}
|
|
1060
|
+
axis: "${axis}"
|
|
1061
|
+
delta: "${delta}"
|
|
1062
|
+
stack: ${err.stack}
|
|
1063
|
+
`, 'JSCAD_UTILS_GROUP_ERROR');
|
|
1175
1064
|
}
|
|
1176
1065
|
};
|
|
1177
1066
|
JsCadUtilsGroup.prototype.center = function center(part) {
|
|
@@ -1183,23 +1072,21 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1183
1072
|
var bounds = self.parts[part].getBounds();
|
|
1184
1073
|
return self.translate([0, 0, -bounds[0].z]);
|
|
1185
1074
|
};
|
|
1186
|
-
JsCadUtilsGroup.prototype.connectTo = function connectTo(partName, connectorName, to, toConnectorName) {
|
|
1187
|
-
var mirror = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
|
|
1188
|
-
var normalrotation = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 0;
|
|
1075
|
+
JsCadUtilsGroup.prototype.connectTo = function connectTo(partName, connectorName, to, toConnectorName, mirror = true, normalrotation = 0) {
|
|
1189
1076
|
debug$3('connectTo', {
|
|
1190
|
-
partName
|
|
1191
|
-
connectorName
|
|
1192
|
-
to
|
|
1193
|
-
toConnectorName
|
|
1194
|
-
mirror
|
|
1195
|
-
normalrotation
|
|
1077
|
+
partName,
|
|
1078
|
+
connectorName,
|
|
1079
|
+
to,
|
|
1080
|
+
toConnectorName,
|
|
1081
|
+
mirror,
|
|
1082
|
+
normalrotation
|
|
1196
1083
|
});
|
|
1197
1084
|
var self = this;
|
|
1198
|
-
var myConnector = connectorName.split('.').reduce(
|
|
1085
|
+
var myConnector = connectorName.split('.').reduce((a, v) => {
|
|
1199
1086
|
return a[v];
|
|
1200
1087
|
}, self.parts[partName].properties);
|
|
1201
1088
|
debug$3('toConnector', to instanceof CSG.Connector);
|
|
1202
|
-
var toConnector = toConnectorName.split('.').reduce(
|
|
1089
|
+
var toConnector = toConnectorName.split('.').reduce((a, v) => {
|
|
1203
1090
|
return a[v];
|
|
1204
1091
|
}, to.properties);
|
|
1205
1092
|
var matrix = myConnector.getTransformationTo(toConnector, mirror, normalrotation);
|
|
@@ -1287,16 +1174,18 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1287
1174
|
* @return {Array} An array of `CSG` objects
|
|
1288
1175
|
*/
|
|
1289
1176
|
JsCadUtilsGroup.prototype.array = function (parts, map) {
|
|
1290
|
-
var _this = this;
|
|
1291
1177
|
var self = this;
|
|
1292
1178
|
// try {
|
|
1293
1179
|
var p = parts && parts.length > 0 && parts.split(',') || self.names;
|
|
1294
1180
|
if (!map) map = identity;
|
|
1295
1181
|
var a = [];
|
|
1296
|
-
p.forEach(
|
|
1182
|
+
p.forEach(name => {
|
|
1297
1183
|
if (!self.parts[name]) {
|
|
1298
|
-
debug$3('array error',
|
|
1299
|
-
throw error(
|
|
1184
|
+
debug$3('array error', this, parts);
|
|
1185
|
+
throw error(`group::array error "${name}" not found.
|
|
1186
|
+
this: ${this}
|
|
1187
|
+
parts: "${parts}"
|
|
1188
|
+
`, 'JSCAD_UTILS_GROUP_ERROR');
|
|
1300
1189
|
}
|
|
1301
1190
|
a.push(map(CSG.fromPolygons(self.parts[name].toPolygons()), name));
|
|
1302
1191
|
});
|
|
@@ -1326,12 +1215,17 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1326
1215
|
var self = this;
|
|
1327
1216
|
var piecesArray = pieces ? pieces.split(',') : self.names;
|
|
1328
1217
|
return piecesArray.map(function (piece) {
|
|
1329
|
-
if (!self.parts[piece]) console.error(
|
|
1218
|
+
if (!self.parts[piece]) console.error(`Cannot find ${piece} in ${self.names}`);
|
|
1330
1219
|
return self.parts[piece];
|
|
1331
1220
|
});
|
|
1332
1221
|
};
|
|
1333
1222
|
JsCadUtilsGroup.prototype.toString = function () {
|
|
1334
|
-
return
|
|
1223
|
+
return `{
|
|
1224
|
+
name: "${this.name}",
|
|
1225
|
+
names: "${this.names.join(',')}",
|
|
1226
|
+
parts: "${Object.keys(this.parts)}",
|
|
1227
|
+
holes: ${Array.isArray(this.holes) ? this.holes.length : this.holes ? 1 : 0}
|
|
1228
|
+
}`;
|
|
1335
1229
|
};
|
|
1336
1230
|
JsCadUtilsGroup.prototype.setName = function (name) {
|
|
1337
1231
|
this.name = name;
|
|
@@ -1380,9 +1274,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1380
1274
|
self.name = objectNames;
|
|
1381
1275
|
} else {
|
|
1382
1276
|
var objects = objectNames; // eslint-disable-line no-redeclare
|
|
1383
|
-
self.names = Object.keys(objects).filter(
|
|
1384
|
-
return k !== 'holes';
|
|
1385
|
-
});
|
|
1277
|
+
self.names = Object.keys(objects).filter(k => k !== 'holes');
|
|
1386
1278
|
self.parts = Object.assign({}, objects);
|
|
1387
1279
|
self.holes = objects.holes;
|
|
1388
1280
|
}
|
|
@@ -1391,45 +1283,43 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1391
1283
|
return new JsCadUtilsGroup(self.names, self.parts, self.holes);
|
|
1392
1284
|
}
|
|
1393
1285
|
|
|
1394
|
-
|
|
1286
|
+
/** @typedef { import('@jscad/csg').CSG } CSG */
|
|
1287
|
+
|
|
1288
|
+
const debug$2 = Debug('jscadUtils:util');
|
|
1395
1289
|
// import utilInit from '../src/add-prototype';
|
|
1396
1290
|
// utilInit(CSG);
|
|
1397
1291
|
// console.trace('CSG', CSG.prototype);
|
|
1398
1292
|
|
|
1399
1293
|
var NOZZEL_SIZE = 0.4;
|
|
1400
|
-
|
|
1294
|
+
const nearest = {
|
|
1401
1295
|
/**
|
|
1402
1296
|
* Return the largest number that is a multiple of the
|
|
1403
1297
|
* nozzel size.
|
|
1404
1298
|
* @param {Number} desired Desired value
|
|
1405
|
-
* @param {Number} [nozzel=NOZZEL_SIZE]
|
|
1299
|
+
* @param {Number} [nozzel=NOZZEL_SIZE] Nozzel size, defaults to `NOZZEL_SIZE`
|
|
1406
1300
|
* @param {Number} [nozzie=0] Number of nozzel sizes to add to the value
|
|
1407
1301
|
* @return {Number} Multiple of nozzel size
|
|
1408
1302
|
*/
|
|
1409
|
-
under: function
|
|
1410
|
-
var nozzel = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : NOZZEL_SIZE;
|
|
1411
|
-
var nozzie = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
1303
|
+
under: function (desired, nozzel = NOZZEL_SIZE, nozzie = 0) {
|
|
1412
1304
|
return (Math.floor(desired / nozzel) + nozzie) * nozzel;
|
|
1413
1305
|
},
|
|
1414
1306
|
/**
|
|
1415
|
-
* Returns the largest number that is a
|
|
1307
|
+
* Returns the largest number that is a multiple of the
|
|
1416
1308
|
* nozzel size, just over the desired value.
|
|
1417
1309
|
* @param {Number} desired Desired value
|
|
1418
|
-
* @param {Number} [nozzel=NOZZEL_SIZE]
|
|
1310
|
+
* @param {Number} [nozzel=NOZZEL_SIZE] Nozzel size, defaults to `NOZZEL_SIZE`
|
|
1419
1311
|
* @param {Number} [nozzie=0] Number of nozzel sizes to add to the value
|
|
1420
1312
|
* @return {Number} Multiple of nozzel size
|
|
1421
1313
|
*/
|
|
1422
|
-
over: function
|
|
1423
|
-
var nozzel = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : NOZZEL_SIZE;
|
|
1424
|
-
var nozzie = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
1314
|
+
over: function (desired, nozzel = NOZZEL_SIZE, nozzie = 0) {
|
|
1425
1315
|
return (Math.ceil(desired / nozzel) + nozzie) * nozzel;
|
|
1426
1316
|
}
|
|
1427
1317
|
};
|
|
1428
1318
|
|
|
1429
1319
|
/**
|
|
1430
|
-
* A function that
|
|
1320
|
+
* A function that returns the first argument. Useful when
|
|
1431
1321
|
* passing in a callback to modify something, and you want a
|
|
1432
|
-
* default
|
|
1322
|
+
* default function hat does nothing.
|
|
1433
1323
|
* @param {object} solid an object that will be returned
|
|
1434
1324
|
* @return {object} the first parameter passed into the function.
|
|
1435
1325
|
* @function identity
|
|
@@ -1439,13 +1329,13 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1439
1329
|
}
|
|
1440
1330
|
|
|
1441
1331
|
/**
|
|
1442
|
-
* If `f` is a
|
|
1332
|
+
* If `f` is a function, it is executed with `object` as the
|
|
1443
1333
|
* parameter. This is used in `CSG.unionIf` and `CSG.subtractIf`,
|
|
1444
1334
|
* allowing you to pass a function instead of an object. Since the
|
|
1445
|
-
* function isn't
|
|
1335
|
+
* function isn't executed until called, the object to `union` or
|
|
1446
1336
|
* `subtract` can be assembled only if the conditional is true.
|
|
1447
1337
|
* @param {object} object the context to run the function with.
|
|
1448
|
-
* @param {function|object} f if a
|
|
1338
|
+
* @param {function|object} f if a function it is executed, otherwise the object is returned.
|
|
1449
1339
|
* @return {object} the result of the function or the object.
|
|
1450
1340
|
* @function result
|
|
1451
1341
|
*/
|
|
@@ -1460,10 +1350,10 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1460
1350
|
/**
|
|
1461
1351
|
* Returns target object with default values assigned. If values already exist, they are not set.
|
|
1462
1352
|
* @param {object} target The target object to return.
|
|
1463
|
-
* @param {object} defaults
|
|
1353
|
+
* @param {object} defaults Default values to add to the object if they don't already exist.
|
|
1464
1354
|
* @return {object} Target object with default values assigned.
|
|
1465
1355
|
* @function defaults
|
|
1466
|
-
* @
|
|
1356
|
+
* @deprecated
|
|
1467
1357
|
*/
|
|
1468
1358
|
function defaults(target, defaults) {
|
|
1469
1359
|
depreciated('defaults', true, 'use Object.assign instead');
|
|
@@ -1477,20 +1367,24 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1477
1367
|
}
|
|
1478
1368
|
|
|
1479
1369
|
/**
|
|
1480
|
-
* Print a message and CSG object bounds and size to the
|
|
1370
|
+
* Print a message and CSG object bounds and size to the console.
|
|
1481
1371
|
* @param {String} msg Message to print
|
|
1482
1372
|
* @param {CSG} o A CSG object to print the bounds and size of.
|
|
1483
1373
|
* @function
|
|
1484
|
-
* @
|
|
1374
|
+
* @deprecated use Debug instead
|
|
1485
1375
|
*/
|
|
1486
1376
|
function print(msg, o) {
|
|
1487
1377
|
debug$2(msg, JSON.stringify(o.getBounds()), JSON.stringify(this.size(o.getBounds())));
|
|
1488
1378
|
}
|
|
1489
1379
|
function jscadToString(o) {
|
|
1490
|
-
if (
|
|
1380
|
+
if (typeof o == 'object') {
|
|
1491
1381
|
if (o.polygons) {
|
|
1492
1382
|
// is this CSG like?
|
|
1493
|
-
return
|
|
1383
|
+
return `{
|
|
1384
|
+
polygons: ${o.polygons.length},
|
|
1385
|
+
properties: "${Object.keys(o.properties)}"
|
|
1386
|
+
}
|
|
1387
|
+
`;
|
|
1494
1388
|
}
|
|
1495
1389
|
} else {
|
|
1496
1390
|
return o.toString();
|
|
@@ -1506,11 +1400,11 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1506
1400
|
|
|
1507
1401
|
/**
|
|
1508
1402
|
* Shows a warning or error message. Used to indicate a method
|
|
1509
|
-
* has been
|
|
1403
|
+
* has been deprecated and what to use instead.
|
|
1510
1404
|
* @function depreciated
|
|
1511
|
-
* @param {string} method The name of the method being
|
|
1405
|
+
* @param {string} method The name of the method being deprecated.
|
|
1512
1406
|
* @param {boolean} [error] Throws an error if called when true.
|
|
1513
|
-
* @param {string} [message] Instructions on what to use instead of the
|
|
1407
|
+
* @param {string} [message] Instructions on what to use instead of the deprecated method.
|
|
1514
1408
|
*/
|
|
1515
1409
|
function depreciated(method, error, message) {
|
|
1516
1410
|
var msg = method + ' is depreciated.' + (' ' + message || '');
|
|
@@ -1559,13 +1453,13 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1559
1453
|
}
|
|
1560
1454
|
function text(text) {
|
|
1561
1455
|
var l = vector_char(0, 0, text); // l contains a list of polylines to draw
|
|
1562
|
-
var
|
|
1456
|
+
var char = l.segments.reduce(function (result, segment) {
|
|
1563
1457
|
var path = new CSG.Path2D(segment);
|
|
1564
1458
|
var cag = path.expandToCAG(2);
|
|
1565
1459
|
// debug('reduce', result, segment, path, cag);
|
|
1566
1460
|
return result ? result.union(cag) : cag;
|
|
1567
1461
|
}, undefined);
|
|
1568
|
-
return
|
|
1462
|
+
return char;
|
|
1569
1463
|
}
|
|
1570
1464
|
function unitCube(length, radius) {
|
|
1571
1465
|
radius = radius || 0.5;
|
|
@@ -1592,7 +1486,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1592
1486
|
* Returns an array of positions along an object on a given axis.
|
|
1593
1487
|
* @param {CSG} object The object to calculate the segments on.
|
|
1594
1488
|
* @param {number} segments The number of segments to create.
|
|
1595
|
-
* @param {string} axis Axis to create the
|
|
1489
|
+
* @param {string} axis Axis to create the segments on.
|
|
1596
1490
|
* @return {Array} An array of segment positions.
|
|
1597
1491
|
* @function segment
|
|
1598
1492
|
*/
|
|
@@ -1638,7 +1532,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1638
1532
|
function mapPick(o, names, f, options) {
|
|
1639
1533
|
return names.reduce(function (result, name, index) {
|
|
1640
1534
|
if (!o[name]) {
|
|
1641
|
-
throw new Error(
|
|
1535
|
+
throw new Error(`${name} not found in ${options.name}: ${Object.keys(o).join(',')}`);
|
|
1642
1536
|
}
|
|
1643
1537
|
result.push(f ? f(o[name], name, index, o) : o[name]);
|
|
1644
1538
|
return result;
|
|
@@ -1670,7 +1564,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1670
1564
|
function xyz2array(size) {
|
|
1671
1565
|
return [size.x, size.y, size.z];
|
|
1672
1566
|
}
|
|
1673
|
-
|
|
1567
|
+
const rotationAxes = {
|
|
1674
1568
|
x: [1, 0, 0],
|
|
1675
1569
|
y: [0, 1, 0],
|
|
1676
1570
|
z: [0, 0, 1]
|
|
@@ -1791,7 +1685,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1791
1685
|
function mirrored4(x) {
|
|
1792
1686
|
return x.union([x.mirroredY(90), x.mirroredX(90), x.mirroredY(90).mirroredX(90)]);
|
|
1793
1687
|
}
|
|
1794
|
-
|
|
1688
|
+
const flushSide = {
|
|
1795
1689
|
'above-outside': [1, 0],
|
|
1796
1690
|
'above-inside': [1, 1],
|
|
1797
1691
|
'below-outside': [0, 1],
|
|
@@ -1824,8 +1718,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1824
1718
|
return w[side[0]][axis] - m[side[1]][axis];
|
|
1825
1719
|
});
|
|
1826
1720
|
}
|
|
1827
|
-
function calcSnap(moveobj, withobj, axes, orientation) {
|
|
1828
|
-
var delta = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
|
|
1721
|
+
function calcSnap(moveobj, withobj, axes, orientation, delta = 0) {
|
|
1829
1722
|
var side = flushSide[orientation];
|
|
1830
1723
|
if (!side) {
|
|
1831
1724
|
var fix = {
|
|
@@ -1903,7 +1796,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1903
1796
|
objectSize = objectSize || size(bounds);
|
|
1904
1797
|
return bounds[0].plus(objectSize.dividedBy(2));
|
|
1905
1798
|
} catch (err) {
|
|
1906
|
-
error(
|
|
1799
|
+
error(`centroid error o:${jscadToString(o)} objectSize: ${objectSize}`, undefined, err);
|
|
1907
1800
|
}
|
|
1908
1801
|
}
|
|
1909
1802
|
|
|
@@ -1915,7 +1808,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1915
1808
|
* @param {CSG} o A CSG object.
|
|
1916
1809
|
* @param {String} axis A string with the axis to operate on.
|
|
1917
1810
|
* @param {Number} to Value to move the midline of the object to.
|
|
1918
|
-
* @return {Number[]} The
|
|
1811
|
+
* @return {Number[]} The transform array needed to move the object.
|
|
1919
1812
|
*/
|
|
1920
1813
|
function calcmidlineTo(o, axis, to) {
|
|
1921
1814
|
var bounds = o.getBounds();
|
|
@@ -1936,8 +1829,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1936
1829
|
});
|
|
1937
1830
|
return t;
|
|
1938
1831
|
}
|
|
1939
|
-
function calcCenterWith(o, axes, withObj) {
|
|
1940
|
-
var delta = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
1832
|
+
function calcCenterWith(o, axes, withObj, delta = 0) {
|
|
1941
1833
|
var objectCentroid = centroid(o);
|
|
1942
1834
|
var withCentroid = centroid(withObj);
|
|
1943
1835
|
var t = axisApply(axes, function (i, axis) {
|
|
@@ -1954,7 +1846,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1954
1846
|
* along the axis will be returned. If no `offset`
|
|
1955
1847
|
* is given, then the midway point on the axis is returned.
|
|
1956
1848
|
* When the `offset` is positive, a point `offset` from the
|
|
1957
|
-
*
|
|
1849
|
+
* minimum axis is returned. When the `offset` is negative,
|
|
1958
1850
|
* the `offset` is subtracted from the axis maximum.
|
|
1959
1851
|
* @param {Size} size Size array of the object
|
|
1960
1852
|
* @param {Bounds} bounds Bounds of the object
|
|
@@ -1999,12 +1891,9 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1999
1891
|
* @param {CSG.Vector3D} [options.rotationCenter]
|
|
2000
1892
|
* @return {JsCadUtilsGroup} Returns a group object with a parts object.
|
|
2001
1893
|
*/
|
|
2002
|
-
function bisect() {
|
|
2003
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
2004
|
-
args[_key] = arguments[_key];
|
|
2005
|
-
}
|
|
1894
|
+
function bisect(...args) {
|
|
2006
1895
|
if (args.length < 2) {
|
|
2007
|
-
error('bisect
|
|
1896
|
+
error('bisect requires an object and an axis', 'JSCAD_UTILS_INVALID_ARGS');
|
|
2008
1897
|
}
|
|
2009
1898
|
var object = args[0];
|
|
2010
1899
|
var axis = args[1];
|
|
@@ -2072,16 +1961,16 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2072
1961
|
var theRotationAxis = rotationAxes[rotateaxis];
|
|
2073
1962
|
var cutplane = CSG.OrthoNormalBasis.GetCartesian(info.orthoNormalCartesian[0], info.orthoNormalCartesian[1]).translate(cutDelta).rotate(rotationCenter, theRotationAxis, angle);
|
|
2074
1963
|
debug$2('bisect', debug$2.enabled && {
|
|
2075
|
-
axis
|
|
2076
|
-
offset
|
|
2077
|
-
angle
|
|
2078
|
-
rotateaxis
|
|
2079
|
-
cutDelta
|
|
2080
|
-
rotateOffsetAxis
|
|
2081
|
-
rotationCenter
|
|
2082
|
-
theRotationAxis
|
|
2083
|
-
cutplane
|
|
2084
|
-
options
|
|
1964
|
+
axis,
|
|
1965
|
+
offset,
|
|
1966
|
+
angle,
|
|
1967
|
+
rotateaxis,
|
|
1968
|
+
cutDelta,
|
|
1969
|
+
rotateOffsetAxis,
|
|
1970
|
+
rotationCenter,
|
|
1971
|
+
theRotationAxis,
|
|
1972
|
+
cutplane,
|
|
1973
|
+
options
|
|
2085
1974
|
});
|
|
2086
1975
|
var g = Group('negative,positive', [object.cutByPlane(cutplane.plane).color(options.color && 'red'), object.cutByPlane(cutplane.plane.flipped()).color(options.color && 'blue')]);
|
|
2087
1976
|
if (options.addRotationCenter) g.add(unitAxis(objectSize.length() + 10, 0.1, rotationCenter), 'rotationCenter');
|
|
@@ -2099,14 +1988,10 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2099
1988
|
* @param {CSG.Vector3D} [options.rotationCenter] The location of the rotation center, defaults to [0,0,0].
|
|
2100
1989
|
* @return {JsCadUtilsGroup} A group with a positive and negative CSG object.
|
|
2101
1990
|
*/
|
|
2102
|
-
function slice(object
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {
|
|
2107
|
-
color: true,
|
|
2108
|
-
addRotationCenter: true
|
|
2109
|
-
};
|
|
1991
|
+
function slice(object, angle = 15, axis = 'x', rotateaxis = 'z', options = {
|
|
1992
|
+
color: true,
|
|
1993
|
+
addRotationCenter: true
|
|
1994
|
+
}) {
|
|
2110
1995
|
var info = normalVector(axis);
|
|
2111
1996
|
var rotationCenter = options.rotationCenter || new CSG.Vector3D(0, 0, 0);
|
|
2112
1997
|
var theRotationAxis = rotationAxes[rotateaxis];
|
|
@@ -2166,7 +2051,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2166
2051
|
* Wraps the `stretchAtPlane` call using the same
|
|
2167
2052
|
* logic as `bisect`.
|
|
2168
2053
|
* @param {CSG} object Object to stretch
|
|
2169
|
-
* @param {String} axis Axis to
|
|
2054
|
+
* @param {String} axis Axis to stretch along
|
|
2170
2055
|
* @param {Number} distance Distance to stretch
|
|
2171
2056
|
* @param {Number} offset Offset along the axis to cut the object
|
|
2172
2057
|
* @return {CSG} The stretched object.
|
|
@@ -2256,7 +2141,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2256
2141
|
flipped: up
|
|
2257
2142
|
}));
|
|
2258
2143
|
|
|
2259
|
-
// rotate with quick short
|
|
2144
|
+
// rotate with quick short circuit
|
|
2260
2145
|
var rotate = twistangle === 0 ? function rotateZero(v) {
|
|
2261
2146
|
return v;
|
|
2262
2147
|
} : function rotate(v, angle, percent) {
|
|
@@ -2347,7 +2232,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2347
2232
|
var absoluteRadius = Math.abs(radius);
|
|
2348
2233
|
var si = sliceParams(orientation, radius, b);
|
|
2349
2234
|
debug$2('reShape', absoluteRadius, si);
|
|
2350
|
-
if (si.axis !== 'z') throw new Error('reShape error: CAG.
|
|
2235
|
+
if (si.axis !== 'z') throw new Error('reShape error: CAG._toPlanePolygons only uses the "z" axis. You must use the "z" axis for now.');
|
|
2351
2236
|
var cutplane = CSG.OrthoNormalBasis.GetCartesian(si.orthoNormalCartesian[0], si.orthoNormalCartesian[1]).translate(si.cutDelta);
|
|
2352
2237
|
var slice = object.sectionCut(cutplane);
|
|
2353
2238
|
var first = axisApply(si.axis, function () {
|
|
@@ -2403,21 +2288,19 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2403
2288
|
var rotationCenter = solid.centroid();
|
|
2404
2289
|
var rotationAxis = axes[axis];
|
|
2405
2290
|
return {
|
|
2406
|
-
rotationCenter
|
|
2407
|
-
rotationAxis
|
|
2291
|
+
rotationCenter,
|
|
2292
|
+
rotationAxis
|
|
2408
2293
|
};
|
|
2409
2294
|
}
|
|
2410
2295
|
function rotateAround(part, solid, axis, angle) {
|
|
2411
|
-
var
|
|
2412
|
-
rotationCenter
|
|
2413
|
-
rotationAxis
|
|
2296
|
+
var {
|
|
2297
|
+
rotationCenter,
|
|
2298
|
+
rotationAxis
|
|
2299
|
+
} = calcRotate(part, solid, axis);
|
|
2414
2300
|
return part.rotate(rotationCenter, rotationAxis, angle);
|
|
2415
2301
|
}
|
|
2416
|
-
function cloneProperties(from, to) {
|
|
2417
|
-
return Object.entries(from).reduce(
|
|
2418
|
-
var _ref2 = _slicedToArray(_ref, 2),
|
|
2419
|
-
key = _ref2[0],
|
|
2420
|
-
value = _ref2[1];
|
|
2302
|
+
function cloneProperties(from, to, depth = 0) {
|
|
2303
|
+
return Object.entries(from).reduce((props, [key, value]) => {
|
|
2421
2304
|
props[key] = value;
|
|
2422
2305
|
return props;
|
|
2423
2306
|
}, to);
|
|
@@ -2438,21 +2321,93 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2438
2321
|
* @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.
|
|
2439
2322
|
* @return {CSG} The CSG object with the new connector added.
|
|
2440
2323
|
*/
|
|
2441
|
-
function addConnector(object, name) {
|
|
2442
|
-
var point = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [0, 0, 0];
|
|
2443
|
-
var axis = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [1, 0, 0];
|
|
2444
|
-
var normal = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [0, 0, 1];
|
|
2324
|
+
function addConnector(object, name, point = [0, 0, 0], axis = [1, 0, 0], normal = [0, 0, 1]) {
|
|
2445
2325
|
object.properties[name] = new CSG.Connector(point, axis, normal);
|
|
2446
2326
|
return object;
|
|
2447
2327
|
}
|
|
2448
2328
|
|
|
2449
|
-
var
|
|
2329
|
+
var util = /*#__PURE__*/Object.freeze({
|
|
2330
|
+
__proto__: null,
|
|
2331
|
+
NOZZEL_SIZE: NOZZEL_SIZE,
|
|
2332
|
+
addConnector: addConnector,
|
|
2333
|
+
axis2array: axis2array,
|
|
2334
|
+
axisApply: axisApply,
|
|
2335
|
+
bisect: bisect,
|
|
2336
|
+
calcCenterWith: calcCenterWith,
|
|
2337
|
+
calcFlush: calcFlush,
|
|
2338
|
+
calcRotate: calcRotate,
|
|
2339
|
+
calcSnap: calcSnap,
|
|
2340
|
+
calcmidlineTo: calcmidlineTo,
|
|
2341
|
+
center: center,
|
|
2342
|
+
centerWith: centerWith,
|
|
2343
|
+
centerX: centerX,
|
|
2344
|
+
centerY: centerY,
|
|
2345
|
+
centroid: centroid,
|
|
2346
|
+
chamfer: chamfer,
|
|
2347
|
+
clone: clone,
|
|
2348
|
+
cm: cm,
|
|
2349
|
+
defaults: defaults,
|
|
2350
|
+
depreciated: depreciated,
|
|
2351
|
+
div: div,
|
|
2352
|
+
divA: divA,
|
|
2353
|
+
divxyz: divxyz,
|
|
2354
|
+
enlarge: enlarge,
|
|
2355
|
+
error: error,
|
|
2356
|
+
fillet: fillet,
|
|
2357
|
+
fit: fit,
|
|
2358
|
+
flush: flush,
|
|
2359
|
+
flushSide: flushSide,
|
|
2360
|
+
getDelta: getDelta,
|
|
2361
|
+
identity: identity,
|
|
2362
|
+
ifArray: ifArray,
|
|
2363
|
+
inch: inch,
|
|
2364
|
+
isEmpty: isEmpty,
|
|
2365
|
+
isNegative: isNegative,
|
|
2366
|
+
jscadToString: jscadToString,
|
|
2367
|
+
label: label,
|
|
2368
|
+
map: map,
|
|
2369
|
+
mapPick: mapPick,
|
|
2370
|
+
mapValues: mapValues,
|
|
2371
|
+
midlineTo: midlineTo,
|
|
2372
|
+
mirrored4: mirrored4,
|
|
2373
|
+
mul: mul,
|
|
2374
|
+
mulxyz: mulxyz,
|
|
2375
|
+
nearest: nearest,
|
|
2376
|
+
normalVector: normalVector,
|
|
2377
|
+
pick: pick,
|
|
2378
|
+
poly2solid: poly2solid,
|
|
2379
|
+
print: print,
|
|
2380
|
+
reShape: reShape,
|
|
2381
|
+
result: result,
|
|
2382
|
+
rotateAround: rotateAround,
|
|
2383
|
+
rotationAxes: rotationAxes,
|
|
2384
|
+
scale: scale,
|
|
2385
|
+
segment: segment,
|
|
2386
|
+
shift: shift,
|
|
2387
|
+
size: size,
|
|
2388
|
+
slice: slice,
|
|
2389
|
+
sliceParams: sliceParams,
|
|
2390
|
+
slices2poly: slices2poly,
|
|
2391
|
+
snap: snap,
|
|
2392
|
+
stretch: stretch,
|
|
2393
|
+
text: text,
|
|
2394
|
+
toArray: toArray,
|
|
2395
|
+
translator: translator,
|
|
2396
|
+
unitAxis: unitAxis,
|
|
2397
|
+
unitCube: unitCube,
|
|
2398
|
+
wedge: wedge,
|
|
2399
|
+
xyz2array: xyz2array,
|
|
2400
|
+
zero: zero,
|
|
2401
|
+
zipObject: zipObject
|
|
2402
|
+
});
|
|
2403
|
+
|
|
2404
|
+
const debug$1 = Debug('jscadUtils:parts');
|
|
2450
2405
|
var parts = {
|
|
2451
2406
|
BBox: BBox$1,
|
|
2452
|
-
Cube
|
|
2453
|
-
RoundedCube
|
|
2454
|
-
Cylinder
|
|
2455
|
-
Cone
|
|
2407
|
+
Cube,
|
|
2408
|
+
RoundedCube,
|
|
2409
|
+
Cylinder,
|
|
2410
|
+
Cone
|
|
2456
2411
|
};
|
|
2457
2412
|
|
|
2458
2413
|
/**
|
|
@@ -2462,16 +2417,13 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2462
2417
|
* @param {CSG} ...objects Any number of CSG objects to create a bounding box for.
|
|
2463
2418
|
* @return {CSG} A box with the size of the extents of all of the passed in objects
|
|
2464
2419
|
*/
|
|
2465
|
-
function BBox$1() {
|
|
2420
|
+
function BBox$1(...objects) {
|
|
2466
2421
|
function box(object) {
|
|
2467
2422
|
return CSG.cube({
|
|
2468
2423
|
center: object.centroid(),
|
|
2469
2424
|
radius: object.size().dividedBy(2)
|
|
2470
2425
|
});
|
|
2471
2426
|
}
|
|
2472
|
-
for (var _len = arguments.length, objects = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
2473
|
-
objects[_key] = arguments[_key];
|
|
2474
|
-
}
|
|
2475
2427
|
return objects.reduce(function (bbox, part) {
|
|
2476
2428
|
var object = bbox ? union([bbox, box(part)]) : part;
|
|
2477
2429
|
return box(object);
|
|
@@ -2531,8 +2483,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2531
2483
|
* @param {number} [options.resolution] The number of segments to create in 360 degrees of rotation.
|
|
2532
2484
|
* @return {CSG} A CSG Cylinder
|
|
2533
2485
|
*/
|
|
2534
|
-
function Cylinder(diameter, height) {
|
|
2535
|
-
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
2486
|
+
function Cylinder(diameter, height, options = {}) {
|
|
2536
2487
|
debug$1('parts.Cylinder', diameter, height, options);
|
|
2537
2488
|
options = Object.assign({
|
|
2538
2489
|
start: [0, 0, 0],
|
|
@@ -2552,8 +2503,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2552
2503
|
* @param {Object} options Additional options passed to `CSG.cylinder`.
|
|
2553
2504
|
* @return {CSG} A CSG cone object.
|
|
2554
2505
|
*/
|
|
2555
|
-
function Cone(diameter1, diameter2, height) {
|
|
2556
|
-
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
2506
|
+
function Cone(diameter1, diameter2, height, options = {}) {
|
|
2557
2507
|
debug$1('parts.Cone', diameter1, diameter2, height, options);
|
|
2558
2508
|
return CSG.cylinder(Object.assign({
|
|
2559
2509
|
start: [0, 0, 0],
|
|
@@ -2614,14 +2564,12 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2614
2564
|
* @param {Number} width
|
|
2615
2565
|
* @param {Number} height
|
|
2616
2566
|
*/
|
|
2617
|
-
function Anchor() {
|
|
2618
|
-
var width = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 10;
|
|
2619
|
-
var height = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10;
|
|
2567
|
+
function Anchor(width = 10, height = 10) {
|
|
2620
2568
|
var hole = Cylinder(width, height).Center().color('red');
|
|
2621
2569
|
var post = Cylinder(height / 2, width * 0.66).rotateX(90).align(hole, 'xz').snap(hole, 'y', 'inside-').translate([0, 0, -height / 6]).color('purple');
|
|
2622
2570
|
return Group({
|
|
2623
|
-
post
|
|
2624
|
-
hole
|
|
2571
|
+
post,
|
|
2572
|
+
hole
|
|
2625
2573
|
});
|
|
2626
2574
|
}
|
|
2627
2575
|
function Board(width, height, corner_radius, thickness) {
|
|
@@ -2636,7 +2584,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2636
2584
|
});
|
|
2637
2585
|
return board;
|
|
2638
2586
|
}
|
|
2639
|
-
|
|
2587
|
+
const Hardware = {
|
|
2640
2588
|
Orientation: {
|
|
2641
2589
|
up: {
|
|
2642
2590
|
head: 'outside-',
|
|
@@ -2647,7 +2595,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2647
2595
|
clear: 'inside-'
|
|
2648
2596
|
}
|
|
2649
2597
|
},
|
|
2650
|
-
Screw: function
|
|
2598
|
+
Screw: function (head, thread, headClearSpace, options) {
|
|
2651
2599
|
depreciated('Screw', false, 'Use the jscad-hardware screw methods instead');
|
|
2652
2600
|
options = Object.assign(options, {
|
|
2653
2601
|
orientation: 'up',
|
|
@@ -2672,7 +2620,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2672
2620
|
* @param {number} clearLength Length of the clearance section of the head.
|
|
2673
2621
|
* @param {object} options Screw options include orientation and clerance scale.
|
|
2674
2622
|
*/
|
|
2675
|
-
PanHeadScrew: function
|
|
2623
|
+
PanHeadScrew: function (headDiameter, headLength, diameter, length, clearLength, options) {
|
|
2676
2624
|
depreciated('PanHeadScrew', false, 'Use the jscad-hardware screw methods instead');
|
|
2677
2625
|
var head = Cylinder(headDiameter, headLength);
|
|
2678
2626
|
var thread = Cylinder(diameter, length);
|
|
@@ -2690,7 +2638,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2690
2638
|
* @param {number} clearLength Length of the clearance section of the head.
|
|
2691
2639
|
* @param {object} options Screw options include orientation and clerance scale.
|
|
2692
2640
|
*/
|
|
2693
|
-
HexHeadScrew: function
|
|
2641
|
+
HexHeadScrew: function (headDiameter, headLength, diameter, length, clearLength, options) {
|
|
2694
2642
|
depreciated('HexHeadScrew', false, 'Use the jscad-hardware screw methods instead');
|
|
2695
2643
|
var head = Hexagon(headDiameter, headLength);
|
|
2696
2644
|
var thread = Cylinder(diameter, length);
|
|
@@ -2708,7 +2656,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2708
2656
|
* @param {number} clearLength clearance length
|
|
2709
2657
|
* @param {object} options options
|
|
2710
2658
|
*/
|
|
2711
|
-
FlatHeadScrew: function
|
|
2659
|
+
FlatHeadScrew: function (headDiameter, headLength, diameter, length, clearLength, options) {
|
|
2712
2660
|
depreciated('FlatHeadScrew', false, 'Use the jscad-hardware screw methods instead');
|
|
2713
2661
|
var head = Cone(headDiameter, diameter, headLength);
|
|
2714
2662
|
// var head = Cylinder(headDiameter, headLength);
|
|
@@ -2722,21 +2670,21 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2722
2670
|
|
|
2723
2671
|
var parts$1 = /*#__PURE__*/Object.freeze({
|
|
2724
2672
|
__proto__: null,
|
|
2725
|
-
|
|
2673
|
+
Anchor: Anchor,
|
|
2726
2674
|
BBox: BBox$1,
|
|
2675
|
+
Board: Board,
|
|
2676
|
+
Cone: Cone,
|
|
2727
2677
|
Cube: Cube,
|
|
2728
|
-
RoundedCube: RoundedCube,
|
|
2729
2678
|
Cylinder: Cylinder,
|
|
2730
|
-
|
|
2679
|
+
Hardware: Hardware,
|
|
2731
2680
|
Hexagon: Hexagon,
|
|
2681
|
+
RoundedCube: RoundedCube,
|
|
2732
2682
|
Triangle: Triangle,
|
|
2733
2683
|
Tube: Tube,
|
|
2734
|
-
|
|
2735
|
-
Board: Board,
|
|
2736
|
-
Hardware: Hardware
|
|
2684
|
+
default: parts
|
|
2737
2685
|
});
|
|
2738
2686
|
|
|
2739
|
-
|
|
2687
|
+
const debug = Debug('jscadUtils:boxes');
|
|
2740
2688
|
|
|
2741
2689
|
/** @typedef {import("./group").JsCadUtilsGroup} JsCadUtilsGroup */
|
|
2742
2690
|
|
|
@@ -2808,8 +2756,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2808
2756
|
* @param {Number} face Size of the join face.
|
|
2809
2757
|
* @return {JsCadUtilsGroup} A group object with `positive`, `negative` parts.
|
|
2810
2758
|
*/
|
|
2811
|
-
function Rabett(box, thickness, gap, height, face) {
|
|
2812
|
-
var options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
|
|
2759
|
+
function Rabett(box, thickness, gap, height, face, options = {}) {
|
|
2813
2760
|
debug('Rabett', 'thickness', thickness, 'gap', gap, 'height', height, 'face', face);
|
|
2814
2761
|
gap = gap || 0.25;
|
|
2815
2762
|
var inside = thickness - gap;
|
|
@@ -2818,16 +2765,18 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2818
2765
|
debug('inside', inside, 'outside', outside);
|
|
2819
2766
|
var group = Group();
|
|
2820
2767
|
// debug('Rabbet top height:', height, 'options:', options);
|
|
2821
|
-
var
|
|
2822
|
-
top
|
|
2823
|
-
lower2_3rd
|
|
2768
|
+
var {
|
|
2769
|
+
positive: top,
|
|
2770
|
+
negative: lower2_3rd
|
|
2771
|
+
} = box.bisect('z', height, options).parts;
|
|
2824
2772
|
|
|
2825
2773
|
// debug('face', face, 'height', height);
|
|
2826
2774
|
var lowerBisectHeight = Math.sign(height) < 0 ? face * Math.sign(height) : height - face;
|
|
2827
2775
|
// debug('Rabbet bottom height:', lowerBisectHeight, 'options:', options);
|
|
2828
|
-
var
|
|
2829
|
-
middle
|
|
2830
|
-
bottom
|
|
2776
|
+
var {
|
|
2777
|
+
positive: middle,
|
|
2778
|
+
negative: bottom
|
|
2779
|
+
} = lower2_3rd.bisect('z', lowerBisectHeight, options).parts;
|
|
2831
2780
|
var middleTop = middle.color('yellow').subtract(middle.color('darkred').enlarge([outside, outside, 0]));
|
|
2832
2781
|
group.add(top
|
|
2833
2782
|
// .color('blue')
|
|
@@ -2871,9 +2820,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2871
2820
|
* @return {JsCadUtilsGroup} An A hollow version of the original object..
|
|
2872
2821
|
* @memberof module:Boxes
|
|
2873
2822
|
*/
|
|
2874
|
-
|
|
2875
|
-
var gap = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0.25;
|
|
2876
|
-
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
2823
|
+
const RabettTopBottom = function rabbetTMB(box, thickness, gap = 0.25, options = {}) {
|
|
2877
2824
|
options = Object.assign({
|
|
2878
2825
|
removableTop: true,
|
|
2879
2826
|
removableBottom: true,
|
|
@@ -2906,7 +2853,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2906
2853
|
}
|
|
2907
2854
|
return group;
|
|
2908
2855
|
};
|
|
2909
|
-
|
|
2856
|
+
const CutOut = function cutOut(o, h, box, plug, gap) {
|
|
2910
2857
|
gap = gap || 0.25;
|
|
2911
2858
|
// console.log('cutOut', o.size(), h, b.size());
|
|
2912
2859
|
// var r = getRadius(o);
|
|
@@ -2926,7 +2873,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2926
2873
|
insert: union([o, top]).intersect(box).subtract(o).enlarge([-gap, 0, 0]).union(clip.subtract(plug).enlarge(-gap, -gap, 0)).color('blue')
|
|
2927
2874
|
});
|
|
2928
2875
|
};
|
|
2929
|
-
|
|
2876
|
+
const Rectangle = function (size, thickness, cb) {
|
|
2930
2877
|
thickness = thickness || 2;
|
|
2931
2878
|
var s = div$1(xyz2array(size), 2);
|
|
2932
2879
|
var r = add(s, thickness);
|
|
@@ -2957,7 +2904,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2957
2904
|
* @return {CSG} An A hollow version of the original object..
|
|
2958
2905
|
* @memberof module:Boxes
|
|
2959
2906
|
*/
|
|
2960
|
-
|
|
2907
|
+
const Hollow = function (object, thickness, interiorcb, exteriorcb) {
|
|
2961
2908
|
thickness = thickness || 2;
|
|
2962
2909
|
var size = -thickness * 2;
|
|
2963
2910
|
interiorcb = interiorcb || identity;
|
|
@@ -2973,7 +2920,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2973
2920
|
* @deprecated use parts.BBox
|
|
2974
2921
|
* @memberof module:Boxes
|
|
2975
2922
|
*/
|
|
2976
|
-
|
|
2923
|
+
const BBox = function (o) {
|
|
2977
2924
|
depreciated('BBox', true, "Use 'parts.BBox' instead");
|
|
2978
2925
|
var s = div$1(xyz2array(o.size()), 2);
|
|
2979
2926
|
return CSG.cube({
|
|
@@ -2984,8 +2931,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2984
2931
|
function getRadius(o) {
|
|
2985
2932
|
return div$1(xyz2array(o.size()), 2);
|
|
2986
2933
|
}
|
|
2987
|
-
function rabbetJoin(box, thickness) {
|
|
2988
|
-
var gap = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0.25;
|
|
2934
|
+
function rabbetJoin(box, thickness, gap = 0.25) {
|
|
2989
2935
|
var r = add(getRadius(box), -thickness / 2);
|
|
2990
2936
|
r[2] = thickness / 2;
|
|
2991
2937
|
var cutter = CSG.cube({
|
|
@@ -3004,25 +2950,30 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
3004
2950
|
|
|
3005
2951
|
var Boxes = /*#__PURE__*/Object.freeze({
|
|
3006
2952
|
__proto__: null,
|
|
2953
|
+
BBox: BBox,
|
|
2954
|
+
CutOut: CutOut,
|
|
2955
|
+
Hollow: Hollow,
|
|
3007
2956
|
RabbetJoin: RabbetJoin,
|
|
3008
|
-
topMiddleBottom: topMiddleBottom,
|
|
3009
2957
|
Rabett: Rabett,
|
|
3010
2958
|
RabettTopBottom: RabettTopBottom,
|
|
3011
|
-
CutOut: CutOut,
|
|
3012
2959
|
Rectangle: Rectangle,
|
|
3013
|
-
|
|
3014
|
-
BBox: BBox
|
|
2960
|
+
topMiddleBottom: topMiddleBottom
|
|
3015
2961
|
});
|
|
3016
2962
|
|
|
3017
|
-
|
|
2963
|
+
/**
|
|
2964
|
+
* JsCad Utilities es6
|
|
2965
|
+
*/
|
|
2966
|
+
|
|
2967
|
+
const compatV1 = {
|
|
2968
|
+
...util,
|
|
3018
2969
|
group: Group,
|
|
3019
2970
|
init: init$1,
|
|
3020
2971
|
triangle: triUtils,
|
|
3021
|
-
array
|
|
2972
|
+
array,
|
|
3022
2973
|
parts: parts$1,
|
|
3023
|
-
Boxes
|
|
3024
|
-
Debug
|
|
3025
|
-
}
|
|
2974
|
+
Boxes,
|
|
2975
|
+
Debug
|
|
2976
|
+
};
|
|
3026
2977
|
|
|
3027
2978
|
exports.Boxes = Boxes;
|
|
3028
2979
|
exports.Debug = Debug;
|
|
@@ -3034,8 +2985,6 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
3034
2985
|
exports.triUtils = triUtils;
|
|
3035
2986
|
exports.util = util;
|
|
3036
2987
|
|
|
3037
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3038
|
-
|
|
3039
2988
|
return exports;
|
|
3040
2989
|
|
|
3041
2990
|
})({}, jsCadCSG, scadApi);
|