@jwc/jscad-utils 4.9.0 → 5.0.1
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
|
@@ -59,329 +59,13 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
59
59
|
});
|
|
60
60
|
var jscadUtils = function(exports, jsCadCSG, scadApi) {
|
|
61
61
|
"use strict";
|
|
62
|
-
function
|
|
63
|
-
return e && typeof e === "object" && "default" in e ? e : {
|
|
64
|
-
default: e
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
var jsCadCSG__default = _interopDefaultLegacy(jsCadCSG);
|
|
68
|
-
var scadApi__default = _interopDefaultLegacy(scadApi);
|
|
69
|
-
var util = Object.freeze({
|
|
70
|
-
__proto__: null,
|
|
71
|
-
get NOZZEL_SIZE() {
|
|
72
|
-
return NOZZEL_SIZE;
|
|
73
|
-
},
|
|
74
|
-
get nearest() {
|
|
75
|
-
return nearest;
|
|
76
|
-
},
|
|
77
|
-
get identity() {
|
|
78
|
-
return identity;
|
|
79
|
-
},
|
|
80
|
-
get result() {
|
|
81
|
-
return result;
|
|
82
|
-
},
|
|
83
|
-
get defaults() {
|
|
84
|
-
return defaults;
|
|
85
|
-
},
|
|
86
|
-
get isEmpty() {
|
|
87
|
-
return isEmpty;
|
|
88
|
-
},
|
|
89
|
-
get isNegative() {
|
|
90
|
-
return isNegative;
|
|
91
|
-
},
|
|
92
|
-
get print() {
|
|
93
|
-
return print;
|
|
94
|
-
},
|
|
95
|
-
get jscadToString() {
|
|
96
|
-
return jscadToString;
|
|
97
|
-
},
|
|
98
|
-
get error() {
|
|
99
|
-
return error;
|
|
100
|
-
},
|
|
101
|
-
get depreciated() {
|
|
102
|
-
return depreciated;
|
|
103
|
-
},
|
|
104
|
-
get inch() {
|
|
105
|
-
return inch;
|
|
106
|
-
},
|
|
107
|
-
get cm() {
|
|
108
|
-
return cm;
|
|
109
|
-
},
|
|
110
|
-
get label() {
|
|
111
|
-
return label;
|
|
112
|
-
},
|
|
113
|
-
get text() {
|
|
114
|
-
return text;
|
|
115
|
-
},
|
|
116
|
-
get unitCube() {
|
|
117
|
-
return unitCube;
|
|
118
|
-
},
|
|
119
|
-
get unitAxis() {
|
|
120
|
-
return unitAxis;
|
|
121
|
-
},
|
|
122
|
-
get toArray() {
|
|
123
|
-
return toArray;
|
|
124
|
-
},
|
|
125
|
-
get ifArray() {
|
|
126
|
-
return ifArray;
|
|
127
|
-
},
|
|
128
|
-
get segment() {
|
|
129
|
-
return segment;
|
|
130
|
-
},
|
|
131
|
-
get zipObject() {
|
|
132
|
-
return zipObject;
|
|
133
|
-
},
|
|
134
|
-
get map() {
|
|
135
|
-
return map;
|
|
136
|
-
},
|
|
137
|
-
get mapValues() {
|
|
138
|
-
return mapValues;
|
|
139
|
-
},
|
|
140
|
-
get pick() {
|
|
141
|
-
return pick;
|
|
142
|
-
},
|
|
143
|
-
get mapPick() {
|
|
144
|
-
return mapPick;
|
|
145
|
-
},
|
|
146
|
-
get divA() {
|
|
147
|
-
return divA;
|
|
148
|
-
},
|
|
149
|
-
get divxyz() {
|
|
150
|
-
return divxyz;
|
|
151
|
-
},
|
|
152
|
-
get div() {
|
|
153
|
-
return div;
|
|
154
|
-
},
|
|
155
|
-
get mulxyz() {
|
|
156
|
-
return mulxyz;
|
|
157
|
-
},
|
|
158
|
-
get mul() {
|
|
159
|
-
return mul;
|
|
160
|
-
},
|
|
161
|
-
get xyz2array() {
|
|
162
|
-
return xyz2array;
|
|
163
|
-
},
|
|
164
|
-
get rotationAxes() {
|
|
165
|
-
return rotationAxes;
|
|
166
|
-
},
|
|
167
|
-
get size() {
|
|
168
|
-
return size;
|
|
169
|
-
},
|
|
170
|
-
get scale() {
|
|
171
|
-
return scale;
|
|
172
|
-
},
|
|
173
|
-
get center() {
|
|
174
|
-
return center;
|
|
175
|
-
},
|
|
176
|
-
get centerY() {
|
|
177
|
-
return centerY;
|
|
178
|
-
},
|
|
179
|
-
get centerX() {
|
|
180
|
-
return centerX;
|
|
181
|
-
},
|
|
182
|
-
get enlarge() {
|
|
183
|
-
return enlarge;
|
|
184
|
-
},
|
|
185
|
-
get fit() {
|
|
186
|
-
return fit;
|
|
187
|
-
},
|
|
188
|
-
get shift() {
|
|
189
|
-
return shift;
|
|
190
|
-
},
|
|
191
|
-
get zero() {
|
|
192
|
-
return zero;
|
|
193
|
-
},
|
|
194
|
-
get mirrored4() {
|
|
195
|
-
return mirrored4;
|
|
196
|
-
},
|
|
197
|
-
get flushSide() {
|
|
198
|
-
return flushSide;
|
|
199
|
-
},
|
|
200
|
-
get calcFlush() {
|
|
201
|
-
return calcFlush;
|
|
202
|
-
},
|
|
203
|
-
get calcSnap() {
|
|
204
|
-
return calcSnap;
|
|
205
|
-
},
|
|
206
|
-
get snap() {
|
|
207
|
-
return snap;
|
|
208
|
-
},
|
|
209
|
-
get flush() {
|
|
210
|
-
return flush;
|
|
211
|
-
},
|
|
212
|
-
get axisApply() {
|
|
213
|
-
return axisApply;
|
|
214
|
-
},
|
|
215
|
-
get axis2array() {
|
|
216
|
-
return axis2array;
|
|
217
|
-
},
|
|
218
|
-
get centroid() {
|
|
219
|
-
return centroid;
|
|
220
|
-
},
|
|
221
|
-
get calcmidlineTo() {
|
|
222
|
-
return calcmidlineTo;
|
|
223
|
-
},
|
|
224
|
-
get midlineTo() {
|
|
225
|
-
return midlineTo;
|
|
226
|
-
},
|
|
227
|
-
get translator() {
|
|
228
|
-
return translator;
|
|
229
|
-
},
|
|
230
|
-
get calcCenterWith() {
|
|
231
|
-
return calcCenterWith;
|
|
232
|
-
},
|
|
233
|
-
get centerWith() {
|
|
234
|
-
return centerWith;
|
|
235
|
-
},
|
|
236
|
-
get getDelta() {
|
|
237
|
-
return getDelta;
|
|
238
|
-
},
|
|
239
|
-
get bisect() {
|
|
240
|
-
return bisect;
|
|
241
|
-
},
|
|
242
|
-
get slice() {
|
|
243
|
-
return slice;
|
|
244
|
-
},
|
|
245
|
-
get wedge() {
|
|
246
|
-
return wedge;
|
|
247
|
-
},
|
|
248
|
-
get stretch() {
|
|
249
|
-
return stretch;
|
|
250
|
-
},
|
|
251
|
-
get poly2solid() {
|
|
252
|
-
return poly2solid;
|
|
253
|
-
},
|
|
254
|
-
get slices2poly() {
|
|
255
|
-
return slices2poly;
|
|
256
|
-
},
|
|
257
|
-
get normalVector() {
|
|
258
|
-
return normalVector;
|
|
259
|
-
},
|
|
260
|
-
get sliceParams() {
|
|
261
|
-
return sliceParams;
|
|
262
|
-
},
|
|
263
|
-
get reShape() {
|
|
264
|
-
return reShape;
|
|
265
|
-
},
|
|
266
|
-
get chamfer() {
|
|
267
|
-
return chamfer;
|
|
268
|
-
},
|
|
269
|
-
get fillet() {
|
|
270
|
-
return fillet;
|
|
271
|
-
},
|
|
272
|
-
get calcRotate() {
|
|
273
|
-
return calcRotate;
|
|
274
|
-
},
|
|
275
|
-
get rotateAround() {
|
|
276
|
-
return rotateAround;
|
|
277
|
-
},
|
|
278
|
-
get clone() {
|
|
279
|
-
return clone;
|
|
280
|
-
},
|
|
281
|
-
get addConnector() {
|
|
282
|
-
return addConnector;
|
|
283
|
-
}
|
|
284
|
-
});
|
|
285
|
-
function _arrayLikeToArray(r, a) {
|
|
286
|
-
(null == a || a > r.length) && (a = r.length);
|
|
287
|
-
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
288
|
-
return n;
|
|
289
|
-
}
|
|
290
|
-
function _arrayWithHoles(r) {
|
|
291
|
-
if (Array.isArray(r)) return r;
|
|
292
|
-
}
|
|
293
|
-
function _defineProperty(e, r, t) {
|
|
294
|
-
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
295
|
-
value: t,
|
|
296
|
-
enumerable: !0,
|
|
297
|
-
configurable: !0,
|
|
298
|
-
writable: !0
|
|
299
|
-
}) : e[r] = t, e;
|
|
300
|
-
}
|
|
301
|
-
function _iterableToArrayLimit(r, l) {
|
|
302
|
-
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
303
|
-
if (null != t) {
|
|
304
|
-
var e, n, i, u, a = [], f = !0, o = !1;
|
|
305
|
-
try {
|
|
306
|
-
if (i = (t = t.call(r)).next, 0 === l) {
|
|
307
|
-
if (Object(t) !== t) return;
|
|
308
|
-
f = !1;
|
|
309
|
-
} else for (;!(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0) ;
|
|
310
|
-
} catch (r) {
|
|
311
|
-
o = !0, n = r;
|
|
312
|
-
} finally {
|
|
313
|
-
try {
|
|
314
|
-
if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
|
|
315
|
-
} finally {
|
|
316
|
-
if (o) throw n;
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
return a;
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
function _nonIterableRest() {
|
|
323
|
-
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
324
|
-
}
|
|
325
|
-
function ownKeys(e, r) {
|
|
326
|
-
var t = Object.keys(e);
|
|
327
|
-
if (Object.getOwnPropertySymbols) {
|
|
328
|
-
var o = Object.getOwnPropertySymbols(e);
|
|
329
|
-
r && (o = o.filter(function(r) {
|
|
330
|
-
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
331
|
-
})), t.push.apply(t, o);
|
|
332
|
-
}
|
|
333
|
-
return t;
|
|
334
|
-
}
|
|
335
|
-
function _objectSpread2(e) {
|
|
336
|
-
for (var r = 1; r < arguments.length; r++) {
|
|
337
|
-
var t = null != arguments[r] ? arguments[r] : {};
|
|
338
|
-
r % 2 ? ownKeys(Object(t), !0).forEach(function(r) {
|
|
339
|
-
_defineProperty(e, r, t[r]);
|
|
340
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r) {
|
|
341
|
-
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
342
|
-
});
|
|
343
|
-
}
|
|
344
|
-
return e;
|
|
345
|
-
}
|
|
346
|
-
function _slicedToArray(r, e) {
|
|
347
|
-
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
|
|
348
|
-
}
|
|
349
|
-
function _toPrimitive(t, r) {
|
|
350
|
-
if ("object" != typeof t || !t) return t;
|
|
351
|
-
var e = t[Symbol.toPrimitive];
|
|
352
|
-
if (void 0 !== e) {
|
|
353
|
-
var i = e.call(t, r || "default");
|
|
354
|
-
if ("object" != typeof i) return i;
|
|
355
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
356
|
-
}
|
|
357
|
-
return ("string" === r ? String : Number)(t);
|
|
358
|
-
}
|
|
359
|
-
function _toPropertyKey(t) {
|
|
360
|
-
var i = _toPrimitive(t, "string");
|
|
361
|
-
return "symbol" == typeof i ? i : i + "";
|
|
362
|
-
}
|
|
363
|
-
function _typeof(o) {
|
|
364
|
-
"@babel/helpers - typeof";
|
|
365
|
-
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
366
|
-
return typeof o;
|
|
367
|
-
} : function(o) {
|
|
368
|
-
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
369
|
-
}, _typeof(o);
|
|
370
|
-
}
|
|
371
|
-
function _unsupportedIterableToArray(r, a) {
|
|
372
|
-
if (r) {
|
|
373
|
-
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
374
|
-
var t = {}.toString.call(r).slice(8, -1);
|
|
375
|
-
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;
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
var toRadians = function toRadians(deg) {
|
|
62
|
+
const toRadians = function toRadians(deg) {
|
|
379
63
|
return deg / 180 * Math.PI;
|
|
380
64
|
};
|
|
381
|
-
|
|
65
|
+
const toDegrees = function toDegrees(rad) {
|
|
382
66
|
return rad * (180 / Math.PI);
|
|
383
67
|
};
|
|
384
|
-
|
|
68
|
+
const solve = function(p1, p2) {
|
|
385
69
|
var r = {
|
|
386
70
|
c: 90,
|
|
387
71
|
A: Math.abs(p2.x - p1.x),
|
|
@@ -393,7 +77,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
393
77
|
r.a = 90 - r.b;
|
|
394
78
|
return r;
|
|
395
79
|
};
|
|
396
|
-
|
|
80
|
+
const solve90SA = function(r) {
|
|
397
81
|
r = Object.assign(r, {
|
|
398
82
|
C: 90
|
|
399
83
|
});
|
|
@@ -405,7 +89,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
405
89
|
r.b = r.b || r.a / Math.tan(arad);
|
|
406
90
|
return r;
|
|
407
91
|
};
|
|
408
|
-
|
|
92
|
+
const solve90ac = function(r) {
|
|
409
93
|
r = Object.assign(r, {
|
|
410
94
|
C: 90
|
|
411
95
|
});
|
|
@@ -426,29 +110,29 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
426
110
|
}
|
|
427
111
|
var triUtils = Object.freeze({
|
|
428
112
|
__proto__: null,
|
|
429
|
-
toRadians,
|
|
430
|
-
toDegrees,
|
|
431
113
|
solve,
|
|
432
114
|
solve90SA,
|
|
433
115
|
solve90ac,
|
|
434
|
-
solveab
|
|
116
|
+
solveab,
|
|
117
|
+
toDegrees,
|
|
118
|
+
toRadians
|
|
435
119
|
});
|
|
436
|
-
|
|
120
|
+
const div$1 = function(a, f) {
|
|
437
121
|
return a.map(function(e) {
|
|
438
122
|
return e / f;
|
|
439
123
|
});
|
|
440
124
|
};
|
|
441
|
-
|
|
125
|
+
const addValue = function(a, f) {
|
|
442
126
|
return a.map(function(e) {
|
|
443
127
|
return e + f;
|
|
444
128
|
});
|
|
445
129
|
};
|
|
446
|
-
|
|
130
|
+
const addArray = function(a, f) {
|
|
447
131
|
return a.map(function(e, i) {
|
|
448
132
|
return e + f[i];
|
|
449
133
|
});
|
|
450
134
|
};
|
|
451
|
-
|
|
135
|
+
const add = function(a) {
|
|
452
136
|
return Array.prototype.slice.call(arguments, 1).reduce(function(result, arg) {
|
|
453
137
|
if (Array.isArray(arg)) {
|
|
454
138
|
result = addArray(result, arg);
|
|
@@ -458,28 +142,28 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
458
142
|
return result;
|
|
459
143
|
}, a);
|
|
460
144
|
};
|
|
461
|
-
|
|
145
|
+
const fromxyz = function(object) {
|
|
462
146
|
return Array.isArray(object) ? object : [ object.x, object.y, object.z ];
|
|
463
147
|
};
|
|
464
|
-
|
|
148
|
+
const toxyz = function(a) {
|
|
465
149
|
return {
|
|
466
150
|
x: a[0],
|
|
467
151
|
y: a[1],
|
|
468
152
|
z: a[2]
|
|
469
153
|
};
|
|
470
154
|
};
|
|
471
|
-
|
|
155
|
+
const first = function(a) {
|
|
472
156
|
return a ? a[0] : undefined;
|
|
473
157
|
};
|
|
474
|
-
|
|
158
|
+
const last = function(a) {
|
|
475
159
|
return a && a.length > 0 ? a[a.length - 1] : undefined;
|
|
476
160
|
};
|
|
477
|
-
|
|
161
|
+
const min = function(a) {
|
|
478
162
|
return a.reduce(function(result, value) {
|
|
479
163
|
return value < result ? value : result;
|
|
480
164
|
}, Number.MAX_VALUE);
|
|
481
165
|
};
|
|
482
|
-
|
|
166
|
+
const range = function(a, b) {
|
|
483
167
|
var result = [];
|
|
484
168
|
for (var i = a; i < b; i++) {
|
|
485
169
|
result.push(i);
|
|
@@ -488,21 +172,21 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
488
172
|
};
|
|
489
173
|
var array = Object.freeze({
|
|
490
174
|
__proto__: null,
|
|
491
|
-
div: div$1,
|
|
492
|
-
addValue,
|
|
493
|
-
addArray,
|
|
494
175
|
add,
|
|
495
|
-
|
|
496
|
-
|
|
176
|
+
addArray,
|
|
177
|
+
addValue,
|
|
178
|
+
div: div$1,
|
|
497
179
|
first,
|
|
180
|
+
fromxyz,
|
|
498
181
|
last,
|
|
499
182
|
min,
|
|
500
|
-
range
|
|
183
|
+
range,
|
|
184
|
+
toxyz
|
|
501
185
|
});
|
|
502
|
-
|
|
503
|
-
|
|
186
|
+
const debugColors = [ "#e41a1c", "#377eb8", "#4daf4a", "#984ea3", "#ff7f00", "#ffff33", "#a65628", "#f781bf", "#999999" ];
|
|
187
|
+
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" ];
|
|
504
188
|
var debugCount = 0;
|
|
505
|
-
|
|
189
|
+
const Debug = function(name) {
|
|
506
190
|
var checks = Object.assign({
|
|
507
191
|
enabled: [],
|
|
508
192
|
disabled: [],
|
|
@@ -510,31 +194,21 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
510
194
|
browser: true
|
|
511
195
|
}
|
|
512
196
|
}, jscadUtilsDebug || {});
|
|
513
|
-
var style = checks.options.browser ?
|
|
197
|
+
var style = checks.options.browser ? `color:${debugColors[debugCount++ % debugColors.length]}` : `${termColors[debugCount++ % termColors.length]}`;
|
|
514
198
|
var enabled = checks.enabled.some(function checkEnabled(check) {
|
|
515
199
|
return check.test(name);
|
|
516
200
|
}) && !checks.disabled.some(function checkEnabled(check) {
|
|
517
201
|
return check.test(name);
|
|
518
202
|
});
|
|
519
|
-
var logger = enabled ? checks.options.browser ?
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
(_console = console).log.apply(_console, [ "%c%s", style, name ].concat(msg));
|
|
525
|
-
} : function() {
|
|
526
|
-
var _console2;
|
|
527
|
-
for (var _len2 = arguments.length, msg = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
528
|
-
msg[_key2] = arguments[_key2];
|
|
529
|
-
}
|
|
530
|
-
(_console2 = console).log.apply(_console2, [ "".concat(name) ].concat(msg));
|
|
531
|
-
} : function() {
|
|
532
|
-
return undefined;
|
|
533
|
-
};
|
|
203
|
+
var logger = enabled ? checks.options.browser ? (...msg) => {
|
|
204
|
+
console.log("%c%s", style, name, ...msg);
|
|
205
|
+
} : (...msg) => {
|
|
206
|
+
console.log(`${name}`, ...msg);
|
|
207
|
+
} : () => undefined;
|
|
534
208
|
logger.enabled = enabled;
|
|
535
209
|
return logger;
|
|
536
210
|
};
|
|
537
|
-
|
|
211
|
+
const nameArray = {
|
|
538
212
|
aliceblue: "#f0f8ff",
|
|
539
213
|
antiquewhite: "#faebd7",
|
|
540
214
|
aqua: "#00ffff",
|
|
@@ -692,9 +366,11 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
692
366
|
h = h.replace(/^\#/, "");
|
|
693
367
|
if (h.length === 6) {
|
|
694
368
|
return [ parseInt(h.substr(0, 2), 16), parseInt(h.substr(2, 2), 16), parseInt(h.substr(4, 2), 16) ];
|
|
369
|
+
} else {
|
|
370
|
+
return [ 0, 0, 0 ];
|
|
695
371
|
}
|
|
696
372
|
}
|
|
697
|
-
|
|
373
|
+
const _name2rgb = {};
|
|
698
374
|
function name2rgb(n) {
|
|
699
375
|
if (!_name2rgb[n]) _name2rgb[n] = hex2rgb(name2hex(n));
|
|
700
376
|
return _name2rgb[n];
|
|
@@ -774,23 +450,14 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
774
450
|
proto.prototype.chamfer = function chamfer$1(radius, orientation, options) {
|
|
775
451
|
return chamfer(this, radius, orientation, options);
|
|
776
452
|
};
|
|
777
|
-
proto.prototype.bisect = function bisect$1() {
|
|
778
|
-
|
|
779
|
-
args[_key] = arguments[_key];
|
|
780
|
-
}
|
|
781
|
-
return bisect.apply(util, [ this ].concat(args));
|
|
453
|
+
proto.prototype.bisect = function bisect$1(...args) {
|
|
454
|
+
return bisect(this, ...args);
|
|
782
455
|
};
|
|
783
|
-
proto.prototype.slice = function slice$1() {
|
|
784
|
-
|
|
785
|
-
args[_key2] = arguments[_key2];
|
|
786
|
-
}
|
|
787
|
-
return slice.apply(util, [ this ].concat(args));
|
|
456
|
+
proto.prototype.slice = function slice$1(...args) {
|
|
457
|
+
return slice(this, ...args);
|
|
788
458
|
};
|
|
789
|
-
proto.prototype.wedge = function wedge$1() {
|
|
790
|
-
|
|
791
|
-
args[_key3] = arguments[_key3];
|
|
792
|
-
}
|
|
793
|
-
return wedge.apply(util, [ this ].concat(args));
|
|
459
|
+
proto.prototype.wedge = function wedge$1(...args) {
|
|
460
|
+
return wedge(this, ...args);
|
|
794
461
|
};
|
|
795
462
|
proto.prototype.stretch = function stretch$1(axis, distance, offset) {
|
|
796
463
|
return stretch(this, axis, distance, offset);
|
|
@@ -807,7 +474,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
807
474
|
return this._translate(arguments[0]);
|
|
808
475
|
} else {
|
|
809
476
|
var t = Array.prototype.slice.call(arguments, 0).reduce(function(result, arg) {
|
|
810
|
-
result = undefined(result, arg);
|
|
477
|
+
result = undefined.addArray(result, arg);
|
|
811
478
|
return result;
|
|
812
479
|
}, [ 0, 0, 0 ]);
|
|
813
480
|
return this._translate(t);
|
|
@@ -816,14 +483,10 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
816
483
|
proto.prototype.addConnector = function addConnector$1(name, point, axis, normal) {
|
|
817
484
|
return addConnector(this, name, point, axis, normal);
|
|
818
485
|
};
|
|
819
|
-
proto.prototype.connect = function connectTo(myConnectorName, otherConnector) {
|
|
820
|
-
var
|
|
821
|
-
var normalrotation = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
822
|
-
var myConnector = myConnectorName.split(".").reduce(function(a, v) {
|
|
823
|
-
return a[v];
|
|
824
|
-
}, this.properties);
|
|
486
|
+
proto.prototype.connect = function connectTo(myConnectorName, otherConnector, mirror = false, normalrotation = 0) {
|
|
487
|
+
var myConnector = myConnectorName.split(".").reduce((a, v) => a[v], this.properties);
|
|
825
488
|
if (!myConnector) {
|
|
826
|
-
error(
|
|
489
|
+
error(`The connector '${myConnectorName}' does not exist on the object [${Object.keys(this.properties).join(",")}]`, "Missing connector property");
|
|
827
490
|
}
|
|
828
491
|
return this.connectTo(myConnector, otherConnector, mirror, normalrotation);
|
|
829
492
|
};
|
|
@@ -833,16 +496,13 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
833
496
|
__proto__: null,
|
|
834
497
|
default: init
|
|
835
498
|
});
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
499
|
+
const {CSG, CAG} = jsCadCSG;
|
|
500
|
+
const {rectangular_extrude} = scadApi.extrusions;
|
|
501
|
+
const {vector_text, vector_char} = scadApi.text;
|
|
502
|
+
const {union} = scadApi.booleanOps;
|
|
840
503
|
init(CSG);
|
|
841
|
-
|
|
842
|
-
function JsCadUtilsGroup() {
|
|
843
|
-
var names = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
844
|
-
var parts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
845
|
-
var holes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
504
|
+
const debug$3 = Debug("jscadUtils:group");
|
|
505
|
+
function JsCadUtilsGroup(names = [], parts = {}, holes = []) {
|
|
846
506
|
this.name = "";
|
|
847
507
|
this.names = names;
|
|
848
508
|
this.parts = parts;
|
|
@@ -870,11 +530,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
870
530
|
}
|
|
871
531
|
return self;
|
|
872
532
|
};
|
|
873
|
-
JsCadUtilsGroup.prototype.combine = function(pieces) {
|
|
874
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
875
|
-
var map = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function(x) {
|
|
876
|
-
return x;
|
|
877
|
-
};
|
|
533
|
+
JsCadUtilsGroup.prototype.combine = function(pieces, options = {}, map = x => x) {
|
|
878
534
|
try {
|
|
879
535
|
var self = this;
|
|
880
536
|
options = Object.assign({
|
|
@@ -882,7 +538,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
882
538
|
}, options);
|
|
883
539
|
pieces = pieces ? pieces.split(",") : self.names;
|
|
884
540
|
if (pieces.length === 0) {
|
|
885
|
-
throw new Error(
|
|
541
|
+
throw new Error(`no pieces found in ${self.name} pieces: ${pieces} parts: ${Object.keys(self.parts)} names: ${self.names}`);
|
|
886
542
|
}
|
|
887
543
|
debug$3("combine", self.names, self.parts);
|
|
888
544
|
var g = union(mapPick(self.parts, pieces, function(value, key, index, object) {
|
|
@@ -892,14 +548,12 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
892
548
|
return g.subtractIf(self.holes && Array.isArray(self.holes) ? union(self.holes) : self.holes, self.holes && !options.noholes);
|
|
893
549
|
} catch (err) {
|
|
894
550
|
debug$3("combine error", this, pieces, options, err);
|
|
895
|
-
throw error(
|
|
551
|
+
throw error(`group::combine error "${err.message || err.toString()}"\nthis: ${this}\npieces: "${pieces}"\noptions: ${JSON.stringify(options, null, 2)}\nstack: ${err.stack}\n`, "JSCAD_UTILS_GROUP_ERROR");
|
|
896
552
|
}
|
|
897
553
|
};
|
|
898
554
|
JsCadUtilsGroup.prototype.map = function(cb) {
|
|
899
555
|
var self = this;
|
|
900
|
-
self.parts = Object.keys(self.parts).filter(function(
|
|
901
|
-
return k !== "holes";
|
|
902
|
-
}).reduce(function(result, key) {
|
|
556
|
+
self.parts = Object.keys(self.parts).filter(k => k !== "holes").reduce(function(result, key) {
|
|
903
557
|
result[key] = cb(self.parts[key], key);
|
|
904
558
|
return result;
|
|
905
559
|
}, {});
|
|
@@ -915,7 +569,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
915
569
|
return self;
|
|
916
570
|
};
|
|
917
571
|
JsCadUtilsGroup.prototype.clone = function(name, map) {
|
|
918
|
-
debug$3("clone", name,
|
|
572
|
+
debug$3("clone", name, typeof name, map);
|
|
919
573
|
var self = this;
|
|
920
574
|
if (typeof name == "function") {
|
|
921
575
|
map = name;
|
|
@@ -967,7 +621,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
967
621
|
return self;
|
|
968
622
|
} catch (err) {
|
|
969
623
|
debug$3("snap error", this, part, to, axis, delta, err);
|
|
970
|
-
throw error(
|
|
624
|
+
throw error(`group::snap error "${err.message || err.toString()}"\nthis: ${this}\npart: "${part}"\nto: ${to}\naxis: "${axis}"\norientation: "${orientation}"\ndelta: "${delta}"\nstack: ${err.stack}\n`, "JSCAD_UTILS_GROUP_ERROR");
|
|
971
625
|
}
|
|
972
626
|
};
|
|
973
627
|
JsCadUtilsGroup.prototype.align = function align(part, to, axis, delta) {
|
|
@@ -982,7 +636,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
982
636
|
return self;
|
|
983
637
|
} catch (err) {
|
|
984
638
|
debug$3("align error", this, part, to, axis, delta, err);
|
|
985
|
-
throw error(
|
|
639
|
+
throw error(`group::align error "${err.message || err.toString()}"\nthis: ${this}\npart: "${part}"\nto: ${to}\naxis: "${axis}"\ndelta: "${delta}"\nstack: ${err.stack}\n`, "JSCAD_UTILS_GROUP_ERROR");
|
|
986
640
|
}
|
|
987
641
|
};
|
|
988
642
|
JsCadUtilsGroup.prototype.center = function center(part) {
|
|
@@ -994,9 +648,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
994
648
|
var bounds = self.parts[part].getBounds();
|
|
995
649
|
return self.translate([ 0, 0, -bounds[0].z ]);
|
|
996
650
|
};
|
|
997
|
-
JsCadUtilsGroup.prototype.connectTo = function connectTo(partName, connectorName, to, toConnectorName) {
|
|
998
|
-
var mirror = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
|
|
999
|
-
var normalrotation = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 0;
|
|
651
|
+
JsCadUtilsGroup.prototype.connectTo = function connectTo(partName, connectorName, to, toConnectorName, mirror = true, normalrotation = 0) {
|
|
1000
652
|
debug$3("connectTo", {
|
|
1001
653
|
partName,
|
|
1002
654
|
connectorName,
|
|
@@ -1006,13 +658,9 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1006
658
|
normalrotation
|
|
1007
659
|
});
|
|
1008
660
|
var self = this;
|
|
1009
|
-
var myConnector = connectorName.split(".").reduce(
|
|
1010
|
-
return a[v];
|
|
1011
|
-
}, self.parts[partName].properties);
|
|
661
|
+
var myConnector = connectorName.split(".").reduce((a, v) => a[v], self.parts[partName].properties);
|
|
1012
662
|
debug$3("toConnector", to instanceof CSG.Connector);
|
|
1013
|
-
var toConnector = toConnectorName.split(".").reduce(
|
|
1014
|
-
return a[v];
|
|
1015
|
-
}, to.properties);
|
|
663
|
+
var toConnector = toConnectorName.split(".").reduce((a, v) => a[v], to.properties);
|
|
1016
664
|
var matrix = myConnector.getTransformationTo(toConnector, mirror, normalrotation);
|
|
1017
665
|
debug$3("connectTo", matrix);
|
|
1018
666
|
self.map(function(part) {
|
|
@@ -1051,15 +699,14 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1051
699
|
return g;
|
|
1052
700
|
};
|
|
1053
701
|
JsCadUtilsGroup.prototype.array = function(parts, map) {
|
|
1054
|
-
var _this = this;
|
|
1055
702
|
var self = this;
|
|
1056
703
|
var p = parts && parts.length > 0 && parts.split(",") || self.names;
|
|
1057
704
|
if (!map) map = identity;
|
|
1058
705
|
var a = [];
|
|
1059
|
-
p.forEach(
|
|
706
|
+
p.forEach(name => {
|
|
1060
707
|
if (!self.parts[name]) {
|
|
1061
|
-
debug$3("array error",
|
|
1062
|
-
throw error(
|
|
708
|
+
debug$3("array error", this, parts);
|
|
709
|
+
throw error(`group::array error "${name}" not found.\nthis: ${this}\nparts: "${parts}"\n`, "JSCAD_UTILS_GROUP_ERROR");
|
|
1063
710
|
}
|
|
1064
711
|
a.push(map(CSG.fromPolygons(self.parts[name].toPolygons()), name));
|
|
1065
712
|
});
|
|
@@ -1069,12 +716,12 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1069
716
|
var self = this;
|
|
1070
717
|
var piecesArray = pieces ? pieces.split(",") : self.names;
|
|
1071
718
|
return piecesArray.map(function(piece) {
|
|
1072
|
-
if (!self.parts[piece]) console.error(
|
|
719
|
+
if (!self.parts[piece]) console.error(`Cannot find ${piece} in ${self.names}`);
|
|
1073
720
|
return self.parts[piece];
|
|
1074
721
|
});
|
|
1075
722
|
};
|
|
1076
723
|
JsCadUtilsGroup.prototype.toString = function() {
|
|
1077
|
-
return
|
|
724
|
+
return `{\n name: "${this.name}",\n names: "${this.names.join(",")}", \n parts: "${Object.keys(this.parts)}",\n holes: ${Array.isArray(this.holes) ? this.holes.length : this.holes ? 1 : 0}\n}`;
|
|
1078
725
|
};
|
|
1079
726
|
JsCadUtilsGroup.prototype.setName = function(name) {
|
|
1080
727
|
this.name = name;
|
|
@@ -1104,9 +751,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1104
751
|
self.name = objectNames;
|
|
1105
752
|
} else {
|
|
1106
753
|
var objects = objectNames;
|
|
1107
|
-
self.names = Object.keys(objects).filter(
|
|
1108
|
-
return k !== "holes";
|
|
1109
|
-
});
|
|
754
|
+
self.names = Object.keys(objects).filter(k => k !== "holes");
|
|
1110
755
|
self.parts = Object.assign({}, objects);
|
|
1111
756
|
self.holes = objects.holes;
|
|
1112
757
|
}
|
|
@@ -1114,17 +759,13 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1114
759
|
}
|
|
1115
760
|
return new JsCadUtilsGroup(self.names, self.parts, self.holes);
|
|
1116
761
|
}
|
|
1117
|
-
|
|
762
|
+
const debug$2 = Debug("jscadUtils:util");
|
|
1118
763
|
var NOZZEL_SIZE = .4;
|
|
1119
|
-
|
|
1120
|
-
under: function
|
|
1121
|
-
var nozzel = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : NOZZEL_SIZE;
|
|
1122
|
-
var nozzie = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
764
|
+
const nearest = {
|
|
765
|
+
under: function(desired, nozzel = NOZZEL_SIZE, nozzie = 0) {
|
|
1123
766
|
return (Math.floor(desired / nozzel) + nozzie) * nozzel;
|
|
1124
767
|
},
|
|
1125
|
-
over: function
|
|
1126
|
-
var nozzel = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : NOZZEL_SIZE;
|
|
1127
|
-
var nozzie = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
768
|
+
over: function(desired, nozzel = NOZZEL_SIZE, nozzie = 0) {
|
|
1128
769
|
return (Math.ceil(desired / nozzel) + nozzie) * nozzel;
|
|
1129
770
|
}
|
|
1130
771
|
};
|
|
@@ -1152,9 +793,9 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1152
793
|
debug$2(msg, JSON.stringify(o.getBounds()), JSON.stringify(this.size(o.getBounds())));
|
|
1153
794
|
}
|
|
1154
795
|
function jscadToString(o) {
|
|
1155
|
-
if (
|
|
796
|
+
if (typeof o == "object") {
|
|
1156
797
|
if (o.polygons) {
|
|
1157
|
-
return
|
|
798
|
+
return `{\npolygons: ${o.polygons.length},\nproperties: "${Object.keys(o.properties)}"\n}\n`;
|
|
1158
799
|
}
|
|
1159
800
|
} else {
|
|
1160
801
|
return o.toString();
|
|
@@ -1195,12 +836,12 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1195
836
|
}
|
|
1196
837
|
function text(text) {
|
|
1197
838
|
var l = vector_char(0, 0, text);
|
|
1198
|
-
var
|
|
839
|
+
var char = l.segments.reduce(function(result, segment) {
|
|
1199
840
|
var path = new CSG.Path2D(segment);
|
|
1200
841
|
var cag = path.expandToCAG(2);
|
|
1201
842
|
return result ? result.union(cag) : cag;
|
|
1202
843
|
}, undefined);
|
|
1203
|
-
return
|
|
844
|
+
return char;
|
|
1204
845
|
}
|
|
1205
846
|
function unitCube(length, radius) {
|
|
1206
847
|
radius = radius || .5;
|
|
@@ -1256,7 +897,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1256
897
|
function mapPick(o, names, f, options) {
|
|
1257
898
|
return names.reduce(function(result, name, index) {
|
|
1258
899
|
if (!o[name]) {
|
|
1259
|
-
throw new Error(
|
|
900
|
+
throw new Error(`${name} not found in ${options.name}: ${Object.keys(o).join(",")}`);
|
|
1260
901
|
}
|
|
1261
902
|
result.push(f ? f(o[name], name, index, o) : o[name]);
|
|
1262
903
|
return result;
|
|
@@ -1288,7 +929,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1288
929
|
function xyz2array(size) {
|
|
1289
930
|
return [ size.x, size.y, size.z ];
|
|
1290
931
|
}
|
|
1291
|
-
|
|
932
|
+
const rotationAxes = {
|
|
1292
933
|
x: [ 1, 0, 0 ],
|
|
1293
934
|
y: [ 0, 1, 0 ],
|
|
1294
935
|
z: [ 0, 0, 1 ]
|
|
@@ -1366,7 +1007,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1366
1007
|
function mirrored4(x) {
|
|
1367
1008
|
return x.union([ x.mirroredY(90), x.mirroredX(90), x.mirroredY(90).mirroredX(90) ]);
|
|
1368
1009
|
}
|
|
1369
|
-
|
|
1010
|
+
const flushSide = {
|
|
1370
1011
|
"above-outside": [ 1, 0 ],
|
|
1371
1012
|
"above-inside": [ 1, 1 ],
|
|
1372
1013
|
"below-outside": [ 0, 1 ],
|
|
@@ -1396,8 +1037,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1396
1037
|
return w[side[0]][axis] - m[side[1]][axis];
|
|
1397
1038
|
});
|
|
1398
1039
|
}
|
|
1399
|
-
function calcSnap(moveobj, withobj, axes, orientation) {
|
|
1400
|
-
var delta = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
|
|
1040
|
+
function calcSnap(moveobj, withobj, axes, orientation, delta = 0) {
|
|
1401
1041
|
var side = flushSide[orientation];
|
|
1402
1042
|
if (!side) {
|
|
1403
1043
|
var fix = {
|
|
@@ -1463,7 +1103,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1463
1103
|
objectSize = objectSize || size(bounds);
|
|
1464
1104
|
return bounds[0].plus(objectSize.dividedBy(2));
|
|
1465
1105
|
} catch (err) {
|
|
1466
|
-
error(
|
|
1106
|
+
error(`centroid error o:${jscadToString(o)} objectSize: ${objectSize}`, undefined, err);
|
|
1467
1107
|
}
|
|
1468
1108
|
}
|
|
1469
1109
|
function calcmidlineTo(o, axis, to) {
|
|
@@ -1484,8 +1124,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1484
1124
|
});
|
|
1485
1125
|
return t;
|
|
1486
1126
|
}
|
|
1487
|
-
function calcCenterWith(o, axes, withObj) {
|
|
1488
|
-
var delta = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
1127
|
+
function calcCenterWith(o, axes, withObj, delta = 0) {
|
|
1489
1128
|
var objectCentroid = centroid(o);
|
|
1490
1129
|
var withCentroid = centroid(withObj);
|
|
1491
1130
|
var t = axisApply(axes, function(i, axis) {
|
|
@@ -1507,12 +1146,9 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1507
1146
|
return bounds[0][a] + (isEmpty(dist) ? size[axis] / 2 : dist);
|
|
1508
1147
|
});
|
|
1509
1148
|
}
|
|
1510
|
-
function bisect() {
|
|
1511
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1512
|
-
args[_key] = arguments[_key];
|
|
1513
|
-
}
|
|
1149
|
+
function bisect(...args) {
|
|
1514
1150
|
if (args.length < 2) {
|
|
1515
|
-
error("bisect
|
|
1151
|
+
error("bisect requires an object and an axis", "JSCAD_UTILS_INVALID_ARGS");
|
|
1516
1152
|
}
|
|
1517
1153
|
var object = args[0];
|
|
1518
1154
|
var axis = args[1];
|
|
@@ -1591,14 +1227,10 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1591
1227
|
if (options.addRotationCenter) g.add(unitAxis(objectSize.length() + 10, .1, rotationCenter), "rotationCenter");
|
|
1592
1228
|
return g;
|
|
1593
1229
|
}
|
|
1594
|
-
function slice(object
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {
|
|
1599
|
-
color: true,
|
|
1600
|
-
addRotationCenter: true
|
|
1601
|
-
};
|
|
1230
|
+
function slice(object, angle = 15, axis = "x", rotateaxis = "z", options = {
|
|
1231
|
+
color: true,
|
|
1232
|
+
addRotationCenter: true
|
|
1233
|
+
}) {
|
|
1602
1234
|
var info = normalVector(axis);
|
|
1603
1235
|
var rotationCenter = options.rotationCenter || new CSG.Vector3D(0, 0, 0);
|
|
1604
1236
|
var theRotationAxis = rotationAxes[rotateaxis];
|
|
@@ -1754,7 +1386,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1754
1386
|
var absoluteRadius = Math.abs(radius);
|
|
1755
1387
|
var si = sliceParams(orientation, radius, b);
|
|
1756
1388
|
debug$2("reShape", absoluteRadius, si);
|
|
1757
|
-
if (si.axis !== "z") throw new Error('reShape error: CAG.
|
|
1389
|
+
if (si.axis !== "z") throw new Error('reShape error: CAG._toPlanePolygons only uses the "z" axis. You must use the "z" axis for now.');
|
|
1758
1390
|
var cutplane = CSG.OrthoNormalBasis.GetCartesian(si.orthoNormalCartesian[0], si.orthoNormalCartesian[1]).translate(si.cutDelta);
|
|
1759
1391
|
var slice = object.sectionCut(cutplane);
|
|
1760
1392
|
var first = axisApply(si.axis, function() {
|
|
@@ -1815,12 +1447,11 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1815
1447
|
};
|
|
1816
1448
|
}
|
|
1817
1449
|
function rotateAround(part, solid, axis, angle) {
|
|
1818
|
-
var
|
|
1450
|
+
var {rotationCenter, rotationAxis} = calcRotate(part, solid, axis);
|
|
1819
1451
|
return part.rotate(rotationCenter, rotationAxis, angle);
|
|
1820
1452
|
}
|
|
1821
|
-
function cloneProperties(from, to) {
|
|
1822
|
-
return Object.entries(from).reduce(
|
|
1823
|
-
var _ref2 = _slicedToArray(_ref, 2), key = _ref2[0], value = _ref2[1];
|
|
1453
|
+
function cloneProperties(from, to, depth = 0) {
|
|
1454
|
+
return Object.entries(from).reduce((props, [key, value]) => {
|
|
1824
1455
|
props[key] = value;
|
|
1825
1456
|
return props;
|
|
1826
1457
|
}, to);
|
|
@@ -1831,14 +1462,85 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1831
1462
|
debug$2("clone", o, c, CSG);
|
|
1832
1463
|
return c;
|
|
1833
1464
|
}
|
|
1834
|
-
function addConnector(object, name) {
|
|
1835
|
-
var point = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [ 0, 0, 0 ];
|
|
1836
|
-
var axis = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [ 1, 0, 0 ];
|
|
1837
|
-
var normal = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [ 0, 0, 1 ];
|
|
1465
|
+
function addConnector(object, name, point = [ 0, 0, 0 ], axis = [ 1, 0, 0 ], normal = [ 0, 0, 1 ]) {
|
|
1838
1466
|
object.properties[name] = new CSG.Connector(point, axis, normal);
|
|
1839
1467
|
return object;
|
|
1840
1468
|
}
|
|
1841
|
-
var
|
|
1469
|
+
var util = Object.freeze({
|
|
1470
|
+
__proto__: null,
|
|
1471
|
+
NOZZEL_SIZE,
|
|
1472
|
+
addConnector,
|
|
1473
|
+
axis2array,
|
|
1474
|
+
axisApply,
|
|
1475
|
+
bisect,
|
|
1476
|
+
calcCenterWith,
|
|
1477
|
+
calcFlush,
|
|
1478
|
+
calcRotate,
|
|
1479
|
+
calcSnap,
|
|
1480
|
+
calcmidlineTo,
|
|
1481
|
+
center,
|
|
1482
|
+
centerWith,
|
|
1483
|
+
centerX,
|
|
1484
|
+
centerY,
|
|
1485
|
+
centroid,
|
|
1486
|
+
chamfer,
|
|
1487
|
+
clone,
|
|
1488
|
+
cm,
|
|
1489
|
+
defaults,
|
|
1490
|
+
depreciated,
|
|
1491
|
+
div,
|
|
1492
|
+
divA,
|
|
1493
|
+
divxyz,
|
|
1494
|
+
enlarge,
|
|
1495
|
+
error,
|
|
1496
|
+
fillet,
|
|
1497
|
+
fit,
|
|
1498
|
+
flush,
|
|
1499
|
+
flushSide,
|
|
1500
|
+
getDelta,
|
|
1501
|
+
identity,
|
|
1502
|
+
ifArray,
|
|
1503
|
+
inch,
|
|
1504
|
+
isEmpty,
|
|
1505
|
+
isNegative,
|
|
1506
|
+
jscadToString,
|
|
1507
|
+
label,
|
|
1508
|
+
map,
|
|
1509
|
+
mapPick,
|
|
1510
|
+
mapValues,
|
|
1511
|
+
midlineTo,
|
|
1512
|
+
mirrored4,
|
|
1513
|
+
mul,
|
|
1514
|
+
mulxyz,
|
|
1515
|
+
nearest,
|
|
1516
|
+
normalVector,
|
|
1517
|
+
pick,
|
|
1518
|
+
poly2solid,
|
|
1519
|
+
print,
|
|
1520
|
+
reShape,
|
|
1521
|
+
result,
|
|
1522
|
+
rotateAround,
|
|
1523
|
+
rotationAxes,
|
|
1524
|
+
scale,
|
|
1525
|
+
segment,
|
|
1526
|
+
shift,
|
|
1527
|
+
size,
|
|
1528
|
+
slice,
|
|
1529
|
+
sliceParams,
|
|
1530
|
+
slices2poly,
|
|
1531
|
+
snap,
|
|
1532
|
+
stretch,
|
|
1533
|
+
text,
|
|
1534
|
+
toArray,
|
|
1535
|
+
translator,
|
|
1536
|
+
unitAxis,
|
|
1537
|
+
unitCube,
|
|
1538
|
+
wedge,
|
|
1539
|
+
xyz2array,
|
|
1540
|
+
zero,
|
|
1541
|
+
zipObject
|
|
1542
|
+
});
|
|
1543
|
+
const debug$1 = Debug("jscadUtils:parts");
|
|
1842
1544
|
var parts = {
|
|
1843
1545
|
BBox: BBox$1,
|
|
1844
1546
|
Cube,
|
|
@@ -1846,16 +1548,13 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1846
1548
|
Cylinder,
|
|
1847
1549
|
Cone
|
|
1848
1550
|
};
|
|
1849
|
-
function BBox$1() {
|
|
1551
|
+
function BBox$1(...objects) {
|
|
1850
1552
|
function box(object) {
|
|
1851
1553
|
return CSG.cube({
|
|
1852
1554
|
center: object.centroid(),
|
|
1853
1555
|
radius: object.size().dividedBy(2)
|
|
1854
1556
|
});
|
|
1855
1557
|
}
|
|
1856
|
-
for (var _len = arguments.length, objects = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1857
|
-
objects[_key] = arguments[_key];
|
|
1858
|
-
}
|
|
1859
1558
|
return objects.reduce(function(bbox, part) {
|
|
1860
1559
|
var object = bbox ? union([ bbox, box(part) ]) : part;
|
|
1861
1560
|
return box(object);
|
|
@@ -1888,8 +1587,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1888
1587
|
});
|
|
1889
1588
|
return roundedcube;
|
|
1890
1589
|
}
|
|
1891
|
-
function Cylinder(diameter, height) {
|
|
1892
|
-
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1590
|
+
function Cylinder(diameter, height, options = {}) {
|
|
1893
1591
|
debug$1("parts.Cylinder", diameter, height, options);
|
|
1894
1592
|
options = Object.assign({
|
|
1895
1593
|
start: [ 0, 0, 0 ],
|
|
@@ -1899,8 +1597,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1899
1597
|
}, options);
|
|
1900
1598
|
return CSG.cylinder(options);
|
|
1901
1599
|
}
|
|
1902
|
-
function Cone(diameter1, diameter2, height) {
|
|
1903
|
-
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
1600
|
+
function Cone(diameter1, diameter2, height, options = {}) {
|
|
1904
1601
|
debug$1("parts.Cone", diameter1, diameter2, height, options);
|
|
1905
1602
|
return CSG.cylinder(Object.assign({
|
|
1906
1603
|
start: [ 0, 0, 0 ],
|
|
@@ -1929,9 +1626,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1929
1626
|
function Tube(outsideDiameter, insideDiameter, height, outsideOptions, insideOptions) {
|
|
1930
1627
|
return Cylinder(outsideDiameter, height, outsideOptions).subtract(Cylinder(insideDiameter, height, insideOptions || outsideOptions));
|
|
1931
1628
|
}
|
|
1932
|
-
function Anchor() {
|
|
1933
|
-
var width = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 10;
|
|
1934
|
-
var height = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10;
|
|
1629
|
+
function Anchor(width = 10, height = 10) {
|
|
1935
1630
|
var hole = Cylinder(width, height).Center().color("red");
|
|
1936
1631
|
var post = Cylinder(height / 2, width * .66).rotateX(90).align(hole, "xz").snap(hole, "y", "inside-").translate([ 0, 0, -height / 6 ]).color("purple");
|
|
1937
1632
|
return Group({
|
|
@@ -1951,7 +1646,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1951
1646
|
});
|
|
1952
1647
|
return board;
|
|
1953
1648
|
}
|
|
1954
|
-
|
|
1649
|
+
const Hardware = {
|
|
1955
1650
|
Orientation: {
|
|
1956
1651
|
up: {
|
|
1957
1652
|
head: "outside-",
|
|
@@ -1962,7 +1657,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1962
1657
|
clear: "inside-"
|
|
1963
1658
|
}
|
|
1964
1659
|
},
|
|
1965
|
-
Screw: function
|
|
1660
|
+
Screw: function(head, thread, headClearSpace, options) {
|
|
1966
1661
|
depreciated("Screw", false, "Use the jscad-hardware screw methods instead");
|
|
1967
1662
|
options = Object.assign(options, {
|
|
1968
1663
|
orientation: "up",
|
|
@@ -1978,7 +1673,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1978
1673
|
}
|
|
1979
1674
|
return group;
|
|
1980
1675
|
},
|
|
1981
|
-
PanHeadScrew: function
|
|
1676
|
+
PanHeadScrew: function(headDiameter, headLength, diameter, length, clearLength, options) {
|
|
1982
1677
|
depreciated("PanHeadScrew", false, "Use the jscad-hardware screw methods instead");
|
|
1983
1678
|
var head = Cylinder(headDiameter, headLength);
|
|
1984
1679
|
var thread = Cylinder(diameter, length);
|
|
@@ -1987,7 +1682,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1987
1682
|
}
|
|
1988
1683
|
return Hardware.Screw(head, thread, headClearSpace, options);
|
|
1989
1684
|
},
|
|
1990
|
-
HexHeadScrew: function
|
|
1685
|
+
HexHeadScrew: function(headDiameter, headLength, diameter, length, clearLength, options) {
|
|
1991
1686
|
depreciated("HexHeadScrew", false, "Use the jscad-hardware screw methods instead");
|
|
1992
1687
|
var head = Hexagon(headDiameter, headLength);
|
|
1993
1688
|
var thread = Cylinder(diameter, length);
|
|
@@ -1996,7 +1691,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1996
1691
|
}
|
|
1997
1692
|
return Hardware.Screw(head, thread, headClearSpace, options);
|
|
1998
1693
|
},
|
|
1999
|
-
FlatHeadScrew: function
|
|
1694
|
+
FlatHeadScrew: function(headDiameter, headLength, diameter, length, clearLength, options) {
|
|
2000
1695
|
depreciated("FlatHeadScrew", false, "Use the jscad-hardware screw methods instead");
|
|
2001
1696
|
var head = Cone(headDiameter, diameter, headLength);
|
|
2002
1697
|
var thread = Cylinder(diameter, length);
|
|
@@ -2008,20 +1703,20 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2008
1703
|
};
|
|
2009
1704
|
var parts$1 = Object.freeze({
|
|
2010
1705
|
__proto__: null,
|
|
2011
|
-
|
|
1706
|
+
Anchor,
|
|
2012
1707
|
BBox: BBox$1,
|
|
1708
|
+
Board,
|
|
1709
|
+
Cone,
|
|
2013
1710
|
Cube,
|
|
2014
|
-
RoundedCube,
|
|
2015
1711
|
Cylinder,
|
|
2016
|
-
|
|
1712
|
+
Hardware,
|
|
2017
1713
|
Hexagon,
|
|
1714
|
+
RoundedCube,
|
|
2018
1715
|
Triangle,
|
|
2019
1716
|
Tube,
|
|
2020
|
-
|
|
2021
|
-
Board,
|
|
2022
|
-
Hardware
|
|
1717
|
+
default: parts
|
|
2023
1718
|
});
|
|
2024
|
-
|
|
1719
|
+
const debug = Debug("jscadUtils:boxes");
|
|
2025
1720
|
function RabbetJoin(box, thickness, cutHeight) {
|
|
2026
1721
|
depreciated("RabbetJoin", true, "Use 'Rabbet' instead");
|
|
2027
1722
|
return rabbetJoin(box, thickness, cutHeight);
|
|
@@ -2034,17 +1729,16 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2034
1729
|
var top = bottom.parts.positive.bisect("z", -thickness);
|
|
2035
1730
|
return Group("top,middle,bottom", [ top.parts.positive, top.parts.negative.color("green"), bottom.parts.negative ]);
|
|
2036
1731
|
}
|
|
2037
|
-
function Rabett(box, thickness, gap, height, face) {
|
|
2038
|
-
var options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
|
|
1732
|
+
function Rabett(box, thickness, gap, height, face, options = {}) {
|
|
2039
1733
|
debug("Rabett", "thickness", thickness, "gap", gap, "height", height, "face", face);
|
|
2040
1734
|
gap = gap || .25;
|
|
2041
1735
|
var inside = thickness - gap;
|
|
2042
1736
|
var outside = -thickness + gap;
|
|
2043
1737
|
debug("inside", inside, "outside", outside);
|
|
2044
1738
|
var group = Group();
|
|
2045
|
-
var
|
|
1739
|
+
var {positive: top, negative: lower2_3rd} = box.bisect("z", height, options).parts;
|
|
2046
1740
|
var lowerBisectHeight = Math.sign(height) < 0 ? face * Math.sign(height) : height - face;
|
|
2047
|
-
var
|
|
1741
|
+
var {positive: middle, negative: bottom} = lower2_3rd.bisect("z", lowerBisectHeight, options).parts;
|
|
2048
1742
|
var middleTop = middle.color("yellow").subtract(middle.color("darkred").enlarge([ outside, outside, 0 ]));
|
|
2049
1743
|
group.add(top.union(middleTop), "top");
|
|
2050
1744
|
var bottomOutline = middle.color("yellow").subtract(middle.color("orange").enlarge([ outside, outside, 0 ])).enlarge([ outside, outside, 0 ]);
|
|
@@ -2053,9 +1747,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2053
1747
|
group.add(bottom.color("orange").union(middle.color("green").subtract(middle.color("red").enlarge([ inside, inside, 0 ])).subtract(middleTop)), "bottom");
|
|
2054
1748
|
return group;
|
|
2055
1749
|
}
|
|
2056
|
-
|
|
2057
|
-
var gap = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : .25;
|
|
2058
|
-
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
1750
|
+
const RabettTopBottom = function rabbetTMB(box, thickness, gap = .25, options = {}) {
|
|
2059
1751
|
options = Object.assign({
|
|
2060
1752
|
removableTop: true,
|
|
2061
1753
|
removableBottom: true,
|
|
@@ -2088,7 +1780,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2088
1780
|
}
|
|
2089
1781
|
return group;
|
|
2090
1782
|
};
|
|
2091
|
-
|
|
1783
|
+
const CutOut = function cutOut(o, h, box, plug, gap) {
|
|
2092
1784
|
gap = gap || .25;
|
|
2093
1785
|
var s = o.size();
|
|
2094
1786
|
var cutout = o.intersect(box);
|
|
@@ -2106,7 +1798,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2106
1798
|
insert: union([ o, top ]).intersect(box).subtract(o).enlarge([ -gap, 0, 0 ]).union(clip.subtract(plug).enlarge(-gap, -gap, 0)).color("blue")
|
|
2107
1799
|
});
|
|
2108
1800
|
};
|
|
2109
|
-
|
|
1801
|
+
const Rectangle = function(size, thickness, cb) {
|
|
2110
1802
|
thickness = thickness || 2;
|
|
2111
1803
|
var s = div$1(xyz2array(size), 2);
|
|
2112
1804
|
var r = add(s, thickness);
|
|
@@ -2120,7 +1812,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2120
1812
|
if (cb) box = cb(box);
|
|
2121
1813
|
return box;
|
|
2122
1814
|
};
|
|
2123
|
-
|
|
1815
|
+
const Hollow = function(object, thickness, interiorcb, exteriorcb) {
|
|
2124
1816
|
thickness = thickness || 2;
|
|
2125
1817
|
var size = -thickness * 2;
|
|
2126
1818
|
interiorcb = interiorcb || identity;
|
|
@@ -2128,7 +1820,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2128
1820
|
if (exteriorcb) box = exteriorcb(box);
|
|
2129
1821
|
return box;
|
|
2130
1822
|
};
|
|
2131
|
-
|
|
1823
|
+
const BBox = function(o) {
|
|
2132
1824
|
depreciated("BBox", true, "Use 'parts.BBox' instead");
|
|
2133
1825
|
var s = div$1(xyz2array(o.size()), 2);
|
|
2134
1826
|
return CSG.cube({
|
|
@@ -2139,8 +1831,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2139
1831
|
function getRadius(o) {
|
|
2140
1832
|
return div$1(xyz2array(o.size()), 2);
|
|
2141
1833
|
}
|
|
2142
|
-
function rabbetJoin(box, thickness) {
|
|
2143
|
-
var gap = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : .25;
|
|
1834
|
+
function rabbetJoin(box, thickness, gap = .25) {
|
|
2144
1835
|
var r = add(getRadius(box), -thickness / 2);
|
|
2145
1836
|
r[2] = thickness / 2;
|
|
2146
1837
|
var cutter = CSG.cube({
|
|
@@ -2158,16 +1849,17 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2158
1849
|
}
|
|
2159
1850
|
var Boxes = Object.freeze({
|
|
2160
1851
|
__proto__: null,
|
|
1852
|
+
BBox,
|
|
1853
|
+
CutOut,
|
|
1854
|
+
Hollow,
|
|
2161
1855
|
RabbetJoin,
|
|
2162
|
-
topMiddleBottom,
|
|
2163
1856
|
Rabett,
|
|
2164
1857
|
RabettTopBottom,
|
|
2165
|
-
CutOut,
|
|
2166
1858
|
Rectangle,
|
|
2167
|
-
|
|
2168
|
-
BBox
|
|
1859
|
+
topMiddleBottom
|
|
2169
1860
|
});
|
|
2170
|
-
|
|
1861
|
+
const compatV1 = {
|
|
1862
|
+
...util,
|
|
2171
1863
|
group: Group,
|
|
2172
1864
|
init: init$1,
|
|
2173
1865
|
triangle: triUtils,
|
|
@@ -2175,7 +1867,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2175
1867
|
parts: parts$1,
|
|
2176
1868
|
Boxes,
|
|
2177
1869
|
Debug
|
|
2178
|
-
}
|
|
1870
|
+
};
|
|
2179
1871
|
exports.Boxes = Boxes;
|
|
2180
1872
|
exports.Debug = Debug;
|
|
2181
1873
|
exports.Group = Group;
|
|
@@ -2185,9 +1877,6 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2185
1877
|
exports.parts = parts$1;
|
|
2186
1878
|
exports.triUtils = triUtils;
|
|
2187
1879
|
exports.util = util;
|
|
2188
|
-
Object.defineProperty(exports, "__esModule", {
|
|
2189
|
-
value: true
|
|
2190
|
-
});
|
|
2191
1880
|
return exports;
|
|
2192
1881
|
}({}, jsCadCSG, scadApi);
|
|
2193
1882
|
const debug = jscadUtils.Debug("jscadUtils:initJscadutils");
|