@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
|
@@ -74,329 +74,13 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
74
74
|
});
|
|
75
75
|
var jscadUtils = function(exports, jsCadCSG, scadApi) {
|
|
76
76
|
"use strict";
|
|
77
|
-
function
|
|
78
|
-
return e && typeof e === "object" && "default" in e ? e : {
|
|
79
|
-
default: e
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
var jsCadCSG__default = _interopDefaultLegacy(jsCadCSG);
|
|
83
|
-
var scadApi__default = _interopDefaultLegacy(scadApi);
|
|
84
|
-
var util = Object.freeze({
|
|
85
|
-
__proto__: null,
|
|
86
|
-
get NOZZEL_SIZE() {
|
|
87
|
-
return NOZZEL_SIZE;
|
|
88
|
-
},
|
|
89
|
-
get nearest() {
|
|
90
|
-
return nearest;
|
|
91
|
-
},
|
|
92
|
-
get identity() {
|
|
93
|
-
return identity;
|
|
94
|
-
},
|
|
95
|
-
get result() {
|
|
96
|
-
return result;
|
|
97
|
-
},
|
|
98
|
-
get defaults() {
|
|
99
|
-
return defaults;
|
|
100
|
-
},
|
|
101
|
-
get isEmpty() {
|
|
102
|
-
return isEmpty;
|
|
103
|
-
},
|
|
104
|
-
get isNegative() {
|
|
105
|
-
return isNegative;
|
|
106
|
-
},
|
|
107
|
-
get print() {
|
|
108
|
-
return print;
|
|
109
|
-
},
|
|
110
|
-
get jscadToString() {
|
|
111
|
-
return jscadToString;
|
|
112
|
-
},
|
|
113
|
-
get error() {
|
|
114
|
-
return error;
|
|
115
|
-
},
|
|
116
|
-
get depreciated() {
|
|
117
|
-
return depreciated;
|
|
118
|
-
},
|
|
119
|
-
get inch() {
|
|
120
|
-
return inch;
|
|
121
|
-
},
|
|
122
|
-
get cm() {
|
|
123
|
-
return cm;
|
|
124
|
-
},
|
|
125
|
-
get label() {
|
|
126
|
-
return label;
|
|
127
|
-
},
|
|
128
|
-
get text() {
|
|
129
|
-
return text;
|
|
130
|
-
},
|
|
131
|
-
get unitCube() {
|
|
132
|
-
return unitCube;
|
|
133
|
-
},
|
|
134
|
-
get unitAxis() {
|
|
135
|
-
return unitAxis;
|
|
136
|
-
},
|
|
137
|
-
get toArray() {
|
|
138
|
-
return toArray;
|
|
139
|
-
},
|
|
140
|
-
get ifArray() {
|
|
141
|
-
return ifArray;
|
|
142
|
-
},
|
|
143
|
-
get segment() {
|
|
144
|
-
return segment;
|
|
145
|
-
},
|
|
146
|
-
get zipObject() {
|
|
147
|
-
return zipObject;
|
|
148
|
-
},
|
|
149
|
-
get map() {
|
|
150
|
-
return map;
|
|
151
|
-
},
|
|
152
|
-
get mapValues() {
|
|
153
|
-
return mapValues;
|
|
154
|
-
},
|
|
155
|
-
get pick() {
|
|
156
|
-
return pick;
|
|
157
|
-
},
|
|
158
|
-
get mapPick() {
|
|
159
|
-
return mapPick;
|
|
160
|
-
},
|
|
161
|
-
get divA() {
|
|
162
|
-
return divA;
|
|
163
|
-
},
|
|
164
|
-
get divxyz() {
|
|
165
|
-
return divxyz;
|
|
166
|
-
},
|
|
167
|
-
get div() {
|
|
168
|
-
return div;
|
|
169
|
-
},
|
|
170
|
-
get mulxyz() {
|
|
171
|
-
return mulxyz;
|
|
172
|
-
},
|
|
173
|
-
get mul() {
|
|
174
|
-
return mul;
|
|
175
|
-
},
|
|
176
|
-
get xyz2array() {
|
|
177
|
-
return xyz2array;
|
|
178
|
-
},
|
|
179
|
-
get rotationAxes() {
|
|
180
|
-
return rotationAxes;
|
|
181
|
-
},
|
|
182
|
-
get size() {
|
|
183
|
-
return size;
|
|
184
|
-
},
|
|
185
|
-
get scale() {
|
|
186
|
-
return scale;
|
|
187
|
-
},
|
|
188
|
-
get center() {
|
|
189
|
-
return center;
|
|
190
|
-
},
|
|
191
|
-
get centerY() {
|
|
192
|
-
return centerY;
|
|
193
|
-
},
|
|
194
|
-
get centerX() {
|
|
195
|
-
return centerX;
|
|
196
|
-
},
|
|
197
|
-
get enlarge() {
|
|
198
|
-
return enlarge;
|
|
199
|
-
},
|
|
200
|
-
get fit() {
|
|
201
|
-
return fit;
|
|
202
|
-
},
|
|
203
|
-
get shift() {
|
|
204
|
-
return shift;
|
|
205
|
-
},
|
|
206
|
-
get zero() {
|
|
207
|
-
return zero;
|
|
208
|
-
},
|
|
209
|
-
get mirrored4() {
|
|
210
|
-
return mirrored4;
|
|
211
|
-
},
|
|
212
|
-
get flushSide() {
|
|
213
|
-
return flushSide;
|
|
214
|
-
},
|
|
215
|
-
get calcFlush() {
|
|
216
|
-
return calcFlush;
|
|
217
|
-
},
|
|
218
|
-
get calcSnap() {
|
|
219
|
-
return calcSnap;
|
|
220
|
-
},
|
|
221
|
-
get snap() {
|
|
222
|
-
return snap;
|
|
223
|
-
},
|
|
224
|
-
get flush() {
|
|
225
|
-
return flush;
|
|
226
|
-
},
|
|
227
|
-
get axisApply() {
|
|
228
|
-
return axisApply;
|
|
229
|
-
},
|
|
230
|
-
get axis2array() {
|
|
231
|
-
return axis2array;
|
|
232
|
-
},
|
|
233
|
-
get centroid() {
|
|
234
|
-
return centroid;
|
|
235
|
-
},
|
|
236
|
-
get calcmidlineTo() {
|
|
237
|
-
return calcmidlineTo;
|
|
238
|
-
},
|
|
239
|
-
get midlineTo() {
|
|
240
|
-
return midlineTo;
|
|
241
|
-
},
|
|
242
|
-
get translator() {
|
|
243
|
-
return translator;
|
|
244
|
-
},
|
|
245
|
-
get calcCenterWith() {
|
|
246
|
-
return calcCenterWith;
|
|
247
|
-
},
|
|
248
|
-
get centerWith() {
|
|
249
|
-
return centerWith;
|
|
250
|
-
},
|
|
251
|
-
get getDelta() {
|
|
252
|
-
return getDelta;
|
|
253
|
-
},
|
|
254
|
-
get bisect() {
|
|
255
|
-
return bisect;
|
|
256
|
-
},
|
|
257
|
-
get slice() {
|
|
258
|
-
return slice;
|
|
259
|
-
},
|
|
260
|
-
get wedge() {
|
|
261
|
-
return wedge;
|
|
262
|
-
},
|
|
263
|
-
get stretch() {
|
|
264
|
-
return stretch;
|
|
265
|
-
},
|
|
266
|
-
get poly2solid() {
|
|
267
|
-
return poly2solid;
|
|
268
|
-
},
|
|
269
|
-
get slices2poly() {
|
|
270
|
-
return slices2poly;
|
|
271
|
-
},
|
|
272
|
-
get normalVector() {
|
|
273
|
-
return normalVector;
|
|
274
|
-
},
|
|
275
|
-
get sliceParams() {
|
|
276
|
-
return sliceParams;
|
|
277
|
-
},
|
|
278
|
-
get reShape() {
|
|
279
|
-
return reShape;
|
|
280
|
-
},
|
|
281
|
-
get chamfer() {
|
|
282
|
-
return chamfer;
|
|
283
|
-
},
|
|
284
|
-
get fillet() {
|
|
285
|
-
return fillet;
|
|
286
|
-
},
|
|
287
|
-
get calcRotate() {
|
|
288
|
-
return calcRotate;
|
|
289
|
-
},
|
|
290
|
-
get rotateAround() {
|
|
291
|
-
return rotateAround;
|
|
292
|
-
},
|
|
293
|
-
get clone() {
|
|
294
|
-
return clone;
|
|
295
|
-
},
|
|
296
|
-
get addConnector() {
|
|
297
|
-
return addConnector;
|
|
298
|
-
}
|
|
299
|
-
});
|
|
300
|
-
function _arrayLikeToArray(r, a) {
|
|
301
|
-
(null == a || a > r.length) && (a = r.length);
|
|
302
|
-
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
303
|
-
return n;
|
|
304
|
-
}
|
|
305
|
-
function _arrayWithHoles(r) {
|
|
306
|
-
if (Array.isArray(r)) return r;
|
|
307
|
-
}
|
|
308
|
-
function _defineProperty(e, r, t) {
|
|
309
|
-
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
310
|
-
value: t,
|
|
311
|
-
enumerable: !0,
|
|
312
|
-
configurable: !0,
|
|
313
|
-
writable: !0
|
|
314
|
-
}) : e[r] = t, e;
|
|
315
|
-
}
|
|
316
|
-
function _iterableToArrayLimit(r, l) {
|
|
317
|
-
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
318
|
-
if (null != t) {
|
|
319
|
-
var e, n, i, u, a = [], f = !0, o = !1;
|
|
320
|
-
try {
|
|
321
|
-
if (i = (t = t.call(r)).next, 0 === l) {
|
|
322
|
-
if (Object(t) !== t) return;
|
|
323
|
-
f = !1;
|
|
324
|
-
} else for (;!(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0) ;
|
|
325
|
-
} catch (r) {
|
|
326
|
-
o = !0, n = r;
|
|
327
|
-
} finally {
|
|
328
|
-
try {
|
|
329
|
-
if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
|
|
330
|
-
} finally {
|
|
331
|
-
if (o) throw n;
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
return a;
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
function _nonIterableRest() {
|
|
338
|
-
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
339
|
-
}
|
|
340
|
-
function ownKeys(e, r) {
|
|
341
|
-
var t = Object.keys(e);
|
|
342
|
-
if (Object.getOwnPropertySymbols) {
|
|
343
|
-
var o = Object.getOwnPropertySymbols(e);
|
|
344
|
-
r && (o = o.filter(function(r) {
|
|
345
|
-
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
346
|
-
})), t.push.apply(t, o);
|
|
347
|
-
}
|
|
348
|
-
return t;
|
|
349
|
-
}
|
|
350
|
-
function _objectSpread2(e) {
|
|
351
|
-
for (var r = 1; r < arguments.length; r++) {
|
|
352
|
-
var t = null != arguments[r] ? arguments[r] : {};
|
|
353
|
-
r % 2 ? ownKeys(Object(t), !0).forEach(function(r) {
|
|
354
|
-
_defineProperty(e, r, t[r]);
|
|
355
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r) {
|
|
356
|
-
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
357
|
-
});
|
|
358
|
-
}
|
|
359
|
-
return e;
|
|
360
|
-
}
|
|
361
|
-
function _slicedToArray(r, e) {
|
|
362
|
-
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
|
|
363
|
-
}
|
|
364
|
-
function _toPrimitive(t, r) {
|
|
365
|
-
if ("object" != typeof t || !t) return t;
|
|
366
|
-
var e = t[Symbol.toPrimitive];
|
|
367
|
-
if (void 0 !== e) {
|
|
368
|
-
var i = e.call(t, r || "default");
|
|
369
|
-
if ("object" != typeof i) return i;
|
|
370
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
371
|
-
}
|
|
372
|
-
return ("string" === r ? String : Number)(t);
|
|
373
|
-
}
|
|
374
|
-
function _toPropertyKey(t) {
|
|
375
|
-
var i = _toPrimitive(t, "string");
|
|
376
|
-
return "symbol" == typeof i ? i : i + "";
|
|
377
|
-
}
|
|
378
|
-
function _typeof(o) {
|
|
379
|
-
"@babel/helpers - typeof";
|
|
380
|
-
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
381
|
-
return typeof o;
|
|
382
|
-
} : function(o) {
|
|
383
|
-
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
384
|
-
}, _typeof(o);
|
|
385
|
-
}
|
|
386
|
-
function _unsupportedIterableToArray(r, a) {
|
|
387
|
-
if (r) {
|
|
388
|
-
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
389
|
-
var t = {}.toString.call(r).slice(8, -1);
|
|
390
|
-
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;
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
var toRadians = function toRadians(deg) {
|
|
77
|
+
const toRadians = function toRadians(deg) {
|
|
394
78
|
return deg / 180 * Math.PI;
|
|
395
79
|
};
|
|
396
|
-
|
|
80
|
+
const toDegrees = function toDegrees(rad) {
|
|
397
81
|
return rad * (180 / Math.PI);
|
|
398
82
|
};
|
|
399
|
-
|
|
83
|
+
const solve = function(p1, p2) {
|
|
400
84
|
var r = {
|
|
401
85
|
c: 90,
|
|
402
86
|
A: Math.abs(p2.x - p1.x),
|
|
@@ -408,7 +92,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
408
92
|
r.a = 90 - r.b;
|
|
409
93
|
return r;
|
|
410
94
|
};
|
|
411
|
-
|
|
95
|
+
const solve90SA = function(r) {
|
|
412
96
|
r = Object.assign(r, {
|
|
413
97
|
C: 90
|
|
414
98
|
});
|
|
@@ -420,7 +104,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
420
104
|
r.b = r.b || r.a / Math.tan(arad);
|
|
421
105
|
return r;
|
|
422
106
|
};
|
|
423
|
-
|
|
107
|
+
const solve90ac = function(r) {
|
|
424
108
|
r = Object.assign(r, {
|
|
425
109
|
C: 90
|
|
426
110
|
});
|
|
@@ -441,29 +125,29 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
441
125
|
}
|
|
442
126
|
var triUtils = Object.freeze({
|
|
443
127
|
__proto__: null,
|
|
444
|
-
toRadians,
|
|
445
|
-
toDegrees,
|
|
446
128
|
solve,
|
|
447
129
|
solve90SA,
|
|
448
130
|
solve90ac,
|
|
449
|
-
solveab
|
|
131
|
+
solveab,
|
|
132
|
+
toDegrees,
|
|
133
|
+
toRadians
|
|
450
134
|
});
|
|
451
|
-
|
|
135
|
+
const div$1 = function(a, f) {
|
|
452
136
|
return a.map(function(e) {
|
|
453
137
|
return e / f;
|
|
454
138
|
});
|
|
455
139
|
};
|
|
456
|
-
|
|
140
|
+
const addValue = function(a, f) {
|
|
457
141
|
return a.map(function(e) {
|
|
458
142
|
return e + f;
|
|
459
143
|
});
|
|
460
144
|
};
|
|
461
|
-
|
|
145
|
+
const addArray = function(a, f) {
|
|
462
146
|
return a.map(function(e, i) {
|
|
463
147
|
return e + f[i];
|
|
464
148
|
});
|
|
465
149
|
};
|
|
466
|
-
|
|
150
|
+
const add = function(a) {
|
|
467
151
|
return Array.prototype.slice.call(arguments, 1).reduce(function(result, arg) {
|
|
468
152
|
if (Array.isArray(arg)) {
|
|
469
153
|
result = addArray(result, arg);
|
|
@@ -473,28 +157,28 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
473
157
|
return result;
|
|
474
158
|
}, a);
|
|
475
159
|
};
|
|
476
|
-
|
|
160
|
+
const fromxyz = function(object) {
|
|
477
161
|
return Array.isArray(object) ? object : [ object.x, object.y, object.z ];
|
|
478
162
|
};
|
|
479
|
-
|
|
163
|
+
const toxyz = function(a) {
|
|
480
164
|
return {
|
|
481
165
|
x: a[0],
|
|
482
166
|
y: a[1],
|
|
483
167
|
z: a[2]
|
|
484
168
|
};
|
|
485
169
|
};
|
|
486
|
-
|
|
170
|
+
const first = function(a) {
|
|
487
171
|
return a ? a[0] : undefined;
|
|
488
172
|
};
|
|
489
|
-
|
|
173
|
+
const last = function(a) {
|
|
490
174
|
return a && a.length > 0 ? a[a.length - 1] : undefined;
|
|
491
175
|
};
|
|
492
|
-
|
|
176
|
+
const min = function(a) {
|
|
493
177
|
return a.reduce(function(result, value) {
|
|
494
178
|
return value < result ? value : result;
|
|
495
179
|
}, Number.MAX_VALUE);
|
|
496
180
|
};
|
|
497
|
-
|
|
181
|
+
const range = function(a, b) {
|
|
498
182
|
var result = [];
|
|
499
183
|
for (var i = a; i < b; i++) {
|
|
500
184
|
result.push(i);
|
|
@@ -503,21 +187,21 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
503
187
|
};
|
|
504
188
|
var array = Object.freeze({
|
|
505
189
|
__proto__: null,
|
|
506
|
-
div: div$1,
|
|
507
|
-
addValue,
|
|
508
|
-
addArray,
|
|
509
190
|
add,
|
|
510
|
-
|
|
511
|
-
|
|
191
|
+
addArray,
|
|
192
|
+
addValue,
|
|
193
|
+
div: div$1,
|
|
512
194
|
first,
|
|
195
|
+
fromxyz,
|
|
513
196
|
last,
|
|
514
197
|
min,
|
|
515
|
-
range
|
|
198
|
+
range,
|
|
199
|
+
toxyz
|
|
516
200
|
});
|
|
517
|
-
|
|
518
|
-
|
|
201
|
+
const debugColors = [ "#e41a1c", "#377eb8", "#4daf4a", "#984ea3", "#ff7f00", "#ffff33", "#a65628", "#f781bf", "#999999" ];
|
|
202
|
+
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" ];
|
|
519
203
|
var debugCount = 0;
|
|
520
|
-
|
|
204
|
+
const Debug = function(name) {
|
|
521
205
|
var checks = Object.assign({
|
|
522
206
|
enabled: [],
|
|
523
207
|
disabled: [],
|
|
@@ -525,31 +209,21 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
525
209
|
browser: true
|
|
526
210
|
}
|
|
527
211
|
}, jscadUtilsDebug || {});
|
|
528
|
-
var style = checks.options.browser ?
|
|
212
|
+
var style = checks.options.browser ? `color:${debugColors[debugCount++ % debugColors.length]}` : `${termColors[debugCount++ % termColors.length]}`;
|
|
529
213
|
var enabled = checks.enabled.some(function checkEnabled(check) {
|
|
530
214
|
return check.test(name);
|
|
531
215
|
}) && !checks.disabled.some(function checkEnabled(check) {
|
|
532
216
|
return check.test(name);
|
|
533
217
|
});
|
|
534
|
-
var logger = enabled ? checks.options.browser ?
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
(_console = console).log.apply(_console, [ "%c%s", style, name ].concat(msg));
|
|
540
|
-
} : function() {
|
|
541
|
-
var _console2;
|
|
542
|
-
for (var _len2 = arguments.length, msg = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
543
|
-
msg[_key2] = arguments[_key2];
|
|
544
|
-
}
|
|
545
|
-
(_console2 = console).log.apply(_console2, [ "".concat(name) ].concat(msg));
|
|
546
|
-
} : function() {
|
|
547
|
-
return undefined;
|
|
548
|
-
};
|
|
218
|
+
var logger = enabled ? checks.options.browser ? (...msg) => {
|
|
219
|
+
console.log("%c%s", style, name, ...msg);
|
|
220
|
+
} : (...msg) => {
|
|
221
|
+
console.log(`${name}`, ...msg);
|
|
222
|
+
} : () => undefined;
|
|
549
223
|
logger.enabled = enabled;
|
|
550
224
|
return logger;
|
|
551
225
|
};
|
|
552
|
-
|
|
226
|
+
const nameArray = {
|
|
553
227
|
aliceblue: "#f0f8ff",
|
|
554
228
|
antiquewhite: "#faebd7",
|
|
555
229
|
aqua: "#00ffff",
|
|
@@ -707,9 +381,11 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
707
381
|
h = h.replace(/^\#/, "");
|
|
708
382
|
if (h.length === 6) {
|
|
709
383
|
return [ parseInt(h.substr(0, 2), 16), parseInt(h.substr(2, 2), 16), parseInt(h.substr(4, 2), 16) ];
|
|
384
|
+
} else {
|
|
385
|
+
return [ 0, 0, 0 ];
|
|
710
386
|
}
|
|
711
387
|
}
|
|
712
|
-
|
|
388
|
+
const _name2rgb = {};
|
|
713
389
|
function name2rgb(n) {
|
|
714
390
|
if (!_name2rgb[n]) _name2rgb[n] = hex2rgb(name2hex(n));
|
|
715
391
|
return _name2rgb[n];
|
|
@@ -789,23 +465,14 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
789
465
|
proto.prototype.chamfer = function chamfer$1(radius, orientation, options) {
|
|
790
466
|
return chamfer(this, radius, orientation, options);
|
|
791
467
|
};
|
|
792
|
-
proto.prototype.bisect = function bisect$1() {
|
|
793
|
-
|
|
794
|
-
args[_key] = arguments[_key];
|
|
795
|
-
}
|
|
796
|
-
return bisect.apply(util, [ this ].concat(args));
|
|
468
|
+
proto.prototype.bisect = function bisect$1(...args) {
|
|
469
|
+
return bisect(this, ...args);
|
|
797
470
|
};
|
|
798
|
-
proto.prototype.slice = function slice$1() {
|
|
799
|
-
|
|
800
|
-
args[_key2] = arguments[_key2];
|
|
801
|
-
}
|
|
802
|
-
return slice.apply(util, [ this ].concat(args));
|
|
471
|
+
proto.prototype.slice = function slice$1(...args) {
|
|
472
|
+
return slice(this, ...args);
|
|
803
473
|
};
|
|
804
|
-
proto.prototype.wedge = function wedge$1() {
|
|
805
|
-
|
|
806
|
-
args[_key3] = arguments[_key3];
|
|
807
|
-
}
|
|
808
|
-
return wedge.apply(util, [ this ].concat(args));
|
|
474
|
+
proto.prototype.wedge = function wedge$1(...args) {
|
|
475
|
+
return wedge(this, ...args);
|
|
809
476
|
};
|
|
810
477
|
proto.prototype.stretch = function stretch$1(axis, distance, offset) {
|
|
811
478
|
return stretch(this, axis, distance, offset);
|
|
@@ -822,7 +489,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
822
489
|
return this._translate(arguments[0]);
|
|
823
490
|
} else {
|
|
824
491
|
var t = Array.prototype.slice.call(arguments, 0).reduce(function(result, arg) {
|
|
825
|
-
result = undefined(result, arg);
|
|
492
|
+
result = undefined.addArray(result, arg);
|
|
826
493
|
return result;
|
|
827
494
|
}, [ 0, 0, 0 ]);
|
|
828
495
|
return this._translate(t);
|
|
@@ -831,14 +498,10 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
831
498
|
proto.prototype.addConnector = function addConnector$1(name, point, axis, normal) {
|
|
832
499
|
return addConnector(this, name, point, axis, normal);
|
|
833
500
|
};
|
|
834
|
-
proto.prototype.connect = function connectTo(myConnectorName, otherConnector) {
|
|
835
|
-
var
|
|
836
|
-
var normalrotation = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
837
|
-
var myConnector = myConnectorName.split(".").reduce(function(a, v) {
|
|
838
|
-
return a[v];
|
|
839
|
-
}, this.properties);
|
|
501
|
+
proto.prototype.connect = function connectTo(myConnectorName, otherConnector, mirror = false, normalrotation = 0) {
|
|
502
|
+
var myConnector = myConnectorName.split(".").reduce((a, v) => a[v], this.properties);
|
|
840
503
|
if (!myConnector) {
|
|
841
|
-
error(
|
|
504
|
+
error(`The connector '${myConnectorName}' does not exist on the object [${Object.keys(this.properties).join(",")}]`, "Missing connector property");
|
|
842
505
|
}
|
|
843
506
|
return this.connectTo(myConnector, otherConnector, mirror, normalrotation);
|
|
844
507
|
};
|
|
@@ -848,16 +511,13 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
848
511
|
__proto__: null,
|
|
849
512
|
default: init
|
|
850
513
|
});
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
514
|
+
const {CSG, CAG} = jsCadCSG;
|
|
515
|
+
const {rectangular_extrude} = scadApi.extrusions;
|
|
516
|
+
const {vector_text, vector_char} = scadApi.text;
|
|
517
|
+
const {union} = scadApi.booleanOps;
|
|
855
518
|
init(CSG);
|
|
856
|
-
|
|
857
|
-
function JsCadUtilsGroup() {
|
|
858
|
-
var names = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
859
|
-
var parts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
860
|
-
var holes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
519
|
+
const debug$3 = Debug("jscadUtils:group");
|
|
520
|
+
function JsCadUtilsGroup(names = [], parts = {}, holes = []) {
|
|
861
521
|
this.name = "";
|
|
862
522
|
this.names = names;
|
|
863
523
|
this.parts = parts;
|
|
@@ -885,11 +545,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
885
545
|
}
|
|
886
546
|
return self;
|
|
887
547
|
};
|
|
888
|
-
JsCadUtilsGroup.prototype.combine = function(pieces) {
|
|
889
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
890
|
-
var map = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function(x) {
|
|
891
|
-
return x;
|
|
892
|
-
};
|
|
548
|
+
JsCadUtilsGroup.prototype.combine = function(pieces, options = {}, map = x => x) {
|
|
893
549
|
try {
|
|
894
550
|
var self = this;
|
|
895
551
|
options = Object.assign({
|
|
@@ -897,7 +553,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
897
553
|
}, options);
|
|
898
554
|
pieces = pieces ? pieces.split(",") : self.names;
|
|
899
555
|
if (pieces.length === 0) {
|
|
900
|
-
throw new Error(
|
|
556
|
+
throw new Error(`no pieces found in ${self.name} pieces: ${pieces} parts: ${Object.keys(self.parts)} names: ${self.names}`);
|
|
901
557
|
}
|
|
902
558
|
debug$3("combine", self.names, self.parts);
|
|
903
559
|
var g = union(mapPick(self.parts, pieces, function(value, key, index, object) {
|
|
@@ -907,14 +563,12 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
907
563
|
return g.subtractIf(self.holes && Array.isArray(self.holes) ? union(self.holes) : self.holes, self.holes && !options.noholes);
|
|
908
564
|
} catch (err) {
|
|
909
565
|
debug$3("combine error", this, pieces, options, err);
|
|
910
|
-
throw error(
|
|
566
|
+
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");
|
|
911
567
|
}
|
|
912
568
|
};
|
|
913
569
|
JsCadUtilsGroup.prototype.map = function(cb) {
|
|
914
570
|
var self = this;
|
|
915
|
-
self.parts = Object.keys(self.parts).filter(function(
|
|
916
|
-
return k !== "holes";
|
|
917
|
-
}).reduce(function(result, key) {
|
|
571
|
+
self.parts = Object.keys(self.parts).filter(k => k !== "holes").reduce(function(result, key) {
|
|
918
572
|
result[key] = cb(self.parts[key], key);
|
|
919
573
|
return result;
|
|
920
574
|
}, {});
|
|
@@ -930,7 +584,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
930
584
|
return self;
|
|
931
585
|
};
|
|
932
586
|
JsCadUtilsGroup.prototype.clone = function(name, map) {
|
|
933
|
-
debug$3("clone", name,
|
|
587
|
+
debug$3("clone", name, typeof name, map);
|
|
934
588
|
var self = this;
|
|
935
589
|
if (typeof name == "function") {
|
|
936
590
|
map = name;
|
|
@@ -982,7 +636,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
982
636
|
return self;
|
|
983
637
|
} catch (err) {
|
|
984
638
|
debug$3("snap error", this, part, to, axis, delta, err);
|
|
985
|
-
throw error(
|
|
639
|
+
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");
|
|
986
640
|
}
|
|
987
641
|
};
|
|
988
642
|
JsCadUtilsGroup.prototype.align = function align(part, to, axis, delta) {
|
|
@@ -997,7 +651,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
997
651
|
return self;
|
|
998
652
|
} catch (err) {
|
|
999
653
|
debug$3("align error", this, part, to, axis, delta, err);
|
|
1000
|
-
throw error(
|
|
654
|
+
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");
|
|
1001
655
|
}
|
|
1002
656
|
};
|
|
1003
657
|
JsCadUtilsGroup.prototype.center = function center(part) {
|
|
@@ -1009,9 +663,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1009
663
|
var bounds = self.parts[part].getBounds();
|
|
1010
664
|
return self.translate([ 0, 0, -bounds[0].z ]);
|
|
1011
665
|
};
|
|
1012
|
-
JsCadUtilsGroup.prototype.connectTo = function connectTo(partName, connectorName, to, toConnectorName) {
|
|
1013
|
-
var mirror = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
|
|
1014
|
-
var normalrotation = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 0;
|
|
666
|
+
JsCadUtilsGroup.prototype.connectTo = function connectTo(partName, connectorName, to, toConnectorName, mirror = true, normalrotation = 0) {
|
|
1015
667
|
debug$3("connectTo", {
|
|
1016
668
|
partName,
|
|
1017
669
|
connectorName,
|
|
@@ -1021,13 +673,9 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1021
673
|
normalrotation
|
|
1022
674
|
});
|
|
1023
675
|
var self = this;
|
|
1024
|
-
var myConnector = connectorName.split(".").reduce(
|
|
1025
|
-
return a[v];
|
|
1026
|
-
}, self.parts[partName].properties);
|
|
676
|
+
var myConnector = connectorName.split(".").reduce((a, v) => a[v], self.parts[partName].properties);
|
|
1027
677
|
debug$3("toConnector", to instanceof CSG.Connector);
|
|
1028
|
-
var toConnector = toConnectorName.split(".").reduce(
|
|
1029
|
-
return a[v];
|
|
1030
|
-
}, to.properties);
|
|
678
|
+
var toConnector = toConnectorName.split(".").reduce((a, v) => a[v], to.properties);
|
|
1031
679
|
var matrix = myConnector.getTransformationTo(toConnector, mirror, normalrotation);
|
|
1032
680
|
debug$3("connectTo", matrix);
|
|
1033
681
|
self.map(function(part) {
|
|
@@ -1066,15 +714,14 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1066
714
|
return g;
|
|
1067
715
|
};
|
|
1068
716
|
JsCadUtilsGroup.prototype.array = function(parts, map) {
|
|
1069
|
-
var _this = this;
|
|
1070
717
|
var self = this;
|
|
1071
718
|
var p = parts && parts.length > 0 && parts.split(",") || self.names;
|
|
1072
719
|
if (!map) map = identity;
|
|
1073
720
|
var a = [];
|
|
1074
|
-
p.forEach(
|
|
721
|
+
p.forEach(name => {
|
|
1075
722
|
if (!self.parts[name]) {
|
|
1076
|
-
debug$3("array error",
|
|
1077
|
-
throw error(
|
|
723
|
+
debug$3("array error", this, parts);
|
|
724
|
+
throw error(`group::array error "${name}" not found.\nthis: ${this}\nparts: "${parts}"\n`, "JSCAD_UTILS_GROUP_ERROR");
|
|
1078
725
|
}
|
|
1079
726
|
a.push(map(CSG.fromPolygons(self.parts[name].toPolygons()), name));
|
|
1080
727
|
});
|
|
@@ -1084,12 +731,12 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1084
731
|
var self = this;
|
|
1085
732
|
var piecesArray = pieces ? pieces.split(",") : self.names;
|
|
1086
733
|
return piecesArray.map(function(piece) {
|
|
1087
|
-
if (!self.parts[piece]) console.error(
|
|
734
|
+
if (!self.parts[piece]) console.error(`Cannot find ${piece} in ${self.names}`);
|
|
1088
735
|
return self.parts[piece];
|
|
1089
736
|
});
|
|
1090
737
|
};
|
|
1091
738
|
JsCadUtilsGroup.prototype.toString = function() {
|
|
1092
|
-
return
|
|
739
|
+
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}`;
|
|
1093
740
|
};
|
|
1094
741
|
JsCadUtilsGroup.prototype.setName = function(name) {
|
|
1095
742
|
this.name = name;
|
|
@@ -1119,9 +766,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1119
766
|
self.name = objectNames;
|
|
1120
767
|
} else {
|
|
1121
768
|
var objects = objectNames;
|
|
1122
|
-
self.names = Object.keys(objects).filter(
|
|
1123
|
-
return k !== "holes";
|
|
1124
|
-
});
|
|
769
|
+
self.names = Object.keys(objects).filter(k => k !== "holes");
|
|
1125
770
|
self.parts = Object.assign({}, objects);
|
|
1126
771
|
self.holes = objects.holes;
|
|
1127
772
|
}
|
|
@@ -1129,17 +774,13 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1129
774
|
}
|
|
1130
775
|
return new JsCadUtilsGroup(self.names, self.parts, self.holes);
|
|
1131
776
|
}
|
|
1132
|
-
|
|
777
|
+
const debug$2 = Debug("jscadUtils:util");
|
|
1133
778
|
var NOZZEL_SIZE = .4;
|
|
1134
|
-
|
|
1135
|
-
under: function
|
|
1136
|
-
var nozzel = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : NOZZEL_SIZE;
|
|
1137
|
-
var nozzie = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
779
|
+
const nearest = {
|
|
780
|
+
under: function(desired, nozzel = NOZZEL_SIZE, nozzie = 0) {
|
|
1138
781
|
return (Math.floor(desired / nozzel) + nozzie) * nozzel;
|
|
1139
782
|
},
|
|
1140
|
-
over: function
|
|
1141
|
-
var nozzel = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : NOZZEL_SIZE;
|
|
1142
|
-
var nozzie = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
783
|
+
over: function(desired, nozzel = NOZZEL_SIZE, nozzie = 0) {
|
|
1143
784
|
return (Math.ceil(desired / nozzel) + nozzie) * nozzel;
|
|
1144
785
|
}
|
|
1145
786
|
};
|
|
@@ -1167,9 +808,9 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1167
808
|
debug$2(msg, JSON.stringify(o.getBounds()), JSON.stringify(this.size(o.getBounds())));
|
|
1168
809
|
}
|
|
1169
810
|
function jscadToString(o) {
|
|
1170
|
-
if (
|
|
811
|
+
if (typeof o == "object") {
|
|
1171
812
|
if (o.polygons) {
|
|
1172
|
-
return
|
|
813
|
+
return `{\npolygons: ${o.polygons.length},\nproperties: "${Object.keys(o.properties)}"\n}\n`;
|
|
1173
814
|
}
|
|
1174
815
|
} else {
|
|
1175
816
|
return o.toString();
|
|
@@ -1210,12 +851,12 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1210
851
|
}
|
|
1211
852
|
function text(text) {
|
|
1212
853
|
var l = vector_char(0, 0, text);
|
|
1213
|
-
var
|
|
854
|
+
var char = l.segments.reduce(function(result, segment) {
|
|
1214
855
|
var path = new CSG.Path2D(segment);
|
|
1215
856
|
var cag = path.expandToCAG(2);
|
|
1216
857
|
return result ? result.union(cag) : cag;
|
|
1217
858
|
}, undefined);
|
|
1218
|
-
return
|
|
859
|
+
return char;
|
|
1219
860
|
}
|
|
1220
861
|
function unitCube(length, radius) {
|
|
1221
862
|
radius = radius || .5;
|
|
@@ -1271,7 +912,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1271
912
|
function mapPick(o, names, f, options) {
|
|
1272
913
|
return names.reduce(function(result, name, index) {
|
|
1273
914
|
if (!o[name]) {
|
|
1274
|
-
throw new Error(
|
|
915
|
+
throw new Error(`${name} not found in ${options.name}: ${Object.keys(o).join(",")}`);
|
|
1275
916
|
}
|
|
1276
917
|
result.push(f ? f(o[name], name, index, o) : o[name]);
|
|
1277
918
|
return result;
|
|
@@ -1303,7 +944,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1303
944
|
function xyz2array(size) {
|
|
1304
945
|
return [ size.x, size.y, size.z ];
|
|
1305
946
|
}
|
|
1306
|
-
|
|
947
|
+
const rotationAxes = {
|
|
1307
948
|
x: [ 1, 0, 0 ],
|
|
1308
949
|
y: [ 0, 1, 0 ],
|
|
1309
950
|
z: [ 0, 0, 1 ]
|
|
@@ -1381,7 +1022,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1381
1022
|
function mirrored4(x) {
|
|
1382
1023
|
return x.union([ x.mirroredY(90), x.mirroredX(90), x.mirroredY(90).mirroredX(90) ]);
|
|
1383
1024
|
}
|
|
1384
|
-
|
|
1025
|
+
const flushSide = {
|
|
1385
1026
|
"above-outside": [ 1, 0 ],
|
|
1386
1027
|
"above-inside": [ 1, 1 ],
|
|
1387
1028
|
"below-outside": [ 0, 1 ],
|
|
@@ -1411,8 +1052,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1411
1052
|
return w[side[0]][axis] - m[side[1]][axis];
|
|
1412
1053
|
});
|
|
1413
1054
|
}
|
|
1414
|
-
function calcSnap(moveobj, withobj, axes, orientation) {
|
|
1415
|
-
var delta = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
|
|
1055
|
+
function calcSnap(moveobj, withobj, axes, orientation, delta = 0) {
|
|
1416
1056
|
var side = flushSide[orientation];
|
|
1417
1057
|
if (!side) {
|
|
1418
1058
|
var fix = {
|
|
@@ -1478,7 +1118,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1478
1118
|
objectSize = objectSize || size(bounds);
|
|
1479
1119
|
return bounds[0].plus(objectSize.dividedBy(2));
|
|
1480
1120
|
} catch (err) {
|
|
1481
|
-
error(
|
|
1121
|
+
error(`centroid error o:${jscadToString(o)} objectSize: ${objectSize}`, undefined, err);
|
|
1482
1122
|
}
|
|
1483
1123
|
}
|
|
1484
1124
|
function calcmidlineTo(o, axis, to) {
|
|
@@ -1499,8 +1139,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1499
1139
|
});
|
|
1500
1140
|
return t;
|
|
1501
1141
|
}
|
|
1502
|
-
function calcCenterWith(o, axes, withObj) {
|
|
1503
|
-
var delta = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
1142
|
+
function calcCenterWith(o, axes, withObj, delta = 0) {
|
|
1504
1143
|
var objectCentroid = centroid(o);
|
|
1505
1144
|
var withCentroid = centroid(withObj);
|
|
1506
1145
|
var t = axisApply(axes, function(i, axis) {
|
|
@@ -1522,12 +1161,9 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1522
1161
|
return bounds[0][a] + (isEmpty(dist) ? size[axis] / 2 : dist);
|
|
1523
1162
|
});
|
|
1524
1163
|
}
|
|
1525
|
-
function bisect() {
|
|
1526
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1527
|
-
args[_key] = arguments[_key];
|
|
1528
|
-
}
|
|
1164
|
+
function bisect(...args) {
|
|
1529
1165
|
if (args.length < 2) {
|
|
1530
|
-
error("bisect
|
|
1166
|
+
error("bisect requires an object and an axis", "JSCAD_UTILS_INVALID_ARGS");
|
|
1531
1167
|
}
|
|
1532
1168
|
var object = args[0];
|
|
1533
1169
|
var axis = args[1];
|
|
@@ -1606,14 +1242,10 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1606
1242
|
if (options.addRotationCenter) g.add(unitAxis(objectSize.length() + 10, .1, rotationCenter), "rotationCenter");
|
|
1607
1243
|
return g;
|
|
1608
1244
|
}
|
|
1609
|
-
function slice(object
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {
|
|
1614
|
-
color: true,
|
|
1615
|
-
addRotationCenter: true
|
|
1616
|
-
};
|
|
1245
|
+
function slice(object, angle = 15, axis = "x", rotateaxis = "z", options = {
|
|
1246
|
+
color: true,
|
|
1247
|
+
addRotationCenter: true
|
|
1248
|
+
}) {
|
|
1617
1249
|
var info = normalVector(axis);
|
|
1618
1250
|
var rotationCenter = options.rotationCenter || new CSG.Vector3D(0, 0, 0);
|
|
1619
1251
|
var theRotationAxis = rotationAxes[rotateaxis];
|
|
@@ -1769,7 +1401,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1769
1401
|
var absoluteRadius = Math.abs(radius);
|
|
1770
1402
|
var si = sliceParams(orientation, radius, b);
|
|
1771
1403
|
debug$2("reShape", absoluteRadius, si);
|
|
1772
|
-
if (si.axis !== "z") throw new Error('reShape error: CAG.
|
|
1404
|
+
if (si.axis !== "z") throw new Error('reShape error: CAG._toPlanePolygons only uses the "z" axis. You must use the "z" axis for now.');
|
|
1773
1405
|
var cutplane = CSG.OrthoNormalBasis.GetCartesian(si.orthoNormalCartesian[0], si.orthoNormalCartesian[1]).translate(si.cutDelta);
|
|
1774
1406
|
var slice = object.sectionCut(cutplane);
|
|
1775
1407
|
var first = axisApply(si.axis, function() {
|
|
@@ -1830,12 +1462,11 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1830
1462
|
};
|
|
1831
1463
|
}
|
|
1832
1464
|
function rotateAround(part, solid, axis, angle) {
|
|
1833
|
-
var
|
|
1465
|
+
var {rotationCenter, rotationAxis} = calcRotate(part, solid, axis);
|
|
1834
1466
|
return part.rotate(rotationCenter, rotationAxis, angle);
|
|
1835
1467
|
}
|
|
1836
|
-
function cloneProperties(from, to) {
|
|
1837
|
-
return Object.entries(from).reduce(
|
|
1838
|
-
var _ref2 = _slicedToArray(_ref, 2), key = _ref2[0], value = _ref2[1];
|
|
1468
|
+
function cloneProperties(from, to, depth = 0) {
|
|
1469
|
+
return Object.entries(from).reduce((props, [key, value]) => {
|
|
1839
1470
|
props[key] = value;
|
|
1840
1471
|
return props;
|
|
1841
1472
|
}, to);
|
|
@@ -1846,14 +1477,85 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1846
1477
|
debug$2("clone", o, c, CSG);
|
|
1847
1478
|
return c;
|
|
1848
1479
|
}
|
|
1849
|
-
function addConnector(object, name) {
|
|
1850
|
-
var point = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [ 0, 0, 0 ];
|
|
1851
|
-
var axis = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [ 1, 0, 0 ];
|
|
1852
|
-
var normal = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [ 0, 0, 1 ];
|
|
1480
|
+
function addConnector(object, name, point = [ 0, 0, 0 ], axis = [ 1, 0, 0 ], normal = [ 0, 0, 1 ]) {
|
|
1853
1481
|
object.properties[name] = new CSG.Connector(point, axis, normal);
|
|
1854
1482
|
return object;
|
|
1855
1483
|
}
|
|
1856
|
-
var
|
|
1484
|
+
var util = Object.freeze({
|
|
1485
|
+
__proto__: null,
|
|
1486
|
+
NOZZEL_SIZE,
|
|
1487
|
+
addConnector,
|
|
1488
|
+
axis2array,
|
|
1489
|
+
axisApply,
|
|
1490
|
+
bisect,
|
|
1491
|
+
calcCenterWith,
|
|
1492
|
+
calcFlush,
|
|
1493
|
+
calcRotate,
|
|
1494
|
+
calcSnap,
|
|
1495
|
+
calcmidlineTo,
|
|
1496
|
+
center,
|
|
1497
|
+
centerWith,
|
|
1498
|
+
centerX,
|
|
1499
|
+
centerY,
|
|
1500
|
+
centroid,
|
|
1501
|
+
chamfer,
|
|
1502
|
+
clone,
|
|
1503
|
+
cm,
|
|
1504
|
+
defaults,
|
|
1505
|
+
depreciated,
|
|
1506
|
+
div,
|
|
1507
|
+
divA,
|
|
1508
|
+
divxyz,
|
|
1509
|
+
enlarge,
|
|
1510
|
+
error,
|
|
1511
|
+
fillet,
|
|
1512
|
+
fit,
|
|
1513
|
+
flush,
|
|
1514
|
+
flushSide,
|
|
1515
|
+
getDelta,
|
|
1516
|
+
identity,
|
|
1517
|
+
ifArray,
|
|
1518
|
+
inch,
|
|
1519
|
+
isEmpty,
|
|
1520
|
+
isNegative,
|
|
1521
|
+
jscadToString,
|
|
1522
|
+
label,
|
|
1523
|
+
map,
|
|
1524
|
+
mapPick,
|
|
1525
|
+
mapValues,
|
|
1526
|
+
midlineTo,
|
|
1527
|
+
mirrored4,
|
|
1528
|
+
mul,
|
|
1529
|
+
mulxyz,
|
|
1530
|
+
nearest,
|
|
1531
|
+
normalVector,
|
|
1532
|
+
pick,
|
|
1533
|
+
poly2solid,
|
|
1534
|
+
print,
|
|
1535
|
+
reShape,
|
|
1536
|
+
result,
|
|
1537
|
+
rotateAround,
|
|
1538
|
+
rotationAxes,
|
|
1539
|
+
scale,
|
|
1540
|
+
segment,
|
|
1541
|
+
shift,
|
|
1542
|
+
size,
|
|
1543
|
+
slice,
|
|
1544
|
+
sliceParams,
|
|
1545
|
+
slices2poly,
|
|
1546
|
+
snap,
|
|
1547
|
+
stretch,
|
|
1548
|
+
text,
|
|
1549
|
+
toArray,
|
|
1550
|
+
translator,
|
|
1551
|
+
unitAxis,
|
|
1552
|
+
unitCube,
|
|
1553
|
+
wedge,
|
|
1554
|
+
xyz2array,
|
|
1555
|
+
zero,
|
|
1556
|
+
zipObject
|
|
1557
|
+
});
|
|
1558
|
+
const debug$1 = Debug("jscadUtils:parts");
|
|
1857
1559
|
var parts = {
|
|
1858
1560
|
BBox: BBox$1,
|
|
1859
1561
|
Cube,
|
|
@@ -1861,16 +1563,13 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1861
1563
|
Cylinder,
|
|
1862
1564
|
Cone
|
|
1863
1565
|
};
|
|
1864
|
-
function BBox$1() {
|
|
1566
|
+
function BBox$1(...objects) {
|
|
1865
1567
|
function box(object) {
|
|
1866
1568
|
return CSG.cube({
|
|
1867
1569
|
center: object.centroid(),
|
|
1868
1570
|
radius: object.size().dividedBy(2)
|
|
1869
1571
|
});
|
|
1870
1572
|
}
|
|
1871
|
-
for (var _len = arguments.length, objects = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1872
|
-
objects[_key] = arguments[_key];
|
|
1873
|
-
}
|
|
1874
1573
|
return objects.reduce(function(bbox, part) {
|
|
1875
1574
|
var object = bbox ? union([ bbox, box(part) ]) : part;
|
|
1876
1575
|
return box(object);
|
|
@@ -1903,8 +1602,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1903
1602
|
});
|
|
1904
1603
|
return roundedcube;
|
|
1905
1604
|
}
|
|
1906
|
-
function Cylinder(diameter, height) {
|
|
1907
|
-
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1605
|
+
function Cylinder(diameter, height, options = {}) {
|
|
1908
1606
|
debug$1("parts.Cylinder", diameter, height, options);
|
|
1909
1607
|
options = Object.assign({
|
|
1910
1608
|
start: [ 0, 0, 0 ],
|
|
@@ -1914,8 +1612,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1914
1612
|
}, options);
|
|
1915
1613
|
return CSG.cylinder(options);
|
|
1916
1614
|
}
|
|
1917
|
-
function Cone(diameter1, diameter2, height) {
|
|
1918
|
-
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
1615
|
+
function Cone(diameter1, diameter2, height, options = {}) {
|
|
1919
1616
|
debug$1("parts.Cone", diameter1, diameter2, height, options);
|
|
1920
1617
|
return CSG.cylinder(Object.assign({
|
|
1921
1618
|
start: [ 0, 0, 0 ],
|
|
@@ -1944,9 +1641,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1944
1641
|
function Tube(outsideDiameter, insideDiameter, height, outsideOptions, insideOptions) {
|
|
1945
1642
|
return Cylinder(outsideDiameter, height, outsideOptions).subtract(Cylinder(insideDiameter, height, insideOptions || outsideOptions));
|
|
1946
1643
|
}
|
|
1947
|
-
function Anchor() {
|
|
1948
|
-
var width = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 10;
|
|
1949
|
-
var height = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10;
|
|
1644
|
+
function Anchor(width = 10, height = 10) {
|
|
1950
1645
|
var hole = Cylinder(width, height).Center().color("red");
|
|
1951
1646
|
var post = Cylinder(height / 2, width * .66).rotateX(90).align(hole, "xz").snap(hole, "y", "inside-").translate([ 0, 0, -height / 6 ]).color("purple");
|
|
1952
1647
|
return Group({
|
|
@@ -1966,7 +1661,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1966
1661
|
});
|
|
1967
1662
|
return board;
|
|
1968
1663
|
}
|
|
1969
|
-
|
|
1664
|
+
const Hardware = {
|
|
1970
1665
|
Orientation: {
|
|
1971
1666
|
up: {
|
|
1972
1667
|
head: "outside-",
|
|
@@ -1977,7 +1672,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1977
1672
|
clear: "inside-"
|
|
1978
1673
|
}
|
|
1979
1674
|
},
|
|
1980
|
-
Screw: function
|
|
1675
|
+
Screw: function(head, thread, headClearSpace, options) {
|
|
1981
1676
|
depreciated("Screw", false, "Use the jscad-hardware screw methods instead");
|
|
1982
1677
|
options = Object.assign(options, {
|
|
1983
1678
|
orientation: "up",
|
|
@@ -1993,7 +1688,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1993
1688
|
}
|
|
1994
1689
|
return group;
|
|
1995
1690
|
},
|
|
1996
|
-
PanHeadScrew: function
|
|
1691
|
+
PanHeadScrew: function(headDiameter, headLength, diameter, length, clearLength, options) {
|
|
1997
1692
|
depreciated("PanHeadScrew", false, "Use the jscad-hardware screw methods instead");
|
|
1998
1693
|
var head = Cylinder(headDiameter, headLength);
|
|
1999
1694
|
var thread = Cylinder(diameter, length);
|
|
@@ -2002,7 +1697,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2002
1697
|
}
|
|
2003
1698
|
return Hardware.Screw(head, thread, headClearSpace, options);
|
|
2004
1699
|
},
|
|
2005
|
-
HexHeadScrew: function
|
|
1700
|
+
HexHeadScrew: function(headDiameter, headLength, diameter, length, clearLength, options) {
|
|
2006
1701
|
depreciated("HexHeadScrew", false, "Use the jscad-hardware screw methods instead");
|
|
2007
1702
|
var head = Hexagon(headDiameter, headLength);
|
|
2008
1703
|
var thread = Cylinder(diameter, length);
|
|
@@ -2011,7 +1706,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2011
1706
|
}
|
|
2012
1707
|
return Hardware.Screw(head, thread, headClearSpace, options);
|
|
2013
1708
|
},
|
|
2014
|
-
FlatHeadScrew: function
|
|
1709
|
+
FlatHeadScrew: function(headDiameter, headLength, diameter, length, clearLength, options) {
|
|
2015
1710
|
depreciated("FlatHeadScrew", false, "Use the jscad-hardware screw methods instead");
|
|
2016
1711
|
var head = Cone(headDiameter, diameter, headLength);
|
|
2017
1712
|
var thread = Cylinder(diameter, length);
|
|
@@ -2023,20 +1718,20 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2023
1718
|
};
|
|
2024
1719
|
var parts$1 = Object.freeze({
|
|
2025
1720
|
__proto__: null,
|
|
2026
|
-
|
|
1721
|
+
Anchor,
|
|
2027
1722
|
BBox: BBox$1,
|
|
1723
|
+
Board,
|
|
1724
|
+
Cone,
|
|
2028
1725
|
Cube,
|
|
2029
|
-
RoundedCube,
|
|
2030
1726
|
Cylinder,
|
|
2031
|
-
|
|
1727
|
+
Hardware,
|
|
2032
1728
|
Hexagon,
|
|
1729
|
+
RoundedCube,
|
|
2033
1730
|
Triangle,
|
|
2034
1731
|
Tube,
|
|
2035
|
-
|
|
2036
|
-
Board,
|
|
2037
|
-
Hardware
|
|
1732
|
+
default: parts
|
|
2038
1733
|
});
|
|
2039
|
-
|
|
1734
|
+
const debug = Debug("jscadUtils:boxes");
|
|
2040
1735
|
function RabbetJoin(box, thickness, cutHeight) {
|
|
2041
1736
|
depreciated("RabbetJoin", true, "Use 'Rabbet' instead");
|
|
2042
1737
|
return rabbetJoin(box, thickness, cutHeight);
|
|
@@ -2049,17 +1744,16 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2049
1744
|
var top = bottom.parts.positive.bisect("z", -thickness);
|
|
2050
1745
|
return Group("top,middle,bottom", [ top.parts.positive, top.parts.negative.color("green"), bottom.parts.negative ]);
|
|
2051
1746
|
}
|
|
2052
|
-
function Rabett(box, thickness, gap, height, face) {
|
|
2053
|
-
var options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
|
|
1747
|
+
function Rabett(box, thickness, gap, height, face, options = {}) {
|
|
2054
1748
|
debug("Rabett", "thickness", thickness, "gap", gap, "height", height, "face", face);
|
|
2055
1749
|
gap = gap || .25;
|
|
2056
1750
|
var inside = thickness - gap;
|
|
2057
1751
|
var outside = -thickness + gap;
|
|
2058
1752
|
debug("inside", inside, "outside", outside);
|
|
2059
1753
|
var group = Group();
|
|
2060
|
-
var
|
|
1754
|
+
var {positive: top, negative: lower2_3rd} = box.bisect("z", height, options).parts;
|
|
2061
1755
|
var lowerBisectHeight = Math.sign(height) < 0 ? face * Math.sign(height) : height - face;
|
|
2062
|
-
var
|
|
1756
|
+
var {positive: middle, negative: bottom} = lower2_3rd.bisect("z", lowerBisectHeight, options).parts;
|
|
2063
1757
|
var middleTop = middle.color("yellow").subtract(middle.color("darkred").enlarge([ outside, outside, 0 ]));
|
|
2064
1758
|
group.add(top.union(middleTop), "top");
|
|
2065
1759
|
var bottomOutline = middle.color("yellow").subtract(middle.color("orange").enlarge([ outside, outside, 0 ])).enlarge([ outside, outside, 0 ]);
|
|
@@ -2068,9 +1762,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2068
1762
|
group.add(bottom.color("orange").union(middle.color("green").subtract(middle.color("red").enlarge([ inside, inside, 0 ])).subtract(middleTop)), "bottom");
|
|
2069
1763
|
return group;
|
|
2070
1764
|
}
|
|
2071
|
-
|
|
2072
|
-
var gap = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : .25;
|
|
2073
|
-
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
1765
|
+
const RabettTopBottom = function rabbetTMB(box, thickness, gap = .25, options = {}) {
|
|
2074
1766
|
options = Object.assign({
|
|
2075
1767
|
removableTop: true,
|
|
2076
1768
|
removableBottom: true,
|
|
@@ -2103,7 +1795,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2103
1795
|
}
|
|
2104
1796
|
return group;
|
|
2105
1797
|
};
|
|
2106
|
-
|
|
1798
|
+
const CutOut = function cutOut(o, h, box, plug, gap) {
|
|
2107
1799
|
gap = gap || .25;
|
|
2108
1800
|
var s = o.size();
|
|
2109
1801
|
var cutout = o.intersect(box);
|
|
@@ -2121,7 +1813,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2121
1813
|
insert: union([ o, top ]).intersect(box).subtract(o).enlarge([ -gap, 0, 0 ]).union(clip.subtract(plug).enlarge(-gap, -gap, 0)).color("blue")
|
|
2122
1814
|
});
|
|
2123
1815
|
};
|
|
2124
|
-
|
|
1816
|
+
const Rectangle = function(size, thickness, cb) {
|
|
2125
1817
|
thickness = thickness || 2;
|
|
2126
1818
|
var s = div$1(xyz2array(size), 2);
|
|
2127
1819
|
var r = add(s, thickness);
|
|
@@ -2135,7 +1827,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2135
1827
|
if (cb) box = cb(box);
|
|
2136
1828
|
return box;
|
|
2137
1829
|
};
|
|
2138
|
-
|
|
1830
|
+
const Hollow = function(object, thickness, interiorcb, exteriorcb) {
|
|
2139
1831
|
thickness = thickness || 2;
|
|
2140
1832
|
var size = -thickness * 2;
|
|
2141
1833
|
interiorcb = interiorcb || identity;
|
|
@@ -2143,7 +1835,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2143
1835
|
if (exteriorcb) box = exteriorcb(box);
|
|
2144
1836
|
return box;
|
|
2145
1837
|
};
|
|
2146
|
-
|
|
1838
|
+
const BBox = function(o) {
|
|
2147
1839
|
depreciated("BBox", true, "Use 'parts.BBox' instead");
|
|
2148
1840
|
var s = div$1(xyz2array(o.size()), 2);
|
|
2149
1841
|
return CSG.cube({
|
|
@@ -2154,8 +1846,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2154
1846
|
function getRadius(o) {
|
|
2155
1847
|
return div$1(xyz2array(o.size()), 2);
|
|
2156
1848
|
}
|
|
2157
|
-
function rabbetJoin(box, thickness) {
|
|
2158
|
-
var gap = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : .25;
|
|
1849
|
+
function rabbetJoin(box, thickness, gap = .25) {
|
|
2159
1850
|
var r = add(getRadius(box), -thickness / 2);
|
|
2160
1851
|
r[2] = thickness / 2;
|
|
2161
1852
|
var cutter = CSG.cube({
|
|
@@ -2173,16 +1864,17 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2173
1864
|
}
|
|
2174
1865
|
var Boxes = Object.freeze({
|
|
2175
1866
|
__proto__: null,
|
|
1867
|
+
BBox,
|
|
1868
|
+
CutOut,
|
|
1869
|
+
Hollow,
|
|
2176
1870
|
RabbetJoin,
|
|
2177
|
-
topMiddleBottom,
|
|
2178
1871
|
Rabett,
|
|
2179
1872
|
RabettTopBottom,
|
|
2180
|
-
CutOut,
|
|
2181
1873
|
Rectangle,
|
|
2182
|
-
|
|
2183
|
-
BBox
|
|
1874
|
+
topMiddleBottom
|
|
2184
1875
|
});
|
|
2185
|
-
|
|
1876
|
+
const compatV1 = {
|
|
1877
|
+
...util,
|
|
2186
1878
|
group: Group,
|
|
2187
1879
|
init: init$1,
|
|
2188
1880
|
triangle: triUtils,
|
|
@@ -2190,7 +1882,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2190
1882
|
parts: parts$1,
|
|
2191
1883
|
Boxes,
|
|
2192
1884
|
Debug
|
|
2193
|
-
}
|
|
1885
|
+
};
|
|
2194
1886
|
exports.Boxes = Boxes;
|
|
2195
1887
|
exports.Debug = Debug;
|
|
2196
1888
|
exports.Group = Group;
|
|
@@ -2200,9 +1892,6 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2200
1892
|
exports.parts = parts$1;
|
|
2201
1893
|
exports.triUtils = triUtils;
|
|
2202
1894
|
exports.util = util;
|
|
2203
|
-
Object.defineProperty(exports, "__esModule", {
|
|
2204
|
-
value: true
|
|
2205
|
-
});
|
|
2206
1895
|
return exports;
|
|
2207
1896
|
}({}, jsCadCSG, scadApi);
|
|
2208
1897
|
const debug = jscadUtils.Debug("jscadUtils:initJscadutils");
|