@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
|
@@ -50,329 +50,13 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
50
50
|
});
|
|
51
51
|
var jscadUtils = function(exports, jsCadCSG, scadApi) {
|
|
52
52
|
"use strict";
|
|
53
|
-
function
|
|
54
|
-
return e && typeof e === "object" && "default" in e ? e : {
|
|
55
|
-
default: e
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
var jsCadCSG__default = _interopDefaultLegacy(jsCadCSG);
|
|
59
|
-
var scadApi__default = _interopDefaultLegacy(scadApi);
|
|
60
|
-
var util = Object.freeze({
|
|
61
|
-
__proto__: null,
|
|
62
|
-
get NOZZEL_SIZE() {
|
|
63
|
-
return NOZZEL_SIZE;
|
|
64
|
-
},
|
|
65
|
-
get nearest() {
|
|
66
|
-
return nearest;
|
|
67
|
-
},
|
|
68
|
-
get identity() {
|
|
69
|
-
return identity;
|
|
70
|
-
},
|
|
71
|
-
get result() {
|
|
72
|
-
return result;
|
|
73
|
-
},
|
|
74
|
-
get defaults() {
|
|
75
|
-
return defaults;
|
|
76
|
-
},
|
|
77
|
-
get isEmpty() {
|
|
78
|
-
return isEmpty;
|
|
79
|
-
},
|
|
80
|
-
get isNegative() {
|
|
81
|
-
return isNegative;
|
|
82
|
-
},
|
|
83
|
-
get print() {
|
|
84
|
-
return print;
|
|
85
|
-
},
|
|
86
|
-
get jscadToString() {
|
|
87
|
-
return jscadToString;
|
|
88
|
-
},
|
|
89
|
-
get error() {
|
|
90
|
-
return error;
|
|
91
|
-
},
|
|
92
|
-
get depreciated() {
|
|
93
|
-
return depreciated;
|
|
94
|
-
},
|
|
95
|
-
get inch() {
|
|
96
|
-
return inch;
|
|
97
|
-
},
|
|
98
|
-
get cm() {
|
|
99
|
-
return cm;
|
|
100
|
-
},
|
|
101
|
-
get label() {
|
|
102
|
-
return label;
|
|
103
|
-
},
|
|
104
|
-
get text() {
|
|
105
|
-
return text;
|
|
106
|
-
},
|
|
107
|
-
get unitCube() {
|
|
108
|
-
return unitCube;
|
|
109
|
-
},
|
|
110
|
-
get unitAxis() {
|
|
111
|
-
return unitAxis;
|
|
112
|
-
},
|
|
113
|
-
get toArray() {
|
|
114
|
-
return toArray;
|
|
115
|
-
},
|
|
116
|
-
get ifArray() {
|
|
117
|
-
return ifArray;
|
|
118
|
-
},
|
|
119
|
-
get segment() {
|
|
120
|
-
return segment;
|
|
121
|
-
},
|
|
122
|
-
get zipObject() {
|
|
123
|
-
return zipObject;
|
|
124
|
-
},
|
|
125
|
-
get map() {
|
|
126
|
-
return map;
|
|
127
|
-
},
|
|
128
|
-
get mapValues() {
|
|
129
|
-
return mapValues;
|
|
130
|
-
},
|
|
131
|
-
get pick() {
|
|
132
|
-
return pick;
|
|
133
|
-
},
|
|
134
|
-
get mapPick() {
|
|
135
|
-
return mapPick;
|
|
136
|
-
},
|
|
137
|
-
get divA() {
|
|
138
|
-
return divA;
|
|
139
|
-
},
|
|
140
|
-
get divxyz() {
|
|
141
|
-
return divxyz;
|
|
142
|
-
},
|
|
143
|
-
get div() {
|
|
144
|
-
return div;
|
|
145
|
-
},
|
|
146
|
-
get mulxyz() {
|
|
147
|
-
return mulxyz;
|
|
148
|
-
},
|
|
149
|
-
get mul() {
|
|
150
|
-
return mul;
|
|
151
|
-
},
|
|
152
|
-
get xyz2array() {
|
|
153
|
-
return xyz2array;
|
|
154
|
-
},
|
|
155
|
-
get rotationAxes() {
|
|
156
|
-
return rotationAxes;
|
|
157
|
-
},
|
|
158
|
-
get size() {
|
|
159
|
-
return size;
|
|
160
|
-
},
|
|
161
|
-
get scale() {
|
|
162
|
-
return scale;
|
|
163
|
-
},
|
|
164
|
-
get center() {
|
|
165
|
-
return center;
|
|
166
|
-
},
|
|
167
|
-
get centerY() {
|
|
168
|
-
return centerY;
|
|
169
|
-
},
|
|
170
|
-
get centerX() {
|
|
171
|
-
return centerX;
|
|
172
|
-
},
|
|
173
|
-
get enlarge() {
|
|
174
|
-
return enlarge;
|
|
175
|
-
},
|
|
176
|
-
get fit() {
|
|
177
|
-
return fit;
|
|
178
|
-
},
|
|
179
|
-
get shift() {
|
|
180
|
-
return shift;
|
|
181
|
-
},
|
|
182
|
-
get zero() {
|
|
183
|
-
return zero;
|
|
184
|
-
},
|
|
185
|
-
get mirrored4() {
|
|
186
|
-
return mirrored4;
|
|
187
|
-
},
|
|
188
|
-
get flushSide() {
|
|
189
|
-
return flushSide;
|
|
190
|
-
},
|
|
191
|
-
get calcFlush() {
|
|
192
|
-
return calcFlush;
|
|
193
|
-
},
|
|
194
|
-
get calcSnap() {
|
|
195
|
-
return calcSnap;
|
|
196
|
-
},
|
|
197
|
-
get snap() {
|
|
198
|
-
return snap;
|
|
199
|
-
},
|
|
200
|
-
get flush() {
|
|
201
|
-
return flush;
|
|
202
|
-
},
|
|
203
|
-
get axisApply() {
|
|
204
|
-
return axisApply;
|
|
205
|
-
},
|
|
206
|
-
get axis2array() {
|
|
207
|
-
return axis2array;
|
|
208
|
-
},
|
|
209
|
-
get centroid() {
|
|
210
|
-
return centroid;
|
|
211
|
-
},
|
|
212
|
-
get calcmidlineTo() {
|
|
213
|
-
return calcmidlineTo;
|
|
214
|
-
},
|
|
215
|
-
get midlineTo() {
|
|
216
|
-
return midlineTo;
|
|
217
|
-
},
|
|
218
|
-
get translator() {
|
|
219
|
-
return translator;
|
|
220
|
-
},
|
|
221
|
-
get calcCenterWith() {
|
|
222
|
-
return calcCenterWith;
|
|
223
|
-
},
|
|
224
|
-
get centerWith() {
|
|
225
|
-
return centerWith;
|
|
226
|
-
},
|
|
227
|
-
get getDelta() {
|
|
228
|
-
return getDelta;
|
|
229
|
-
},
|
|
230
|
-
get bisect() {
|
|
231
|
-
return bisect;
|
|
232
|
-
},
|
|
233
|
-
get slice() {
|
|
234
|
-
return slice;
|
|
235
|
-
},
|
|
236
|
-
get wedge() {
|
|
237
|
-
return wedge;
|
|
238
|
-
},
|
|
239
|
-
get stretch() {
|
|
240
|
-
return stretch;
|
|
241
|
-
},
|
|
242
|
-
get poly2solid() {
|
|
243
|
-
return poly2solid;
|
|
244
|
-
},
|
|
245
|
-
get slices2poly() {
|
|
246
|
-
return slices2poly;
|
|
247
|
-
},
|
|
248
|
-
get normalVector() {
|
|
249
|
-
return normalVector;
|
|
250
|
-
},
|
|
251
|
-
get sliceParams() {
|
|
252
|
-
return sliceParams;
|
|
253
|
-
},
|
|
254
|
-
get reShape() {
|
|
255
|
-
return reShape;
|
|
256
|
-
},
|
|
257
|
-
get chamfer() {
|
|
258
|
-
return chamfer;
|
|
259
|
-
},
|
|
260
|
-
get fillet() {
|
|
261
|
-
return fillet;
|
|
262
|
-
},
|
|
263
|
-
get calcRotate() {
|
|
264
|
-
return calcRotate;
|
|
265
|
-
},
|
|
266
|
-
get rotateAround() {
|
|
267
|
-
return rotateAround;
|
|
268
|
-
},
|
|
269
|
-
get clone() {
|
|
270
|
-
return clone;
|
|
271
|
-
},
|
|
272
|
-
get addConnector() {
|
|
273
|
-
return addConnector;
|
|
274
|
-
}
|
|
275
|
-
});
|
|
276
|
-
function _arrayLikeToArray(r, a) {
|
|
277
|
-
(null == a || a > r.length) && (a = r.length);
|
|
278
|
-
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
279
|
-
return n;
|
|
280
|
-
}
|
|
281
|
-
function _arrayWithHoles(r) {
|
|
282
|
-
if (Array.isArray(r)) return r;
|
|
283
|
-
}
|
|
284
|
-
function _defineProperty(e, r, t) {
|
|
285
|
-
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
286
|
-
value: t,
|
|
287
|
-
enumerable: !0,
|
|
288
|
-
configurable: !0,
|
|
289
|
-
writable: !0
|
|
290
|
-
}) : e[r] = t, e;
|
|
291
|
-
}
|
|
292
|
-
function _iterableToArrayLimit(r, l) {
|
|
293
|
-
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
294
|
-
if (null != t) {
|
|
295
|
-
var e, n, i, u, a = [], f = !0, o = !1;
|
|
296
|
-
try {
|
|
297
|
-
if (i = (t = t.call(r)).next, 0 === l) {
|
|
298
|
-
if (Object(t) !== t) return;
|
|
299
|
-
f = !1;
|
|
300
|
-
} else for (;!(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0) ;
|
|
301
|
-
} catch (r) {
|
|
302
|
-
o = !0, n = r;
|
|
303
|
-
} finally {
|
|
304
|
-
try {
|
|
305
|
-
if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
|
|
306
|
-
} finally {
|
|
307
|
-
if (o) throw n;
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
return a;
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
function _nonIterableRest() {
|
|
314
|
-
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
315
|
-
}
|
|
316
|
-
function ownKeys(e, r) {
|
|
317
|
-
var t = Object.keys(e);
|
|
318
|
-
if (Object.getOwnPropertySymbols) {
|
|
319
|
-
var o = Object.getOwnPropertySymbols(e);
|
|
320
|
-
r && (o = o.filter(function(r) {
|
|
321
|
-
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
322
|
-
})), t.push.apply(t, o);
|
|
323
|
-
}
|
|
324
|
-
return t;
|
|
325
|
-
}
|
|
326
|
-
function _objectSpread2(e) {
|
|
327
|
-
for (var r = 1; r < arguments.length; r++) {
|
|
328
|
-
var t = null != arguments[r] ? arguments[r] : {};
|
|
329
|
-
r % 2 ? ownKeys(Object(t), !0).forEach(function(r) {
|
|
330
|
-
_defineProperty(e, r, t[r]);
|
|
331
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r) {
|
|
332
|
-
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
333
|
-
});
|
|
334
|
-
}
|
|
335
|
-
return e;
|
|
336
|
-
}
|
|
337
|
-
function _slicedToArray(r, e) {
|
|
338
|
-
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
|
|
339
|
-
}
|
|
340
|
-
function _toPrimitive(t, r) {
|
|
341
|
-
if ("object" != typeof t || !t) return t;
|
|
342
|
-
var e = t[Symbol.toPrimitive];
|
|
343
|
-
if (void 0 !== e) {
|
|
344
|
-
var i = e.call(t, r || "default");
|
|
345
|
-
if ("object" != typeof i) return i;
|
|
346
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
347
|
-
}
|
|
348
|
-
return ("string" === r ? String : Number)(t);
|
|
349
|
-
}
|
|
350
|
-
function _toPropertyKey(t) {
|
|
351
|
-
var i = _toPrimitive(t, "string");
|
|
352
|
-
return "symbol" == typeof i ? i : i + "";
|
|
353
|
-
}
|
|
354
|
-
function _typeof(o) {
|
|
355
|
-
"@babel/helpers - typeof";
|
|
356
|
-
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
357
|
-
return typeof o;
|
|
358
|
-
} : function(o) {
|
|
359
|
-
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
360
|
-
}, _typeof(o);
|
|
361
|
-
}
|
|
362
|
-
function _unsupportedIterableToArray(r, a) {
|
|
363
|
-
if (r) {
|
|
364
|
-
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
365
|
-
var t = {}.toString.call(r).slice(8, -1);
|
|
366
|
-
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;
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
var toRadians = function toRadians(deg) {
|
|
53
|
+
const toRadians = function toRadians(deg) {
|
|
370
54
|
return deg / 180 * Math.PI;
|
|
371
55
|
};
|
|
372
|
-
|
|
56
|
+
const toDegrees = function toDegrees(rad) {
|
|
373
57
|
return rad * (180 / Math.PI);
|
|
374
58
|
};
|
|
375
|
-
|
|
59
|
+
const solve = function(p1, p2) {
|
|
376
60
|
var r = {
|
|
377
61
|
c: 90,
|
|
378
62
|
A: Math.abs(p2.x - p1.x),
|
|
@@ -384,7 +68,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
384
68
|
r.a = 90 - r.b;
|
|
385
69
|
return r;
|
|
386
70
|
};
|
|
387
|
-
|
|
71
|
+
const solve90SA = function(r) {
|
|
388
72
|
r = Object.assign(r, {
|
|
389
73
|
C: 90
|
|
390
74
|
});
|
|
@@ -396,7 +80,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
396
80
|
r.b = r.b || r.a / Math.tan(arad);
|
|
397
81
|
return r;
|
|
398
82
|
};
|
|
399
|
-
|
|
83
|
+
const solve90ac = function(r) {
|
|
400
84
|
r = Object.assign(r, {
|
|
401
85
|
C: 90
|
|
402
86
|
});
|
|
@@ -417,29 +101,29 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
417
101
|
}
|
|
418
102
|
var triUtils = Object.freeze({
|
|
419
103
|
__proto__: null,
|
|
420
|
-
toRadians,
|
|
421
|
-
toDegrees,
|
|
422
104
|
solve,
|
|
423
105
|
solve90SA,
|
|
424
106
|
solve90ac,
|
|
425
|
-
solveab
|
|
107
|
+
solveab,
|
|
108
|
+
toDegrees,
|
|
109
|
+
toRadians
|
|
426
110
|
});
|
|
427
|
-
|
|
111
|
+
const div$1 = function(a, f) {
|
|
428
112
|
return a.map(function(e) {
|
|
429
113
|
return e / f;
|
|
430
114
|
});
|
|
431
115
|
};
|
|
432
|
-
|
|
116
|
+
const addValue = function(a, f) {
|
|
433
117
|
return a.map(function(e) {
|
|
434
118
|
return e + f;
|
|
435
119
|
});
|
|
436
120
|
};
|
|
437
|
-
|
|
121
|
+
const addArray = function(a, f) {
|
|
438
122
|
return a.map(function(e, i) {
|
|
439
123
|
return e + f[i];
|
|
440
124
|
});
|
|
441
125
|
};
|
|
442
|
-
|
|
126
|
+
const add = function(a) {
|
|
443
127
|
return Array.prototype.slice.call(arguments, 1).reduce(function(result, arg) {
|
|
444
128
|
if (Array.isArray(arg)) {
|
|
445
129
|
result = addArray(result, arg);
|
|
@@ -449,28 +133,28 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
449
133
|
return result;
|
|
450
134
|
}, a);
|
|
451
135
|
};
|
|
452
|
-
|
|
136
|
+
const fromxyz = function(object) {
|
|
453
137
|
return Array.isArray(object) ? object : [ object.x, object.y, object.z ];
|
|
454
138
|
};
|
|
455
|
-
|
|
139
|
+
const toxyz = function(a) {
|
|
456
140
|
return {
|
|
457
141
|
x: a[0],
|
|
458
142
|
y: a[1],
|
|
459
143
|
z: a[2]
|
|
460
144
|
};
|
|
461
145
|
};
|
|
462
|
-
|
|
146
|
+
const first = function(a) {
|
|
463
147
|
return a ? a[0] : undefined;
|
|
464
148
|
};
|
|
465
|
-
|
|
149
|
+
const last = function(a) {
|
|
466
150
|
return a && a.length > 0 ? a[a.length - 1] : undefined;
|
|
467
151
|
};
|
|
468
|
-
|
|
152
|
+
const min = function(a) {
|
|
469
153
|
return a.reduce(function(result, value) {
|
|
470
154
|
return value < result ? value : result;
|
|
471
155
|
}, Number.MAX_VALUE);
|
|
472
156
|
};
|
|
473
|
-
|
|
157
|
+
const range = function(a, b) {
|
|
474
158
|
var result = [];
|
|
475
159
|
for (var i = a; i < b; i++) {
|
|
476
160
|
result.push(i);
|
|
@@ -479,21 +163,21 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
479
163
|
};
|
|
480
164
|
var array = Object.freeze({
|
|
481
165
|
__proto__: null,
|
|
482
|
-
div: div$1,
|
|
483
|
-
addValue,
|
|
484
|
-
addArray,
|
|
485
166
|
add,
|
|
486
|
-
|
|
487
|
-
|
|
167
|
+
addArray,
|
|
168
|
+
addValue,
|
|
169
|
+
div: div$1,
|
|
488
170
|
first,
|
|
171
|
+
fromxyz,
|
|
489
172
|
last,
|
|
490
173
|
min,
|
|
491
|
-
range
|
|
174
|
+
range,
|
|
175
|
+
toxyz
|
|
492
176
|
});
|
|
493
|
-
|
|
494
|
-
|
|
177
|
+
const debugColors = [ "#e41a1c", "#377eb8", "#4daf4a", "#984ea3", "#ff7f00", "#ffff33", "#a65628", "#f781bf", "#999999" ];
|
|
178
|
+
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" ];
|
|
495
179
|
var debugCount = 0;
|
|
496
|
-
|
|
180
|
+
const Debug = function(name) {
|
|
497
181
|
var checks = Object.assign({
|
|
498
182
|
enabled: [],
|
|
499
183
|
disabled: [],
|
|
@@ -501,31 +185,21 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
501
185
|
browser: true
|
|
502
186
|
}
|
|
503
187
|
}, jscadUtilsDebug || {});
|
|
504
|
-
var style = checks.options.browser ?
|
|
188
|
+
var style = checks.options.browser ? `color:${debugColors[debugCount++ % debugColors.length]}` : `${termColors[debugCount++ % termColors.length]}`;
|
|
505
189
|
var enabled = checks.enabled.some(function checkEnabled(check) {
|
|
506
190
|
return check.test(name);
|
|
507
191
|
}) && !checks.disabled.some(function checkEnabled(check) {
|
|
508
192
|
return check.test(name);
|
|
509
193
|
});
|
|
510
|
-
var logger = enabled ? checks.options.browser ?
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
(_console = console).log.apply(_console, [ "%c%s", style, name ].concat(msg));
|
|
516
|
-
} : function() {
|
|
517
|
-
var _console2;
|
|
518
|
-
for (var _len2 = arguments.length, msg = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
519
|
-
msg[_key2] = arguments[_key2];
|
|
520
|
-
}
|
|
521
|
-
(_console2 = console).log.apply(_console2, [ "".concat(name) ].concat(msg));
|
|
522
|
-
} : function() {
|
|
523
|
-
return undefined;
|
|
524
|
-
};
|
|
194
|
+
var logger = enabled ? checks.options.browser ? (...msg) => {
|
|
195
|
+
console.log("%c%s", style, name, ...msg);
|
|
196
|
+
} : (...msg) => {
|
|
197
|
+
console.log(`${name}`, ...msg);
|
|
198
|
+
} : () => undefined;
|
|
525
199
|
logger.enabled = enabled;
|
|
526
200
|
return logger;
|
|
527
201
|
};
|
|
528
|
-
|
|
202
|
+
const nameArray = {
|
|
529
203
|
aliceblue: "#f0f8ff",
|
|
530
204
|
antiquewhite: "#faebd7",
|
|
531
205
|
aqua: "#00ffff",
|
|
@@ -683,9 +357,11 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
683
357
|
h = h.replace(/^\#/, "");
|
|
684
358
|
if (h.length === 6) {
|
|
685
359
|
return [ parseInt(h.substr(0, 2), 16), parseInt(h.substr(2, 2), 16), parseInt(h.substr(4, 2), 16) ];
|
|
360
|
+
} else {
|
|
361
|
+
return [ 0, 0, 0 ];
|
|
686
362
|
}
|
|
687
363
|
}
|
|
688
|
-
|
|
364
|
+
const _name2rgb = {};
|
|
689
365
|
function name2rgb(n) {
|
|
690
366
|
if (!_name2rgb[n]) _name2rgb[n] = hex2rgb(name2hex(n));
|
|
691
367
|
return _name2rgb[n];
|
|
@@ -765,23 +441,14 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
765
441
|
proto.prototype.chamfer = function chamfer$1(radius, orientation, options) {
|
|
766
442
|
return chamfer(this, radius, orientation, options);
|
|
767
443
|
};
|
|
768
|
-
proto.prototype.bisect = function bisect$1() {
|
|
769
|
-
|
|
770
|
-
args[_key] = arguments[_key];
|
|
771
|
-
}
|
|
772
|
-
return bisect.apply(util, [ this ].concat(args));
|
|
444
|
+
proto.prototype.bisect = function bisect$1(...args) {
|
|
445
|
+
return bisect(this, ...args);
|
|
773
446
|
};
|
|
774
|
-
proto.prototype.slice = function slice$1() {
|
|
775
|
-
|
|
776
|
-
args[_key2] = arguments[_key2];
|
|
777
|
-
}
|
|
778
|
-
return slice.apply(util, [ this ].concat(args));
|
|
447
|
+
proto.prototype.slice = function slice$1(...args) {
|
|
448
|
+
return slice(this, ...args);
|
|
779
449
|
};
|
|
780
|
-
proto.prototype.wedge = function wedge$1() {
|
|
781
|
-
|
|
782
|
-
args[_key3] = arguments[_key3];
|
|
783
|
-
}
|
|
784
|
-
return wedge.apply(util, [ this ].concat(args));
|
|
450
|
+
proto.prototype.wedge = function wedge$1(...args) {
|
|
451
|
+
return wedge(this, ...args);
|
|
785
452
|
};
|
|
786
453
|
proto.prototype.stretch = function stretch$1(axis, distance, offset) {
|
|
787
454
|
return stretch(this, axis, distance, offset);
|
|
@@ -798,7 +465,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
798
465
|
return this._translate(arguments[0]);
|
|
799
466
|
} else {
|
|
800
467
|
var t = Array.prototype.slice.call(arguments, 0).reduce(function(result, arg) {
|
|
801
|
-
result = undefined(result, arg);
|
|
468
|
+
result = undefined.addArray(result, arg);
|
|
802
469
|
return result;
|
|
803
470
|
}, [ 0, 0, 0 ]);
|
|
804
471
|
return this._translate(t);
|
|
@@ -807,14 +474,10 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
807
474
|
proto.prototype.addConnector = function addConnector$1(name, point, axis, normal) {
|
|
808
475
|
return addConnector(this, name, point, axis, normal);
|
|
809
476
|
};
|
|
810
|
-
proto.prototype.connect = function connectTo(myConnectorName, otherConnector) {
|
|
811
|
-
var
|
|
812
|
-
var normalrotation = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
813
|
-
var myConnector = myConnectorName.split(".").reduce(function(a, v) {
|
|
814
|
-
return a[v];
|
|
815
|
-
}, this.properties);
|
|
477
|
+
proto.prototype.connect = function connectTo(myConnectorName, otherConnector, mirror = false, normalrotation = 0) {
|
|
478
|
+
var myConnector = myConnectorName.split(".").reduce((a, v) => a[v], this.properties);
|
|
816
479
|
if (!myConnector) {
|
|
817
|
-
error(
|
|
480
|
+
error(`The connector '${myConnectorName}' does not exist on the object [${Object.keys(this.properties).join(",")}]`, "Missing connector property");
|
|
818
481
|
}
|
|
819
482
|
return this.connectTo(myConnector, otherConnector, mirror, normalrotation);
|
|
820
483
|
};
|
|
@@ -824,16 +487,13 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
824
487
|
__proto__: null,
|
|
825
488
|
default: init
|
|
826
489
|
});
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
490
|
+
const {CSG, CAG} = jsCadCSG;
|
|
491
|
+
const {rectangular_extrude} = scadApi.extrusions;
|
|
492
|
+
const {vector_text, vector_char} = scadApi.text;
|
|
493
|
+
const {union} = scadApi.booleanOps;
|
|
831
494
|
init(CSG);
|
|
832
|
-
|
|
833
|
-
function JsCadUtilsGroup() {
|
|
834
|
-
var names = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
835
|
-
var parts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
836
|
-
var holes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
495
|
+
const debug$3 = Debug("jscadUtils:group");
|
|
496
|
+
function JsCadUtilsGroup(names = [], parts = {}, holes = []) {
|
|
837
497
|
this.name = "";
|
|
838
498
|
this.names = names;
|
|
839
499
|
this.parts = parts;
|
|
@@ -861,11 +521,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
861
521
|
}
|
|
862
522
|
return self;
|
|
863
523
|
};
|
|
864
|
-
JsCadUtilsGroup.prototype.combine = function(pieces) {
|
|
865
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
866
|
-
var map = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function(x) {
|
|
867
|
-
return x;
|
|
868
|
-
};
|
|
524
|
+
JsCadUtilsGroup.prototype.combine = function(pieces, options = {}, map = x => x) {
|
|
869
525
|
try {
|
|
870
526
|
var self = this;
|
|
871
527
|
options = Object.assign({
|
|
@@ -873,7 +529,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
873
529
|
}, options);
|
|
874
530
|
pieces = pieces ? pieces.split(",") : self.names;
|
|
875
531
|
if (pieces.length === 0) {
|
|
876
|
-
throw new Error(
|
|
532
|
+
throw new Error(`no pieces found in ${self.name} pieces: ${pieces} parts: ${Object.keys(self.parts)} names: ${self.names}`);
|
|
877
533
|
}
|
|
878
534
|
debug$3("combine", self.names, self.parts);
|
|
879
535
|
var g = union(mapPick(self.parts, pieces, function(value, key, index, object) {
|
|
@@ -883,14 +539,12 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
883
539
|
return g.subtractIf(self.holes && Array.isArray(self.holes) ? union(self.holes) : self.holes, self.holes && !options.noholes);
|
|
884
540
|
} catch (err) {
|
|
885
541
|
debug$3("combine error", this, pieces, options, err);
|
|
886
|
-
throw error(
|
|
542
|
+
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");
|
|
887
543
|
}
|
|
888
544
|
};
|
|
889
545
|
JsCadUtilsGroup.prototype.map = function(cb) {
|
|
890
546
|
var self = this;
|
|
891
|
-
self.parts = Object.keys(self.parts).filter(function(
|
|
892
|
-
return k !== "holes";
|
|
893
|
-
}).reduce(function(result, key) {
|
|
547
|
+
self.parts = Object.keys(self.parts).filter(k => k !== "holes").reduce(function(result, key) {
|
|
894
548
|
result[key] = cb(self.parts[key], key);
|
|
895
549
|
return result;
|
|
896
550
|
}, {});
|
|
@@ -906,7 +560,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
906
560
|
return self;
|
|
907
561
|
};
|
|
908
562
|
JsCadUtilsGroup.prototype.clone = function(name, map) {
|
|
909
|
-
debug$3("clone", name,
|
|
563
|
+
debug$3("clone", name, typeof name, map);
|
|
910
564
|
var self = this;
|
|
911
565
|
if (typeof name == "function") {
|
|
912
566
|
map = name;
|
|
@@ -958,7 +612,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
958
612
|
return self;
|
|
959
613
|
} catch (err) {
|
|
960
614
|
debug$3("snap error", this, part, to, axis, delta, err);
|
|
961
|
-
throw error(
|
|
615
|
+
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");
|
|
962
616
|
}
|
|
963
617
|
};
|
|
964
618
|
JsCadUtilsGroup.prototype.align = function align(part, to, axis, delta) {
|
|
@@ -973,7 +627,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
973
627
|
return self;
|
|
974
628
|
} catch (err) {
|
|
975
629
|
debug$3("align error", this, part, to, axis, delta, err);
|
|
976
|
-
throw error(
|
|
630
|
+
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");
|
|
977
631
|
}
|
|
978
632
|
};
|
|
979
633
|
JsCadUtilsGroup.prototype.center = function center(part) {
|
|
@@ -985,9 +639,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
985
639
|
var bounds = self.parts[part].getBounds();
|
|
986
640
|
return self.translate([ 0, 0, -bounds[0].z ]);
|
|
987
641
|
};
|
|
988
|
-
JsCadUtilsGroup.prototype.connectTo = function connectTo(partName, connectorName, to, toConnectorName) {
|
|
989
|
-
var mirror = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
|
|
990
|
-
var normalrotation = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 0;
|
|
642
|
+
JsCadUtilsGroup.prototype.connectTo = function connectTo(partName, connectorName, to, toConnectorName, mirror = true, normalrotation = 0) {
|
|
991
643
|
debug$3("connectTo", {
|
|
992
644
|
partName,
|
|
993
645
|
connectorName,
|
|
@@ -997,13 +649,9 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
997
649
|
normalrotation
|
|
998
650
|
});
|
|
999
651
|
var self = this;
|
|
1000
|
-
var myConnector = connectorName.split(".").reduce(
|
|
1001
|
-
return a[v];
|
|
1002
|
-
}, self.parts[partName].properties);
|
|
652
|
+
var myConnector = connectorName.split(".").reduce((a, v) => a[v], self.parts[partName].properties);
|
|
1003
653
|
debug$3("toConnector", to instanceof CSG.Connector);
|
|
1004
|
-
var toConnector = toConnectorName.split(".").reduce(
|
|
1005
|
-
return a[v];
|
|
1006
|
-
}, to.properties);
|
|
654
|
+
var toConnector = toConnectorName.split(".").reduce((a, v) => a[v], to.properties);
|
|
1007
655
|
var matrix = myConnector.getTransformationTo(toConnector, mirror, normalrotation);
|
|
1008
656
|
debug$3("connectTo", matrix);
|
|
1009
657
|
self.map(function(part) {
|
|
@@ -1042,15 +690,14 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1042
690
|
return g;
|
|
1043
691
|
};
|
|
1044
692
|
JsCadUtilsGroup.prototype.array = function(parts, map) {
|
|
1045
|
-
var _this = this;
|
|
1046
693
|
var self = this;
|
|
1047
694
|
var p = parts && parts.length > 0 && parts.split(",") || self.names;
|
|
1048
695
|
if (!map) map = identity;
|
|
1049
696
|
var a = [];
|
|
1050
|
-
p.forEach(
|
|
697
|
+
p.forEach(name => {
|
|
1051
698
|
if (!self.parts[name]) {
|
|
1052
|
-
debug$3("array error",
|
|
1053
|
-
throw error(
|
|
699
|
+
debug$3("array error", this, parts);
|
|
700
|
+
throw error(`group::array error "${name}" not found.\nthis: ${this}\nparts: "${parts}"\n`, "JSCAD_UTILS_GROUP_ERROR");
|
|
1054
701
|
}
|
|
1055
702
|
a.push(map(CSG.fromPolygons(self.parts[name].toPolygons()), name));
|
|
1056
703
|
});
|
|
@@ -1060,12 +707,12 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1060
707
|
var self = this;
|
|
1061
708
|
var piecesArray = pieces ? pieces.split(",") : self.names;
|
|
1062
709
|
return piecesArray.map(function(piece) {
|
|
1063
|
-
if (!self.parts[piece]) console.error(
|
|
710
|
+
if (!self.parts[piece]) console.error(`Cannot find ${piece} in ${self.names}`);
|
|
1064
711
|
return self.parts[piece];
|
|
1065
712
|
});
|
|
1066
713
|
};
|
|
1067
714
|
JsCadUtilsGroup.prototype.toString = function() {
|
|
1068
|
-
return
|
|
715
|
+
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}`;
|
|
1069
716
|
};
|
|
1070
717
|
JsCadUtilsGroup.prototype.setName = function(name) {
|
|
1071
718
|
this.name = name;
|
|
@@ -1095,9 +742,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1095
742
|
self.name = objectNames;
|
|
1096
743
|
} else {
|
|
1097
744
|
var objects = objectNames;
|
|
1098
|
-
self.names = Object.keys(objects).filter(
|
|
1099
|
-
return k !== "holes";
|
|
1100
|
-
});
|
|
745
|
+
self.names = Object.keys(objects).filter(k => k !== "holes");
|
|
1101
746
|
self.parts = Object.assign({}, objects);
|
|
1102
747
|
self.holes = objects.holes;
|
|
1103
748
|
}
|
|
@@ -1105,17 +750,13 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1105
750
|
}
|
|
1106
751
|
return new JsCadUtilsGroup(self.names, self.parts, self.holes);
|
|
1107
752
|
}
|
|
1108
|
-
|
|
753
|
+
const debug$2 = Debug("jscadUtils:util");
|
|
1109
754
|
var NOZZEL_SIZE = .4;
|
|
1110
|
-
|
|
1111
|
-
under: function
|
|
1112
|
-
var nozzel = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : NOZZEL_SIZE;
|
|
1113
|
-
var nozzie = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
755
|
+
const nearest = {
|
|
756
|
+
under: function(desired, nozzel = NOZZEL_SIZE, nozzie = 0) {
|
|
1114
757
|
return (Math.floor(desired / nozzel) + nozzie) * nozzel;
|
|
1115
758
|
},
|
|
1116
|
-
over: function
|
|
1117
|
-
var nozzel = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : NOZZEL_SIZE;
|
|
1118
|
-
var nozzie = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
759
|
+
over: function(desired, nozzel = NOZZEL_SIZE, nozzie = 0) {
|
|
1119
760
|
return (Math.ceil(desired / nozzel) + nozzie) * nozzel;
|
|
1120
761
|
}
|
|
1121
762
|
};
|
|
@@ -1143,9 +784,9 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1143
784
|
debug$2(msg, JSON.stringify(o.getBounds()), JSON.stringify(this.size(o.getBounds())));
|
|
1144
785
|
}
|
|
1145
786
|
function jscadToString(o) {
|
|
1146
|
-
if (
|
|
787
|
+
if (typeof o == "object") {
|
|
1147
788
|
if (o.polygons) {
|
|
1148
|
-
return
|
|
789
|
+
return `{\npolygons: ${o.polygons.length},\nproperties: "${Object.keys(o.properties)}"\n}\n`;
|
|
1149
790
|
}
|
|
1150
791
|
} else {
|
|
1151
792
|
return o.toString();
|
|
@@ -1186,12 +827,12 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1186
827
|
}
|
|
1187
828
|
function text(text) {
|
|
1188
829
|
var l = vector_char(0, 0, text);
|
|
1189
|
-
var
|
|
830
|
+
var char = l.segments.reduce(function(result, segment) {
|
|
1190
831
|
var path = new CSG.Path2D(segment);
|
|
1191
832
|
var cag = path.expandToCAG(2);
|
|
1192
833
|
return result ? result.union(cag) : cag;
|
|
1193
834
|
}, undefined);
|
|
1194
|
-
return
|
|
835
|
+
return char;
|
|
1195
836
|
}
|
|
1196
837
|
function unitCube(length, radius) {
|
|
1197
838
|
radius = radius || .5;
|
|
@@ -1247,7 +888,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1247
888
|
function mapPick(o, names, f, options) {
|
|
1248
889
|
return names.reduce(function(result, name, index) {
|
|
1249
890
|
if (!o[name]) {
|
|
1250
|
-
throw new Error(
|
|
891
|
+
throw new Error(`${name} not found in ${options.name}: ${Object.keys(o).join(",")}`);
|
|
1251
892
|
}
|
|
1252
893
|
result.push(f ? f(o[name], name, index, o) : o[name]);
|
|
1253
894
|
return result;
|
|
@@ -1279,7 +920,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1279
920
|
function xyz2array(size) {
|
|
1280
921
|
return [ size.x, size.y, size.z ];
|
|
1281
922
|
}
|
|
1282
|
-
|
|
923
|
+
const rotationAxes = {
|
|
1283
924
|
x: [ 1, 0, 0 ],
|
|
1284
925
|
y: [ 0, 1, 0 ],
|
|
1285
926
|
z: [ 0, 0, 1 ]
|
|
@@ -1357,7 +998,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1357
998
|
function mirrored4(x) {
|
|
1358
999
|
return x.union([ x.mirroredY(90), x.mirroredX(90), x.mirroredY(90).mirroredX(90) ]);
|
|
1359
1000
|
}
|
|
1360
|
-
|
|
1001
|
+
const flushSide = {
|
|
1361
1002
|
"above-outside": [ 1, 0 ],
|
|
1362
1003
|
"above-inside": [ 1, 1 ],
|
|
1363
1004
|
"below-outside": [ 0, 1 ],
|
|
@@ -1387,8 +1028,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1387
1028
|
return w[side[0]][axis] - m[side[1]][axis];
|
|
1388
1029
|
});
|
|
1389
1030
|
}
|
|
1390
|
-
function calcSnap(moveobj, withobj, axes, orientation) {
|
|
1391
|
-
var delta = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
|
|
1031
|
+
function calcSnap(moveobj, withobj, axes, orientation, delta = 0) {
|
|
1392
1032
|
var side = flushSide[orientation];
|
|
1393
1033
|
if (!side) {
|
|
1394
1034
|
var fix = {
|
|
@@ -1454,7 +1094,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1454
1094
|
objectSize = objectSize || size(bounds);
|
|
1455
1095
|
return bounds[0].plus(objectSize.dividedBy(2));
|
|
1456
1096
|
} catch (err) {
|
|
1457
|
-
error(
|
|
1097
|
+
error(`centroid error o:${jscadToString(o)} objectSize: ${objectSize}`, undefined, err);
|
|
1458
1098
|
}
|
|
1459
1099
|
}
|
|
1460
1100
|
function calcmidlineTo(o, axis, to) {
|
|
@@ -1475,8 +1115,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1475
1115
|
});
|
|
1476
1116
|
return t;
|
|
1477
1117
|
}
|
|
1478
|
-
function calcCenterWith(o, axes, withObj) {
|
|
1479
|
-
var delta = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
1118
|
+
function calcCenterWith(o, axes, withObj, delta = 0) {
|
|
1480
1119
|
var objectCentroid = centroid(o);
|
|
1481
1120
|
var withCentroid = centroid(withObj);
|
|
1482
1121
|
var t = axisApply(axes, function(i, axis) {
|
|
@@ -1498,12 +1137,9 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1498
1137
|
return bounds[0][a] + (isEmpty(dist) ? size[axis] / 2 : dist);
|
|
1499
1138
|
});
|
|
1500
1139
|
}
|
|
1501
|
-
function bisect() {
|
|
1502
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1503
|
-
args[_key] = arguments[_key];
|
|
1504
|
-
}
|
|
1140
|
+
function bisect(...args) {
|
|
1505
1141
|
if (args.length < 2) {
|
|
1506
|
-
error("bisect
|
|
1142
|
+
error("bisect requires an object and an axis", "JSCAD_UTILS_INVALID_ARGS");
|
|
1507
1143
|
}
|
|
1508
1144
|
var object = args[0];
|
|
1509
1145
|
var axis = args[1];
|
|
@@ -1582,14 +1218,10 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1582
1218
|
if (options.addRotationCenter) g.add(unitAxis(objectSize.length() + 10, .1, rotationCenter), "rotationCenter");
|
|
1583
1219
|
return g;
|
|
1584
1220
|
}
|
|
1585
|
-
function slice(object
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {
|
|
1590
|
-
color: true,
|
|
1591
|
-
addRotationCenter: true
|
|
1592
|
-
};
|
|
1221
|
+
function slice(object, angle = 15, axis = "x", rotateaxis = "z", options = {
|
|
1222
|
+
color: true,
|
|
1223
|
+
addRotationCenter: true
|
|
1224
|
+
}) {
|
|
1593
1225
|
var info = normalVector(axis);
|
|
1594
1226
|
var rotationCenter = options.rotationCenter || new CSG.Vector3D(0, 0, 0);
|
|
1595
1227
|
var theRotationAxis = rotationAxes[rotateaxis];
|
|
@@ -1745,7 +1377,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1745
1377
|
var absoluteRadius = Math.abs(radius);
|
|
1746
1378
|
var si = sliceParams(orientation, radius, b);
|
|
1747
1379
|
debug$2("reShape", absoluteRadius, si);
|
|
1748
|
-
if (si.axis !== "z") throw new Error('reShape error: CAG.
|
|
1380
|
+
if (si.axis !== "z") throw new Error('reShape error: CAG._toPlanePolygons only uses the "z" axis. You must use the "z" axis for now.');
|
|
1749
1381
|
var cutplane = CSG.OrthoNormalBasis.GetCartesian(si.orthoNormalCartesian[0], si.orthoNormalCartesian[1]).translate(si.cutDelta);
|
|
1750
1382
|
var slice = object.sectionCut(cutplane);
|
|
1751
1383
|
var first = axisApply(si.axis, function() {
|
|
@@ -1806,12 +1438,11 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1806
1438
|
};
|
|
1807
1439
|
}
|
|
1808
1440
|
function rotateAround(part, solid, axis, angle) {
|
|
1809
|
-
var
|
|
1441
|
+
var {rotationCenter, rotationAxis} = calcRotate(part, solid, axis);
|
|
1810
1442
|
return part.rotate(rotationCenter, rotationAxis, angle);
|
|
1811
1443
|
}
|
|
1812
|
-
function cloneProperties(from, to) {
|
|
1813
|
-
return Object.entries(from).reduce(
|
|
1814
|
-
var _ref2 = _slicedToArray(_ref, 2), key = _ref2[0], value = _ref2[1];
|
|
1444
|
+
function cloneProperties(from, to, depth = 0) {
|
|
1445
|
+
return Object.entries(from).reduce((props, [key, value]) => {
|
|
1815
1446
|
props[key] = value;
|
|
1816
1447
|
return props;
|
|
1817
1448
|
}, to);
|
|
@@ -1822,14 +1453,85 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1822
1453
|
debug$2("clone", o, c, CSG);
|
|
1823
1454
|
return c;
|
|
1824
1455
|
}
|
|
1825
|
-
function addConnector(object, name) {
|
|
1826
|
-
var point = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [ 0, 0, 0 ];
|
|
1827
|
-
var axis = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [ 1, 0, 0 ];
|
|
1828
|
-
var normal = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [ 0, 0, 1 ];
|
|
1456
|
+
function addConnector(object, name, point = [ 0, 0, 0 ], axis = [ 1, 0, 0 ], normal = [ 0, 0, 1 ]) {
|
|
1829
1457
|
object.properties[name] = new CSG.Connector(point, axis, normal);
|
|
1830
1458
|
return object;
|
|
1831
1459
|
}
|
|
1832
|
-
var
|
|
1460
|
+
var util = Object.freeze({
|
|
1461
|
+
__proto__: null,
|
|
1462
|
+
NOZZEL_SIZE,
|
|
1463
|
+
addConnector,
|
|
1464
|
+
axis2array,
|
|
1465
|
+
axisApply,
|
|
1466
|
+
bisect,
|
|
1467
|
+
calcCenterWith,
|
|
1468
|
+
calcFlush,
|
|
1469
|
+
calcRotate,
|
|
1470
|
+
calcSnap,
|
|
1471
|
+
calcmidlineTo,
|
|
1472
|
+
center,
|
|
1473
|
+
centerWith,
|
|
1474
|
+
centerX,
|
|
1475
|
+
centerY,
|
|
1476
|
+
centroid,
|
|
1477
|
+
chamfer,
|
|
1478
|
+
clone,
|
|
1479
|
+
cm,
|
|
1480
|
+
defaults,
|
|
1481
|
+
depreciated,
|
|
1482
|
+
div,
|
|
1483
|
+
divA,
|
|
1484
|
+
divxyz,
|
|
1485
|
+
enlarge,
|
|
1486
|
+
error,
|
|
1487
|
+
fillet,
|
|
1488
|
+
fit,
|
|
1489
|
+
flush,
|
|
1490
|
+
flushSide,
|
|
1491
|
+
getDelta,
|
|
1492
|
+
identity,
|
|
1493
|
+
ifArray,
|
|
1494
|
+
inch,
|
|
1495
|
+
isEmpty,
|
|
1496
|
+
isNegative,
|
|
1497
|
+
jscadToString,
|
|
1498
|
+
label,
|
|
1499
|
+
map,
|
|
1500
|
+
mapPick,
|
|
1501
|
+
mapValues,
|
|
1502
|
+
midlineTo,
|
|
1503
|
+
mirrored4,
|
|
1504
|
+
mul,
|
|
1505
|
+
mulxyz,
|
|
1506
|
+
nearest,
|
|
1507
|
+
normalVector,
|
|
1508
|
+
pick,
|
|
1509
|
+
poly2solid,
|
|
1510
|
+
print,
|
|
1511
|
+
reShape,
|
|
1512
|
+
result,
|
|
1513
|
+
rotateAround,
|
|
1514
|
+
rotationAxes,
|
|
1515
|
+
scale,
|
|
1516
|
+
segment,
|
|
1517
|
+
shift,
|
|
1518
|
+
size,
|
|
1519
|
+
slice,
|
|
1520
|
+
sliceParams,
|
|
1521
|
+
slices2poly,
|
|
1522
|
+
snap,
|
|
1523
|
+
stretch,
|
|
1524
|
+
text,
|
|
1525
|
+
toArray,
|
|
1526
|
+
translator,
|
|
1527
|
+
unitAxis,
|
|
1528
|
+
unitCube,
|
|
1529
|
+
wedge,
|
|
1530
|
+
xyz2array,
|
|
1531
|
+
zero,
|
|
1532
|
+
zipObject
|
|
1533
|
+
});
|
|
1534
|
+
const debug$1 = Debug("jscadUtils:parts");
|
|
1833
1535
|
var parts = {
|
|
1834
1536
|
BBox: BBox$1,
|
|
1835
1537
|
Cube,
|
|
@@ -1837,16 +1539,13 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1837
1539
|
Cylinder,
|
|
1838
1540
|
Cone
|
|
1839
1541
|
};
|
|
1840
|
-
function BBox$1() {
|
|
1542
|
+
function BBox$1(...objects) {
|
|
1841
1543
|
function box(object) {
|
|
1842
1544
|
return CSG.cube({
|
|
1843
1545
|
center: object.centroid(),
|
|
1844
1546
|
radius: object.size().dividedBy(2)
|
|
1845
1547
|
});
|
|
1846
1548
|
}
|
|
1847
|
-
for (var _len = arguments.length, objects = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1848
|
-
objects[_key] = arguments[_key];
|
|
1849
|
-
}
|
|
1850
1549
|
return objects.reduce(function(bbox, part) {
|
|
1851
1550
|
var object = bbox ? union([ bbox, box(part) ]) : part;
|
|
1852
1551
|
return box(object);
|
|
@@ -1879,8 +1578,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1879
1578
|
});
|
|
1880
1579
|
return roundedcube;
|
|
1881
1580
|
}
|
|
1882
|
-
function Cylinder(diameter, height) {
|
|
1883
|
-
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1581
|
+
function Cylinder(diameter, height, options = {}) {
|
|
1884
1582
|
debug$1("parts.Cylinder", diameter, height, options);
|
|
1885
1583
|
options = Object.assign({
|
|
1886
1584
|
start: [ 0, 0, 0 ],
|
|
@@ -1890,8 +1588,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1890
1588
|
}, options);
|
|
1891
1589
|
return CSG.cylinder(options);
|
|
1892
1590
|
}
|
|
1893
|
-
function Cone(diameter1, diameter2, height) {
|
|
1894
|
-
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
1591
|
+
function Cone(diameter1, diameter2, height, options = {}) {
|
|
1895
1592
|
debug$1("parts.Cone", diameter1, diameter2, height, options);
|
|
1896
1593
|
return CSG.cylinder(Object.assign({
|
|
1897
1594
|
start: [ 0, 0, 0 ],
|
|
@@ -1920,9 +1617,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1920
1617
|
function Tube(outsideDiameter, insideDiameter, height, outsideOptions, insideOptions) {
|
|
1921
1618
|
return Cylinder(outsideDiameter, height, outsideOptions).subtract(Cylinder(insideDiameter, height, insideOptions || outsideOptions));
|
|
1922
1619
|
}
|
|
1923
|
-
function Anchor() {
|
|
1924
|
-
var width = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 10;
|
|
1925
|
-
var height = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10;
|
|
1620
|
+
function Anchor(width = 10, height = 10) {
|
|
1926
1621
|
var hole = Cylinder(width, height).Center().color("red");
|
|
1927
1622
|
var post = Cylinder(height / 2, width * .66).rotateX(90).align(hole, "xz").snap(hole, "y", "inside-").translate([ 0, 0, -height / 6 ]).color("purple");
|
|
1928
1623
|
return Group({
|
|
@@ -1942,7 +1637,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1942
1637
|
});
|
|
1943
1638
|
return board;
|
|
1944
1639
|
}
|
|
1945
|
-
|
|
1640
|
+
const Hardware = {
|
|
1946
1641
|
Orientation: {
|
|
1947
1642
|
up: {
|
|
1948
1643
|
head: "outside-",
|
|
@@ -1953,7 +1648,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1953
1648
|
clear: "inside-"
|
|
1954
1649
|
}
|
|
1955
1650
|
},
|
|
1956
|
-
Screw: function
|
|
1651
|
+
Screw: function(head, thread, headClearSpace, options) {
|
|
1957
1652
|
depreciated("Screw", false, "Use the jscad-hardware screw methods instead");
|
|
1958
1653
|
options = Object.assign(options, {
|
|
1959
1654
|
orientation: "up",
|
|
@@ -1969,7 +1664,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1969
1664
|
}
|
|
1970
1665
|
return group;
|
|
1971
1666
|
},
|
|
1972
|
-
PanHeadScrew: function
|
|
1667
|
+
PanHeadScrew: function(headDiameter, headLength, diameter, length, clearLength, options) {
|
|
1973
1668
|
depreciated("PanHeadScrew", false, "Use the jscad-hardware screw methods instead");
|
|
1974
1669
|
var head = Cylinder(headDiameter, headLength);
|
|
1975
1670
|
var thread = Cylinder(diameter, length);
|
|
@@ -1978,7 +1673,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1978
1673
|
}
|
|
1979
1674
|
return Hardware.Screw(head, thread, headClearSpace, options);
|
|
1980
1675
|
},
|
|
1981
|
-
HexHeadScrew: function
|
|
1676
|
+
HexHeadScrew: function(headDiameter, headLength, diameter, length, clearLength, options) {
|
|
1982
1677
|
depreciated("HexHeadScrew", false, "Use the jscad-hardware screw methods instead");
|
|
1983
1678
|
var head = Hexagon(headDiameter, headLength);
|
|
1984
1679
|
var thread = Cylinder(diameter, length);
|
|
@@ -1987,7 +1682,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1987
1682
|
}
|
|
1988
1683
|
return Hardware.Screw(head, thread, headClearSpace, options);
|
|
1989
1684
|
},
|
|
1990
|
-
FlatHeadScrew: function
|
|
1685
|
+
FlatHeadScrew: function(headDiameter, headLength, diameter, length, clearLength, options) {
|
|
1991
1686
|
depreciated("FlatHeadScrew", false, "Use the jscad-hardware screw methods instead");
|
|
1992
1687
|
var head = Cone(headDiameter, diameter, headLength);
|
|
1993
1688
|
var thread = Cylinder(diameter, length);
|
|
@@ -1999,20 +1694,20 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1999
1694
|
};
|
|
2000
1695
|
var parts$1 = Object.freeze({
|
|
2001
1696
|
__proto__: null,
|
|
2002
|
-
|
|
1697
|
+
Anchor,
|
|
2003
1698
|
BBox: BBox$1,
|
|
1699
|
+
Board,
|
|
1700
|
+
Cone,
|
|
2004
1701
|
Cube,
|
|
2005
|
-
RoundedCube,
|
|
2006
1702
|
Cylinder,
|
|
2007
|
-
|
|
1703
|
+
Hardware,
|
|
2008
1704
|
Hexagon,
|
|
1705
|
+
RoundedCube,
|
|
2009
1706
|
Triangle,
|
|
2010
1707
|
Tube,
|
|
2011
|
-
|
|
2012
|
-
Board,
|
|
2013
|
-
Hardware
|
|
1708
|
+
default: parts
|
|
2014
1709
|
});
|
|
2015
|
-
|
|
1710
|
+
const debug = Debug("jscadUtils:boxes");
|
|
2016
1711
|
function RabbetJoin(box, thickness, cutHeight) {
|
|
2017
1712
|
depreciated("RabbetJoin", true, "Use 'Rabbet' instead");
|
|
2018
1713
|
return rabbetJoin(box, thickness, cutHeight);
|
|
@@ -2025,17 +1720,16 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2025
1720
|
var top = bottom.parts.positive.bisect("z", -thickness);
|
|
2026
1721
|
return Group("top,middle,bottom", [ top.parts.positive, top.parts.negative.color("green"), bottom.parts.negative ]);
|
|
2027
1722
|
}
|
|
2028
|
-
function Rabett(box, thickness, gap, height, face) {
|
|
2029
|
-
var options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
|
|
1723
|
+
function Rabett(box, thickness, gap, height, face, options = {}) {
|
|
2030
1724
|
debug("Rabett", "thickness", thickness, "gap", gap, "height", height, "face", face);
|
|
2031
1725
|
gap = gap || .25;
|
|
2032
1726
|
var inside = thickness - gap;
|
|
2033
1727
|
var outside = -thickness + gap;
|
|
2034
1728
|
debug("inside", inside, "outside", outside);
|
|
2035
1729
|
var group = Group();
|
|
2036
|
-
var
|
|
1730
|
+
var {positive: top, negative: lower2_3rd} = box.bisect("z", height, options).parts;
|
|
2037
1731
|
var lowerBisectHeight = Math.sign(height) < 0 ? face * Math.sign(height) : height - face;
|
|
2038
|
-
var
|
|
1732
|
+
var {positive: middle, negative: bottom} = lower2_3rd.bisect("z", lowerBisectHeight, options).parts;
|
|
2039
1733
|
var middleTop = middle.color("yellow").subtract(middle.color("darkred").enlarge([ outside, outside, 0 ]));
|
|
2040
1734
|
group.add(top.union(middleTop), "top");
|
|
2041
1735
|
var bottomOutline = middle.color("yellow").subtract(middle.color("orange").enlarge([ outside, outside, 0 ])).enlarge([ outside, outside, 0 ]);
|
|
@@ -2044,9 +1738,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2044
1738
|
group.add(bottom.color("orange").union(middle.color("green").subtract(middle.color("red").enlarge([ inside, inside, 0 ])).subtract(middleTop)), "bottom");
|
|
2045
1739
|
return group;
|
|
2046
1740
|
}
|
|
2047
|
-
|
|
2048
|
-
var gap = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : .25;
|
|
2049
|
-
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
1741
|
+
const RabettTopBottom = function rabbetTMB(box, thickness, gap = .25, options = {}) {
|
|
2050
1742
|
options = Object.assign({
|
|
2051
1743
|
removableTop: true,
|
|
2052
1744
|
removableBottom: true,
|
|
@@ -2079,7 +1771,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2079
1771
|
}
|
|
2080
1772
|
return group;
|
|
2081
1773
|
};
|
|
2082
|
-
|
|
1774
|
+
const CutOut = function cutOut(o, h, box, plug, gap) {
|
|
2083
1775
|
gap = gap || .25;
|
|
2084
1776
|
var s = o.size();
|
|
2085
1777
|
var cutout = o.intersect(box);
|
|
@@ -2097,7 +1789,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2097
1789
|
insert: union([ o, top ]).intersect(box).subtract(o).enlarge([ -gap, 0, 0 ]).union(clip.subtract(plug).enlarge(-gap, -gap, 0)).color("blue")
|
|
2098
1790
|
});
|
|
2099
1791
|
};
|
|
2100
|
-
|
|
1792
|
+
const Rectangle = function(size, thickness, cb) {
|
|
2101
1793
|
thickness = thickness || 2;
|
|
2102
1794
|
var s = div$1(xyz2array(size), 2);
|
|
2103
1795
|
var r = add(s, thickness);
|
|
@@ -2111,7 +1803,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2111
1803
|
if (cb) box = cb(box);
|
|
2112
1804
|
return box;
|
|
2113
1805
|
};
|
|
2114
|
-
|
|
1806
|
+
const Hollow = function(object, thickness, interiorcb, exteriorcb) {
|
|
2115
1807
|
thickness = thickness || 2;
|
|
2116
1808
|
var size = -thickness * 2;
|
|
2117
1809
|
interiorcb = interiorcb || identity;
|
|
@@ -2119,7 +1811,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2119
1811
|
if (exteriorcb) box = exteriorcb(box);
|
|
2120
1812
|
return box;
|
|
2121
1813
|
};
|
|
2122
|
-
|
|
1814
|
+
const BBox = function(o) {
|
|
2123
1815
|
depreciated("BBox", true, "Use 'parts.BBox' instead");
|
|
2124
1816
|
var s = div$1(xyz2array(o.size()), 2);
|
|
2125
1817
|
return CSG.cube({
|
|
@@ -2130,8 +1822,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2130
1822
|
function getRadius(o) {
|
|
2131
1823
|
return div$1(xyz2array(o.size()), 2);
|
|
2132
1824
|
}
|
|
2133
|
-
function rabbetJoin(box, thickness) {
|
|
2134
|
-
var gap = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : .25;
|
|
1825
|
+
function rabbetJoin(box, thickness, gap = .25) {
|
|
2135
1826
|
var r = add(getRadius(box), -thickness / 2);
|
|
2136
1827
|
r[2] = thickness / 2;
|
|
2137
1828
|
var cutter = CSG.cube({
|
|
@@ -2149,16 +1840,17 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2149
1840
|
}
|
|
2150
1841
|
var Boxes = Object.freeze({
|
|
2151
1842
|
__proto__: null,
|
|
1843
|
+
BBox,
|
|
1844
|
+
CutOut,
|
|
1845
|
+
Hollow,
|
|
2152
1846
|
RabbetJoin,
|
|
2153
|
-
topMiddleBottom,
|
|
2154
1847
|
Rabett,
|
|
2155
1848
|
RabettTopBottom,
|
|
2156
|
-
CutOut,
|
|
2157
1849
|
Rectangle,
|
|
2158
|
-
|
|
2159
|
-
BBox
|
|
1850
|
+
topMiddleBottom
|
|
2160
1851
|
});
|
|
2161
|
-
|
|
1852
|
+
const compatV1 = {
|
|
1853
|
+
...util,
|
|
2162
1854
|
group: Group,
|
|
2163
1855
|
init: init$1,
|
|
2164
1856
|
triangle: triUtils,
|
|
@@ -2166,7 +1858,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2166
1858
|
parts: parts$1,
|
|
2167
1859
|
Boxes,
|
|
2168
1860
|
Debug
|
|
2169
|
-
}
|
|
1861
|
+
};
|
|
2170
1862
|
exports.Boxes = Boxes;
|
|
2171
1863
|
exports.Debug = Debug;
|
|
2172
1864
|
exports.Group = Group;
|
|
@@ -2176,9 +1868,6 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2176
1868
|
exports.parts = parts$1;
|
|
2177
1869
|
exports.triUtils = triUtils;
|
|
2178
1870
|
exports.util = util;
|
|
2179
|
-
Object.defineProperty(exports, "__esModule", {
|
|
2180
|
-
value: true
|
|
2181
|
-
});
|
|
2182
1871
|
return exports;
|
|
2183
1872
|
}({}, jsCadCSG, scadApi);
|
|
2184
1873
|
const debug = jscadUtils.Debug("jscadUtils:initJscadutils");
|