@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
|
@@ -101,329 +101,13 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
101
101
|
});
|
|
102
102
|
var jscadUtils = function(exports, jsCadCSG, scadApi) {
|
|
103
103
|
"use strict";
|
|
104
|
-
function
|
|
105
|
-
return e && typeof e === "object" && "default" in e ? e : {
|
|
106
|
-
default: e
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
var jsCadCSG__default = _interopDefaultLegacy(jsCadCSG);
|
|
110
|
-
var scadApi__default = _interopDefaultLegacy(scadApi);
|
|
111
|
-
var util = Object.freeze({
|
|
112
|
-
__proto__: null,
|
|
113
|
-
get NOZZEL_SIZE() {
|
|
114
|
-
return NOZZEL_SIZE;
|
|
115
|
-
},
|
|
116
|
-
get nearest() {
|
|
117
|
-
return nearest;
|
|
118
|
-
},
|
|
119
|
-
get identity() {
|
|
120
|
-
return identity;
|
|
121
|
-
},
|
|
122
|
-
get result() {
|
|
123
|
-
return result;
|
|
124
|
-
},
|
|
125
|
-
get defaults() {
|
|
126
|
-
return defaults;
|
|
127
|
-
},
|
|
128
|
-
get isEmpty() {
|
|
129
|
-
return isEmpty;
|
|
130
|
-
},
|
|
131
|
-
get isNegative() {
|
|
132
|
-
return isNegative;
|
|
133
|
-
},
|
|
134
|
-
get print() {
|
|
135
|
-
return print;
|
|
136
|
-
},
|
|
137
|
-
get jscadToString() {
|
|
138
|
-
return jscadToString;
|
|
139
|
-
},
|
|
140
|
-
get error() {
|
|
141
|
-
return error;
|
|
142
|
-
},
|
|
143
|
-
get depreciated() {
|
|
144
|
-
return depreciated;
|
|
145
|
-
},
|
|
146
|
-
get inch() {
|
|
147
|
-
return inch;
|
|
148
|
-
},
|
|
149
|
-
get cm() {
|
|
150
|
-
return cm;
|
|
151
|
-
},
|
|
152
|
-
get label() {
|
|
153
|
-
return label;
|
|
154
|
-
},
|
|
155
|
-
get text() {
|
|
156
|
-
return text;
|
|
157
|
-
},
|
|
158
|
-
get unitCube() {
|
|
159
|
-
return unitCube;
|
|
160
|
-
},
|
|
161
|
-
get unitAxis() {
|
|
162
|
-
return unitAxis;
|
|
163
|
-
},
|
|
164
|
-
get toArray() {
|
|
165
|
-
return toArray;
|
|
166
|
-
},
|
|
167
|
-
get ifArray() {
|
|
168
|
-
return ifArray;
|
|
169
|
-
},
|
|
170
|
-
get segment() {
|
|
171
|
-
return segment;
|
|
172
|
-
},
|
|
173
|
-
get zipObject() {
|
|
174
|
-
return zipObject;
|
|
175
|
-
},
|
|
176
|
-
get map() {
|
|
177
|
-
return map;
|
|
178
|
-
},
|
|
179
|
-
get mapValues() {
|
|
180
|
-
return mapValues;
|
|
181
|
-
},
|
|
182
|
-
get pick() {
|
|
183
|
-
return pick;
|
|
184
|
-
},
|
|
185
|
-
get mapPick() {
|
|
186
|
-
return mapPick;
|
|
187
|
-
},
|
|
188
|
-
get divA() {
|
|
189
|
-
return divA;
|
|
190
|
-
},
|
|
191
|
-
get divxyz() {
|
|
192
|
-
return divxyz;
|
|
193
|
-
},
|
|
194
|
-
get div() {
|
|
195
|
-
return div;
|
|
196
|
-
},
|
|
197
|
-
get mulxyz() {
|
|
198
|
-
return mulxyz;
|
|
199
|
-
},
|
|
200
|
-
get mul() {
|
|
201
|
-
return mul;
|
|
202
|
-
},
|
|
203
|
-
get xyz2array() {
|
|
204
|
-
return xyz2array;
|
|
205
|
-
},
|
|
206
|
-
get rotationAxes() {
|
|
207
|
-
return rotationAxes;
|
|
208
|
-
},
|
|
209
|
-
get size() {
|
|
210
|
-
return size;
|
|
211
|
-
},
|
|
212
|
-
get scale() {
|
|
213
|
-
return scale;
|
|
214
|
-
},
|
|
215
|
-
get center() {
|
|
216
|
-
return center;
|
|
217
|
-
},
|
|
218
|
-
get centerY() {
|
|
219
|
-
return centerY;
|
|
220
|
-
},
|
|
221
|
-
get centerX() {
|
|
222
|
-
return centerX;
|
|
223
|
-
},
|
|
224
|
-
get enlarge() {
|
|
225
|
-
return enlarge;
|
|
226
|
-
},
|
|
227
|
-
get fit() {
|
|
228
|
-
return fit;
|
|
229
|
-
},
|
|
230
|
-
get shift() {
|
|
231
|
-
return shift;
|
|
232
|
-
},
|
|
233
|
-
get zero() {
|
|
234
|
-
return zero;
|
|
235
|
-
},
|
|
236
|
-
get mirrored4() {
|
|
237
|
-
return mirrored4;
|
|
238
|
-
},
|
|
239
|
-
get flushSide() {
|
|
240
|
-
return flushSide;
|
|
241
|
-
},
|
|
242
|
-
get calcFlush() {
|
|
243
|
-
return calcFlush;
|
|
244
|
-
},
|
|
245
|
-
get calcSnap() {
|
|
246
|
-
return calcSnap;
|
|
247
|
-
},
|
|
248
|
-
get snap() {
|
|
249
|
-
return snap;
|
|
250
|
-
},
|
|
251
|
-
get flush() {
|
|
252
|
-
return flush;
|
|
253
|
-
},
|
|
254
|
-
get axisApply() {
|
|
255
|
-
return axisApply;
|
|
256
|
-
},
|
|
257
|
-
get axis2array() {
|
|
258
|
-
return axis2array;
|
|
259
|
-
},
|
|
260
|
-
get centroid() {
|
|
261
|
-
return centroid;
|
|
262
|
-
},
|
|
263
|
-
get calcmidlineTo() {
|
|
264
|
-
return calcmidlineTo;
|
|
265
|
-
},
|
|
266
|
-
get midlineTo() {
|
|
267
|
-
return midlineTo;
|
|
268
|
-
},
|
|
269
|
-
get translator() {
|
|
270
|
-
return translator;
|
|
271
|
-
},
|
|
272
|
-
get calcCenterWith() {
|
|
273
|
-
return calcCenterWith;
|
|
274
|
-
},
|
|
275
|
-
get centerWith() {
|
|
276
|
-
return centerWith;
|
|
277
|
-
},
|
|
278
|
-
get getDelta() {
|
|
279
|
-
return getDelta;
|
|
280
|
-
},
|
|
281
|
-
get bisect() {
|
|
282
|
-
return bisect;
|
|
283
|
-
},
|
|
284
|
-
get slice() {
|
|
285
|
-
return slice;
|
|
286
|
-
},
|
|
287
|
-
get wedge() {
|
|
288
|
-
return wedge;
|
|
289
|
-
},
|
|
290
|
-
get stretch() {
|
|
291
|
-
return stretch;
|
|
292
|
-
},
|
|
293
|
-
get poly2solid() {
|
|
294
|
-
return poly2solid;
|
|
295
|
-
},
|
|
296
|
-
get slices2poly() {
|
|
297
|
-
return slices2poly;
|
|
298
|
-
},
|
|
299
|
-
get normalVector() {
|
|
300
|
-
return normalVector;
|
|
301
|
-
},
|
|
302
|
-
get sliceParams() {
|
|
303
|
-
return sliceParams;
|
|
304
|
-
},
|
|
305
|
-
get reShape() {
|
|
306
|
-
return reShape;
|
|
307
|
-
},
|
|
308
|
-
get chamfer() {
|
|
309
|
-
return chamfer;
|
|
310
|
-
},
|
|
311
|
-
get fillet() {
|
|
312
|
-
return fillet;
|
|
313
|
-
},
|
|
314
|
-
get calcRotate() {
|
|
315
|
-
return calcRotate;
|
|
316
|
-
},
|
|
317
|
-
get rotateAround() {
|
|
318
|
-
return rotateAround;
|
|
319
|
-
},
|
|
320
|
-
get clone() {
|
|
321
|
-
return clone;
|
|
322
|
-
},
|
|
323
|
-
get addConnector() {
|
|
324
|
-
return addConnector;
|
|
325
|
-
}
|
|
326
|
-
});
|
|
327
|
-
function _arrayLikeToArray(r, a) {
|
|
328
|
-
(null == a || a > r.length) && (a = r.length);
|
|
329
|
-
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
330
|
-
return n;
|
|
331
|
-
}
|
|
332
|
-
function _arrayWithHoles(r) {
|
|
333
|
-
if (Array.isArray(r)) return r;
|
|
334
|
-
}
|
|
335
|
-
function _defineProperty(e, r, t) {
|
|
336
|
-
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
337
|
-
value: t,
|
|
338
|
-
enumerable: !0,
|
|
339
|
-
configurable: !0,
|
|
340
|
-
writable: !0
|
|
341
|
-
}) : e[r] = t, e;
|
|
342
|
-
}
|
|
343
|
-
function _iterableToArrayLimit(r, l) {
|
|
344
|
-
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
345
|
-
if (null != t) {
|
|
346
|
-
var e, n, i, u, a = [], f = !0, o = !1;
|
|
347
|
-
try {
|
|
348
|
-
if (i = (t = t.call(r)).next, 0 === l) {
|
|
349
|
-
if (Object(t) !== t) return;
|
|
350
|
-
f = !1;
|
|
351
|
-
} else for (;!(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0) ;
|
|
352
|
-
} catch (r) {
|
|
353
|
-
o = !0, n = r;
|
|
354
|
-
} finally {
|
|
355
|
-
try {
|
|
356
|
-
if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
|
|
357
|
-
} finally {
|
|
358
|
-
if (o) throw n;
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
return a;
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
function _nonIterableRest() {
|
|
365
|
-
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
366
|
-
}
|
|
367
|
-
function ownKeys(e, r) {
|
|
368
|
-
var t = Object.keys(e);
|
|
369
|
-
if (Object.getOwnPropertySymbols) {
|
|
370
|
-
var o = Object.getOwnPropertySymbols(e);
|
|
371
|
-
r && (o = o.filter(function(r) {
|
|
372
|
-
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
373
|
-
})), t.push.apply(t, o);
|
|
374
|
-
}
|
|
375
|
-
return t;
|
|
376
|
-
}
|
|
377
|
-
function _objectSpread2(e) {
|
|
378
|
-
for (var r = 1; r < arguments.length; r++) {
|
|
379
|
-
var t = null != arguments[r] ? arguments[r] : {};
|
|
380
|
-
r % 2 ? ownKeys(Object(t), !0).forEach(function(r) {
|
|
381
|
-
_defineProperty(e, r, t[r]);
|
|
382
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r) {
|
|
383
|
-
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
384
|
-
});
|
|
385
|
-
}
|
|
386
|
-
return e;
|
|
387
|
-
}
|
|
388
|
-
function _slicedToArray(r, e) {
|
|
389
|
-
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
|
|
390
|
-
}
|
|
391
|
-
function _toPrimitive(t, r) {
|
|
392
|
-
if ("object" != typeof t || !t) return t;
|
|
393
|
-
var e = t[Symbol.toPrimitive];
|
|
394
|
-
if (void 0 !== e) {
|
|
395
|
-
var i = e.call(t, r || "default");
|
|
396
|
-
if ("object" != typeof i) return i;
|
|
397
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
398
|
-
}
|
|
399
|
-
return ("string" === r ? String : Number)(t);
|
|
400
|
-
}
|
|
401
|
-
function _toPropertyKey(t) {
|
|
402
|
-
var i = _toPrimitive(t, "string");
|
|
403
|
-
return "symbol" == typeof i ? i : i + "";
|
|
404
|
-
}
|
|
405
|
-
function _typeof(o) {
|
|
406
|
-
"@babel/helpers - typeof";
|
|
407
|
-
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
408
|
-
return typeof o;
|
|
409
|
-
} : function(o) {
|
|
410
|
-
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
411
|
-
}, _typeof(o);
|
|
412
|
-
}
|
|
413
|
-
function _unsupportedIterableToArray(r, a) {
|
|
414
|
-
if (r) {
|
|
415
|
-
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
416
|
-
var t = {}.toString.call(r).slice(8, -1);
|
|
417
|
-
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;
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
var toRadians = function toRadians(deg) {
|
|
104
|
+
const toRadians = function toRadians(deg) {
|
|
421
105
|
return deg / 180 * Math.PI;
|
|
422
106
|
};
|
|
423
|
-
|
|
107
|
+
const toDegrees = function toDegrees(rad) {
|
|
424
108
|
return rad * (180 / Math.PI);
|
|
425
109
|
};
|
|
426
|
-
|
|
110
|
+
const solve = function(p1, p2) {
|
|
427
111
|
var r = {
|
|
428
112
|
c: 90,
|
|
429
113
|
A: Math.abs(p2.x - p1.x),
|
|
@@ -435,7 +119,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
435
119
|
r.a = 90 - r.b;
|
|
436
120
|
return r;
|
|
437
121
|
};
|
|
438
|
-
|
|
122
|
+
const solve90SA = function(r) {
|
|
439
123
|
r = Object.assign(r, {
|
|
440
124
|
C: 90
|
|
441
125
|
});
|
|
@@ -447,7 +131,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
447
131
|
r.b = r.b || r.a / Math.tan(arad);
|
|
448
132
|
return r;
|
|
449
133
|
};
|
|
450
|
-
|
|
134
|
+
const solve90ac = function(r) {
|
|
451
135
|
r = Object.assign(r, {
|
|
452
136
|
C: 90
|
|
453
137
|
});
|
|
@@ -468,29 +152,29 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
468
152
|
}
|
|
469
153
|
var triUtils = Object.freeze({
|
|
470
154
|
__proto__: null,
|
|
471
|
-
toRadians,
|
|
472
|
-
toDegrees,
|
|
473
155
|
solve,
|
|
474
156
|
solve90SA,
|
|
475
157
|
solve90ac,
|
|
476
|
-
solveab
|
|
158
|
+
solveab,
|
|
159
|
+
toDegrees,
|
|
160
|
+
toRadians
|
|
477
161
|
});
|
|
478
|
-
|
|
162
|
+
const div$1 = function(a, f) {
|
|
479
163
|
return a.map(function(e) {
|
|
480
164
|
return e / f;
|
|
481
165
|
});
|
|
482
166
|
};
|
|
483
|
-
|
|
167
|
+
const addValue = function(a, f) {
|
|
484
168
|
return a.map(function(e) {
|
|
485
169
|
return e + f;
|
|
486
170
|
});
|
|
487
171
|
};
|
|
488
|
-
|
|
172
|
+
const addArray = function(a, f) {
|
|
489
173
|
return a.map(function(e, i) {
|
|
490
174
|
return e + f[i];
|
|
491
175
|
});
|
|
492
176
|
};
|
|
493
|
-
|
|
177
|
+
const add = function(a) {
|
|
494
178
|
return Array.prototype.slice.call(arguments, 1).reduce(function(result, arg) {
|
|
495
179
|
if (Array.isArray(arg)) {
|
|
496
180
|
result = addArray(result, arg);
|
|
@@ -500,28 +184,28 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
500
184
|
return result;
|
|
501
185
|
}, a);
|
|
502
186
|
};
|
|
503
|
-
|
|
187
|
+
const fromxyz = function(object) {
|
|
504
188
|
return Array.isArray(object) ? object : [ object.x, object.y, object.z ];
|
|
505
189
|
};
|
|
506
|
-
|
|
190
|
+
const toxyz = function(a) {
|
|
507
191
|
return {
|
|
508
192
|
x: a[0],
|
|
509
193
|
y: a[1],
|
|
510
194
|
z: a[2]
|
|
511
195
|
};
|
|
512
196
|
};
|
|
513
|
-
|
|
197
|
+
const first = function(a) {
|
|
514
198
|
return a ? a[0] : undefined;
|
|
515
199
|
};
|
|
516
|
-
|
|
200
|
+
const last = function(a) {
|
|
517
201
|
return a && a.length > 0 ? a[a.length - 1] : undefined;
|
|
518
202
|
};
|
|
519
|
-
|
|
203
|
+
const min = function(a) {
|
|
520
204
|
return a.reduce(function(result, value) {
|
|
521
205
|
return value < result ? value : result;
|
|
522
206
|
}, Number.MAX_VALUE);
|
|
523
207
|
};
|
|
524
|
-
|
|
208
|
+
const range = function(a, b) {
|
|
525
209
|
var result = [];
|
|
526
210
|
for (var i = a; i < b; i++) {
|
|
527
211
|
result.push(i);
|
|
@@ -530,21 +214,21 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
530
214
|
};
|
|
531
215
|
var array = Object.freeze({
|
|
532
216
|
__proto__: null,
|
|
533
|
-
div: div$1,
|
|
534
|
-
addValue,
|
|
535
|
-
addArray,
|
|
536
217
|
add,
|
|
537
|
-
|
|
538
|
-
|
|
218
|
+
addArray,
|
|
219
|
+
addValue,
|
|
220
|
+
div: div$1,
|
|
539
221
|
first,
|
|
222
|
+
fromxyz,
|
|
540
223
|
last,
|
|
541
224
|
min,
|
|
542
|
-
range
|
|
225
|
+
range,
|
|
226
|
+
toxyz
|
|
543
227
|
});
|
|
544
|
-
|
|
545
|
-
|
|
228
|
+
const debugColors = [ "#e41a1c", "#377eb8", "#4daf4a", "#984ea3", "#ff7f00", "#ffff33", "#a65628", "#f781bf", "#999999" ];
|
|
229
|
+
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" ];
|
|
546
230
|
var debugCount = 0;
|
|
547
|
-
|
|
231
|
+
const Debug = function(name) {
|
|
548
232
|
var checks = Object.assign({
|
|
549
233
|
enabled: [],
|
|
550
234
|
disabled: [],
|
|
@@ -552,31 +236,21 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
552
236
|
browser: true
|
|
553
237
|
}
|
|
554
238
|
}, jscadUtilsDebug || {});
|
|
555
|
-
var style = checks.options.browser ?
|
|
239
|
+
var style = checks.options.browser ? `color:${debugColors[debugCount++ % debugColors.length]}` : `${termColors[debugCount++ % termColors.length]}`;
|
|
556
240
|
var enabled = checks.enabled.some(function checkEnabled(check) {
|
|
557
241
|
return check.test(name);
|
|
558
242
|
}) && !checks.disabled.some(function checkEnabled(check) {
|
|
559
243
|
return check.test(name);
|
|
560
244
|
});
|
|
561
|
-
var logger = enabled ? checks.options.browser ?
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
(_console = console).log.apply(_console, [ "%c%s", style, name ].concat(msg));
|
|
567
|
-
} : function() {
|
|
568
|
-
var _console2;
|
|
569
|
-
for (var _len2 = arguments.length, msg = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
570
|
-
msg[_key2] = arguments[_key2];
|
|
571
|
-
}
|
|
572
|
-
(_console2 = console).log.apply(_console2, [ "".concat(name) ].concat(msg));
|
|
573
|
-
} : function() {
|
|
574
|
-
return undefined;
|
|
575
|
-
};
|
|
245
|
+
var logger = enabled ? checks.options.browser ? (...msg) => {
|
|
246
|
+
console.log("%c%s", style, name, ...msg);
|
|
247
|
+
} : (...msg) => {
|
|
248
|
+
console.log(`${name}`, ...msg);
|
|
249
|
+
} : () => undefined;
|
|
576
250
|
logger.enabled = enabled;
|
|
577
251
|
return logger;
|
|
578
252
|
};
|
|
579
|
-
|
|
253
|
+
const nameArray = {
|
|
580
254
|
aliceblue: "#f0f8ff",
|
|
581
255
|
antiquewhite: "#faebd7",
|
|
582
256
|
aqua: "#00ffff",
|
|
@@ -734,9 +408,11 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
734
408
|
h = h.replace(/^\#/, "");
|
|
735
409
|
if (h.length === 6) {
|
|
736
410
|
return [ parseInt(h.substr(0, 2), 16), parseInt(h.substr(2, 2), 16), parseInt(h.substr(4, 2), 16) ];
|
|
411
|
+
} else {
|
|
412
|
+
return [ 0, 0, 0 ];
|
|
737
413
|
}
|
|
738
414
|
}
|
|
739
|
-
|
|
415
|
+
const _name2rgb = {};
|
|
740
416
|
function name2rgb(n) {
|
|
741
417
|
if (!_name2rgb[n]) _name2rgb[n] = hex2rgb(name2hex(n));
|
|
742
418
|
return _name2rgb[n];
|
|
@@ -816,23 +492,14 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
816
492
|
proto.prototype.chamfer = function chamfer$1(radius, orientation, options) {
|
|
817
493
|
return chamfer(this, radius, orientation, options);
|
|
818
494
|
};
|
|
819
|
-
proto.prototype.bisect = function bisect$1() {
|
|
820
|
-
|
|
821
|
-
args[_key] = arguments[_key];
|
|
822
|
-
}
|
|
823
|
-
return bisect.apply(util, [ this ].concat(args));
|
|
495
|
+
proto.prototype.bisect = function bisect$1(...args) {
|
|
496
|
+
return bisect(this, ...args);
|
|
824
497
|
};
|
|
825
|
-
proto.prototype.slice = function slice$1() {
|
|
826
|
-
|
|
827
|
-
args[_key2] = arguments[_key2];
|
|
828
|
-
}
|
|
829
|
-
return slice.apply(util, [ this ].concat(args));
|
|
498
|
+
proto.prototype.slice = function slice$1(...args) {
|
|
499
|
+
return slice(this, ...args);
|
|
830
500
|
};
|
|
831
|
-
proto.prototype.wedge = function wedge$1() {
|
|
832
|
-
|
|
833
|
-
args[_key3] = arguments[_key3];
|
|
834
|
-
}
|
|
835
|
-
return wedge.apply(util, [ this ].concat(args));
|
|
501
|
+
proto.prototype.wedge = function wedge$1(...args) {
|
|
502
|
+
return wedge(this, ...args);
|
|
836
503
|
};
|
|
837
504
|
proto.prototype.stretch = function stretch$1(axis, distance, offset) {
|
|
838
505
|
return stretch(this, axis, distance, offset);
|
|
@@ -849,7 +516,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
849
516
|
return this._translate(arguments[0]);
|
|
850
517
|
} else {
|
|
851
518
|
var t = Array.prototype.slice.call(arguments, 0).reduce(function(result, arg) {
|
|
852
|
-
result = undefined(result, arg);
|
|
519
|
+
result = undefined.addArray(result, arg);
|
|
853
520
|
return result;
|
|
854
521
|
}, [ 0, 0, 0 ]);
|
|
855
522
|
return this._translate(t);
|
|
@@ -858,14 +525,10 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
858
525
|
proto.prototype.addConnector = function addConnector$1(name, point, axis, normal) {
|
|
859
526
|
return addConnector(this, name, point, axis, normal);
|
|
860
527
|
};
|
|
861
|
-
proto.prototype.connect = function connectTo(myConnectorName, otherConnector) {
|
|
862
|
-
var
|
|
863
|
-
var normalrotation = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
864
|
-
var myConnector = myConnectorName.split(".").reduce(function(a, v) {
|
|
865
|
-
return a[v];
|
|
866
|
-
}, this.properties);
|
|
528
|
+
proto.prototype.connect = function connectTo(myConnectorName, otherConnector, mirror = false, normalrotation = 0) {
|
|
529
|
+
var myConnector = myConnectorName.split(".").reduce((a, v) => a[v], this.properties);
|
|
867
530
|
if (!myConnector) {
|
|
868
|
-
error(
|
|
531
|
+
error(`The connector '${myConnectorName}' does not exist on the object [${Object.keys(this.properties).join(",")}]`, "Missing connector property");
|
|
869
532
|
}
|
|
870
533
|
return this.connectTo(myConnector, otherConnector, mirror, normalrotation);
|
|
871
534
|
};
|
|
@@ -875,16 +538,13 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
875
538
|
__proto__: null,
|
|
876
539
|
default: init
|
|
877
540
|
});
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
541
|
+
const {CSG, CAG} = jsCadCSG;
|
|
542
|
+
const {rectangular_extrude} = scadApi.extrusions;
|
|
543
|
+
const {vector_text, vector_char} = scadApi.text;
|
|
544
|
+
const {union} = scadApi.booleanOps;
|
|
882
545
|
init(CSG);
|
|
883
|
-
|
|
884
|
-
function JsCadUtilsGroup() {
|
|
885
|
-
var names = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
886
|
-
var parts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
887
|
-
var holes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
546
|
+
const debug$3 = Debug("jscadUtils:group");
|
|
547
|
+
function JsCadUtilsGroup(names = [], parts = {}, holes = []) {
|
|
888
548
|
this.name = "";
|
|
889
549
|
this.names = names;
|
|
890
550
|
this.parts = parts;
|
|
@@ -912,11 +572,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
912
572
|
}
|
|
913
573
|
return self;
|
|
914
574
|
};
|
|
915
|
-
JsCadUtilsGroup.prototype.combine = function(pieces) {
|
|
916
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
917
|
-
var map = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function(x) {
|
|
918
|
-
return x;
|
|
919
|
-
};
|
|
575
|
+
JsCadUtilsGroup.prototype.combine = function(pieces, options = {}, map = x => x) {
|
|
920
576
|
try {
|
|
921
577
|
var self = this;
|
|
922
578
|
options = Object.assign({
|
|
@@ -924,7 +580,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
924
580
|
}, options);
|
|
925
581
|
pieces = pieces ? pieces.split(",") : self.names;
|
|
926
582
|
if (pieces.length === 0) {
|
|
927
|
-
throw new Error(
|
|
583
|
+
throw new Error(`no pieces found in ${self.name} pieces: ${pieces} parts: ${Object.keys(self.parts)} names: ${self.names}`);
|
|
928
584
|
}
|
|
929
585
|
debug$3("combine", self.names, self.parts);
|
|
930
586
|
var g = union(mapPick(self.parts, pieces, function(value, key, index, object) {
|
|
@@ -934,14 +590,12 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
934
590
|
return g.subtractIf(self.holes && Array.isArray(self.holes) ? union(self.holes) : self.holes, self.holes && !options.noholes);
|
|
935
591
|
} catch (err) {
|
|
936
592
|
debug$3("combine error", this, pieces, options, err);
|
|
937
|
-
throw error(
|
|
593
|
+
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");
|
|
938
594
|
}
|
|
939
595
|
};
|
|
940
596
|
JsCadUtilsGroup.prototype.map = function(cb) {
|
|
941
597
|
var self = this;
|
|
942
|
-
self.parts = Object.keys(self.parts).filter(function(
|
|
943
|
-
return k !== "holes";
|
|
944
|
-
}).reduce(function(result, key) {
|
|
598
|
+
self.parts = Object.keys(self.parts).filter(k => k !== "holes").reduce(function(result, key) {
|
|
945
599
|
result[key] = cb(self.parts[key], key);
|
|
946
600
|
return result;
|
|
947
601
|
}, {});
|
|
@@ -957,7 +611,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
957
611
|
return self;
|
|
958
612
|
};
|
|
959
613
|
JsCadUtilsGroup.prototype.clone = function(name, map) {
|
|
960
|
-
debug$3("clone", name,
|
|
614
|
+
debug$3("clone", name, typeof name, map);
|
|
961
615
|
var self = this;
|
|
962
616
|
if (typeof name == "function") {
|
|
963
617
|
map = name;
|
|
@@ -1009,7 +663,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1009
663
|
return self;
|
|
1010
664
|
} catch (err) {
|
|
1011
665
|
debug$3("snap error", this, part, to, axis, delta, err);
|
|
1012
|
-
throw error(
|
|
666
|
+
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");
|
|
1013
667
|
}
|
|
1014
668
|
};
|
|
1015
669
|
JsCadUtilsGroup.prototype.align = function align(part, to, axis, delta) {
|
|
@@ -1024,7 +678,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1024
678
|
return self;
|
|
1025
679
|
} catch (err) {
|
|
1026
680
|
debug$3("align error", this, part, to, axis, delta, err);
|
|
1027
|
-
throw error(
|
|
681
|
+
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");
|
|
1028
682
|
}
|
|
1029
683
|
};
|
|
1030
684
|
JsCadUtilsGroup.prototype.center = function center(part) {
|
|
@@ -1036,9 +690,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1036
690
|
var bounds = self.parts[part].getBounds();
|
|
1037
691
|
return self.translate([ 0, 0, -bounds[0].z ]);
|
|
1038
692
|
};
|
|
1039
|
-
JsCadUtilsGroup.prototype.connectTo = function connectTo(partName, connectorName, to, toConnectorName) {
|
|
1040
|
-
var mirror = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
|
|
1041
|
-
var normalrotation = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 0;
|
|
693
|
+
JsCadUtilsGroup.prototype.connectTo = function connectTo(partName, connectorName, to, toConnectorName, mirror = true, normalrotation = 0) {
|
|
1042
694
|
debug$3("connectTo", {
|
|
1043
695
|
partName,
|
|
1044
696
|
connectorName,
|
|
@@ -1048,13 +700,9 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1048
700
|
normalrotation
|
|
1049
701
|
});
|
|
1050
702
|
var self = this;
|
|
1051
|
-
var myConnector = connectorName.split(".").reduce(
|
|
1052
|
-
return a[v];
|
|
1053
|
-
}, self.parts[partName].properties);
|
|
703
|
+
var myConnector = connectorName.split(".").reduce((a, v) => a[v], self.parts[partName].properties);
|
|
1054
704
|
debug$3("toConnector", to instanceof CSG.Connector);
|
|
1055
|
-
var toConnector = toConnectorName.split(".").reduce(
|
|
1056
|
-
return a[v];
|
|
1057
|
-
}, to.properties);
|
|
705
|
+
var toConnector = toConnectorName.split(".").reduce((a, v) => a[v], to.properties);
|
|
1058
706
|
var matrix = myConnector.getTransformationTo(toConnector, mirror, normalrotation);
|
|
1059
707
|
debug$3("connectTo", matrix);
|
|
1060
708
|
self.map(function(part) {
|
|
@@ -1093,15 +741,14 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1093
741
|
return g;
|
|
1094
742
|
};
|
|
1095
743
|
JsCadUtilsGroup.prototype.array = function(parts, map) {
|
|
1096
|
-
var _this = this;
|
|
1097
744
|
var self = this;
|
|
1098
745
|
var p = parts && parts.length > 0 && parts.split(",") || self.names;
|
|
1099
746
|
if (!map) map = identity;
|
|
1100
747
|
var a = [];
|
|
1101
|
-
p.forEach(
|
|
748
|
+
p.forEach(name => {
|
|
1102
749
|
if (!self.parts[name]) {
|
|
1103
|
-
debug$3("array error",
|
|
1104
|
-
throw error(
|
|
750
|
+
debug$3("array error", this, parts);
|
|
751
|
+
throw error(`group::array error "${name}" not found.\nthis: ${this}\nparts: "${parts}"\n`, "JSCAD_UTILS_GROUP_ERROR");
|
|
1105
752
|
}
|
|
1106
753
|
a.push(map(CSG.fromPolygons(self.parts[name].toPolygons()), name));
|
|
1107
754
|
});
|
|
@@ -1111,12 +758,12 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1111
758
|
var self = this;
|
|
1112
759
|
var piecesArray = pieces ? pieces.split(",") : self.names;
|
|
1113
760
|
return piecesArray.map(function(piece) {
|
|
1114
|
-
if (!self.parts[piece]) console.error(
|
|
761
|
+
if (!self.parts[piece]) console.error(`Cannot find ${piece} in ${self.names}`);
|
|
1115
762
|
return self.parts[piece];
|
|
1116
763
|
});
|
|
1117
764
|
};
|
|
1118
765
|
JsCadUtilsGroup.prototype.toString = function() {
|
|
1119
|
-
return
|
|
766
|
+
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}`;
|
|
1120
767
|
};
|
|
1121
768
|
JsCadUtilsGroup.prototype.setName = function(name) {
|
|
1122
769
|
this.name = name;
|
|
@@ -1146,9 +793,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1146
793
|
self.name = objectNames;
|
|
1147
794
|
} else {
|
|
1148
795
|
var objects = objectNames;
|
|
1149
|
-
self.names = Object.keys(objects).filter(
|
|
1150
|
-
return k !== "holes";
|
|
1151
|
-
});
|
|
796
|
+
self.names = Object.keys(objects).filter(k => k !== "holes");
|
|
1152
797
|
self.parts = Object.assign({}, objects);
|
|
1153
798
|
self.holes = objects.holes;
|
|
1154
799
|
}
|
|
@@ -1156,17 +801,13 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1156
801
|
}
|
|
1157
802
|
return new JsCadUtilsGroup(self.names, self.parts, self.holes);
|
|
1158
803
|
}
|
|
1159
|
-
|
|
804
|
+
const debug$2 = Debug("jscadUtils:util");
|
|
1160
805
|
var NOZZEL_SIZE = .4;
|
|
1161
|
-
|
|
1162
|
-
under: function
|
|
1163
|
-
var nozzel = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : NOZZEL_SIZE;
|
|
1164
|
-
var nozzie = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
806
|
+
const nearest = {
|
|
807
|
+
under: function(desired, nozzel = NOZZEL_SIZE, nozzie = 0) {
|
|
1165
808
|
return (Math.floor(desired / nozzel) + nozzie) * nozzel;
|
|
1166
809
|
},
|
|
1167
|
-
over: function
|
|
1168
|
-
var nozzel = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : NOZZEL_SIZE;
|
|
1169
|
-
var nozzie = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
810
|
+
over: function(desired, nozzel = NOZZEL_SIZE, nozzie = 0) {
|
|
1170
811
|
return (Math.ceil(desired / nozzel) + nozzie) * nozzel;
|
|
1171
812
|
}
|
|
1172
813
|
};
|
|
@@ -1194,9 +835,9 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1194
835
|
debug$2(msg, JSON.stringify(o.getBounds()), JSON.stringify(this.size(o.getBounds())));
|
|
1195
836
|
}
|
|
1196
837
|
function jscadToString(o) {
|
|
1197
|
-
if (
|
|
838
|
+
if (typeof o == "object") {
|
|
1198
839
|
if (o.polygons) {
|
|
1199
|
-
return
|
|
840
|
+
return `{\npolygons: ${o.polygons.length},\nproperties: "${Object.keys(o.properties)}"\n}\n`;
|
|
1200
841
|
}
|
|
1201
842
|
} else {
|
|
1202
843
|
return o.toString();
|
|
@@ -1237,12 +878,12 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1237
878
|
}
|
|
1238
879
|
function text(text) {
|
|
1239
880
|
var l = vector_char(0, 0, text);
|
|
1240
|
-
var
|
|
881
|
+
var char = l.segments.reduce(function(result, segment) {
|
|
1241
882
|
var path = new CSG.Path2D(segment);
|
|
1242
883
|
var cag = path.expandToCAG(2);
|
|
1243
884
|
return result ? result.union(cag) : cag;
|
|
1244
885
|
}, undefined);
|
|
1245
|
-
return
|
|
886
|
+
return char;
|
|
1246
887
|
}
|
|
1247
888
|
function unitCube(length, radius) {
|
|
1248
889
|
radius = radius || .5;
|
|
@@ -1298,7 +939,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1298
939
|
function mapPick(o, names, f, options) {
|
|
1299
940
|
return names.reduce(function(result, name, index) {
|
|
1300
941
|
if (!o[name]) {
|
|
1301
|
-
throw new Error(
|
|
942
|
+
throw new Error(`${name} not found in ${options.name}: ${Object.keys(o).join(",")}`);
|
|
1302
943
|
}
|
|
1303
944
|
result.push(f ? f(o[name], name, index, o) : o[name]);
|
|
1304
945
|
return result;
|
|
@@ -1330,7 +971,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1330
971
|
function xyz2array(size) {
|
|
1331
972
|
return [ size.x, size.y, size.z ];
|
|
1332
973
|
}
|
|
1333
|
-
|
|
974
|
+
const rotationAxes = {
|
|
1334
975
|
x: [ 1, 0, 0 ],
|
|
1335
976
|
y: [ 0, 1, 0 ],
|
|
1336
977
|
z: [ 0, 0, 1 ]
|
|
@@ -1408,7 +1049,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1408
1049
|
function mirrored4(x) {
|
|
1409
1050
|
return x.union([ x.mirroredY(90), x.mirroredX(90), x.mirroredY(90).mirroredX(90) ]);
|
|
1410
1051
|
}
|
|
1411
|
-
|
|
1052
|
+
const flushSide = {
|
|
1412
1053
|
"above-outside": [ 1, 0 ],
|
|
1413
1054
|
"above-inside": [ 1, 1 ],
|
|
1414
1055
|
"below-outside": [ 0, 1 ],
|
|
@@ -1438,8 +1079,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1438
1079
|
return w[side[0]][axis] - m[side[1]][axis];
|
|
1439
1080
|
});
|
|
1440
1081
|
}
|
|
1441
|
-
function calcSnap(moveobj, withobj, axes, orientation) {
|
|
1442
|
-
var delta = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
|
|
1082
|
+
function calcSnap(moveobj, withobj, axes, orientation, delta = 0) {
|
|
1443
1083
|
var side = flushSide[orientation];
|
|
1444
1084
|
if (!side) {
|
|
1445
1085
|
var fix = {
|
|
@@ -1505,7 +1145,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1505
1145
|
objectSize = objectSize || size(bounds);
|
|
1506
1146
|
return bounds[0].plus(objectSize.dividedBy(2));
|
|
1507
1147
|
} catch (err) {
|
|
1508
|
-
error(
|
|
1148
|
+
error(`centroid error o:${jscadToString(o)} objectSize: ${objectSize}`, undefined, err);
|
|
1509
1149
|
}
|
|
1510
1150
|
}
|
|
1511
1151
|
function calcmidlineTo(o, axis, to) {
|
|
@@ -1526,8 +1166,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1526
1166
|
});
|
|
1527
1167
|
return t;
|
|
1528
1168
|
}
|
|
1529
|
-
function calcCenterWith(o, axes, withObj) {
|
|
1530
|
-
var delta = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
1169
|
+
function calcCenterWith(o, axes, withObj, delta = 0) {
|
|
1531
1170
|
var objectCentroid = centroid(o);
|
|
1532
1171
|
var withCentroid = centroid(withObj);
|
|
1533
1172
|
var t = axisApply(axes, function(i, axis) {
|
|
@@ -1549,12 +1188,9 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1549
1188
|
return bounds[0][a] + (isEmpty(dist) ? size[axis] / 2 : dist);
|
|
1550
1189
|
});
|
|
1551
1190
|
}
|
|
1552
|
-
function bisect() {
|
|
1553
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1554
|
-
args[_key] = arguments[_key];
|
|
1555
|
-
}
|
|
1191
|
+
function bisect(...args) {
|
|
1556
1192
|
if (args.length < 2) {
|
|
1557
|
-
error("bisect
|
|
1193
|
+
error("bisect requires an object and an axis", "JSCAD_UTILS_INVALID_ARGS");
|
|
1558
1194
|
}
|
|
1559
1195
|
var object = args[0];
|
|
1560
1196
|
var axis = args[1];
|
|
@@ -1633,14 +1269,10 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1633
1269
|
if (options.addRotationCenter) g.add(unitAxis(objectSize.length() + 10, .1, rotationCenter), "rotationCenter");
|
|
1634
1270
|
return g;
|
|
1635
1271
|
}
|
|
1636
|
-
function slice(object
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {
|
|
1641
|
-
color: true,
|
|
1642
|
-
addRotationCenter: true
|
|
1643
|
-
};
|
|
1272
|
+
function slice(object, angle = 15, axis = "x", rotateaxis = "z", options = {
|
|
1273
|
+
color: true,
|
|
1274
|
+
addRotationCenter: true
|
|
1275
|
+
}) {
|
|
1644
1276
|
var info = normalVector(axis);
|
|
1645
1277
|
var rotationCenter = options.rotationCenter || new CSG.Vector3D(0, 0, 0);
|
|
1646
1278
|
var theRotationAxis = rotationAxes[rotateaxis];
|
|
@@ -1796,7 +1428,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1796
1428
|
var absoluteRadius = Math.abs(radius);
|
|
1797
1429
|
var si = sliceParams(orientation, radius, b);
|
|
1798
1430
|
debug$2("reShape", absoluteRadius, si);
|
|
1799
|
-
if (si.axis !== "z") throw new Error('reShape error: CAG.
|
|
1431
|
+
if (si.axis !== "z") throw new Error('reShape error: CAG._toPlanePolygons only uses the "z" axis. You must use the "z" axis for now.');
|
|
1800
1432
|
var cutplane = CSG.OrthoNormalBasis.GetCartesian(si.orthoNormalCartesian[0], si.orthoNormalCartesian[1]).translate(si.cutDelta);
|
|
1801
1433
|
var slice = object.sectionCut(cutplane);
|
|
1802
1434
|
var first = axisApply(si.axis, function() {
|
|
@@ -1857,12 +1489,11 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1857
1489
|
};
|
|
1858
1490
|
}
|
|
1859
1491
|
function rotateAround(part, solid, axis, angle) {
|
|
1860
|
-
var
|
|
1492
|
+
var {rotationCenter, rotationAxis} = calcRotate(part, solid, axis);
|
|
1861
1493
|
return part.rotate(rotationCenter, rotationAxis, angle);
|
|
1862
1494
|
}
|
|
1863
|
-
function cloneProperties(from, to) {
|
|
1864
|
-
return Object.entries(from).reduce(
|
|
1865
|
-
var _ref2 = _slicedToArray(_ref, 2), key = _ref2[0], value = _ref2[1];
|
|
1495
|
+
function cloneProperties(from, to, depth = 0) {
|
|
1496
|
+
return Object.entries(from).reduce((props, [key, value]) => {
|
|
1866
1497
|
props[key] = value;
|
|
1867
1498
|
return props;
|
|
1868
1499
|
}, to);
|
|
@@ -1873,14 +1504,85 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1873
1504
|
debug$2("clone", o, c, CSG);
|
|
1874
1505
|
return c;
|
|
1875
1506
|
}
|
|
1876
|
-
function addConnector(object, name) {
|
|
1877
|
-
var point = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [ 0, 0, 0 ];
|
|
1878
|
-
var axis = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [ 1, 0, 0 ];
|
|
1879
|
-
var normal = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [ 0, 0, 1 ];
|
|
1507
|
+
function addConnector(object, name, point = [ 0, 0, 0 ], axis = [ 1, 0, 0 ], normal = [ 0, 0, 1 ]) {
|
|
1880
1508
|
object.properties[name] = new CSG.Connector(point, axis, normal);
|
|
1881
1509
|
return object;
|
|
1882
1510
|
}
|
|
1883
|
-
var
|
|
1511
|
+
var util = Object.freeze({
|
|
1512
|
+
__proto__: null,
|
|
1513
|
+
NOZZEL_SIZE,
|
|
1514
|
+
addConnector,
|
|
1515
|
+
axis2array,
|
|
1516
|
+
axisApply,
|
|
1517
|
+
bisect,
|
|
1518
|
+
calcCenterWith,
|
|
1519
|
+
calcFlush,
|
|
1520
|
+
calcRotate,
|
|
1521
|
+
calcSnap,
|
|
1522
|
+
calcmidlineTo,
|
|
1523
|
+
center,
|
|
1524
|
+
centerWith,
|
|
1525
|
+
centerX,
|
|
1526
|
+
centerY,
|
|
1527
|
+
centroid,
|
|
1528
|
+
chamfer,
|
|
1529
|
+
clone,
|
|
1530
|
+
cm,
|
|
1531
|
+
defaults,
|
|
1532
|
+
depreciated,
|
|
1533
|
+
div,
|
|
1534
|
+
divA,
|
|
1535
|
+
divxyz,
|
|
1536
|
+
enlarge,
|
|
1537
|
+
error,
|
|
1538
|
+
fillet,
|
|
1539
|
+
fit,
|
|
1540
|
+
flush,
|
|
1541
|
+
flushSide,
|
|
1542
|
+
getDelta,
|
|
1543
|
+
identity,
|
|
1544
|
+
ifArray,
|
|
1545
|
+
inch,
|
|
1546
|
+
isEmpty,
|
|
1547
|
+
isNegative,
|
|
1548
|
+
jscadToString,
|
|
1549
|
+
label,
|
|
1550
|
+
map,
|
|
1551
|
+
mapPick,
|
|
1552
|
+
mapValues,
|
|
1553
|
+
midlineTo,
|
|
1554
|
+
mirrored4,
|
|
1555
|
+
mul,
|
|
1556
|
+
mulxyz,
|
|
1557
|
+
nearest,
|
|
1558
|
+
normalVector,
|
|
1559
|
+
pick,
|
|
1560
|
+
poly2solid,
|
|
1561
|
+
print,
|
|
1562
|
+
reShape,
|
|
1563
|
+
result,
|
|
1564
|
+
rotateAround,
|
|
1565
|
+
rotationAxes,
|
|
1566
|
+
scale,
|
|
1567
|
+
segment,
|
|
1568
|
+
shift,
|
|
1569
|
+
size,
|
|
1570
|
+
slice,
|
|
1571
|
+
sliceParams,
|
|
1572
|
+
slices2poly,
|
|
1573
|
+
snap,
|
|
1574
|
+
stretch,
|
|
1575
|
+
text,
|
|
1576
|
+
toArray,
|
|
1577
|
+
translator,
|
|
1578
|
+
unitAxis,
|
|
1579
|
+
unitCube,
|
|
1580
|
+
wedge,
|
|
1581
|
+
xyz2array,
|
|
1582
|
+
zero,
|
|
1583
|
+
zipObject
|
|
1584
|
+
});
|
|
1585
|
+
const debug$1 = Debug("jscadUtils:parts");
|
|
1884
1586
|
var parts = {
|
|
1885
1587
|
BBox: BBox$1,
|
|
1886
1588
|
Cube,
|
|
@@ -1888,16 +1590,13 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1888
1590
|
Cylinder,
|
|
1889
1591
|
Cone
|
|
1890
1592
|
};
|
|
1891
|
-
function BBox$1() {
|
|
1593
|
+
function BBox$1(...objects) {
|
|
1892
1594
|
function box(object) {
|
|
1893
1595
|
return CSG.cube({
|
|
1894
1596
|
center: object.centroid(),
|
|
1895
1597
|
radius: object.size().dividedBy(2)
|
|
1896
1598
|
});
|
|
1897
1599
|
}
|
|
1898
|
-
for (var _len = arguments.length, objects = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1899
|
-
objects[_key] = arguments[_key];
|
|
1900
|
-
}
|
|
1901
1600
|
return objects.reduce(function(bbox, part) {
|
|
1902
1601
|
var object = bbox ? union([ bbox, box(part) ]) : part;
|
|
1903
1602
|
return box(object);
|
|
@@ -1930,8 +1629,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1930
1629
|
});
|
|
1931
1630
|
return roundedcube;
|
|
1932
1631
|
}
|
|
1933
|
-
function Cylinder(diameter, height) {
|
|
1934
|
-
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1632
|
+
function Cylinder(diameter, height, options = {}) {
|
|
1935
1633
|
debug$1("parts.Cylinder", diameter, height, options);
|
|
1936
1634
|
options = Object.assign({
|
|
1937
1635
|
start: [ 0, 0, 0 ],
|
|
@@ -1941,8 +1639,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1941
1639
|
}, options);
|
|
1942
1640
|
return CSG.cylinder(options);
|
|
1943
1641
|
}
|
|
1944
|
-
function Cone(diameter1, diameter2, height) {
|
|
1945
|
-
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
1642
|
+
function Cone(diameter1, diameter2, height, options = {}) {
|
|
1946
1643
|
debug$1("parts.Cone", diameter1, diameter2, height, options);
|
|
1947
1644
|
return CSG.cylinder(Object.assign({
|
|
1948
1645
|
start: [ 0, 0, 0 ],
|
|
@@ -1971,9 +1668,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1971
1668
|
function Tube(outsideDiameter, insideDiameter, height, outsideOptions, insideOptions) {
|
|
1972
1669
|
return Cylinder(outsideDiameter, height, outsideOptions).subtract(Cylinder(insideDiameter, height, insideOptions || outsideOptions));
|
|
1973
1670
|
}
|
|
1974
|
-
function Anchor() {
|
|
1975
|
-
var width = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 10;
|
|
1976
|
-
var height = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10;
|
|
1671
|
+
function Anchor(width = 10, height = 10) {
|
|
1977
1672
|
var hole = Cylinder(width, height).Center().color("red");
|
|
1978
1673
|
var post = Cylinder(height / 2, width * .66).rotateX(90).align(hole, "xz").snap(hole, "y", "inside-").translate([ 0, 0, -height / 6 ]).color("purple");
|
|
1979
1674
|
return Group({
|
|
@@ -1993,7 +1688,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1993
1688
|
});
|
|
1994
1689
|
return board;
|
|
1995
1690
|
}
|
|
1996
|
-
|
|
1691
|
+
const Hardware = {
|
|
1997
1692
|
Orientation: {
|
|
1998
1693
|
up: {
|
|
1999
1694
|
head: "outside-",
|
|
@@ -2004,7 +1699,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2004
1699
|
clear: "inside-"
|
|
2005
1700
|
}
|
|
2006
1701
|
},
|
|
2007
|
-
Screw: function
|
|
1702
|
+
Screw: function(head, thread, headClearSpace, options) {
|
|
2008
1703
|
depreciated("Screw", false, "Use the jscad-hardware screw methods instead");
|
|
2009
1704
|
options = Object.assign(options, {
|
|
2010
1705
|
orientation: "up",
|
|
@@ -2020,7 +1715,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2020
1715
|
}
|
|
2021
1716
|
return group;
|
|
2022
1717
|
},
|
|
2023
|
-
PanHeadScrew: function
|
|
1718
|
+
PanHeadScrew: function(headDiameter, headLength, diameter, length, clearLength, options) {
|
|
2024
1719
|
depreciated("PanHeadScrew", false, "Use the jscad-hardware screw methods instead");
|
|
2025
1720
|
var head = Cylinder(headDiameter, headLength);
|
|
2026
1721
|
var thread = Cylinder(diameter, length);
|
|
@@ -2029,7 +1724,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2029
1724
|
}
|
|
2030
1725
|
return Hardware.Screw(head, thread, headClearSpace, options);
|
|
2031
1726
|
},
|
|
2032
|
-
HexHeadScrew: function
|
|
1727
|
+
HexHeadScrew: function(headDiameter, headLength, diameter, length, clearLength, options) {
|
|
2033
1728
|
depreciated("HexHeadScrew", false, "Use the jscad-hardware screw methods instead");
|
|
2034
1729
|
var head = Hexagon(headDiameter, headLength);
|
|
2035
1730
|
var thread = Cylinder(diameter, length);
|
|
@@ -2038,7 +1733,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2038
1733
|
}
|
|
2039
1734
|
return Hardware.Screw(head, thread, headClearSpace, options);
|
|
2040
1735
|
},
|
|
2041
|
-
FlatHeadScrew: function
|
|
1736
|
+
FlatHeadScrew: function(headDiameter, headLength, diameter, length, clearLength, options) {
|
|
2042
1737
|
depreciated("FlatHeadScrew", false, "Use the jscad-hardware screw methods instead");
|
|
2043
1738
|
var head = Cone(headDiameter, diameter, headLength);
|
|
2044
1739
|
var thread = Cylinder(diameter, length);
|
|
@@ -2050,20 +1745,20 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2050
1745
|
};
|
|
2051
1746
|
var parts$1 = Object.freeze({
|
|
2052
1747
|
__proto__: null,
|
|
2053
|
-
|
|
1748
|
+
Anchor,
|
|
2054
1749
|
BBox: BBox$1,
|
|
1750
|
+
Board,
|
|
1751
|
+
Cone,
|
|
2055
1752
|
Cube,
|
|
2056
|
-
RoundedCube,
|
|
2057
1753
|
Cylinder,
|
|
2058
|
-
|
|
1754
|
+
Hardware,
|
|
2059
1755
|
Hexagon,
|
|
1756
|
+
RoundedCube,
|
|
2060
1757
|
Triangle,
|
|
2061
1758
|
Tube,
|
|
2062
|
-
|
|
2063
|
-
Board,
|
|
2064
|
-
Hardware
|
|
1759
|
+
default: parts
|
|
2065
1760
|
});
|
|
2066
|
-
|
|
1761
|
+
const debug = Debug("jscadUtils:boxes");
|
|
2067
1762
|
function RabbetJoin(box, thickness, cutHeight) {
|
|
2068
1763
|
depreciated("RabbetJoin", true, "Use 'Rabbet' instead");
|
|
2069
1764
|
return rabbetJoin(box, thickness, cutHeight);
|
|
@@ -2076,17 +1771,16 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2076
1771
|
var top = bottom.parts.positive.bisect("z", -thickness);
|
|
2077
1772
|
return Group("top,middle,bottom", [ top.parts.positive, top.parts.negative.color("green"), bottom.parts.negative ]);
|
|
2078
1773
|
}
|
|
2079
|
-
function Rabett(box, thickness, gap, height, face) {
|
|
2080
|
-
var options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
|
|
1774
|
+
function Rabett(box, thickness, gap, height, face, options = {}) {
|
|
2081
1775
|
debug("Rabett", "thickness", thickness, "gap", gap, "height", height, "face", face);
|
|
2082
1776
|
gap = gap || .25;
|
|
2083
1777
|
var inside = thickness - gap;
|
|
2084
1778
|
var outside = -thickness + gap;
|
|
2085
1779
|
debug("inside", inside, "outside", outside);
|
|
2086
1780
|
var group = Group();
|
|
2087
|
-
var
|
|
1781
|
+
var {positive: top, negative: lower2_3rd} = box.bisect("z", height, options).parts;
|
|
2088
1782
|
var lowerBisectHeight = Math.sign(height) < 0 ? face * Math.sign(height) : height - face;
|
|
2089
|
-
var
|
|
1783
|
+
var {positive: middle, negative: bottom} = lower2_3rd.bisect("z", lowerBisectHeight, options).parts;
|
|
2090
1784
|
var middleTop = middle.color("yellow").subtract(middle.color("darkred").enlarge([ outside, outside, 0 ]));
|
|
2091
1785
|
group.add(top.union(middleTop), "top");
|
|
2092
1786
|
var bottomOutline = middle.color("yellow").subtract(middle.color("orange").enlarge([ outside, outside, 0 ])).enlarge([ outside, outside, 0 ]);
|
|
@@ -2095,9 +1789,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2095
1789
|
group.add(bottom.color("orange").union(middle.color("green").subtract(middle.color("red").enlarge([ inside, inside, 0 ])).subtract(middleTop)), "bottom");
|
|
2096
1790
|
return group;
|
|
2097
1791
|
}
|
|
2098
|
-
|
|
2099
|
-
var gap = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : .25;
|
|
2100
|
-
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
1792
|
+
const RabettTopBottom = function rabbetTMB(box, thickness, gap = .25, options = {}) {
|
|
2101
1793
|
options = Object.assign({
|
|
2102
1794
|
removableTop: true,
|
|
2103
1795
|
removableBottom: true,
|
|
@@ -2130,7 +1822,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2130
1822
|
}
|
|
2131
1823
|
return group;
|
|
2132
1824
|
};
|
|
2133
|
-
|
|
1825
|
+
const CutOut = function cutOut(o, h, box, plug, gap) {
|
|
2134
1826
|
gap = gap || .25;
|
|
2135
1827
|
var s = o.size();
|
|
2136
1828
|
var cutout = o.intersect(box);
|
|
@@ -2148,7 +1840,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2148
1840
|
insert: union([ o, top ]).intersect(box).subtract(o).enlarge([ -gap, 0, 0 ]).union(clip.subtract(plug).enlarge(-gap, -gap, 0)).color("blue")
|
|
2149
1841
|
});
|
|
2150
1842
|
};
|
|
2151
|
-
|
|
1843
|
+
const Rectangle = function(size, thickness, cb) {
|
|
2152
1844
|
thickness = thickness || 2;
|
|
2153
1845
|
var s = div$1(xyz2array(size), 2);
|
|
2154
1846
|
var r = add(s, thickness);
|
|
@@ -2162,7 +1854,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2162
1854
|
if (cb) box = cb(box);
|
|
2163
1855
|
return box;
|
|
2164
1856
|
};
|
|
2165
|
-
|
|
1857
|
+
const Hollow = function(object, thickness, interiorcb, exteriorcb) {
|
|
2166
1858
|
thickness = thickness || 2;
|
|
2167
1859
|
var size = -thickness * 2;
|
|
2168
1860
|
interiorcb = interiorcb || identity;
|
|
@@ -2170,7 +1862,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2170
1862
|
if (exteriorcb) box = exteriorcb(box);
|
|
2171
1863
|
return box;
|
|
2172
1864
|
};
|
|
2173
|
-
|
|
1865
|
+
const BBox = function(o) {
|
|
2174
1866
|
depreciated("BBox", true, "Use 'parts.BBox' instead");
|
|
2175
1867
|
var s = div$1(xyz2array(o.size()), 2);
|
|
2176
1868
|
return CSG.cube({
|
|
@@ -2181,8 +1873,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2181
1873
|
function getRadius(o) {
|
|
2182
1874
|
return div$1(xyz2array(o.size()), 2);
|
|
2183
1875
|
}
|
|
2184
|
-
function rabbetJoin(box, thickness) {
|
|
2185
|
-
var gap = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : .25;
|
|
1876
|
+
function rabbetJoin(box, thickness, gap = .25) {
|
|
2186
1877
|
var r = add(getRadius(box), -thickness / 2);
|
|
2187
1878
|
r[2] = thickness / 2;
|
|
2188
1879
|
var cutter = CSG.cube({
|
|
@@ -2200,16 +1891,17 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2200
1891
|
}
|
|
2201
1892
|
var Boxes = Object.freeze({
|
|
2202
1893
|
__proto__: null,
|
|
1894
|
+
BBox,
|
|
1895
|
+
CutOut,
|
|
1896
|
+
Hollow,
|
|
2203
1897
|
RabbetJoin,
|
|
2204
|
-
topMiddleBottom,
|
|
2205
1898
|
Rabett,
|
|
2206
1899
|
RabettTopBottom,
|
|
2207
|
-
CutOut,
|
|
2208
1900
|
Rectangle,
|
|
2209
|
-
|
|
2210
|
-
BBox
|
|
1901
|
+
topMiddleBottom
|
|
2211
1902
|
});
|
|
2212
|
-
|
|
1903
|
+
const compatV1 = {
|
|
1904
|
+
...util,
|
|
2213
1905
|
group: Group,
|
|
2214
1906
|
init: init$1,
|
|
2215
1907
|
triangle: triUtils,
|
|
@@ -2217,7 +1909,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2217
1909
|
parts: parts$1,
|
|
2218
1910
|
Boxes,
|
|
2219
1911
|
Debug
|
|
2220
|
-
}
|
|
1912
|
+
};
|
|
2221
1913
|
exports.Boxes = Boxes;
|
|
2222
1914
|
exports.Debug = Debug;
|
|
2223
1915
|
exports.Group = Group;
|
|
@@ -2227,9 +1919,6 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2227
1919
|
exports.parts = parts$1;
|
|
2228
1920
|
exports.triUtils = triUtils;
|
|
2229
1921
|
exports.util = util;
|
|
2230
|
-
Object.defineProperty(exports, "__esModule", {
|
|
2231
|
-
value: true
|
|
2232
|
-
});
|
|
2233
1922
|
return exports;
|
|
2234
1923
|
}({}, jsCadCSG, scadApi);
|
|
2235
1924
|
const debug = jscadUtils.Debug("jscadUtils:initJscadutils");
|