@jwc/jscad-utils 4.8.4 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/dist/compat.js +659 -841
- package/dist/examples/bisect.jscad +342 -658
- package/dist/examples/boxes.jscad +342 -658
- package/dist/examples/chamfer.jscad +342 -658
- package/dist/examples/fillet.jscad +342 -658
- package/dist/examples/fit.jscad +342 -658
- package/dist/examples/groups.jscad +342 -658
- package/dist/examples/midlineTo.jscad +342 -658
- package/dist/examples/parts-hexagon.jscad +342 -658
- package/dist/examples/rabett-tb.jscad +342 -658
- package/dist/examples/rabett.jscad +342 -658
- package/dist/examples/rabett2.jscad +342 -658
- package/dist/examples/retraction-test.jscad +342 -658
- package/dist/examples/size.jscad +342 -658
- package/dist/examples/snap.jscad +342 -658
- package/dist/examples/text.jscad +342 -658
- package/dist/examples/wedge.jscad +342 -658
- package/dist/index.js +659 -841
- package/package.json +16 -52
- package/src/add-prototype.js +87 -7
- package/src/boxes.js +1 -1
- package/src/color.js +36 -46
- package/src/util.js +35 -33
package/dist/compat.js
CHANGED
|
@@ -43,207 +43,6 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
43
43
|
var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
44
44
|
'use strict';
|
|
45
45
|
|
|
46
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
47
|
-
|
|
48
|
-
var jsCadCSG__default = /*#__PURE__*/_interopDefaultLegacy(jsCadCSG);
|
|
49
|
-
var scadApi__default = /*#__PURE__*/_interopDefaultLegacy(scadApi);
|
|
50
|
-
|
|
51
|
-
var util = /*#__PURE__*/Object.freeze({
|
|
52
|
-
__proto__: null,
|
|
53
|
-
get NOZZEL_SIZE () { return NOZZEL_SIZE; },
|
|
54
|
-
get nearest () { return nearest; },
|
|
55
|
-
get identity () { return identity; },
|
|
56
|
-
get result () { return result; },
|
|
57
|
-
get defaults () { return defaults; },
|
|
58
|
-
get isEmpty () { return isEmpty; },
|
|
59
|
-
get isNegative () { return isNegative; },
|
|
60
|
-
get print () { return print; },
|
|
61
|
-
get jscadToString () { return jscadToString; },
|
|
62
|
-
get error () { return error; },
|
|
63
|
-
get depreciated () { return depreciated; },
|
|
64
|
-
get inch () { return inch; },
|
|
65
|
-
get cm () { return cm; },
|
|
66
|
-
get label () { return label; },
|
|
67
|
-
get text () { return text; },
|
|
68
|
-
get unitCube () { return unitCube; },
|
|
69
|
-
get unitAxis () { return unitAxis; },
|
|
70
|
-
get toArray () { return toArray; },
|
|
71
|
-
get ifArray () { return ifArray; },
|
|
72
|
-
get segment () { return segment; },
|
|
73
|
-
get zipObject () { return zipObject; },
|
|
74
|
-
get map () { return map; },
|
|
75
|
-
get mapValues () { return mapValues; },
|
|
76
|
-
get pick () { return pick; },
|
|
77
|
-
get mapPick () { return mapPick; },
|
|
78
|
-
get divA () { return divA; },
|
|
79
|
-
get divxyz () { return divxyz; },
|
|
80
|
-
get div () { return div$1; },
|
|
81
|
-
get mulxyz () { return mulxyz; },
|
|
82
|
-
get mul () { return mul; },
|
|
83
|
-
get xyz2array () { return xyz2array; },
|
|
84
|
-
get rotationAxes () { return rotationAxes; },
|
|
85
|
-
get size () { return size; },
|
|
86
|
-
get scale () { return scale; },
|
|
87
|
-
get center () { return center; },
|
|
88
|
-
get centerY () { return centerY; },
|
|
89
|
-
get centerX () { return centerX; },
|
|
90
|
-
get enlarge () { return enlarge; },
|
|
91
|
-
get fit () { return fit; },
|
|
92
|
-
get shift () { return shift; },
|
|
93
|
-
get zero () { return zero; },
|
|
94
|
-
get mirrored4 () { return mirrored4; },
|
|
95
|
-
get flushSide () { return flushSide; },
|
|
96
|
-
get calcFlush () { return calcFlush; },
|
|
97
|
-
get calcSnap () { return calcSnap; },
|
|
98
|
-
get snap () { return snap; },
|
|
99
|
-
get flush () { return flush; },
|
|
100
|
-
get axisApply () { return axisApply; },
|
|
101
|
-
get axis2array () { return axis2array; },
|
|
102
|
-
get centroid () { return centroid; },
|
|
103
|
-
get calcmidlineTo () { return calcmidlineTo; },
|
|
104
|
-
get midlineTo () { return midlineTo; },
|
|
105
|
-
get translator () { return translator; },
|
|
106
|
-
get calcCenterWith () { return calcCenterWith; },
|
|
107
|
-
get centerWith () { return centerWith; },
|
|
108
|
-
get getDelta () { return getDelta; },
|
|
109
|
-
get bisect () { return bisect; },
|
|
110
|
-
get slice () { return slice; },
|
|
111
|
-
get wedge () { return wedge; },
|
|
112
|
-
get stretch () { return stretch; },
|
|
113
|
-
get poly2solid () { return poly2solid; },
|
|
114
|
-
get slices2poly () { return slices2poly; },
|
|
115
|
-
get normalVector () { return normalVector; },
|
|
116
|
-
get sliceParams () { return sliceParams; },
|
|
117
|
-
get reShape () { return reShape; },
|
|
118
|
-
get chamfer () { return chamfer; },
|
|
119
|
-
get fillet () { return fillet; },
|
|
120
|
-
get calcRotate () { return calcRotate; },
|
|
121
|
-
get rotateAround () { return rotateAround; },
|
|
122
|
-
get clone () { return clone; },
|
|
123
|
-
get addConnector () { return addConnector; }
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
function _typeof(obj) {
|
|
127
|
-
"@babel/helpers - typeof";
|
|
128
|
-
|
|
129
|
-
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
|
|
130
|
-
_typeof = function (obj) {
|
|
131
|
-
return typeof obj;
|
|
132
|
-
};
|
|
133
|
-
} else {
|
|
134
|
-
_typeof = function (obj) {
|
|
135
|
-
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
return _typeof(obj);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
function _defineProperty(obj, key, value) {
|
|
143
|
-
if (key in obj) {
|
|
144
|
-
Object.defineProperty(obj, key, {
|
|
145
|
-
value: value,
|
|
146
|
-
enumerable: true,
|
|
147
|
-
configurable: true,
|
|
148
|
-
writable: true
|
|
149
|
-
});
|
|
150
|
-
} else {
|
|
151
|
-
obj[key] = value;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
return obj;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
function ownKeys(object, enumerableOnly) {
|
|
158
|
-
var keys = Object.keys(object);
|
|
159
|
-
|
|
160
|
-
if (Object.getOwnPropertySymbols) {
|
|
161
|
-
var symbols = Object.getOwnPropertySymbols(object);
|
|
162
|
-
if (enumerableOnly) symbols = symbols.filter(function (sym) {
|
|
163
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
164
|
-
});
|
|
165
|
-
keys.push.apply(keys, symbols);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
return keys;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
function _objectSpread2(target) {
|
|
172
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
173
|
-
var source = arguments[i] != null ? arguments[i] : {};
|
|
174
|
-
|
|
175
|
-
if (i % 2) {
|
|
176
|
-
ownKeys(Object(source), true).forEach(function (key) {
|
|
177
|
-
_defineProperty(target, key, source[key]);
|
|
178
|
-
});
|
|
179
|
-
} else if (Object.getOwnPropertyDescriptors) {
|
|
180
|
-
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
181
|
-
} else {
|
|
182
|
-
ownKeys(Object(source)).forEach(function (key) {
|
|
183
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
return target;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
function _slicedToArray(arr, i) {
|
|
192
|
-
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
function _arrayWithHoles(arr) {
|
|
196
|
-
if (Array.isArray(arr)) return arr;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
function _iterableToArrayLimit(arr, i) {
|
|
200
|
-
if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
|
|
201
|
-
var _arr = [];
|
|
202
|
-
var _n = true;
|
|
203
|
-
var _d = false;
|
|
204
|
-
var _e = undefined;
|
|
205
|
-
|
|
206
|
-
try {
|
|
207
|
-
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
|
|
208
|
-
_arr.push(_s.value);
|
|
209
|
-
|
|
210
|
-
if (i && _arr.length === i) break;
|
|
211
|
-
}
|
|
212
|
-
} catch (err) {
|
|
213
|
-
_d = true;
|
|
214
|
-
_e = err;
|
|
215
|
-
} finally {
|
|
216
|
-
try {
|
|
217
|
-
if (!_n && _i["return"] != null) _i["return"]();
|
|
218
|
-
} finally {
|
|
219
|
-
if (_d) throw _e;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
return _arr;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
function _unsupportedIterableToArray(o, minLen) {
|
|
227
|
-
if (!o) return;
|
|
228
|
-
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
229
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
230
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
231
|
-
if (n === "Map" || n === "Set") return Array.from(o);
|
|
232
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
function _arrayLikeToArray(arr, len) {
|
|
236
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
237
|
-
|
|
238
|
-
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
239
|
-
|
|
240
|
-
return arr2;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
function _nonIterableRest() {
|
|
244
|
-
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
245
|
-
}
|
|
246
|
-
|
|
247
46
|
/** @module triangle */
|
|
248
47
|
|
|
249
48
|
/**
|
|
@@ -251,18 +50,19 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
251
50
|
* @param {Number} deg value in degrees
|
|
252
51
|
* @return {Number} value in radians
|
|
253
52
|
*/
|
|
254
|
-
|
|
53
|
+
const toRadians = function toRadians(deg) {
|
|
255
54
|
return deg / 180 * Math.PI;
|
|
256
55
|
};
|
|
56
|
+
|
|
257
57
|
/**
|
|
258
58
|
* Convert radians to degrees.
|
|
259
59
|
* @param {Number} rad value in radians
|
|
260
60
|
* @return {Number} value in degrees
|
|
261
61
|
*/
|
|
262
|
-
|
|
263
|
-
var toDegrees = function toDegrees(rad) {
|
|
62
|
+
const toDegrees = function toDegrees(rad) {
|
|
264
63
|
return rad * (180 / Math.PI);
|
|
265
64
|
};
|
|
65
|
+
|
|
266
66
|
/**
|
|
267
67
|
* Solve a 90 degree triangle from two points.
|
|
268
68
|
* @param {Number} p1.x Point 1 x coordinate
|
|
@@ -271,20 +71,20 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
271
71
|
* @param {Number} p2.y Point 2 y coordinate
|
|
272
72
|
* @return {Object} A triangle object {A,B,C,a,b,c}
|
|
273
73
|
*/
|
|
274
|
-
|
|
275
|
-
var solve = function solve(p1, p2) {
|
|
74
|
+
const solve = function (p1, p2) {
|
|
276
75
|
var r = {
|
|
277
76
|
c: 90,
|
|
278
77
|
A: Math.abs(p2.x - p1.x),
|
|
279
78
|
B: Math.abs(p2.y - p1.y)
|
|
280
79
|
};
|
|
281
80
|
var brad = Math.atan2(r.B, r.A);
|
|
282
|
-
r.b = this.toDegrees(brad);
|
|
283
|
-
|
|
81
|
+
r.b = this.toDegrees(brad);
|
|
82
|
+
// r.C = Math.sqrt(Math.pow(r.B, 2) + Math.pow(r.A, 2));
|
|
284
83
|
r.C = r.B / Math.sin(brad);
|
|
285
84
|
r.a = 90 - r.b;
|
|
286
85
|
return r;
|
|
287
86
|
};
|
|
87
|
+
|
|
288
88
|
/**
|
|
289
89
|
* Solve a partial triangle object. Angles are in degrees.
|
|
290
90
|
* Angle `C` is set to 90 degrees. Requires a Side and an
|
|
@@ -313,43 +113,48 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
313
113
|
* @param {Number} r.c Length of side `c`
|
|
314
114
|
* @return {Object} A solved triangle object {A,B,C,a,b,c}
|
|
315
115
|
*/
|
|
316
|
-
|
|
317
|
-
var solve90SA = function solve90SA(r) {
|
|
116
|
+
const solve90SA = function (r) {
|
|
318
117
|
r = Object.assign(r, {
|
|
319
118
|
C: 90
|
|
320
119
|
});
|
|
321
120
|
r.A = r.A || 90 - r.B;
|
|
322
121
|
r.B = r.B || 90 - r.A;
|
|
323
|
-
var arad = toRadians(r.A);
|
|
122
|
+
var arad = toRadians(r.A);
|
|
123
|
+
|
|
124
|
+
// sinA = a/c
|
|
324
125
|
// a = c * sinA
|
|
325
126
|
// tanA = a/b
|
|
326
127
|
// a = b * tanA
|
|
128
|
+
r.a = r.a || (r.c ? r.c * Math.sin(arad) : r.b * Math.tan(arad));
|
|
327
129
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
r.c = r.c || r.a / Math.sin(arad); // tanA = a/b
|
|
130
|
+
// sinA = a/c
|
|
131
|
+
r.c = r.c || r.a / Math.sin(arad);
|
|
331
132
|
|
|
133
|
+
// tanA = a/b
|
|
332
134
|
r.b = r.b || r.a / Math.tan(arad);
|
|
333
135
|
return r;
|
|
334
136
|
};
|
|
335
|
-
|
|
137
|
+
const solve90ac = function (r) {
|
|
336
138
|
r = Object.assign(r, {
|
|
337
139
|
C: 90
|
|
338
|
-
});
|
|
339
|
-
// a = arcsin(a/c)
|
|
140
|
+
});
|
|
340
141
|
|
|
142
|
+
// sinA = a/c
|
|
143
|
+
// a = arcsin(a/c)
|
|
341
144
|
var arad = Math.asin(r.a / r.c);
|
|
342
145
|
r.A = toDegrees(arad);
|
|
343
|
-
r.B = 90 - r.A;
|
|
146
|
+
r.B = 90 - r.A;
|
|
147
|
+
|
|
148
|
+
// tanA = a/b
|
|
344
149
|
// r.b = r.a / Math.tan(arad);
|
|
345
150
|
// or
|
|
346
151
|
// a*a + b*b = c*c
|
|
347
152
|
// b*b = c*c - a*a
|
|
348
153
|
// b = sqr(c*c - a*a)
|
|
349
|
-
|
|
350
154
|
r.b = Math.sqrt(Math.pow(r.c, 2) - Math.pow(r.a, 2));
|
|
351
155
|
return r;
|
|
352
156
|
};
|
|
157
|
+
|
|
353
158
|
/**
|
|
354
159
|
* @function solveab
|
|
355
160
|
* Solve a partial right triangle object from two sides (a and b). Angles are in degrees.
|
|
@@ -368,28 +173,30 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
368
173
|
* @param {Number} r.b Length of side `b`
|
|
369
174
|
* @return {Object} A solved triangle object {A,B,C,a,b,c}
|
|
370
175
|
*/
|
|
371
|
-
|
|
372
176
|
function solveab(r) {
|
|
373
177
|
r = Object.assign(r, {
|
|
374
178
|
C: 90
|
|
375
|
-
});
|
|
179
|
+
});
|
|
376
180
|
|
|
377
|
-
|
|
181
|
+
// c = sqr(a*a + b*b)
|
|
182
|
+
r.c = Math.sqrt(Math.pow(r.a, 2) + Math.pow(r.b, 2));
|
|
378
183
|
|
|
379
|
-
|
|
184
|
+
// A = arcsin(a/c)
|
|
185
|
+
r.A = toDegrees(Math.asin(r.a / r.c));
|
|
380
186
|
|
|
187
|
+
// B = arcsin(b/c);
|
|
381
188
|
r.B = toDegrees(Math.asin(r.b / r.c));
|
|
382
189
|
return r;
|
|
383
190
|
}
|
|
384
191
|
|
|
385
192
|
var triUtils = /*#__PURE__*/Object.freeze({
|
|
386
193
|
__proto__: null,
|
|
387
|
-
toRadians: toRadians,
|
|
388
|
-
toDegrees: toDegrees,
|
|
389
194
|
solve: solve,
|
|
390
195
|
solve90SA: solve90SA,
|
|
391
196
|
solve90ac: solve90ac,
|
|
392
|
-
solveab: solveab
|
|
197
|
+
solveab: solveab,
|
|
198
|
+
toDegrees: toDegrees,
|
|
199
|
+
toRadians: toRadians
|
|
393
200
|
});
|
|
394
201
|
|
|
395
202
|
/**
|
|
@@ -404,11 +211,12 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
404
211
|
* @param {Number} f
|
|
405
212
|
* @memberof! array
|
|
406
213
|
*/
|
|
407
|
-
|
|
214
|
+
const div$1 = function (a, f) {
|
|
408
215
|
return a.map(function (e) {
|
|
409
216
|
return e / f;
|
|
410
217
|
});
|
|
411
218
|
};
|
|
219
|
+
|
|
412
220
|
/**
|
|
413
221
|
* Adds a value to each element of an array of numbers.
|
|
414
222
|
* @function addValue
|
|
@@ -416,12 +224,12 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
416
224
|
* @param {Number} f A value to add to each element of the original array.
|
|
417
225
|
* @return {Array} A new array with the values added together.
|
|
418
226
|
*/
|
|
419
|
-
|
|
420
|
-
var addValue = function addValue(a, f) {
|
|
227
|
+
const addValue = function (a, f) {
|
|
421
228
|
return a.map(function (e) {
|
|
422
229
|
return e + f;
|
|
423
230
|
});
|
|
424
231
|
};
|
|
232
|
+
|
|
425
233
|
/**
|
|
426
234
|
* Adds two arrays together. The shorter array must be the first argument.
|
|
427
235
|
*
|
|
@@ -430,78 +238,77 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
430
238
|
* @param {Array} f Another array of numbers, if
|
|
431
239
|
* @return {Array} A new array with the two values added together.
|
|
432
240
|
*/
|
|
433
|
-
|
|
434
|
-
var addArray = function addArray(a, f) {
|
|
241
|
+
const addArray = function (a, f) {
|
|
435
242
|
return a.map(function (e, i) {
|
|
436
243
|
return e + f[i];
|
|
437
244
|
});
|
|
438
245
|
};
|
|
246
|
+
|
|
439
247
|
/**
|
|
440
248
|
* Adds a value or array to another array.
|
|
441
249
|
* @function add
|
|
442
250
|
* @param {Array} a An array of numbers .
|
|
443
251
|
* @return {Array} A new array with the two values added together.
|
|
444
252
|
*/
|
|
445
|
-
|
|
446
|
-
var add = function add(a) {
|
|
253
|
+
const add = function (a) {
|
|
447
254
|
return Array.prototype.slice.call(arguments, 1).reduce(function (result, arg) {
|
|
448
255
|
if (Array.isArray(arg)) {
|
|
449
256
|
result = addArray(result, arg);
|
|
450
257
|
} else {
|
|
451
258
|
result = addValue(result, arg);
|
|
452
259
|
}
|
|
453
|
-
|
|
454
260
|
return result;
|
|
455
261
|
}, a);
|
|
456
262
|
};
|
|
263
|
+
|
|
457
264
|
/**
|
|
458
265
|
* Converts an object with x, y, and z properties into
|
|
459
266
|
* an array, or an array if passed an array.
|
|
460
267
|
* @function fromxyz
|
|
461
268
|
* @param {Object|Array} object
|
|
462
269
|
*/
|
|
463
|
-
|
|
464
|
-
var fromxyz = function fromxyz(object) {
|
|
270
|
+
const fromxyz = function (object) {
|
|
465
271
|
return Array.isArray(object) ? object : [object.x, object.y, object.z];
|
|
466
272
|
};
|
|
467
|
-
|
|
273
|
+
const toxyz = function (a) {
|
|
468
274
|
return {
|
|
469
275
|
x: a[0],
|
|
470
276
|
y: a[1],
|
|
471
277
|
z: a[2]
|
|
472
278
|
};
|
|
473
279
|
};
|
|
280
|
+
|
|
474
281
|
/**
|
|
475
282
|
* Returns the first value of an array.
|
|
476
283
|
* @function first
|
|
477
284
|
* @param {Array} a An array of numbers.
|
|
478
285
|
* @return {Number} The value of the first element of the array or undefined.
|
|
479
286
|
*/
|
|
480
|
-
|
|
481
|
-
var first = function first(a) {
|
|
287
|
+
const first = function (a) {
|
|
482
288
|
return a ? a[0] : undefined;
|
|
483
289
|
};
|
|
290
|
+
|
|
484
291
|
/**
|
|
485
292
|
* @function last
|
|
486
293
|
* @param {Array} a An array of numbers.
|
|
487
294
|
* @return {Number} The value of the last element of the array or undefined.
|
|
488
295
|
*/
|
|
489
|
-
|
|
490
|
-
var last = function last(a) {
|
|
296
|
+
const last = function (a) {
|
|
491
297
|
return a && a.length > 0 ? a[a.length - 1] : undefined;
|
|
492
298
|
};
|
|
299
|
+
|
|
493
300
|
/**
|
|
494
301
|
* Finds the minimum value of an array.
|
|
495
302
|
* @function min
|
|
496
303
|
* @param {Array} a An array of numbers.
|
|
497
304
|
* @return {Number} The minimum value in an array of numbers.
|
|
498
305
|
*/
|
|
499
|
-
|
|
500
|
-
var min = function min(a) {
|
|
306
|
+
const min = function (a) {
|
|
501
307
|
return a.reduce(function (result, value) {
|
|
502
308
|
return value < result ? value : result;
|
|
503
309
|
}, Number.MAX_VALUE);
|
|
504
310
|
};
|
|
311
|
+
|
|
505
312
|
/**
|
|
506
313
|
* Creates a array of numbers given the start and end points.
|
|
507
314
|
* @function range
|
|
@@ -509,35 +316,34 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
509
316
|
* @param {Number} b The ending value.
|
|
510
317
|
* @return {Array} An array of values from `a` to `b`.
|
|
511
318
|
*/
|
|
512
|
-
|
|
513
|
-
var range = function range(a, b) {
|
|
319
|
+
const range = function (a, b) {
|
|
514
320
|
var result = [];
|
|
515
|
-
|
|
516
321
|
for (var i = a; i < b; i++) {
|
|
517
322
|
result.push(i);
|
|
518
323
|
}
|
|
519
|
-
|
|
520
324
|
return result;
|
|
521
325
|
};
|
|
522
326
|
|
|
523
327
|
var array = /*#__PURE__*/Object.freeze({
|
|
524
328
|
__proto__: null,
|
|
525
|
-
div: div,
|
|
526
|
-
addValue: addValue,
|
|
527
|
-
addArray: addArray,
|
|
528
329
|
add: add,
|
|
529
|
-
|
|
530
|
-
|
|
330
|
+
addArray: addArray,
|
|
331
|
+
addValue: addValue,
|
|
332
|
+
div: div$1,
|
|
531
333
|
first: first,
|
|
334
|
+
fromxyz: fromxyz,
|
|
532
335
|
last: last,
|
|
533
336
|
min: min,
|
|
534
|
-
range: range
|
|
337
|
+
range: range,
|
|
338
|
+
toxyz: toxyz
|
|
535
339
|
});
|
|
536
340
|
|
|
537
341
|
/* globals jscadUtilsDebug */
|
|
538
|
-
|
|
539
|
-
|
|
342
|
+
|
|
343
|
+
const debugColors = ['#e41a1c', '#377eb8', '#4daf4a', '#984ea3', '#ff7f00', '#ffff33', '#a65628', '#f781bf', '#999999'];
|
|
344
|
+
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'];
|
|
540
345
|
var debugCount = 0;
|
|
346
|
+
|
|
541
347
|
/**
|
|
542
348
|
* Creates a function that uses `console.log` with a styled name. The name
|
|
543
349
|
* is checked against the `jscadUtilsDebug` settings `enabled` and `disabled` list.
|
|
@@ -556,8 +362,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
556
362
|
* @param {String} name The name of the debug function.
|
|
557
363
|
* @return {Function} A debug function if enabled otherwise an empty function.
|
|
558
364
|
*/
|
|
559
|
-
|
|
560
|
-
var Debug = function Debug(name) {
|
|
365
|
+
const Debug = function (name) {
|
|
561
366
|
var checks = Object.assign({
|
|
562
367
|
enabled: [],
|
|
563
368
|
disabled: [],
|
|
@@ -565,35 +370,25 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
565
370
|
browser: true
|
|
566
371
|
}
|
|
567
372
|
}, jscadUtilsDebug || {});
|
|
568
|
-
var style = checks.options.browser ?
|
|
373
|
+
var style = checks.options.browser ? `color:${debugColors[debugCount++ % debugColors.length]}` : `${termColors[debugCount++ % termColors.length]}`;
|
|
569
374
|
var enabled = checks.enabled.some(function checkEnabled(check) {
|
|
570
375
|
return check.test(name);
|
|
571
376
|
}) && !checks.disabled.some(function checkEnabled(check) {
|
|
572
377
|
return check.test(name);
|
|
573
378
|
});
|
|
574
|
-
var logger = enabled ? checks.options.browser ?
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
(_console = console).log.apply(_console, ['%c%s', style, name].concat(msg));
|
|
582
|
-
} : function () {
|
|
583
|
-
var _console2;
|
|
584
|
-
|
|
585
|
-
for (var _len2 = arguments.length, msg = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
586
|
-
msg[_key2] = arguments[_key2];
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
(_console2 = console).log.apply(_console2, ["".concat(name)].concat(msg));
|
|
590
|
-
} : function () {
|
|
591
|
-
return undefined;
|
|
592
|
-
};
|
|
379
|
+
var logger = enabled ? checks.options.browser ? (...msg) => {
|
|
380
|
+
console.log('%c%s', style, name, ...msg);
|
|
381
|
+
} : (...msg) => {
|
|
382
|
+
console.log(`${name}`, ...msg);
|
|
383
|
+
} : () => undefined;
|
|
593
384
|
logger.enabled = enabled;
|
|
594
385
|
return logger;
|
|
595
386
|
};
|
|
596
387
|
|
|
388
|
+
/** @typedef { import('@jscad/csg').CSG } CSG */
|
|
389
|
+
|
|
390
|
+
/** @typedef {"aliceblue"|"antiquewhite"|"aqua"|"aquamarine"|"azure"|"beige"|"bisque"|"black"|"blanchedalmond"|"blue"|"blueviolet"|"brown"|"burlywood"|"cadetblue"|"chartreuse"|"chocolate"|"coral"|"cornflowerblue"|"cornsilk"|"crimson"|"cyan"|"darkblue"|"darkcyan"|"darkgoldenrod"|"darkgray"|"darkgrey"|"darkgreen"|"darkkhaki"|"darkmagenta"|"darkolivegreen"|"darkorange"|"darkorchid"|"darkred"|"darksalmon"|"darkseagreen"|"darkslateblue"|"darkslategray"|"darkslategrey"|"darkturquoise"|"darkviolet"|"deeppink"|"deepskyblue"|"dimgray"|"dimgrey"|"dodgerblue"|"firebrick"|"floralwhite"|"forestgreen"|"fuchsia"|"gainsboro"|"ghostwhite"|"gold"|"goldenrod"|"gray"|"grey"|"green"|"greenyellow"|"honeydew"|"hotpink"|"indianred"|"indigo"|"ivory"|"khaki"|"lavender"|"lavenderblush"|"lawngreen"|"lemonchiffon"|"lightblue"|"lightcoral"|"lightcyan"|"lightgoldenrodyellow"|"lightgray"|"lightgrey"|"lightgreen"|"lightpink"|"lightsalmon"|"lightseagreen"|"lightskyblue"|"lightslategray"|"lightslategrey"|"lightsteelblue"|"lightyellow"|"lime"|"limegreen"|"linen"|"magenta"|"maroon"|"mediumaquamarine"|"mediumblue"|"mediumorchid"|"mediumpurple"|"mediumseagreen"|"mediumslateblue"|"mediumspringgreen"|"mediumturquoise"|"mediumvioletred"|"midnightblue"|"mintcream"|"mistyrose"|"moccasin"|"navajowhite"|"navy"|"oldlace"|"olive"|"olivedrab"|"orange"|"orangered"|"orchid"|"palegoldenrod"|"palegreen"|"paleturquoise"|"palevioletred"|"papayawhip"|"peachpuff"|"peru"|"pink"|"plum"|"powderblue"|"purple"|"red"|"rosybrown"|"royalblue"|"saddlebrown"|"salmon"|"sandybrown"|"seagreen"|"seashell"|"sienna"|"silver"|"skyblue"|"slateblue"|"slategray"|"slategrey"|"snow"|"springgreen"|"steelblue"|"tan"|"teal"|"thistle"|"tomato"|"turquoise"|"violet"|"wheat"|"white"|"whitesmoke"|"yellow"|"yellowgreen"} ColorName */
|
|
391
|
+
|
|
597
392
|
/**
|
|
598
393
|
* Color utilities for jscad. Makes setting colors easier using css color names. Using `.init()` adds a `.color()` function to the CSG object.
|
|
599
394
|
* > You must use `Colors.init(CSG)` in the `main()` function. The `CSG` class is not available before
|
|
@@ -606,9 +401,9 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
606
401
|
* // draws a purple cube
|
|
607
402
|
* return CSG.cube({radius: [10, 10, 10]}).color('purple');
|
|
608
403
|
*}
|
|
609
|
-
* @type {
|
|
404
|
+
* @type {Record<ColorName, string>}
|
|
610
405
|
*/
|
|
611
|
-
|
|
406
|
+
const nameArray = {
|
|
612
407
|
aliceblue: '#f0f8ff',
|
|
613
408
|
antiquewhite: '#faebd7',
|
|
614
409
|
aqua: '#00ffff',
|
|
@@ -757,274 +552,307 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
757
552
|
yellow: '#ffff00',
|
|
758
553
|
yellowgreen: '#9acd32'
|
|
759
554
|
};
|
|
555
|
+
|
|
556
|
+
/**
|
|
557
|
+
* Converts a css color name to a hex string.
|
|
558
|
+
* @param {ColorName} n A css color name
|
|
559
|
+
* @returns {string}
|
|
560
|
+
*/
|
|
760
561
|
function name2hex(n) {
|
|
761
|
-
n = n.toLowerCase();
|
|
562
|
+
n = /** @type {ColorName} */n.toLowerCase();
|
|
762
563
|
if (!nameArray[n]) return 'Invalid Color Name';
|
|
763
564
|
return nameArray[n];
|
|
764
565
|
}
|
|
566
|
+
|
|
567
|
+
/**
|
|
568
|
+
* Converts a hex color string to an rgb array.
|
|
569
|
+
* @param {string} h
|
|
570
|
+
* @returns {number[]}
|
|
571
|
+
*/
|
|
765
572
|
function hex2rgb(h) {
|
|
766
573
|
h = h.replace(/^\#/, '');
|
|
767
|
-
|
|
768
574
|
if (h.length === 6) {
|
|
769
575
|
return [parseInt(h.substr(0, 2), 16), parseInt(h.substr(2, 2), 16), parseInt(h.substr(4, 2), 16)];
|
|
576
|
+
} else {
|
|
577
|
+
return [0, 0, 0];
|
|
770
578
|
}
|
|
771
579
|
}
|
|
772
|
-
|
|
580
|
+
|
|
581
|
+
/**
|
|
582
|
+
* @type {Record<ColorName, number[]>}
|
|
583
|
+
*/
|
|
584
|
+
const _name2rgb = {};
|
|
585
|
+
|
|
586
|
+
/**
|
|
587
|
+
* Converts a css color name to an rgb array.
|
|
588
|
+
* @param {ColorName} n A css color name
|
|
589
|
+
* @returns {number[]}
|
|
590
|
+
*/
|
|
773
591
|
function name2rgb(n) {
|
|
774
592
|
if (!_name2rgb[n]) _name2rgb[n] = hex2rgb(name2hex(n));
|
|
775
593
|
return _name2rgb[n];
|
|
776
594
|
}
|
|
595
|
+
|
|
596
|
+
/**
|
|
597
|
+
*
|
|
598
|
+
* @param {CSG} o
|
|
599
|
+
* @param {number|string} r The red channel value (0.0 - 1.0) or a css color name
|
|
600
|
+
* @param {number} [g] The green channel value (0.0 - 1.0) or the alpha channel when used with a css color string
|
|
601
|
+
* @param {number} [b] The blue channel value (0.0 - 1.0)
|
|
602
|
+
* @param {number} [a] The alpha channel value (0.0 - 1.0)
|
|
603
|
+
* @returns {CSG} Returns a `CSG` object set to the desired color.
|
|
604
|
+
*/
|
|
777
605
|
function color(o, r, g, b, a) {
|
|
778
606
|
if (typeof r !== 'string') return o.setColor(r, g, b, a);
|
|
779
607
|
if (r === '') return o; // shortcut for no color
|
|
780
|
-
|
|
781
|
-
var c = name2rgb(r).map(function (x) {
|
|
608
|
+
var c = name2rgb(/** @type {ColorName} */r).map(function (x) {
|
|
782
609
|
return x / 255;
|
|
783
610
|
});
|
|
784
611
|
c[3] = g || 1.0;
|
|
785
612
|
return o.setColor(c);
|
|
786
613
|
}
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
* @
|
|
790
|
-
* @
|
|
791
|
-
* @
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
614
|
+
|
|
615
|
+
/** @typedef {object} ExtendedCSG
|
|
616
|
+
* @property {object} prototype
|
|
617
|
+
* @property {function} prototype.color
|
|
618
|
+
* @property {function} prototype.flush
|
|
619
|
+
* @property {function} prototype.snap
|
|
620
|
+
* @property {function} prototype.calcSnap
|
|
621
|
+
* @property {function} prototype.midlineTo
|
|
622
|
+
* @property {function} prototype.calcmidlineTo
|
|
623
|
+
* @property {function} prototype.centerWith
|
|
624
|
+
* @property {function} prototype.calcCenter
|
|
625
|
+
* @property {function} prototype.align
|
|
626
|
+
* @property {function} prototype.calcAlign
|
|
627
|
+
* @property {function} prototype.enlarge
|
|
628
|
+
* @property {function} prototype.fit
|
|
629
|
+
* @property {function} prototype.size
|
|
630
|
+
* @property {function} prototype.centroid
|
|
631
|
+
* @property {function} prototype.Zero
|
|
632
|
+
* @property {function} prototype.Center
|
|
633
|
+
* @property {function} prototype.fillet
|
|
634
|
+
* @property {function} prototype.chamfer
|
|
635
|
+
* @property {function} prototype.bisect
|
|
636
|
+
* @property {function} prototype.slice
|
|
637
|
+
* @property {function} prototype.wedge
|
|
638
|
+
* @property {function} prototype.stretch
|
|
639
|
+
* @property {function} prototype.unionIf
|
|
640
|
+
* @property {function} prototype.subtractIf
|
|
641
|
+
* @property {function} prototype.translate
|
|
642
|
+
* @property {function} prototype.addConnector
|
|
643
|
+
* @property {function} prototype.connect
|
|
644
|
+
* @property {function} prototype.connectTo
|
|
645
|
+
* @property {object} Vector2D
|
|
646
|
+
* @property {function} Vector2D.prototype.map
|
|
647
|
+
* @property {boolean} prototype._jscadutilsinit
|
|
648
|
+
* @property {function} result
|
|
649
|
+
* @property {function} array.addArray
|
|
650
|
+
* @property {function} unitCube
|
|
651
|
+
* @property {function} depreciated
|
|
652
|
+
* @property {function} error
|
|
653
|
+
* @property {function} size
|
|
654
|
+
* @property {function} centroid
|
|
655
|
+
* @property {function} zero
|
|
656
|
+
* @property {function} calcCenterWith
|
|
657
|
+
* @property {function} fillet
|
|
658
|
+
* @property {function} chamfer
|
|
659
|
+
* @property {function} bisect
|
|
660
|
+
* @property {function} slice
|
|
661
|
+
* @property {function} wedge
|
|
662
|
+
* @property {function} stretch
|
|
663
|
+
* @property {function} addConnector
|
|
664
|
+
* @property {function} echo
|
|
665
|
+
* @property {function} log
|
|
666
|
+
* @property {function} warn
|
|
667
|
+
* @property {function} info
|
|
668
|
+
* @property {function} debug
|
|
669
|
+
* @property {function} table
|
|
670
|
+
* @property {function} dir
|
|
671
|
+
* @property {function} dirxml
|
|
672
|
+
* @property {function} trace
|
|
673
|
+
* @property {function} group
|
|
674
|
+
* @property {function} clear
|
|
675
|
+
* @property {function} count
|
|
676
|
+
* @property {function} countReset
|
|
677
|
+
* @property {function} time
|
|
678
|
+
* @property {function} timeLog
|
|
679
|
+
* @property {function} timeEnd
|
|
680
|
+
* @property {function} assert
|
|
681
|
+
* @property {function} profile
|
|
682
|
+
* @property {function} profileEnd
|
|
683
|
+
* @property {function} timeStamp
|
|
684
|
+
* @property {function} stackTrace
|
|
685
|
+
* @property {function} getConnector
|
|
686
|
+
*/
|
|
687
|
+
|
|
828
688
|
|
|
829
689
|
/**
|
|
830
690
|
* Initialize `jscad-utils` and add utilities to the `proto` object.
|
|
831
|
-
* @param {
|
|
832
|
-
* @augments proto
|
|
691
|
+
* @param {CSG} proto The global `proto` object
|
|
833
692
|
*/
|
|
834
|
-
|
|
835
693
|
function init(proto) {
|
|
836
694
|
/**
|
|
837
|
-
* Short
|
|
695
|
+
* Short circuit out if the prototypes have already been added.
|
|
838
696
|
*/
|
|
839
|
-
if (proto.prototype._jscadutilsinit) return;
|
|
697
|
+
if (proto.prototype._jscadutilsinit) return;
|
|
840
698
|
|
|
699
|
+
/**
|
|
700
|
+
*
|
|
701
|
+
* @param {ColorName | number} r The red channel value (0.0 - 1.0) or a css color name
|
|
702
|
+
* @param {number} [g] The green channel value (0.0 - 1.0) or the alpha channel when used with a css color string
|
|
703
|
+
* @param {number} [b] The blue channel value (0.0 - 1.0)
|
|
704
|
+
* @param {number} [a] The alpha channel value (0.0 - 1.0)
|
|
705
|
+
* @returns {CSG} The colored object
|
|
706
|
+
*/
|
|
841
707
|
proto.prototype.color = function (r, g, b, a) {
|
|
842
708
|
if (!r) return this; // shortcut empty color values to do nothing.
|
|
843
|
-
|
|
844
709
|
return color(this, r, g, b, a);
|
|
845
710
|
};
|
|
846
|
-
|
|
847
711
|
proto.prototype.flush = function flush$1(to, axis, mside, wside) {
|
|
848
712
|
return flush(this, to, axis, mside, wside);
|
|
849
713
|
};
|
|
850
|
-
|
|
851
714
|
proto.prototype.snap = function snap$1(to, axis, orientation, delta) {
|
|
852
715
|
return snap(this, to, axis, orientation, delta);
|
|
853
716
|
};
|
|
854
|
-
|
|
855
717
|
proto.prototype.calcSnap = function calcSnap$1(to, axis, orientation, delta) {
|
|
856
718
|
return calcSnap(this, to, axis, orientation, delta);
|
|
857
719
|
};
|
|
858
|
-
|
|
859
720
|
proto.prototype.midlineTo = function midlineTo$1(axis, to) {
|
|
860
721
|
return midlineTo(this, axis, to);
|
|
861
722
|
};
|
|
862
|
-
|
|
863
723
|
proto.prototype.calcmidlineTo = function midlineTo(axis, to) {
|
|
864
724
|
return calcmidlineTo(this, axis, to);
|
|
865
725
|
};
|
|
866
|
-
|
|
867
726
|
proto.prototype.centerWith = function centerWith$1(axis, to) {
|
|
868
727
|
depreciated('centerWith', true, 'Use align instead.');
|
|
869
728
|
return centerWith(this, axis, to);
|
|
870
729
|
};
|
|
871
|
-
|
|
872
730
|
if (proto.center) echo('proto already has .center');
|
|
873
|
-
|
|
874
731
|
proto.prototype.center = function center(axis) {
|
|
875
|
-
// console.log('center', axis, this.getBounds());
|
|
876
732
|
return centerWith(this, axis || 'xyz', unitCube());
|
|
877
733
|
};
|
|
878
|
-
|
|
879
734
|
proto.prototype.calcCenter = function centerWith(axis) {
|
|
880
735
|
return calcCenterWith(this, axis || 'xyz', unitCube(), 0);
|
|
881
736
|
};
|
|
882
|
-
|
|
883
737
|
proto.prototype.align = function align(to, axis) {
|
|
884
|
-
// console.log('align', to.getBounds(), axis);
|
|
885
738
|
return centerWith(this, axis, to);
|
|
886
739
|
};
|
|
887
|
-
|
|
888
740
|
proto.prototype.calcAlign = function calcAlign(to, axis, delta) {
|
|
889
741
|
return calcCenterWith(this, axis, to, delta);
|
|
890
742
|
};
|
|
891
|
-
|
|
892
743
|
proto.prototype.enlarge = function enlarge$1(x, y, z) {
|
|
893
744
|
return enlarge(this, x, y, z);
|
|
894
745
|
};
|
|
895
|
-
|
|
896
746
|
proto.prototype.fit = function fit$1(x, y, z, a) {
|
|
897
747
|
return fit(this, x, y, z, a);
|
|
898
748
|
};
|
|
899
|
-
|
|
900
749
|
if (proto.size) echo('proto already has .size');
|
|
901
|
-
|
|
902
750
|
proto.prototype.size = function () {
|
|
903
751
|
return size(this.getBounds());
|
|
904
752
|
};
|
|
905
|
-
|
|
906
753
|
proto.prototype.centroid = function () {
|
|
907
754
|
return centroid(this);
|
|
908
755
|
};
|
|
909
|
-
|
|
910
756
|
proto.prototype.Zero = function zero$1() {
|
|
911
757
|
return zero(this);
|
|
912
758
|
};
|
|
913
|
-
|
|
914
759
|
proto.prototype.Center = function Center(axes) {
|
|
915
760
|
return this.align(unitCube(), axes || 'xy');
|
|
916
761
|
};
|
|
917
|
-
|
|
918
762
|
proto.Vector2D.prototype.map = function Vector2D_map(cb) {
|
|
919
763
|
return new proto.Vector2D(cb(this.x), cb(this.y));
|
|
920
764
|
};
|
|
921
|
-
|
|
922
765
|
proto.prototype.fillet = function fillet$1(radius, orientation, options) {
|
|
923
766
|
return fillet(this, radius, orientation, options);
|
|
924
767
|
};
|
|
925
|
-
|
|
926
768
|
proto.prototype.chamfer = function chamfer$1(radius, orientation, options) {
|
|
927
769
|
return chamfer(this, radius, orientation, options);
|
|
928
770
|
};
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
932
|
-
args[_key] = arguments[_key];
|
|
933
|
-
}
|
|
934
|
-
|
|
935
|
-
return bisect.apply(util, [this].concat(args));
|
|
771
|
+
proto.prototype.bisect = function bisect$1(...args) {
|
|
772
|
+
return bisect(this, ...args);
|
|
936
773
|
};
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
940
|
-
args[_key2] = arguments[_key2];
|
|
941
|
-
}
|
|
942
|
-
|
|
943
|
-
return slice.apply(util, [this].concat(args));
|
|
774
|
+
proto.prototype.slice = function slice$1(...args) {
|
|
775
|
+
return slice(this, ...args);
|
|
944
776
|
};
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
948
|
-
args[_key3] = arguments[_key3];
|
|
949
|
-
}
|
|
950
|
-
|
|
951
|
-
return wedge.apply(util, [this].concat(args));
|
|
777
|
+
proto.prototype.wedge = function wedge$1(...args) {
|
|
778
|
+
return wedge(this, ...args);
|
|
952
779
|
};
|
|
953
|
-
|
|
954
780
|
proto.prototype.stretch = function stretch$1(axis, distance, offset) {
|
|
955
781
|
return stretch(this, axis, distance, offset);
|
|
956
782
|
};
|
|
957
|
-
|
|
958
783
|
proto.prototype.unionIf = function unionIf(object, condition) {
|
|
959
784
|
return condition ? this.union(result(this, object)) : this;
|
|
960
785
|
};
|
|
961
|
-
|
|
962
786
|
proto.prototype.subtractIf = function subtractIf(object, condition) {
|
|
963
787
|
return condition ? this.subtract(result(this, object)) : this;
|
|
964
788
|
};
|
|
965
|
-
|
|
966
789
|
proto.prototype._translate = proto.prototype.translate;
|
|
790
|
+
|
|
967
791
|
/**
|
|
968
792
|
* This modifies the normal `proto.translate` method to accept
|
|
969
793
|
* multiple translations, adding the translations together.
|
|
970
794
|
* The original translate is available on `proto._translate` and
|
|
971
|
-
* a short
|
|
795
|
+
* a short circuit is applied when only one parameter is given.
|
|
972
796
|
* @return {proto} The resulting object.
|
|
973
797
|
*/
|
|
974
|
-
|
|
975
798
|
proto.prototype.translate = function translate() {
|
|
976
799
|
if (arguments.length === 1) {
|
|
977
800
|
return this._translate(arguments[0]);
|
|
978
801
|
} else {
|
|
979
802
|
var t = Array.prototype.slice.call(arguments, 0).reduce(function (result, arg) {
|
|
980
803
|
// console.log('arg', arg);
|
|
981
|
-
result = undefined(result, arg);
|
|
804
|
+
result = undefined.addArray(result, arg);
|
|
982
805
|
return result;
|
|
983
|
-
}, [0, 0, 0]);
|
|
806
|
+
}, [0, 0, 0]);
|
|
984
807
|
|
|
808
|
+
// console.log('translate', t);
|
|
985
809
|
return this._translate(t);
|
|
986
810
|
}
|
|
987
811
|
};
|
|
988
|
-
|
|
989
812
|
proto.prototype.addConnector = function addConnector$1(name, point, axis, normal) {
|
|
990
813
|
return addConnector(this, name, point, axis, normal);
|
|
991
814
|
};
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
var mirror = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
995
|
-
var normalrotation = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
996
|
-
var myConnector = myConnectorName.split('.').reduce(function (a, v) {
|
|
815
|
+
proto.prototype.connect = function connectTo(myConnectorName, otherConnector, mirror = false, normalrotation = 0) {
|
|
816
|
+
var myConnector = myConnectorName.split('.').reduce((a, v) => {
|
|
997
817
|
return a[v];
|
|
998
818
|
}, this.properties);
|
|
819
|
+
|
|
999
820
|
/**
|
|
1000
821
|
* Check for missing property.
|
|
1001
822
|
*/
|
|
1002
|
-
|
|
1003
823
|
if (!myConnector) {
|
|
1004
|
-
error(
|
|
824
|
+
error(`The connector '${myConnectorName}' does not exist on the object [${Object.keys(this.properties).join(',')}]`, 'Missing connector property');
|
|
1005
825
|
}
|
|
1006
|
-
|
|
1007
826
|
return this.connectTo(myConnector, otherConnector, mirror, normalrotation);
|
|
1008
827
|
};
|
|
828
|
+
proto.prototype._jscadutilsinit = true;
|
|
1009
829
|
|
|
1010
|
-
|
|
830
|
+
// console.trace('init', proto.prototype);
|
|
1011
831
|
}
|
|
1012
832
|
|
|
1013
833
|
var init$1 = /*#__PURE__*/Object.freeze({
|
|
1014
834
|
__proto__: null,
|
|
1015
|
-
|
|
835
|
+
default: init
|
|
1016
836
|
});
|
|
1017
837
|
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
838
|
+
const {
|
|
839
|
+
CSG,
|
|
840
|
+
CAG
|
|
841
|
+
} = jsCadCSG;
|
|
842
|
+
const {
|
|
843
|
+
rectangular_extrude
|
|
844
|
+
} = scadApi.extrusions;
|
|
845
|
+
const {
|
|
846
|
+
vector_text,
|
|
847
|
+
vector_char
|
|
848
|
+
} = scadApi.text;
|
|
849
|
+
const {
|
|
850
|
+
union
|
|
851
|
+
} = scadApi.booleanOps;
|
|
1025
852
|
init(CSG);
|
|
1026
853
|
|
|
1027
|
-
|
|
854
|
+
const debug$3 = Debug('jscadUtils:group');
|
|
855
|
+
|
|
1028
856
|
/**
|
|
1029
857
|
* @function JsCadUtilsGroup
|
|
1030
858
|
* @param {string[]} names An array of object names in the group.
|
|
@@ -1032,16 +860,13 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1032
860
|
* @param {CSG[]} holes An array of CSG objects that will be subtracted after combination.
|
|
1033
861
|
* @namespace JsCadUtilsGroup
|
|
1034
862
|
*/
|
|
1035
|
-
|
|
1036
|
-
function JsCadUtilsGroup() {
|
|
1037
|
-
var names = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
1038
|
-
var parts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1039
|
-
var holes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
863
|
+
function JsCadUtilsGroup(names = [], parts = {}, holes = []) {
|
|
1040
864
|
this.name = '';
|
|
1041
865
|
this.names = names;
|
|
1042
866
|
this.parts = parts;
|
|
1043
867
|
this.holes = holes;
|
|
1044
868
|
}
|
|
869
|
+
|
|
1045
870
|
/**
|
|
1046
871
|
* Add a CSG object to the current group.
|
|
1047
872
|
* @param {CSG|JsCadUtilsGroup} object Object to add the parts dictionary.
|
|
@@ -1052,17 +877,14 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1052
877
|
* @function add
|
|
1053
878
|
* @memberof! JsCadUtilsGroup
|
|
1054
879
|
*/
|
|
1055
|
-
|
|
1056
880
|
JsCadUtilsGroup.prototype.add = function (object, name, hidden, subparts, parts) {
|
|
1057
|
-
debug('add', object, name, hidden, subparts, parts);
|
|
881
|
+
debug$3('add', object, name, hidden, subparts, parts);
|
|
1058
882
|
var self = this;
|
|
1059
|
-
|
|
1060
883
|
if (object.parts) {
|
|
1061
884
|
if (name) {
|
|
1062
885
|
// add the combined part
|
|
1063
886
|
if (!hidden) self.names.push(name);
|
|
1064
887
|
self.parts[name] = object.combine(parts);
|
|
1065
|
-
|
|
1066
888
|
if (subparts) {
|
|
1067
889
|
Object.keys(object.parts).forEach(function (key) {
|
|
1068
890
|
self.parts[subparts + key] = object.parts[key];
|
|
@@ -1076,9 +898,9 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1076
898
|
if (!hidden) self.names.push(name);
|
|
1077
899
|
self.parts[name] = object;
|
|
1078
900
|
}
|
|
1079
|
-
|
|
1080
901
|
return self;
|
|
1081
902
|
};
|
|
903
|
+
|
|
1082
904
|
/**
|
|
1083
905
|
* @function combine
|
|
1084
906
|
* @param {String} [pieces] The parts to combine, if empty, then all named parts.
|
|
@@ -1086,54 +908,46 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1086
908
|
* @param {Function} map A function that is run before unioning the parts together.
|
|
1087
909
|
* @return {CSG} A single `CSG` object of the unioned parts.
|
|
1088
910
|
*/
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
JsCadUtilsGroup.prototype.combine = function (pieces) {
|
|
1092
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1093
|
-
var map = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function (x) {
|
|
1094
|
-
return x;
|
|
1095
|
-
};
|
|
1096
|
-
|
|
911
|
+
JsCadUtilsGroup.prototype.combine = function (pieces, options = {}, map = x => x) {
|
|
1097
912
|
try {
|
|
1098
913
|
var self = this;
|
|
1099
914
|
options = Object.assign({
|
|
1100
915
|
noholes: false
|
|
1101
916
|
}, options);
|
|
1102
917
|
pieces = pieces ? pieces.split(',') : self.names;
|
|
1103
|
-
|
|
1104
918
|
if (pieces.length === 0) {
|
|
1105
|
-
throw new Error(
|
|
919
|
+
throw new Error(`no pieces found in ${self.name} pieces: ${pieces} parts: ${Object.keys(self.parts)} names: ${self.names}`);
|
|
1106
920
|
}
|
|
1107
|
-
|
|
1108
|
-
debug('combine', self.names, self.parts);
|
|
921
|
+
debug$3('combine', self.names, self.parts);
|
|
1109
922
|
var g = union(mapPick(self.parts, pieces, function (value, key, index, object) {
|
|
1110
|
-
|
|
923
|
+
debug$3('combine mapPick', value, key, object);
|
|
1111
924
|
return map ? map(value, key, index, object) : identity(value);
|
|
1112
925
|
}, self.name));
|
|
1113
926
|
return g.subtractIf(self.holes && Array.isArray(self.holes) ? union(self.holes) : self.holes, self.holes && !options.noholes);
|
|
1114
927
|
} catch (err) {
|
|
1115
|
-
debug('combine error', this, pieces, options, err);
|
|
1116
|
-
throw error(
|
|
928
|
+
debug$3('combine error', this, pieces, options, err);
|
|
929
|
+
throw error(`group::combine error "${err.message || err.toString()}"
|
|
930
|
+
this: ${this}
|
|
931
|
+
pieces: "${pieces}"
|
|
932
|
+
options: ${JSON.stringify(options, null, 2)}
|
|
933
|
+
stack: ${err.stack}
|
|
934
|
+
`, 'JSCAD_UTILS_GROUP_ERROR');
|
|
1117
935
|
}
|
|
1118
936
|
};
|
|
937
|
+
|
|
1119
938
|
/**
|
|
1120
939
|
* Apply a function to each element in the group.
|
|
1121
|
-
* @param {Function} cb Callback
|
|
940
|
+
* @param {Function} cb Callback function applied to each part.
|
|
1122
941
|
* It is called with the parameters `(value, key)`
|
|
1123
942
|
* @return {Object} Returns this object so it can be chained
|
|
1124
943
|
* @function map
|
|
1125
944
|
*/
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
945
|
JsCadUtilsGroup.prototype.map = function (cb) {
|
|
1129
946
|
var self = this;
|
|
1130
|
-
self.parts = Object.keys(self.parts).filter(function (
|
|
1131
|
-
return k !== 'holes';
|
|
1132
|
-
}).reduce(function (result, key) {
|
|
947
|
+
self.parts = Object.keys(self.parts).filter(k => k !== 'holes').reduce(function (result, key) {
|
|
1133
948
|
result[key] = cb(self.parts[key], key);
|
|
1134
949
|
return result;
|
|
1135
950
|
}, {});
|
|
1136
|
-
|
|
1137
951
|
if (self.holes) {
|
|
1138
952
|
if (Array.isArray(self.holes)) {
|
|
1139
953
|
self.holes = self.holes.map(function (hole, idx) {
|
|
@@ -1143,9 +957,9 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1143
957
|
self.holes = cb(self.holes, 'holes');
|
|
1144
958
|
}
|
|
1145
959
|
}
|
|
1146
|
-
|
|
1147
960
|
return self;
|
|
1148
961
|
};
|
|
962
|
+
|
|
1149
963
|
/**
|
|
1150
964
|
* Clone a group into a new group.
|
|
1151
965
|
* @function clone
|
|
@@ -1153,47 +967,41 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1153
967
|
* @param {Function} [map] A function called on each part.
|
|
1154
968
|
* @return {JsCadUtilsGroup} The new group.
|
|
1155
969
|
*/
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
970
|
JsCadUtilsGroup.prototype.clone = function (name, map) {
|
|
1159
|
-
debug('clone', name,
|
|
971
|
+
debug$3('clone', name, typeof name, map);
|
|
1160
972
|
var self = this;
|
|
1161
973
|
/**
|
|
1162
974
|
* For backwards compatibility
|
|
1163
975
|
*/
|
|
1164
|
-
|
|
1165
976
|
if (typeof name == 'function') {
|
|
1166
977
|
map = name;
|
|
1167
978
|
name = undefined;
|
|
1168
979
|
}
|
|
980
|
+
if (!map) map = identity;
|
|
1169
981
|
|
|
1170
|
-
|
|
1171
|
-
|
|
982
|
+
// console.warn('clone() has been refactored');
|
|
1172
983
|
var group = Group(name);
|
|
1173
984
|
Object.keys(self.parts).forEach(function (key) {
|
|
1174
985
|
var part = self.parts[key];
|
|
1175
986
|
var hidden = self.names.indexOf(key) == -1;
|
|
1176
987
|
group.add(map(clone(part)), key, hidden);
|
|
1177
988
|
});
|
|
1178
|
-
|
|
1179
989
|
if (self.holes) {
|
|
1180
990
|
group.holes = toArray(self.holes).map(function (part) {
|
|
1181
991
|
return map(CSG.fromPolygons(part.toPolygons()), 'holes');
|
|
1182
992
|
});
|
|
1183
993
|
}
|
|
1184
|
-
|
|
1185
994
|
return group;
|
|
1186
995
|
};
|
|
996
|
+
|
|
1187
997
|
/**
|
|
1188
998
|
* Rotate the group around a solids centroid. This mutates the group.
|
|
1189
999
|
* @param {CSG|String} solid The solid to rotate the group around
|
|
1190
1000
|
* @param {String} axis Axis to rotate
|
|
1191
1001
|
* @param {Number} angle Angle in degrees
|
|
1192
|
-
* @return {JsCadUtilsGroup} The
|
|
1002
|
+
* @return {JsCadUtilsGroup} The rotated group.
|
|
1193
1003
|
* @function rotate
|
|
1194
1004
|
*/
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
1005
|
JsCadUtilsGroup.prototype.rotate = function (solid, axis, angle) {
|
|
1198
1006
|
var self = this;
|
|
1199
1007
|
var axes = {
|
|
@@ -1201,12 +1009,10 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1201
1009
|
y: [0, 1, 0],
|
|
1202
1010
|
z: [0, 0, 1]
|
|
1203
1011
|
};
|
|
1204
|
-
|
|
1205
1012
|
if (typeof solid === 'string') {
|
|
1206
1013
|
var _names = solid;
|
|
1207
1014
|
solid = self.combine(_names);
|
|
1208
1015
|
}
|
|
1209
|
-
|
|
1210
1016
|
var rotationCenter = solid.centroid();
|
|
1211
1017
|
var rotationAxis = axes[axis];
|
|
1212
1018
|
self.map(function (part) {
|
|
@@ -1214,6 +1020,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1214
1020
|
});
|
|
1215
1021
|
return self;
|
|
1216
1022
|
};
|
|
1023
|
+
|
|
1217
1024
|
/**
|
|
1218
1025
|
* Combines all parts, named and unnamed.
|
|
1219
1026
|
* @function combineAll
|
|
@@ -1221,12 +1028,11 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1221
1028
|
* @param {Function} map A function run on each part before unioning.
|
|
1222
1029
|
* @return {CSG} A `CSG` object of all combined parts.
|
|
1223
1030
|
*/
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
1031
|
JsCadUtilsGroup.prototype.combineAll = function (options, map) {
|
|
1227
1032
|
var self = this;
|
|
1228
1033
|
return self.combine(Object.keys(self.parts).join(','), options, map);
|
|
1229
1034
|
};
|
|
1035
|
+
|
|
1230
1036
|
/**
|
|
1231
1037
|
* Snaps a named part of a group to another `CSG` objects
|
|
1232
1038
|
* bounding box.
|
|
@@ -1238,22 +1044,29 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1238
1044
|
* @param {Number} [delta=0] An offset to apply with the snap, in millimeters.
|
|
1239
1045
|
* @return {JsCadUtilsGroup} The group after snapping all parts to the `to` object.
|
|
1240
1046
|
*/
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
1047
|
JsCadUtilsGroup.prototype.snap = function snap(part, to, axis, orientation, delta) {
|
|
1244
1048
|
try {
|
|
1245
|
-
var self = this;
|
|
1246
|
-
|
|
1049
|
+
var self = this;
|
|
1050
|
+
// debug(', self);
|
|
1247
1051
|
var t = calcSnap(self.combine(part), to, axis, orientation, delta);
|
|
1248
1052
|
self.map(function (part) {
|
|
1249
1053
|
return part.translate(t);
|
|
1250
1054
|
});
|
|
1251
1055
|
return self;
|
|
1252
1056
|
} catch (err) {
|
|
1253
|
-
debug('snap error', this, part, to, axis, delta, err);
|
|
1254
|
-
throw error(
|
|
1057
|
+
debug$3('snap error', this, part, to, axis, delta, err);
|
|
1058
|
+
throw error(`group::snap error "${err.message || err.toString()}"
|
|
1059
|
+
this: ${this}
|
|
1060
|
+
part: "${part}"
|
|
1061
|
+
to: ${to}
|
|
1062
|
+
axis: "${axis}"
|
|
1063
|
+
orientation: "${orientation}"
|
|
1064
|
+
delta: "${delta}"
|
|
1065
|
+
stack: ${err.stack}
|
|
1066
|
+
`, 'JSCAD_UTILS_GROUP_ERROR');
|
|
1255
1067
|
}
|
|
1256
1068
|
};
|
|
1069
|
+
|
|
1257
1070
|
/**
|
|
1258
1071
|
* Aligns all parts in a group to another `CSG` object.
|
|
1259
1072
|
* @function align
|
|
@@ -1264,67 +1077,68 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1264
1077
|
* @return {JsCadUtilsGroup} The group after aligning all parts to the `to` object.
|
|
1265
1078
|
|
|
1266
1079
|
*/
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
1080
|
JsCadUtilsGroup.prototype.align = function align(part, to, axis, delta) {
|
|
1270
1081
|
try {
|
|
1271
1082
|
var self = this;
|
|
1272
1083
|
var t = calcCenterWith(self.combine(part, {
|
|
1273
1084
|
noholes: true
|
|
1274
1085
|
}), axis, to, delta);
|
|
1275
|
-
self.map(function (part
|
|
1276
|
-
/*, name */
|
|
1277
|
-
) {
|
|
1086
|
+
self.map(function (part /*, name */) {
|
|
1278
1087
|
return part.translate(t);
|
|
1279
|
-
});
|
|
1088
|
+
});
|
|
1089
|
+
|
|
1090
|
+
// if (self.holes)
|
|
1280
1091
|
// self.holes = util.ifArray(self.holes, function(hole) {
|
|
1281
1092
|
// return hole.translate(t);
|
|
1282
1093
|
// });
|
|
1283
1094
|
|
|
1284
1095
|
return self;
|
|
1285
1096
|
} catch (err) {
|
|
1286
|
-
debug('align error', this, part, to, axis, delta, err);
|
|
1287
|
-
throw error(
|
|
1097
|
+
debug$3('align error', this, part, to, axis, delta, err);
|
|
1098
|
+
throw error(`group::align error "${err.message || err.toString()}"
|
|
1099
|
+
this: ${this}
|
|
1100
|
+
part: "${part}"
|
|
1101
|
+
to: ${to}
|
|
1102
|
+
axis: "${axis}"
|
|
1103
|
+
delta: "${delta}"
|
|
1104
|
+
stack: ${err.stack}
|
|
1105
|
+
`, 'JSCAD_UTILS_GROUP_ERROR');
|
|
1288
1106
|
}
|
|
1289
1107
|
};
|
|
1290
|
-
|
|
1291
1108
|
JsCadUtilsGroup.prototype.center = function center(part) {
|
|
1292
1109
|
var self = this;
|
|
1293
1110
|
return self.align(part, unitCube(), 'xyz');
|
|
1294
1111
|
};
|
|
1295
|
-
|
|
1296
1112
|
JsCadUtilsGroup.prototype.zero = function zero(part) {
|
|
1297
1113
|
var self = this;
|
|
1298
1114
|
var bounds = self.parts[part].getBounds();
|
|
1299
1115
|
return self.translate([0, 0, -bounds[0].z]);
|
|
1300
1116
|
};
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
toConnectorName: toConnectorName,
|
|
1310
|
-
mirror: mirror,
|
|
1311
|
-
normalrotation: normalrotation
|
|
1117
|
+
JsCadUtilsGroup.prototype.connectTo = function connectTo(partName, connectorName, to, toConnectorName, mirror = true, normalrotation = 0) {
|
|
1118
|
+
debug$3('connectTo', {
|
|
1119
|
+
partName,
|
|
1120
|
+
connectorName,
|
|
1121
|
+
to,
|
|
1122
|
+
toConnectorName,
|
|
1123
|
+
mirror,
|
|
1124
|
+
normalrotation
|
|
1312
1125
|
});
|
|
1313
1126
|
var self = this;
|
|
1314
|
-
var myConnector = connectorName.split('.').reduce(
|
|
1127
|
+
var myConnector = connectorName.split('.').reduce((a, v) => {
|
|
1315
1128
|
return a[v];
|
|
1316
1129
|
}, self.parts[partName].properties);
|
|
1317
|
-
debug('toConnector', to instanceof CSG.Connector);
|
|
1318
|
-
var toConnector = toConnectorName.split('.').reduce(
|
|
1130
|
+
debug$3('toConnector', to instanceof CSG.Connector);
|
|
1131
|
+
var toConnector = toConnectorName.split('.').reduce((a, v) => {
|
|
1319
1132
|
return a[v];
|
|
1320
1133
|
}, to.properties);
|
|
1321
1134
|
var matrix = myConnector.getTransformationTo(toConnector, mirror, normalrotation);
|
|
1322
|
-
debug('connectTo', matrix);
|
|
1135
|
+
debug$3('connectTo', matrix);
|
|
1323
1136
|
self.map(function (part) {
|
|
1324
1137
|
return part.transform(matrix);
|
|
1325
1138
|
});
|
|
1326
1139
|
return self;
|
|
1327
1140
|
};
|
|
1141
|
+
|
|
1328
1142
|
/**
|
|
1329
1143
|
* @function midlineTo
|
|
1330
1144
|
* @param {String} part Comma separated list of parts in the group to align.
|
|
@@ -1332,48 +1146,50 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1332
1146
|
* @param {String} axis An axis string to align on can be any combination of `x`, `y`, or `z`.
|
|
1333
1147
|
* @return {JsCadUtilsGroup} The group after aligning all parts to the `to` object.
|
|
1334
1148
|
*/
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
1149
|
JsCadUtilsGroup.prototype.midlineTo = function midlineTo(part, axis, to) {
|
|
1338
1150
|
var self = this;
|
|
1339
1151
|
var size = self.combine(part).size();
|
|
1340
1152
|
var t = axisApply(axis, function (i, a) {
|
|
1341
1153
|
return to - size[a] / 2;
|
|
1342
|
-
});
|
|
1154
|
+
});
|
|
1155
|
+
// debug(' part, t);
|
|
1343
1156
|
// var t = util.calcCenterWith(self.combine(part), axis, to, delta);
|
|
1344
|
-
|
|
1345
1157
|
self.map(function (part) {
|
|
1346
1158
|
return part.translate(t);
|
|
1347
|
-
});
|
|
1159
|
+
});
|
|
1160
|
+
|
|
1161
|
+
// if (self.holes)
|
|
1348
1162
|
// self.holes = util.ifArray(self.holes, function(hole) {
|
|
1349
1163
|
// return hole.translate(t);
|
|
1350
1164
|
// });
|
|
1351
1165
|
|
|
1352
1166
|
return self;
|
|
1353
1167
|
};
|
|
1168
|
+
|
|
1354
1169
|
/**
|
|
1355
|
-
* Translates a group by a given
|
|
1170
|
+
* Translates a group by a given amount
|
|
1356
1171
|
* @function translate
|
|
1357
1172
|
* @param {Number|Array} x The `x` value or an array of x, y and z.
|
|
1358
1173
|
* @param {Number} [y] The `y` value.
|
|
1359
1174
|
* @param {Number} [z] The `z` value.
|
|
1360
1175
|
* @return {JsCadUtilsGroup} The translated group.
|
|
1361
1176
|
*/
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
1177
|
JsCadUtilsGroup.prototype.translate = function translate(x, y, z) {
|
|
1365
1178
|
var self = this;
|
|
1366
1179
|
var t = Array.isArray(x) ? x : [x, y, z];
|
|
1367
|
-
debug('translate', t);
|
|
1180
|
+
debug$3('translate', t);
|
|
1368
1181
|
self.map(function (part) {
|
|
1369
1182
|
return part.translate(t);
|
|
1370
|
-
});
|
|
1183
|
+
});
|
|
1184
|
+
|
|
1185
|
+
// if (self.holes)
|
|
1371
1186
|
// self.holes = util.ifArray(self.holes, function(hole) {
|
|
1372
1187
|
// return hole.translate(t);
|
|
1373
1188
|
// });
|
|
1374
1189
|
|
|
1375
1190
|
return self;
|
|
1376
1191
|
};
|
|
1192
|
+
|
|
1377
1193
|
/**
|
|
1378
1194
|
* Returns a new group from the list of parts.
|
|
1379
1195
|
* @function pick
|
|
@@ -1381,8 +1197,6 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1381
1197
|
* @param {function} map A function run on each part as its added to the new group.
|
|
1382
1198
|
* @return {JsCadUtilsGroup} The new group with the picked parts.
|
|
1383
1199
|
*/
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
1200
|
JsCadUtilsGroup.prototype.pick = function (parts, map) {
|
|
1387
1201
|
var self = this;
|
|
1388
1202
|
var p = parts && parts.length > 0 && parts.split(',') || self.names;
|
|
@@ -1393,32 +1207,32 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1393
1207
|
});
|
|
1394
1208
|
return g;
|
|
1395
1209
|
};
|
|
1210
|
+
|
|
1396
1211
|
/**
|
|
1397
1212
|
* Converts a group into an array of `CSG` objects.
|
|
1398
1213
|
* @function array
|
|
1399
|
-
* @param {String} parts A comma separated list of parts it include in the new array.
|
|
1400
|
-
* @param {Function} map A function run on each part as its added to the new array.
|
|
1214
|
+
* @param {String} [parts] A comma separated list of parts it include in the new array.
|
|
1215
|
+
* @param {Function} [map] A function run on each part as its added to the new array.
|
|
1401
1216
|
* @return {Array} An array of `CSG` objects
|
|
1402
1217
|
*/
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
1218
|
JsCadUtilsGroup.prototype.array = function (parts, map) {
|
|
1406
|
-
var
|
|
1407
|
-
|
|
1408
|
-
var self = this; // try {
|
|
1409
|
-
|
|
1219
|
+
var self = this;
|
|
1220
|
+
// try {
|
|
1410
1221
|
var p = parts && parts.length > 0 && parts.split(',') || self.names;
|
|
1411
1222
|
if (!map) map = identity;
|
|
1412
1223
|
var a = [];
|
|
1413
|
-
p.forEach(
|
|
1224
|
+
p.forEach(name => {
|
|
1414
1225
|
if (!self.parts[name]) {
|
|
1415
|
-
debug('array error',
|
|
1416
|
-
throw error(
|
|
1226
|
+
debug$3('array error', this, parts);
|
|
1227
|
+
throw error(`group::array error "${name}" not found.
|
|
1228
|
+
this: ${this}
|
|
1229
|
+
parts: "${parts}"
|
|
1230
|
+
`, 'JSCAD_UTILS_GROUP_ERROR');
|
|
1417
1231
|
}
|
|
1418
|
-
|
|
1419
1232
|
a.push(map(CSG.fromPolygons(self.parts[name].toPolygons()), name));
|
|
1420
1233
|
});
|
|
1421
|
-
return a;
|
|
1234
|
+
return a;
|
|
1235
|
+
// } catch (err) {
|
|
1422
1236
|
// debug('array error', this, parts, err);
|
|
1423
1237
|
// throw error(
|
|
1424
1238
|
// `group::array error "${err.message || err.toString()}"
|
|
@@ -1430,6 +1244,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1430
1244
|
// );
|
|
1431
1245
|
// }
|
|
1432
1246
|
};
|
|
1247
|
+
|
|
1433
1248
|
/**
|
|
1434
1249
|
* Converts all pieces or the picked pieces of a group into an array of `CSG`
|
|
1435
1250
|
* objects.
|
|
@@ -1438,25 +1253,27 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1438
1253
|
* @return {Array} An array of `CSG` objects.
|
|
1439
1254
|
* @deprecated Use `array` instead of `toArray`.
|
|
1440
1255
|
*/
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
1256
|
JsCadUtilsGroup.prototype.toArray = function (pieces) {
|
|
1444
1257
|
var self = this;
|
|
1445
1258
|
var piecesArray = pieces ? pieces.split(',') : self.names;
|
|
1446
1259
|
return piecesArray.map(function (piece) {
|
|
1447
|
-
if (!self.parts[piece]) console.error(
|
|
1260
|
+
if (!self.parts[piece]) console.error(`Cannot find ${piece} in ${self.names}`);
|
|
1448
1261
|
return self.parts[piece];
|
|
1449
1262
|
});
|
|
1450
1263
|
};
|
|
1451
|
-
|
|
1452
1264
|
JsCadUtilsGroup.prototype.toString = function () {
|
|
1453
|
-
return
|
|
1265
|
+
return `{
|
|
1266
|
+
name: "${this.name}",
|
|
1267
|
+
names: "${this.names.join(',')}",
|
|
1268
|
+
parts: "${Object.keys(this.parts)}",
|
|
1269
|
+
holes: ${Array.isArray(this.holes) ? this.holes.length : this.holes ? 1 : 0}
|
|
1270
|
+
}`;
|
|
1454
1271
|
};
|
|
1455
|
-
|
|
1456
1272
|
JsCadUtilsGroup.prototype.setName = function (name) {
|
|
1457
1273
|
this.name = name;
|
|
1458
1274
|
return this;
|
|
1459
1275
|
};
|
|
1276
|
+
|
|
1460
1277
|
/**
|
|
1461
1278
|
* Creates a `group` object given a comma separated
|
|
1462
1279
|
* list of names, and an array or object. If an object
|
|
@@ -1465,29 +1282,25 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1465
1282
|
*
|
|
1466
1283
|
* You can call the `combine()` function with a list of parts you want combined into one.
|
|
1467
1284
|
*
|
|
1468
|
-
* The `map()`
|
|
1285
|
+
* The `map()` function allows you to modify each part
|
|
1469
1286
|
* contained in the group object.
|
|
1470
1287
|
*
|
|
1471
1288
|
* @param {string | object} [objectNames] Comma separated list of part names.
|
|
1472
1289
|
* @param {array | object} [addObjects] Array or object of parts. If Array, the names list is used as names for each part.
|
|
1473
1290
|
* @return {JsCadUtilsGroup} An object that has a parts dictionary, a `combine()` and `map()` function.
|
|
1474
1291
|
*/
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
1292
|
function Group(objectNames, addObjects) {
|
|
1478
|
-
debug('Group', objectNames, addObjects);
|
|
1293
|
+
debug$3('Group', objectNames, addObjects);
|
|
1479
1294
|
var self = {
|
|
1480
1295
|
name: '',
|
|
1481
1296
|
names: [],
|
|
1482
1297
|
parts: {}
|
|
1483
1298
|
};
|
|
1484
|
-
|
|
1485
1299
|
if (objectNames) {
|
|
1486
1300
|
if (addObjects) {
|
|
1487
1301
|
var names = objectNames;
|
|
1488
1302
|
var objects = addObjects;
|
|
1489
1303
|
self.names = names && names.length > 0 && names.split(',') || [];
|
|
1490
|
-
|
|
1491
1304
|
if (Array.isArray(objects)) {
|
|
1492
1305
|
self.parts = zipObject(self.names, objects);
|
|
1493
1306
|
} else if (objects instanceof CSG) {
|
|
@@ -1503,77 +1316,71 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1503
1316
|
self.name = objectNames;
|
|
1504
1317
|
} else {
|
|
1505
1318
|
var objects = objectNames; // eslint-disable-line no-redeclare
|
|
1506
|
-
|
|
1507
|
-
self.names = Object.keys(objects).filter(function (k) {
|
|
1508
|
-
return k !== 'holes';
|
|
1509
|
-
});
|
|
1319
|
+
self.names = Object.keys(objects).filter(k => k !== 'holes');
|
|
1510
1320
|
self.parts = Object.assign({}, objects);
|
|
1511
1321
|
self.holes = objects.holes;
|
|
1512
1322
|
}
|
|
1513
1323
|
}
|
|
1514
1324
|
}
|
|
1515
|
-
|
|
1516
1325
|
return new JsCadUtilsGroup(self.names, self.parts, self.holes);
|
|
1517
1326
|
}
|
|
1518
1327
|
|
|
1519
|
-
|
|
1328
|
+
/** @typedef { import('@jscad/csg').CSG } CSG */
|
|
1329
|
+
|
|
1330
|
+
const debug$2 = Debug('jscadUtils:util');
|
|
1331
|
+
// import utilInit from '../src/add-prototype';
|
|
1520
1332
|
// utilInit(CSG);
|
|
1521
1333
|
// console.trace('CSG', CSG.prototype);
|
|
1522
1334
|
|
|
1523
1335
|
var NOZZEL_SIZE = 0.4;
|
|
1524
|
-
|
|
1336
|
+
const nearest = {
|
|
1525
1337
|
/**
|
|
1526
1338
|
* Return the largest number that is a multiple of the
|
|
1527
1339
|
* nozzel size.
|
|
1528
1340
|
* @param {Number} desired Desired value
|
|
1529
|
-
* @param {Number} [nozzel=NOZZEL_SIZE]
|
|
1341
|
+
* @param {Number} [nozzel=NOZZEL_SIZE] Nozzel size, defaults to `NOZZEL_SIZE`
|
|
1530
1342
|
* @param {Number} [nozzie=0] Number of nozzel sizes to add to the value
|
|
1531
1343
|
* @return {Number} Multiple of nozzel size
|
|
1532
1344
|
*/
|
|
1533
|
-
under: function
|
|
1534
|
-
var nozzel = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : NOZZEL_SIZE;
|
|
1535
|
-
var nozzie = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
1345
|
+
under: function (desired, nozzel = NOZZEL_SIZE, nozzie = 0) {
|
|
1536
1346
|
return (Math.floor(desired / nozzel) + nozzie) * nozzel;
|
|
1537
1347
|
},
|
|
1538
|
-
|
|
1539
1348
|
/**
|
|
1540
|
-
* Returns the largest number that is a
|
|
1349
|
+
* Returns the largest number that is a multiple of the
|
|
1541
1350
|
* nozzel size, just over the desired value.
|
|
1542
1351
|
* @param {Number} desired Desired value
|
|
1543
|
-
* @param {Number} [nozzel=NOZZEL_SIZE]
|
|
1352
|
+
* @param {Number} [nozzel=NOZZEL_SIZE] Nozzel size, defaults to `NOZZEL_SIZE`
|
|
1544
1353
|
* @param {Number} [nozzie=0] Number of nozzel sizes to add to the value
|
|
1545
1354
|
* @return {Number} Multiple of nozzel size
|
|
1546
1355
|
*/
|
|
1547
|
-
over: function
|
|
1548
|
-
var nozzel = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : NOZZEL_SIZE;
|
|
1549
|
-
var nozzie = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
1356
|
+
over: function (desired, nozzel = NOZZEL_SIZE, nozzie = 0) {
|
|
1550
1357
|
return (Math.ceil(desired / nozzel) + nozzie) * nozzel;
|
|
1551
1358
|
}
|
|
1552
1359
|
};
|
|
1360
|
+
|
|
1553
1361
|
/**
|
|
1554
|
-
* A function that
|
|
1362
|
+
* A function that returns the first argument. Useful when
|
|
1555
1363
|
* passing in a callback to modify something, and you want a
|
|
1556
|
-
* default
|
|
1364
|
+
* default function hat does nothing.
|
|
1557
1365
|
* @param {object} solid an object that will be returned
|
|
1558
1366
|
* @return {object} the first parameter passed into the function.
|
|
1559
1367
|
* @function identity
|
|
1560
1368
|
*/
|
|
1561
|
-
|
|
1562
1369
|
function identity(solid) {
|
|
1563
1370
|
return solid;
|
|
1564
1371
|
}
|
|
1372
|
+
|
|
1565
1373
|
/**
|
|
1566
|
-
* If `f` is a
|
|
1374
|
+
* If `f` is a function, it is executed with `object` as the
|
|
1567
1375
|
* parameter. This is used in `CSG.unionIf` and `CSG.subtractIf`,
|
|
1568
1376
|
* allowing you to pass a function instead of an object. Since the
|
|
1569
|
-
* function isn't
|
|
1377
|
+
* function isn't executed until called, the object to `union` or
|
|
1570
1378
|
* `subtract` can be assembled only if the conditional is true.
|
|
1571
1379
|
* @param {object} object the context to run the function with.
|
|
1572
|
-
* @param {function|object} f if a
|
|
1380
|
+
* @param {function|object} f if a function it is executed, otherwise the object is returned.
|
|
1573
1381
|
* @return {object} the result of the function or the object.
|
|
1574
1382
|
* @function result
|
|
1575
1383
|
*/
|
|
1576
|
-
|
|
1577
1384
|
function result(object, f) {
|
|
1578
1385
|
if (typeof f === 'function') {
|
|
1579
1386
|
return f.call(object);
|
|
@@ -1581,15 +1388,15 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1581
1388
|
return f;
|
|
1582
1389
|
}
|
|
1583
1390
|
}
|
|
1391
|
+
|
|
1584
1392
|
/**
|
|
1585
1393
|
* Returns target object with default values assigned. If values already exist, they are not set.
|
|
1586
1394
|
* @param {object} target The target object to return.
|
|
1587
|
-
* @param {object} defaults
|
|
1395
|
+
* @param {object} defaults Default values to add to the object if they don't already exist.
|
|
1588
1396
|
* @return {object} Target object with default values assigned.
|
|
1589
1397
|
* @function defaults
|
|
1590
|
-
* @
|
|
1398
|
+
* @deprecated
|
|
1591
1399
|
*/
|
|
1592
|
-
|
|
1593
1400
|
function defaults(target, defaults) {
|
|
1594
1401
|
depreciated('defaults', true, 'use Object.assign instead');
|
|
1595
1402
|
return Object.assign(defaults, target);
|
|
@@ -1600,22 +1407,26 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1600
1407
|
function isNegative(n) {
|
|
1601
1408
|
return ((n = +n) || 1 / n) < 0;
|
|
1602
1409
|
}
|
|
1410
|
+
|
|
1603
1411
|
/**
|
|
1604
|
-
* Print a message and CSG object bounds and size to the
|
|
1412
|
+
* Print a message and CSG object bounds and size to the console.
|
|
1605
1413
|
* @param {String} msg Message to print
|
|
1606
1414
|
* @param {CSG} o A CSG object to print the bounds and size of.
|
|
1607
1415
|
* @function
|
|
1608
|
-
* @
|
|
1416
|
+
* @deprecated use Debug instead
|
|
1609
1417
|
*/
|
|
1610
|
-
|
|
1611
1418
|
function print(msg, o) {
|
|
1612
|
-
debug$
|
|
1419
|
+
debug$2(msg, JSON.stringify(o.getBounds()), JSON.stringify(this.size(o.getBounds())));
|
|
1613
1420
|
}
|
|
1614
1421
|
function jscadToString(o) {
|
|
1615
|
-
if (
|
|
1422
|
+
if (typeof o == 'object') {
|
|
1616
1423
|
if (o.polygons) {
|
|
1617
1424
|
// is this CSG like?
|
|
1618
|
-
return
|
|
1425
|
+
return `{
|
|
1426
|
+
polygons: ${o.polygons.length},
|
|
1427
|
+
properties: "${Object.keys(o.properties)}"
|
|
1428
|
+
}
|
|
1429
|
+
`;
|
|
1619
1430
|
}
|
|
1620
1431
|
} else {
|
|
1621
1432
|
return o.toString();
|
|
@@ -1623,55 +1434,52 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1623
1434
|
}
|
|
1624
1435
|
function error(msg, name, error) {
|
|
1625
1436
|
if (console && console.error) console.error(msg, error); // eslint-disable-line no-console
|
|
1626
|
-
|
|
1627
1437
|
var err = new Error(msg);
|
|
1628
1438
|
err.name = name || 'JSCAD_UTILS_ERROR';
|
|
1629
1439
|
err._error = error;
|
|
1630
1440
|
throw err;
|
|
1631
1441
|
}
|
|
1442
|
+
|
|
1632
1443
|
/**
|
|
1633
1444
|
* Shows a warning or error message. Used to indicate a method
|
|
1634
|
-
* has been
|
|
1445
|
+
* has been deprecated and what to use instead.
|
|
1635
1446
|
* @function depreciated
|
|
1636
|
-
* @param {string} method The name of the method being
|
|
1447
|
+
* @param {string} method The name of the method being deprecated.
|
|
1637
1448
|
* @param {boolean} [error] Throws an error if called when true.
|
|
1638
|
-
* @param {string} [message] Instructions on what to use instead of the
|
|
1449
|
+
* @param {string} [message] Instructions on what to use instead of the deprecated method.
|
|
1639
1450
|
*/
|
|
1640
|
-
|
|
1641
1451
|
function depreciated(method, error, message) {
|
|
1642
|
-
var msg = method + ' is depreciated.' + (' ' + message || '');
|
|
1643
|
-
|
|
1452
|
+
var msg = method + ' is depreciated.' + (' ' + message || '');
|
|
1453
|
+
// eslint-disable-next-line no-console
|
|
1644
1454
|
if (!error && console && console.error) console[error ? 'error' : 'warn'](msg); // eslint-disable-line no-console
|
|
1645
|
-
|
|
1646
1455
|
if (error) {
|
|
1647
1456
|
var err = new Error(msg);
|
|
1648
1457
|
err.name = 'JSCAD_UTILS_DEPRECATED';
|
|
1649
1458
|
throw err;
|
|
1650
1459
|
}
|
|
1651
1460
|
}
|
|
1461
|
+
|
|
1652
1462
|
/**
|
|
1653
1463
|
* Convert an imperial `inch` to metric `mm`.
|
|
1654
1464
|
* @param {Number} x Value in inches
|
|
1655
1465
|
* @return {Number} Result in mm
|
|
1656
1466
|
* @function inch
|
|
1657
1467
|
*/
|
|
1658
|
-
|
|
1659
1468
|
function inch(x) {
|
|
1660
1469
|
return x * 25.4;
|
|
1661
1470
|
}
|
|
1471
|
+
|
|
1662
1472
|
/**
|
|
1663
1473
|
* Convert metric `cm` to imperial `inch`.
|
|
1664
1474
|
* @param {Number} x Value in cm
|
|
1665
1475
|
* @return {Number} Result in inches
|
|
1666
1476
|
* @function cm
|
|
1667
1477
|
*/
|
|
1668
|
-
|
|
1669
1478
|
function cm(x) {
|
|
1670
1479
|
return x / 25.4;
|
|
1671
1480
|
}
|
|
1672
1481
|
function label(text, x, y, width, height) {
|
|
1673
1482
|
var l = vector_text(x || 0, y || 0, text); // l contains a list of polylines to draw
|
|
1674
|
-
|
|
1675
1483
|
var o = [];
|
|
1676
1484
|
l.forEach(function (pl) {
|
|
1677
1485
|
// pl = polyline (not closed)
|
|
@@ -1679,23 +1487,21 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1679
1487
|
w: width || 2,
|
|
1680
1488
|
h: height || 2
|
|
1681
1489
|
})); // extrude it to 3D
|
|
1682
|
-
});
|
|
1490
|
+
});
|
|
1491
|
+
// console.trace('label', Object.getPrototypeOf(union(o)));
|
|
1683
1492
|
// var foo = union(o);
|
|
1684
1493
|
// console.trace('typeof', typeof foo);
|
|
1685
|
-
|
|
1686
1494
|
return center(union(o));
|
|
1687
1495
|
}
|
|
1688
1496
|
function text(text) {
|
|
1689
1497
|
var l = vector_char(0, 0, text); // l contains a list of polylines to draw
|
|
1690
|
-
|
|
1691
|
-
var _char = l.segments.reduce(function (result, segment) {
|
|
1498
|
+
var char = l.segments.reduce(function (result, segment) {
|
|
1692
1499
|
var path = new CSG.Path2D(segment);
|
|
1693
|
-
var cag = path.expandToCAG(2);
|
|
1694
|
-
|
|
1500
|
+
var cag = path.expandToCAG(2);
|
|
1501
|
+
// debug('reduce', result, segment, path, cag);
|
|
1695
1502
|
return result ? result.union(cag) : cag;
|
|
1696
1503
|
}, undefined);
|
|
1697
|
-
|
|
1698
|
-
return _char;
|
|
1504
|
+
return char;
|
|
1699
1505
|
}
|
|
1700
1506
|
function unitCube(length, radius) {
|
|
1701
1507
|
radius = radius || 0.5;
|
|
@@ -1705,7 +1511,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1705
1511
|
});
|
|
1706
1512
|
}
|
|
1707
1513
|
function unitAxis(length, radius, centroid) {
|
|
1708
|
-
debug$
|
|
1514
|
+
debug$2('unitAxis', length, radius, centroid);
|
|
1709
1515
|
centroid = centroid || [0, 0, 0];
|
|
1710
1516
|
var unitaxis = unitCube(length, radius).setColor(1, 0, 0).union([unitCube(length, radius).rotateY(90).setColor(0, 1, 0), unitCube(length, radius).rotateX(90).setColor(0, 0, 1)]);
|
|
1711
1517
|
unitaxis.properties.origin = new CSG.Connector([0, 0, 0], [1, 0, 0], [0, 1, 0]);
|
|
@@ -1717,24 +1523,22 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1717
1523
|
function ifArray(a, cb) {
|
|
1718
1524
|
return Array.isArray(a) ? a.map(cb) : cb(a);
|
|
1719
1525
|
}
|
|
1526
|
+
|
|
1720
1527
|
/**
|
|
1721
1528
|
* Returns an array of positions along an object on a given axis.
|
|
1722
1529
|
* @param {CSG} object The object to calculate the segments on.
|
|
1723
1530
|
* @param {number} segments The number of segments to create.
|
|
1724
|
-
* @param {string} axis Axis to create the
|
|
1531
|
+
* @param {string} axis Axis to create the segments on.
|
|
1725
1532
|
* @return {Array} An array of segment positions.
|
|
1726
1533
|
* @function segment
|
|
1727
1534
|
*/
|
|
1728
|
-
|
|
1729
1535
|
function segment(object, segments, axis) {
|
|
1730
1536
|
var size = object.size()[axis];
|
|
1731
1537
|
var width = size / segments;
|
|
1732
1538
|
var result = [];
|
|
1733
|
-
|
|
1734
1539
|
for (var i = width; i < size; i += width) {
|
|
1735
1540
|
result.push(i);
|
|
1736
1541
|
}
|
|
1737
|
-
|
|
1738
1542
|
return result;
|
|
1739
1543
|
}
|
|
1740
1544
|
function zipObject(names, values) {
|
|
@@ -1743,6 +1547,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1743
1547
|
return result;
|
|
1744
1548
|
}, {});
|
|
1745
1549
|
}
|
|
1550
|
+
|
|
1746
1551
|
/**
|
|
1747
1552
|
* Object map function, returns an array of the object mapped into an array.
|
|
1748
1553
|
* @param {object} o Object to map
|
|
@@ -1750,7 +1555,6 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1750
1555
|
* @return {array} an array of the mapped object.
|
|
1751
1556
|
* @function map
|
|
1752
1557
|
*/
|
|
1753
|
-
|
|
1754
1558
|
function map(o, f) {
|
|
1755
1559
|
return Object.keys(o).map(function (key) {
|
|
1756
1560
|
return f(o[key], key, o);
|
|
@@ -1770,15 +1574,14 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1770
1574
|
function mapPick(o, names, f, options) {
|
|
1771
1575
|
return names.reduce(function (result, name, index) {
|
|
1772
1576
|
if (!o[name]) {
|
|
1773
|
-
throw new Error(
|
|
1577
|
+
throw new Error(`${name} not found in ${options.name}: ${Object.keys(o).join(',')}`);
|
|
1774
1578
|
}
|
|
1775
|
-
|
|
1776
1579
|
result.push(f ? f(o[name], name, index, o) : o[name]);
|
|
1777
1580
|
return result;
|
|
1778
1581
|
}, []);
|
|
1779
1582
|
}
|
|
1780
1583
|
function divA(a, f) {
|
|
1781
|
-
return div(a, f);
|
|
1584
|
+
return div$1(a, f);
|
|
1782
1585
|
}
|
|
1783
1586
|
function divxyz(size, x, y, z) {
|
|
1784
1587
|
return {
|
|
@@ -1787,7 +1590,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1787
1590
|
z: size.z / z
|
|
1788
1591
|
};
|
|
1789
1592
|
}
|
|
1790
|
-
function div
|
|
1593
|
+
function div(size, d) {
|
|
1791
1594
|
return this.divxyz(size, d, d, d);
|
|
1792
1595
|
}
|
|
1793
1596
|
function mulxyz(size, x, y, z) {
|
|
@@ -1803,23 +1606,24 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1803
1606
|
function xyz2array(size) {
|
|
1804
1607
|
return [size.x, size.y, size.z];
|
|
1805
1608
|
}
|
|
1806
|
-
|
|
1609
|
+
const rotationAxes = {
|
|
1807
1610
|
x: [1, 0, 0],
|
|
1808
1611
|
y: [0, 1, 0],
|
|
1809
1612
|
z: [0, 0, 1]
|
|
1810
1613
|
};
|
|
1614
|
+
|
|
1811
1615
|
/**
|
|
1812
1616
|
* Returns a `Vector3D` with the size of the object.
|
|
1813
1617
|
* @param {CSG} o A `CSG` like object or an array of `CSG.Vector3D` objects (the result of getBounds()).
|
|
1814
1618
|
* @return {CSG.Vector3D} Vector3d with the size of the object
|
|
1815
1619
|
* @function size
|
|
1816
1620
|
*/
|
|
1817
|
-
|
|
1818
1621
|
function size(o) {
|
|
1819
1622
|
var bbox = o.getBounds ? o.getBounds() : o;
|
|
1820
1623
|
var foo = bbox[1].minus(bbox[0]);
|
|
1821
1624
|
return foo;
|
|
1822
1625
|
}
|
|
1626
|
+
|
|
1823
1627
|
/**
|
|
1824
1628
|
* Returns a scale factor (0.0-1.0) for an object
|
|
1825
1629
|
* that will resize it by a value in size units instead
|
|
@@ -1829,7 +1633,6 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1829
1633
|
* @return {number} Scale factor
|
|
1830
1634
|
* @function scale
|
|
1831
1635
|
*/
|
|
1832
|
-
|
|
1833
1636
|
function scale(size, value) {
|
|
1834
1637
|
if (value == 0) return 1;
|
|
1835
1638
|
return 1 + 100 / (size / value) / 100;
|
|
@@ -1846,6 +1649,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1846
1649
|
objectSize = objectSize || size(object.getBounds());
|
|
1847
1650
|
return object.translate([-objectSize.x / 2, 0, 0]);
|
|
1848
1651
|
}
|
|
1652
|
+
|
|
1849
1653
|
/**
|
|
1850
1654
|
* Enlarge an object by scale units, while keeping the same
|
|
1851
1655
|
* centroid. For example `enlarge(mycsg, 1, 1, 1)` enlarges
|
|
@@ -1857,16 +1661,13 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1857
1661
|
* @return {CSG} [description]
|
|
1858
1662
|
* @function enlarge
|
|
1859
1663
|
*/
|
|
1860
|
-
|
|
1861
1664
|
function enlarge(object, x, y, z) {
|
|
1862
1665
|
var a;
|
|
1863
|
-
|
|
1864
1666
|
if (Array.isArray(x)) {
|
|
1865
1667
|
a = x;
|
|
1866
1668
|
} else {
|
|
1867
1669
|
a = [x, y || x, z || x];
|
|
1868
1670
|
}
|
|
1869
|
-
|
|
1870
1671
|
var objectSize = size(object);
|
|
1871
1672
|
var objectCentroid = centroid(object, objectSize);
|
|
1872
1673
|
var idx = 0;
|
|
@@ -1874,11 +1675,13 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1874
1675
|
return scale(i, a[idx++]);
|
|
1875
1676
|
});
|
|
1876
1677
|
var new_object = object.scale(t);
|
|
1877
|
-
var new_centroid = centroid(new_object);
|
|
1678
|
+
var new_centroid = centroid(new_object);
|
|
1878
1679
|
|
|
1680
|
+
/// Calculate the difference between the original centroid and the new
|
|
1879
1681
|
var delta = new_centroid.minus(objectCentroid).times(-1);
|
|
1880
1682
|
return new_object.translate(delta);
|
|
1881
1683
|
}
|
|
1684
|
+
|
|
1882
1685
|
/**
|
|
1883
1686
|
* Fit an object inside a bounding box. Often used
|
|
1884
1687
|
* with text labels.
|
|
@@ -1890,10 +1693,8 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1890
1693
|
* @return {CSG} [description]
|
|
1891
1694
|
* @function fit
|
|
1892
1695
|
*/
|
|
1893
|
-
|
|
1894
1696
|
function fit(object, x, y, z, keep_aspect_ratio) {
|
|
1895
1697
|
var a;
|
|
1896
|
-
|
|
1897
1698
|
if (Array.isArray(x)) {
|
|
1898
1699
|
a = x;
|
|
1899
1700
|
keep_aspect_ratio = y;
|
|
@@ -1903,19 +1704,15 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1903
1704
|
} else {
|
|
1904
1705
|
a = [x, y, z];
|
|
1905
1706
|
}
|
|
1906
|
-
|
|
1907
1707
|
var objectSize = size(object.getBounds());
|
|
1908
|
-
|
|
1909
1708
|
function scale(size, value) {
|
|
1910
1709
|
if (value == 0) return 1;
|
|
1911
1710
|
return value / size;
|
|
1912
1711
|
}
|
|
1913
|
-
|
|
1914
1712
|
var s = [scale(objectSize.x, x), scale(objectSize.y, y), scale(objectSize.z, z)];
|
|
1915
1713
|
var min$1 = min(s);
|
|
1916
1714
|
return centerWith(object.scale(s.map(function (d, i) {
|
|
1917
1715
|
if (a[i] === 0) return 1; // don't scale when value is zero
|
|
1918
|
-
|
|
1919
1716
|
return keep_aspect_ratio ? min$1 : d;
|
|
1920
1717
|
})), 'xyz', object);
|
|
1921
1718
|
}
|
|
@@ -1930,7 +1727,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1930
1727
|
function mirrored4(x) {
|
|
1931
1728
|
return x.union([x.mirroredY(90), x.mirroredX(90), x.mirroredY(90).mirroredX(90)]);
|
|
1932
1729
|
}
|
|
1933
|
-
|
|
1730
|
+
const flushSide = {
|
|
1934
1731
|
'above-outside': [1, 0],
|
|
1935
1732
|
'above-inside': [1, 1],
|
|
1936
1733
|
'below-outside': [0, 1],
|
|
@@ -1945,7 +1742,6 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1945
1742
|
function calcFlush(moveobj, withobj, axes, mside, wside) {
|
|
1946
1743
|
depreciated('calcFlush', false, 'Use calcSnap instead.');
|
|
1947
1744
|
var side;
|
|
1948
|
-
|
|
1949
1745
|
if (mside === 0 || mside === 1) {
|
|
1950
1746
|
// wside = wside !== undefined ? wside : mside;
|
|
1951
1747
|
side = [wside !== undefined ? wside : mside, mside];
|
|
@@ -1953,22 +1749,19 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1953
1749
|
side = flushSide[mside];
|
|
1954
1750
|
if (!side) error('invalid side: ' + mside);
|
|
1955
1751
|
}
|
|
1956
|
-
|
|
1957
1752
|
var m = moveobj.getBounds();
|
|
1958
|
-
var w = withobj.getBounds();
|
|
1753
|
+
var w = withobj.getBounds();
|
|
1959
1754
|
|
|
1755
|
+
// Add centroid if needed
|
|
1960
1756
|
if (side[0] === -1) {
|
|
1961
1757
|
w[-1] = toxyz(withobj.centroid());
|
|
1962
1758
|
}
|
|
1963
|
-
|
|
1964
1759
|
return this.axisApply(axes, function (i, axis) {
|
|
1965
1760
|
return w[side[0]][axis] - m[side[1]][axis];
|
|
1966
1761
|
});
|
|
1967
1762
|
}
|
|
1968
|
-
function calcSnap(moveobj, withobj, axes, orientation) {
|
|
1969
|
-
var delta = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
|
|
1763
|
+
function calcSnap(moveobj, withobj, axes, orientation, delta = 0) {
|
|
1970
1764
|
var side = flushSide[orientation];
|
|
1971
|
-
|
|
1972
1765
|
if (!side) {
|
|
1973
1766
|
var fix = {
|
|
1974
1767
|
'01': 'outside+',
|
|
@@ -1980,14 +1773,13 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1980
1773
|
};
|
|
1981
1774
|
error('calcSnap: invalid side: ' + orientation + ' should be ' + fix['' + orientation + delta]);
|
|
1982
1775
|
}
|
|
1983
|
-
|
|
1984
1776
|
var m = moveobj.getBounds();
|
|
1985
|
-
var w = withobj.getBounds();
|
|
1777
|
+
var w = withobj.getBounds();
|
|
1986
1778
|
|
|
1779
|
+
// Add centroid if needed
|
|
1987
1780
|
if (side[0] === -1) {
|
|
1988
1781
|
w[-1] = withobj.centroid();
|
|
1989
1782
|
}
|
|
1990
|
-
|
|
1991
1783
|
var t = axisApply(axes, function (i, axis) {
|
|
1992
1784
|
return w[side[0]][axis] - m[side[1]][axis];
|
|
1993
1785
|
});
|
|
@@ -1996,10 +1788,11 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1996
1788
|
}) : t;
|
|
1997
1789
|
}
|
|
1998
1790
|
function snap(moveobj, withobj, axis, orientation, delta) {
|
|
1999
|
-
debug$
|
|
1791
|
+
debug$2('snap', moveobj, withobj, axis, orientation, delta);
|
|
2000
1792
|
var t = calcSnap(moveobj, withobj, axis, orientation, delta);
|
|
2001
1793
|
return moveobj.translate(t);
|
|
2002
1794
|
}
|
|
1795
|
+
|
|
2003
1796
|
/**
|
|
2004
1797
|
* Moves an object flush with another object
|
|
2005
1798
|
* @param {CSG} moveobj Object to move
|
|
@@ -2009,12 +1802,11 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2009
1802
|
* @param {Number} wside 0 or 1
|
|
2010
1803
|
* @return {CSG} [description]
|
|
2011
1804
|
*/
|
|
2012
|
-
|
|
2013
1805
|
function flush(moveobj, withobj, axis, mside, wside) {
|
|
2014
1806
|
return moveobj.translate(calcFlush(moveobj, withobj, axis, mside, wside));
|
|
2015
1807
|
}
|
|
2016
1808
|
function axisApply(axes, valfun, a) {
|
|
2017
|
-
debug$
|
|
1809
|
+
debug$2('axisApply', axes, valfun, a);
|
|
2018
1810
|
var retval = a || [0, 0, 0];
|
|
2019
1811
|
var lookup = {
|
|
2020
1812
|
x: 0,
|
|
@@ -2046,9 +1838,10 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2046
1838
|
objectSize = objectSize || size(bounds);
|
|
2047
1839
|
return bounds[0].plus(objectSize.dividedBy(2));
|
|
2048
1840
|
} catch (err) {
|
|
2049
|
-
error(
|
|
1841
|
+
error(`centroid error o:${jscadToString(o)} objectSize: ${objectSize}`, undefined, err);
|
|
2050
1842
|
}
|
|
2051
1843
|
}
|
|
1844
|
+
|
|
2052
1845
|
/**
|
|
2053
1846
|
* Calculates the transform array to move the midline of an object
|
|
2054
1847
|
* by value. This is useful when you have a diagram that provides
|
|
@@ -2057,9 +1850,8 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2057
1850
|
* @param {CSG} o A CSG object.
|
|
2058
1851
|
* @param {String} axis A string with the axis to operate on.
|
|
2059
1852
|
* @param {Number} to Value to move the midline of the object to.
|
|
2060
|
-
* @return {Number[]} The
|
|
1853
|
+
* @return {Number[]} The transform array needed to move the object.
|
|
2061
1854
|
*/
|
|
2062
|
-
|
|
2063
1855
|
function calcmidlineTo(o, axis, to) {
|
|
2064
1856
|
var bounds = o.getBounds();
|
|
2065
1857
|
var objectSize = size(bounds);
|
|
@@ -2072,15 +1864,14 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2072
1864
|
}
|
|
2073
1865
|
function translator(o, axis, withObj) {
|
|
2074
1866
|
var objectCentroid = centroid(o);
|
|
2075
|
-
var withCentroid = centroid(withObj);
|
|
2076
|
-
|
|
1867
|
+
var withCentroid = centroid(withObj);
|
|
1868
|
+
// echo('centerWith', centroid, withCentroid);
|
|
2077
1869
|
var t = axisApply(axis, function (i) {
|
|
2078
1870
|
return withCentroid[i] - objectCentroid[i];
|
|
2079
1871
|
});
|
|
2080
1872
|
return t;
|
|
2081
1873
|
}
|
|
2082
|
-
function calcCenterWith(o, axes, withObj) {
|
|
2083
|
-
var delta = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
1874
|
+
function calcCenterWith(o, axes, withObj, delta = 0) {
|
|
2084
1875
|
var objectCentroid = centroid(o);
|
|
2085
1876
|
var withCentroid = centroid(withObj);
|
|
2086
1877
|
var t = axisApply(axes, function (i, axis) {
|
|
@@ -2091,12 +1882,13 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2091
1882
|
function centerWith(o, axis, withObj) {
|
|
2092
1883
|
return o.translate(calcCenterWith(o, axis, withObj));
|
|
2093
1884
|
}
|
|
1885
|
+
|
|
2094
1886
|
/**
|
|
2095
1887
|
* Given an size, bounds and an axis, a Point
|
|
2096
1888
|
* along the axis will be returned. If no `offset`
|
|
2097
1889
|
* is given, then the midway point on the axis is returned.
|
|
2098
1890
|
* When the `offset` is positive, a point `offset` from the
|
|
2099
|
-
*
|
|
1891
|
+
* minimum axis is returned. When the `offset` is negative,
|
|
2100
1892
|
* the `offset` is subtracted from the axis maximum.
|
|
2101
1893
|
* @param {Size} size Size array of the object
|
|
2102
1894
|
* @param {Bounds} bounds Bounds of the object
|
|
@@ -2105,21 +1897,20 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2105
1897
|
* @param {Boolean} [nonzero] When true, no offset values under 1e-4 are allowed.
|
|
2106
1898
|
* @return {Point} The point along the axis.
|
|
2107
1899
|
*/
|
|
2108
|
-
|
|
2109
1900
|
function getDelta(size, bounds, axis, offset, nonzero) {
|
|
2110
1901
|
if (!isEmpty(offset) && nonzero) {
|
|
2111
1902
|
if (Math.abs(offset) < 1e-4) {
|
|
2112
1903
|
offset = 1e-4 * (isNegative(offset) ? -1 : 1);
|
|
2113
1904
|
}
|
|
2114
|
-
}
|
|
1905
|
+
}
|
|
1906
|
+
// if the offset is negative, then it's an offset from
|
|
2115
1907
|
// the positive side of the axis
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
1908
|
var dist = isNegative(offset) ? offset = size[axis] + offset : offset;
|
|
2119
1909
|
return axisApply(axis, function (i, a) {
|
|
2120
1910
|
return bounds[0][a] + (isEmpty(dist) ? size[axis] / 2 : dist);
|
|
2121
1911
|
});
|
|
2122
1912
|
}
|
|
1913
|
+
|
|
2123
1914
|
/**
|
|
2124
1915
|
* Cut an object into two pieces, along a given axis. The offset
|
|
2125
1916
|
* allows you to move the cut plane along the cut axis. For example,
|
|
@@ -2129,7 +1920,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2129
1920
|
*
|
|
2130
1921
|
* You can angle the cut plane and position the rotation point.
|
|
2131
1922
|
*
|
|
2132
|
-
* 
|
|
2133
1924
|
* @param {CSG} object object to bisect
|
|
2134
1925
|
* @param {string} axis axis to cut along
|
|
2135
1926
|
* @param {number} [offset] offset to cut at
|
|
@@ -2142,27 +1933,21 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2142
1933
|
* @param {CSG.Vector3D} [options.rotationCenter]
|
|
2143
1934
|
* @return {JsCadUtilsGroup} Returns a group object with a parts object.
|
|
2144
1935
|
*/
|
|
2145
|
-
|
|
2146
|
-
function bisect() {
|
|
2147
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
2148
|
-
args[_key] = arguments[_key];
|
|
2149
|
-
}
|
|
2150
|
-
|
|
1936
|
+
function bisect(...args) {
|
|
2151
1937
|
if (args.length < 2) {
|
|
2152
|
-
error('bisect
|
|
1938
|
+
error('bisect requires an object and an axis', 'JSCAD_UTILS_INVALID_ARGS');
|
|
2153
1939
|
}
|
|
2154
|
-
|
|
2155
1940
|
var object = args[0];
|
|
2156
1941
|
var axis = args[1];
|
|
2157
1942
|
var offset,
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
1943
|
+
angle = 0,
|
|
1944
|
+
rotateaxis,
|
|
1945
|
+
rotateoffset,
|
|
1946
|
+
options = {};
|
|
1947
|
+
|
|
2162
1948
|
/**
|
|
2163
1949
|
* Allow the options object to include the parameters.
|
|
2164
1950
|
*/
|
|
2165
|
-
|
|
2166
1951
|
for (var i = 2; i < args.length; i++) {
|
|
2167
1952
|
if (args[i] instanceof Object) {
|
|
2168
1953
|
options = args[i];
|
|
@@ -2175,26 +1960,21 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2175
1960
|
case 2:
|
|
2176
1961
|
offset = args[i];
|
|
2177
1962
|
break;
|
|
2178
|
-
|
|
2179
1963
|
case 3:
|
|
2180
1964
|
angle = args[i];
|
|
2181
1965
|
break;
|
|
2182
|
-
|
|
2183
1966
|
case 4:
|
|
2184
1967
|
rotateaxis = args[i];
|
|
2185
1968
|
break;
|
|
2186
|
-
|
|
2187
1969
|
case 5:
|
|
2188
1970
|
rotateoffset = args[i];
|
|
2189
1971
|
break;
|
|
2190
|
-
|
|
2191
1972
|
case 6:
|
|
2192
1973
|
options = args[i];
|
|
2193
1974
|
break;
|
|
2194
1975
|
}
|
|
2195
1976
|
}
|
|
2196
1977
|
}
|
|
2197
|
-
|
|
2198
1978
|
options = Object.assign({
|
|
2199
1979
|
addRotationCenter: false
|
|
2200
1980
|
}, options);
|
|
@@ -2222,17 +2002,17 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2222
2002
|
}));
|
|
2223
2003
|
var theRotationAxis = rotationAxes[rotateaxis];
|
|
2224
2004
|
var cutplane = CSG.OrthoNormalBasis.GetCartesian(info.orthoNormalCartesian[0], info.orthoNormalCartesian[1]).translate(cutDelta).rotate(rotationCenter, theRotationAxis, angle);
|
|
2225
|
-
debug$
|
|
2226
|
-
axis
|
|
2227
|
-
offset
|
|
2228
|
-
angle
|
|
2229
|
-
rotateaxis
|
|
2230
|
-
cutDelta
|
|
2231
|
-
rotateOffsetAxis
|
|
2232
|
-
rotationCenter
|
|
2233
|
-
theRotationAxis
|
|
2234
|
-
cutplane
|
|
2235
|
-
options
|
|
2005
|
+
debug$2('bisect', debug$2.enabled && {
|
|
2006
|
+
axis,
|
|
2007
|
+
offset,
|
|
2008
|
+
angle,
|
|
2009
|
+
rotateaxis,
|
|
2010
|
+
cutDelta,
|
|
2011
|
+
rotateOffsetAxis,
|
|
2012
|
+
rotationCenter,
|
|
2013
|
+
theRotationAxis,
|
|
2014
|
+
cutplane,
|
|
2015
|
+
options
|
|
2236
2016
|
});
|
|
2237
2017
|
var g = Group('negative,positive', [object.cutByPlane(cutplane.plane).color(options.color && 'red'), object.cutByPlane(cutplane.plane.flipped()).color(options.color && 'blue')]);
|
|
2238
2018
|
if (options.addRotationCenter) g.add(unitAxis(objectSize.length() + 10, 0.1, rotationCenter), 'rotationCenter');
|
|
@@ -2250,34 +2030,29 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2250
2030
|
* @param {CSG.Vector3D} [options.rotationCenter] The location of the rotation center, defaults to [0,0,0].
|
|
2251
2031
|
* @return {JsCadUtilsGroup} A group with a positive and negative CSG object.
|
|
2252
2032
|
*/
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
var rotateaxis = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'z';
|
|
2258
|
-
var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {
|
|
2259
|
-
color: true,
|
|
2260
|
-
addRotationCenter: true
|
|
2261
|
-
};
|
|
2033
|
+
function slice(object, angle = 15, axis = 'x', rotateaxis = 'z', options = {
|
|
2034
|
+
color: true,
|
|
2035
|
+
addRotationCenter: true
|
|
2036
|
+
}) {
|
|
2262
2037
|
var info = normalVector(axis);
|
|
2263
2038
|
var rotationCenter = options.rotationCenter || new CSG.Vector3D(0, 0, 0);
|
|
2264
2039
|
var theRotationAxis = rotationAxes[rotateaxis];
|
|
2265
|
-
var cutplane = CSG.OrthoNormalBasis.GetCartesian(info.orthoNormalCartesian[0], info.orthoNormalCartesian[1])
|
|
2040
|
+
var cutplane = CSG.OrthoNormalBasis.GetCartesian(info.orthoNormalCartesian[0], info.orthoNormalCartesian[1])
|
|
2041
|
+
// .translate(cutDelta)
|
|
2266
2042
|
.rotate(rotationCenter, theRotationAxis, angle);
|
|
2267
2043
|
var g = Group('negative,positive', [object.cutByPlane(cutplane.plane).color(options.color && 'red'), object.cutByPlane(cutplane.plane.flipped()).color(options.color && 'blue')]);
|
|
2268
|
-
|
|
2269
2044
|
if (options.addRotationCenter) {
|
|
2270
2045
|
var objectSize = size(object);
|
|
2271
2046
|
g.add(unitAxis(objectSize.length() + 10, 0.1, rotationCenter), 'rotationCenter');
|
|
2272
2047
|
}
|
|
2273
|
-
|
|
2274
2048
|
return g;
|
|
2275
2049
|
}
|
|
2050
|
+
|
|
2276
2051
|
/**
|
|
2277
2052
|
* Creates a `JsCadUtilsGroup` object that has `body` and `wedge` objects. The `wedge` object
|
|
2278
2053
|
* is created by radially cutting the object from the `start` to the `end` angle.
|
|
2279
2054
|
*
|
|
2280
|
-
* 
|
|
2281
2056
|
*
|
|
2282
2057
|
*
|
|
2283
2058
|
* @example
|
|
@@ -2305,7 +2080,6 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2305
2080
|
* @param {'x'|'y'|'z'} axis The axis to cut the wedge in.
|
|
2306
2081
|
* @return {JsCadUtilsGroup} A group object with a `body` and `wedge` parts.
|
|
2307
2082
|
*/
|
|
2308
|
-
|
|
2309
2083
|
function wedge(object, start, end, axis) {
|
|
2310
2084
|
var a = slice(object, start, axis);
|
|
2311
2085
|
var b = slice(a.parts.positive, end, axis);
|
|
@@ -2314,16 +2088,16 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2314
2088
|
wedge: b.parts.negative.color('red')
|
|
2315
2089
|
});
|
|
2316
2090
|
}
|
|
2091
|
+
|
|
2317
2092
|
/**
|
|
2318
2093
|
* Wraps the `stretchAtPlane` call using the same
|
|
2319
2094
|
* logic as `bisect`.
|
|
2320
2095
|
* @param {CSG} object Object to stretch
|
|
2321
|
-
* @param {String} axis Axis to
|
|
2096
|
+
* @param {String} axis Axis to stretch along
|
|
2322
2097
|
* @param {Number} distance Distance to stretch
|
|
2323
2098
|
* @param {Number} offset Offset along the axis to cut the object
|
|
2324
2099
|
* @return {CSG} The stretched object.
|
|
2325
2100
|
*/
|
|
2326
|
-
|
|
2327
2101
|
function stretch(object, axis, distance, offset) {
|
|
2328
2102
|
var normal = {
|
|
2329
2103
|
x: [1, 0, 0],
|
|
@@ -2332,10 +2106,11 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2332
2106
|
};
|
|
2333
2107
|
var bounds = object.getBounds();
|
|
2334
2108
|
var objectSize = size(object);
|
|
2335
|
-
var cutDelta = getDelta(objectSize, bounds, axis, offset, true);
|
|
2336
|
-
|
|
2109
|
+
var cutDelta = getDelta(objectSize, bounds, axis, offset, true);
|
|
2110
|
+
// debug('stretch.cutDelta', cutDelta, normal[axis]);
|
|
2337
2111
|
return object.stretchAtPlane(normal[axis], cutDelta, distance);
|
|
2338
2112
|
}
|
|
2113
|
+
|
|
2339
2114
|
/**
|
|
2340
2115
|
* Takes two CSG polygons and creates a solid of `height`.
|
|
2341
2116
|
* Similar to `CSG.extrude`, except you can resize either
|
|
@@ -2345,18 +2120,16 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2345
2120
|
* @param {number} height height of solid
|
|
2346
2121
|
* @return {CSG} generated solid
|
|
2347
2122
|
*/
|
|
2348
|
-
|
|
2349
2123
|
function poly2solid(top, bottom, height) {
|
|
2350
2124
|
if (top.sides.length == 0) {
|
|
2351
2125
|
// empty!
|
|
2352
2126
|
return new CSG();
|
|
2353
|
-
}
|
|
2354
|
-
|
|
2355
|
-
|
|
2127
|
+
}
|
|
2128
|
+
// var offsetVector = CSG.parseOptionAs3DVector(options, "offset", [0, 0, 10]);
|
|
2356
2129
|
var offsetVector = CSG.Vector3D.Create(0, 0, height);
|
|
2357
2130
|
var normalVector = CSG.Vector3D.Create(0, 1, 0);
|
|
2358
|
-
var polygons = [];
|
|
2359
|
-
|
|
2131
|
+
var polygons = [];
|
|
2132
|
+
// bottom and top
|
|
2360
2133
|
polygons = polygons.concat(bottom._toPlanePolygons({
|
|
2361
2134
|
translation: [0, 0, 0],
|
|
2362
2135
|
normalVector: normalVector,
|
|
@@ -2366,40 +2139,38 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2366
2139
|
translation: offsetVector,
|
|
2367
2140
|
normalVector: normalVector,
|
|
2368
2141
|
flipped: offsetVector.z < 0
|
|
2369
|
-
}));
|
|
2370
|
-
|
|
2142
|
+
}));
|
|
2143
|
+
// walls
|
|
2371
2144
|
var c1 = new CSG.Connector(offsetVector.times(0), [0, 0, offsetVector.z], normalVector);
|
|
2372
2145
|
var c2 = new CSG.Connector(offsetVector, [0, 0, offsetVector.z], normalVector);
|
|
2373
2146
|
polygons = polygons.concat(bottom._toWallPolygons({
|
|
2374
2147
|
cag: top,
|
|
2375
2148
|
toConnector1: c1,
|
|
2376
2149
|
toConnector2: c2
|
|
2377
|
-
}));
|
|
2150
|
+
}));
|
|
2151
|
+
// }
|
|
2378
2152
|
|
|
2379
2153
|
return CSG.fromPolygons(polygons);
|
|
2380
2154
|
}
|
|
2381
2155
|
function slices2poly(slices, options, axis) {
|
|
2382
|
-
debug$
|
|
2156
|
+
debug$2('slices2poly', slices, options, axis);
|
|
2383
2157
|
options = Object.assign({
|
|
2384
2158
|
twistangle: 0,
|
|
2385
2159
|
twiststeps: 0
|
|
2386
2160
|
}, options);
|
|
2387
2161
|
var twistangle = options && parseFloat(options.twistangle) || 0;
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
if (twistangle == 0 || twiststeps < 1) {
|
|
2391
|
-
twiststeps = 1;
|
|
2392
|
-
}
|
|
2393
|
-
|
|
2162
|
+
options && parseInt(options.twiststeps) || CSG.defaultResolution3D;
|
|
2394
2163
|
var normalVector = options.si.normalVector;
|
|
2395
|
-
var polygons = [];
|
|
2164
|
+
var polygons = [];
|
|
2396
2165
|
|
|
2166
|
+
// bottom and top
|
|
2397
2167
|
var first$1 = first(slices);
|
|
2398
2168
|
var last$1 = last(slices);
|
|
2399
|
-
debug$
|
|
2400
|
-
var up = first$1.offset[axis] > last$1.offset[axis];
|
|
2401
|
-
// to create the poly using 'x' and 'y'.
|
|
2169
|
+
debug$2('slices2poly first', first$1, first$1.offset, 'last', last$1);
|
|
2170
|
+
var up = first$1.offset[axis] > last$1.offset[axis];
|
|
2402
2171
|
|
|
2172
|
+
// _toPlanePolygons only works in the 'z' axis. It's hard coded
|
|
2173
|
+
// to create the poly using 'x' and 'y'.
|
|
2403
2174
|
polygons = polygons.concat(first$1.poly._toPlanePolygons({
|
|
2404
2175
|
translation: first$1.offset,
|
|
2405
2176
|
normalVector: normalVector,
|
|
@@ -2410,24 +2181,27 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2410
2181
|
translation: last$1.offset,
|
|
2411
2182
|
normalVector: normalVector[rotateAxis](twistangle),
|
|
2412
2183
|
flipped: up
|
|
2413
|
-
}));
|
|
2184
|
+
}));
|
|
2414
2185
|
|
|
2186
|
+
// rotate with quick short circuit
|
|
2415
2187
|
var rotate = twistangle === 0 ? function rotateZero(v) {
|
|
2416
2188
|
return v;
|
|
2417
2189
|
} : function rotate(v, angle, percent) {
|
|
2418
2190
|
return v[rotateAxis](angle * percent);
|
|
2419
|
-
};
|
|
2420
|
-
|
|
2421
|
-
var connectorAxis = last$1.offset.minus(first$1.offset).abs(); // debug('connectorAxis', connectorAxis);
|
|
2191
|
+
};
|
|
2422
2192
|
|
|
2193
|
+
// walls
|
|
2194
|
+
var connectorAxis = last$1.offset.minus(first$1.offset).abs();
|
|
2195
|
+
// debug('connectorAxis', connectorAxis);
|
|
2423
2196
|
slices.forEach(function (slice, idx) {
|
|
2424
2197
|
if (idx < slices.length - 1) {
|
|
2425
2198
|
var nextidx = idx + 1;
|
|
2426
2199
|
var top = !up ? slices[nextidx] : slice;
|
|
2427
2200
|
var bottom = up ? slices[nextidx] : slice;
|
|
2428
2201
|
var c1 = new CSG.Connector(bottom.offset, connectorAxis, rotate(normalVector, twistangle, idx / slices.length));
|
|
2429
|
-
var c2 = new CSG.Connector(top.offset, connectorAxis, rotate(normalVector, twistangle, nextidx / slices.length));
|
|
2202
|
+
var c2 = new CSG.Connector(top.offset, connectorAxis, rotate(normalVector, twistangle, nextidx / slices.length));
|
|
2430
2203
|
|
|
2204
|
+
// debug('slices2poly.slices', c1.point, c2.point);
|
|
2431
2205
|
polygons = polygons.concat(bottom.poly._toWallPolygons({
|
|
2432
2206
|
cag: top.poly,
|
|
2433
2207
|
toConnector1: c1,
|
|
@@ -2482,7 +2256,9 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2482
2256
|
return bounds[info.sizeIdx][a] + Math.abs(radius) * info.moveDir;
|
|
2483
2257
|
})
|
|
2484
2258
|
}, info, normalVector(axis));
|
|
2485
|
-
}
|
|
2259
|
+
}
|
|
2260
|
+
|
|
2261
|
+
// export function solidFromSlices(slices, heights) {
|
|
2486
2262
|
// var si = {
|
|
2487
2263
|
// axis: 'z',
|
|
2488
2264
|
// cutDelta: {},
|
|
@@ -2497,8 +2273,8 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2497
2273
|
var b = object.getBounds();
|
|
2498
2274
|
var absoluteRadius = Math.abs(radius);
|
|
2499
2275
|
var si = sliceParams(orientation, radius, b);
|
|
2500
|
-
debug$
|
|
2501
|
-
if (si.axis !== 'z') throw new Error('reShape error: CAG.
|
|
2276
|
+
debug$2('reShape', absoluteRadius, si);
|
|
2277
|
+
if (si.axis !== 'z') throw new Error('reShape error: CAG._toPlanePolygons only uses the "z" axis. You must use the "z" axis for now.');
|
|
2502
2278
|
var cutplane = CSG.OrthoNormalBasis.GetCartesian(si.orthoNormalCartesian[0], si.orthoNormalCartesian[1]).translate(si.cutDelta);
|
|
2503
2279
|
var slice = object.sectionCut(cutplane);
|
|
2504
2280
|
var first = axisApply(si.axis, function () {
|
|
@@ -2508,7 +2284,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2508
2284
|
return si.positive ? absoluteRadius : 0;
|
|
2509
2285
|
});
|
|
2510
2286
|
var plane = si.positive ? cutplane.plane : cutplane.plane.flipped();
|
|
2511
|
-
debug$
|
|
2287
|
+
debug$2('reShape first/last', first, last);
|
|
2512
2288
|
var slices = slicer(first, last, slice, radius);
|
|
2513
2289
|
var delta = slices2poly(slices, Object.assign(options, {
|
|
2514
2290
|
si: si
|
|
@@ -2545,9 +2321,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2545
2321
|
return slices;
|
|
2546
2322
|
});
|
|
2547
2323
|
}
|
|
2548
|
-
function calcRotate(part, solid, axis
|
|
2549
|
-
/* , angle */
|
|
2550
|
-
) {
|
|
2324
|
+
function calcRotate(part, solid, axis /* , angle */) {
|
|
2551
2325
|
var axes = {
|
|
2552
2326
|
x: [1, 0, 0],
|
|
2553
2327
|
y: [0, 1, 0],
|
|
@@ -2556,35 +2330,30 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2556
2330
|
var rotationCenter = solid.centroid();
|
|
2557
2331
|
var rotationAxis = axes[axis];
|
|
2558
2332
|
return {
|
|
2559
|
-
rotationCenter
|
|
2560
|
-
rotationAxis
|
|
2333
|
+
rotationCenter,
|
|
2334
|
+
rotationAxis
|
|
2561
2335
|
};
|
|
2562
2336
|
}
|
|
2563
2337
|
function rotateAround(part, solid, axis, angle) {
|
|
2564
|
-
var
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2338
|
+
var {
|
|
2339
|
+
rotationCenter,
|
|
2340
|
+
rotationAxis
|
|
2341
|
+
} = calcRotate(part, solid, axis);
|
|
2568
2342
|
return part.rotate(rotationCenter, rotationAxis, angle);
|
|
2569
2343
|
}
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
return Object.entries(from).reduce(function (props, _ref) {
|
|
2573
|
-
var _ref2 = _slicedToArray(_ref, 2),
|
|
2574
|
-
key = _ref2[0],
|
|
2575
|
-
value = _ref2[1];
|
|
2576
|
-
|
|
2344
|
+
function cloneProperties(from, to, depth = 0) {
|
|
2345
|
+
return Object.entries(from).reduce((props, [key, value]) => {
|
|
2577
2346
|
props[key] = value;
|
|
2578
2347
|
return props;
|
|
2579
2348
|
}, to);
|
|
2580
2349
|
}
|
|
2581
|
-
|
|
2582
2350
|
function clone(o) {
|
|
2583
2351
|
var c = CSG.fromPolygons(o.toPolygons());
|
|
2584
2352
|
cloneProperties(o, c);
|
|
2585
|
-
debug$
|
|
2353
|
+
debug$2('clone', o, c, CSG);
|
|
2586
2354
|
return c;
|
|
2587
2355
|
}
|
|
2356
|
+
|
|
2588
2357
|
/**
|
|
2589
2358
|
* @function addConnector
|
|
2590
2359
|
* @param {CSG} object The object to add the connector to.
|
|
@@ -2594,23 +2363,95 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2594
2363
|
* @param {Array} point=[0,0,0] a 3 axis array direction vector somewhat perpendicular to axis; this defines the “12 o'clock” orientation of the connection.
|
|
2595
2364
|
* @return {CSG} The CSG object with the new connector added.
|
|
2596
2365
|
*/
|
|
2597
|
-
|
|
2598
|
-
function addConnector(object, name) {
|
|
2599
|
-
var point = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [0, 0, 0];
|
|
2600
|
-
var axis = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [1, 0, 0];
|
|
2601
|
-
var normal = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [0, 0, 1];
|
|
2366
|
+
function addConnector(object, name, point = [0, 0, 0], axis = [1, 0, 0], normal = [0, 0, 1]) {
|
|
2602
2367
|
object.properties[name] = new CSG.Connector(point, axis, normal);
|
|
2603
2368
|
return object;
|
|
2604
2369
|
}
|
|
2605
2370
|
|
|
2606
|
-
var
|
|
2371
|
+
var util = /*#__PURE__*/Object.freeze({
|
|
2372
|
+
__proto__: null,
|
|
2373
|
+
NOZZEL_SIZE: NOZZEL_SIZE,
|
|
2374
|
+
addConnector: addConnector,
|
|
2375
|
+
axis2array: axis2array,
|
|
2376
|
+
axisApply: axisApply,
|
|
2377
|
+
bisect: bisect,
|
|
2378
|
+
calcCenterWith: calcCenterWith,
|
|
2379
|
+
calcFlush: calcFlush,
|
|
2380
|
+
calcRotate: calcRotate,
|
|
2381
|
+
calcSnap: calcSnap,
|
|
2382
|
+
calcmidlineTo: calcmidlineTo,
|
|
2383
|
+
center: center,
|
|
2384
|
+
centerWith: centerWith,
|
|
2385
|
+
centerX: centerX,
|
|
2386
|
+
centerY: centerY,
|
|
2387
|
+
centroid: centroid,
|
|
2388
|
+
chamfer: chamfer,
|
|
2389
|
+
clone: clone,
|
|
2390
|
+
cm: cm,
|
|
2391
|
+
defaults: defaults,
|
|
2392
|
+
depreciated: depreciated,
|
|
2393
|
+
div: div,
|
|
2394
|
+
divA: divA,
|
|
2395
|
+
divxyz: divxyz,
|
|
2396
|
+
enlarge: enlarge,
|
|
2397
|
+
error: error,
|
|
2398
|
+
fillet: fillet,
|
|
2399
|
+
fit: fit,
|
|
2400
|
+
flush: flush,
|
|
2401
|
+
flushSide: flushSide,
|
|
2402
|
+
getDelta: getDelta,
|
|
2403
|
+
identity: identity,
|
|
2404
|
+
ifArray: ifArray,
|
|
2405
|
+
inch: inch,
|
|
2406
|
+
isEmpty: isEmpty,
|
|
2407
|
+
isNegative: isNegative,
|
|
2408
|
+
jscadToString: jscadToString,
|
|
2409
|
+
label: label,
|
|
2410
|
+
map: map,
|
|
2411
|
+
mapPick: mapPick,
|
|
2412
|
+
mapValues: mapValues,
|
|
2413
|
+
midlineTo: midlineTo,
|
|
2414
|
+
mirrored4: mirrored4,
|
|
2415
|
+
mul: mul,
|
|
2416
|
+
mulxyz: mulxyz,
|
|
2417
|
+
nearest: nearest,
|
|
2418
|
+
normalVector: normalVector,
|
|
2419
|
+
pick: pick,
|
|
2420
|
+
poly2solid: poly2solid,
|
|
2421
|
+
print: print,
|
|
2422
|
+
reShape: reShape,
|
|
2423
|
+
result: result,
|
|
2424
|
+
rotateAround: rotateAround,
|
|
2425
|
+
rotationAxes: rotationAxes,
|
|
2426
|
+
scale: scale,
|
|
2427
|
+
segment: segment,
|
|
2428
|
+
shift: shift,
|
|
2429
|
+
size: size,
|
|
2430
|
+
slice: slice,
|
|
2431
|
+
sliceParams: sliceParams,
|
|
2432
|
+
slices2poly: slices2poly,
|
|
2433
|
+
snap: snap,
|
|
2434
|
+
stretch: stretch,
|
|
2435
|
+
text: text,
|
|
2436
|
+
toArray: toArray,
|
|
2437
|
+
translator: translator,
|
|
2438
|
+
unitAxis: unitAxis,
|
|
2439
|
+
unitCube: unitCube,
|
|
2440
|
+
wedge: wedge,
|
|
2441
|
+
xyz2array: xyz2array,
|
|
2442
|
+
zero: zero,
|
|
2443
|
+
zipObject: zipObject
|
|
2444
|
+
});
|
|
2445
|
+
|
|
2446
|
+
const debug$1 = Debug('jscadUtils:parts');
|
|
2607
2447
|
var parts = {
|
|
2608
|
-
BBox: BBox,
|
|
2609
|
-
Cube
|
|
2610
|
-
RoundedCube
|
|
2611
|
-
Cylinder
|
|
2612
|
-
Cone
|
|
2448
|
+
BBox: BBox$1,
|
|
2449
|
+
Cube,
|
|
2450
|
+
RoundedCube,
|
|
2451
|
+
Cylinder,
|
|
2452
|
+
Cone
|
|
2613
2453
|
};
|
|
2454
|
+
|
|
2614
2455
|
/**
|
|
2615
2456
|
* Returns a CSG cube object with the same extent of all
|
|
2616
2457
|
* parameters objects passed in.
|
|
@@ -2618,37 +2459,32 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2618
2459
|
* @param {CSG} ...objects Any number of CSG objects to create a bounding box for.
|
|
2619
2460
|
* @return {CSG} A box with the size of the extents of all of the passed in objects
|
|
2620
2461
|
*/
|
|
2621
|
-
|
|
2622
|
-
function BBox() {
|
|
2462
|
+
function BBox$1(...objects) {
|
|
2623
2463
|
function box(object) {
|
|
2624
2464
|
return CSG.cube({
|
|
2625
2465
|
center: object.centroid(),
|
|
2626
2466
|
radius: object.size().dividedBy(2)
|
|
2627
2467
|
});
|
|
2628
2468
|
}
|
|
2629
|
-
|
|
2630
|
-
for (var _len = arguments.length, objects = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
2631
|
-
objects[_key] = arguments[_key];
|
|
2632
|
-
}
|
|
2633
|
-
|
|
2634
2469
|
return objects.reduce(function (bbox, part) {
|
|
2635
2470
|
var object = bbox ? union([bbox, box(part)]) : part;
|
|
2636
2471
|
return box(object);
|
|
2637
2472
|
}, undefined);
|
|
2638
2473
|
}
|
|
2639
2474
|
function Cube(width) {
|
|
2640
|
-
var r = div(fromxyz(width), 2);
|
|
2475
|
+
var r = div$1(fromxyz(width), 2);
|
|
2641
2476
|
return CSG.cube({
|
|
2642
2477
|
center: r,
|
|
2643
2478
|
radius: r
|
|
2644
2479
|
});
|
|
2645
|
-
}
|
|
2480
|
+
}
|
|
2481
|
+
|
|
2482
|
+
// export function Sphere(diameter) {
|
|
2646
2483
|
// return CSG.sphere({
|
|
2647
2484
|
// cener: [0, 0, 0],
|
|
2648
2485
|
// radius: diameter / 2
|
|
2649
2486
|
// });
|
|
2650
2487
|
// }
|
|
2651
|
-
|
|
2652
2488
|
/**
|
|
2653
2489
|
* Creates a cube with the `x` and `y` corners rounded. The `z` faces are flat.
|
|
2654
2490
|
* Intended to create circut boards and similar objects.
|
|
@@ -2660,7 +2496,6 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2660
2496
|
* @param {Number} [corner_radius] Radius of the corners.
|
|
2661
2497
|
* @return {CSG} A csg rounded cube.
|
|
2662
2498
|
*/
|
|
2663
|
-
|
|
2664
2499
|
function RoundedCube(x, y, thickness, corner_radius) {
|
|
2665
2500
|
if (x.getBounds) {
|
|
2666
2501
|
var size$1 = size(x.getBounds());
|
|
@@ -2670,8 +2505,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2670
2505
|
} else {
|
|
2671
2506
|
var r = [x / 2, y / 2]; // eslint-disable-line no-redeclare
|
|
2672
2507
|
}
|
|
2673
|
-
|
|
2674
|
-
debug$2('RoundedCube', size$1, r, thickness, corner_radius);
|
|
2508
|
+
debug$1('RoundedCube', size$1, r, thickness, corner_radius);
|
|
2675
2509
|
var roundedcube = CAG.roundedRectangle({
|
|
2676
2510
|
center: [r[0], r[1], 0],
|
|
2677
2511
|
radius: r,
|
|
@@ -2682,6 +2516,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2682
2516
|
});
|
|
2683
2517
|
return roundedcube;
|
|
2684
2518
|
}
|
|
2519
|
+
|
|
2685
2520
|
/**
|
|
2686
2521
|
* A Cylinder primative located at the origin.
|
|
2687
2522
|
* @param {Number} diameter Diameter of the cylinder
|
|
@@ -2690,10 +2525,8 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2690
2525
|
* @param {number} [options.resolution] The number of segments to create in 360 degrees of rotation.
|
|
2691
2526
|
* @return {CSG} A CSG Cylinder
|
|
2692
2527
|
*/
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
2696
|
-
debug$2('parts.Cylinder', diameter, height, options);
|
|
2528
|
+
function Cylinder(diameter, height, options = {}) {
|
|
2529
|
+
debug$1('parts.Cylinder', diameter, height, options);
|
|
2697
2530
|
options = Object.assign({
|
|
2698
2531
|
start: [0, 0, 0],
|
|
2699
2532
|
end: [0, 0, height],
|
|
@@ -2702,6 +2535,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2702
2535
|
}, options);
|
|
2703
2536
|
return CSG.cylinder(options);
|
|
2704
2537
|
}
|
|
2538
|
+
|
|
2705
2539
|
/**
|
|
2706
2540
|
* Creats a cone.
|
|
2707
2541
|
* @function Cone
|
|
@@ -2711,10 +2545,8 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2711
2545
|
* @param {Object} options Additional options passed to `CSG.cylinder`.
|
|
2712
2546
|
* @return {CSG} A CSG cone object.
|
|
2713
2547
|
*/
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
2717
|
-
debug$2('parts.Cone', diameter1, diameter2, height, options);
|
|
2548
|
+
function Cone(diameter1, diameter2, height, options = {}) {
|
|
2549
|
+
debug$1('parts.Cone', diameter1, diameter2, height, options);
|
|
2718
2550
|
return CSG.cylinder(Object.assign({
|
|
2719
2551
|
start: [0, 0, 0],
|
|
2720
2552
|
end: [0, 0, height],
|
|
@@ -2723,14 +2555,14 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2723
2555
|
resolution: CSG.defaultResolution2D
|
|
2724
2556
|
}, options));
|
|
2725
2557
|
}
|
|
2558
|
+
|
|
2726
2559
|
/**
|
|
2727
2560
|
* Creates a hexagon.
|
|
2728
2561
|
* @param {number} diameter Outside diameter of the hexagon
|
|
2729
2562
|
* @param {number} height height of the hexagon
|
|
2730
2563
|
*/
|
|
2731
|
-
|
|
2732
2564
|
function Hexagon(diameter, height) {
|
|
2733
|
-
debug$
|
|
2565
|
+
debug$1('hexagon', diameter, height);
|
|
2734
2566
|
var radius = diameter / 2;
|
|
2735
2567
|
var sqrt3 = Math.sqrt(3) / 2;
|
|
2736
2568
|
var hex = CAG.fromPoints([[radius, 0], [radius / 2, radius * sqrt3], [-radius / 2, radius * sqrt3], [-radius, 0], [-radius / 2, -radius * sqrt3], [radius / 2, -radius * sqrt3]]);
|
|
@@ -2738,6 +2570,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2738
2570
|
offset: [0, 0, height]
|
|
2739
2571
|
});
|
|
2740
2572
|
}
|
|
2573
|
+
|
|
2741
2574
|
/**
|
|
2742
2575
|
* Creats a 3 sided prisim
|
|
2743
2576
|
* @function Triangle
|
|
@@ -2745,7 +2578,6 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2745
2578
|
* @param {Number} height The height of the prisim.
|
|
2746
2579
|
* @return {CSG} A prisim object.
|
|
2747
2580
|
*/
|
|
2748
|
-
|
|
2749
2581
|
function Triangle(base, height) {
|
|
2750
2582
|
var radius = base / 2;
|
|
2751
2583
|
var tri = CAG.fromPoints([[-radius, 0], [radius, 0], [0, Math.sin(30) * radius]]);
|
|
@@ -2753,6 +2585,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2753
2585
|
offset: [0, 0, height]
|
|
2754
2586
|
});
|
|
2755
2587
|
}
|
|
2588
|
+
|
|
2756
2589
|
/**
|
|
2757
2590
|
* Create a tube
|
|
2758
2591
|
* @param {Number} outsideDiameter Outside diameter of the tube.
|
|
@@ -2764,24 +2597,21 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2764
2597
|
* @param {number} [insideOptions.resolution] The resolution option determines the number of segments to create in 360 degrees of rotation.
|
|
2765
2598
|
* @returns {CSG} A CSG Tube
|
|
2766
2599
|
*/
|
|
2767
|
-
|
|
2768
2600
|
function Tube(outsideDiameter, insideDiameter, height, outsideOptions, insideOptions) {
|
|
2769
2601
|
return Cylinder(outsideDiameter, height, outsideOptions).subtract(Cylinder(insideDiameter, height, insideOptions || outsideOptions));
|
|
2770
2602
|
}
|
|
2603
|
+
|
|
2771
2604
|
/**
|
|
2772
2605
|
*
|
|
2773
2606
|
* @param {Number} width
|
|
2774
2607
|
* @param {Number} height
|
|
2775
2608
|
*/
|
|
2776
|
-
|
|
2777
|
-
function Anchor() {
|
|
2778
|
-
var width = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 10;
|
|
2779
|
-
var height = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10;
|
|
2609
|
+
function Anchor(width = 10, height = 10) {
|
|
2780
2610
|
var hole = Cylinder(width, height).Center().color('red');
|
|
2781
2611
|
var post = Cylinder(height / 2, width * 0.66).rotateX(90).align(hole, 'xz').snap(hole, 'y', 'inside-').translate([0, 0, -height / 6]).color('purple');
|
|
2782
2612
|
return Group({
|
|
2783
|
-
post
|
|
2784
|
-
hole
|
|
2613
|
+
post,
|
|
2614
|
+
hole
|
|
2785
2615
|
});
|
|
2786
2616
|
}
|
|
2787
2617
|
function Board(width, height, corner_radius, thickness) {
|
|
@@ -2796,7 +2626,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2796
2626
|
});
|
|
2797
2627
|
return board;
|
|
2798
2628
|
}
|
|
2799
|
-
|
|
2629
|
+
const Hardware = {
|
|
2800
2630
|
Orientation: {
|
|
2801
2631
|
up: {
|
|
2802
2632
|
head: 'outside-',
|
|
@@ -2807,7 +2637,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2807
2637
|
clear: 'inside-'
|
|
2808
2638
|
}
|
|
2809
2639
|
},
|
|
2810
|
-
Screw: function
|
|
2640
|
+
Screw: function (head, thread, headClearSpace, options) {
|
|
2811
2641
|
depreciated('Screw', false, 'Use the jscad-hardware screw methods instead');
|
|
2812
2642
|
options = Object.assign(options, {
|
|
2813
2643
|
orientation: 'up',
|
|
@@ -2818,14 +2648,11 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2818
2648
|
head: head.color('gray'),
|
|
2819
2649
|
thread: thread.snap(head, 'z', orientation.head).color('silver')
|
|
2820
2650
|
});
|
|
2821
|
-
|
|
2822
2651
|
if (headClearSpace) {
|
|
2823
2652
|
group.add(headClearSpace.enlarge(options.clearance).snap(head, 'z', orientation.clear).color('red'), 'headClearSpace', true);
|
|
2824
2653
|
}
|
|
2825
|
-
|
|
2826
2654
|
return group;
|
|
2827
2655
|
},
|
|
2828
|
-
|
|
2829
2656
|
/**
|
|
2830
2657
|
* Creates a `Group` object with a Pan Head Screw.
|
|
2831
2658
|
* @param {number} headDiameter Diameter of the head of the screw
|
|
@@ -2835,18 +2662,15 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2835
2662
|
* @param {number} clearLength Length of the clearance section of the head.
|
|
2836
2663
|
* @param {object} options Screw options include orientation and clerance scale.
|
|
2837
2664
|
*/
|
|
2838
|
-
PanHeadScrew: function
|
|
2665
|
+
PanHeadScrew: function (headDiameter, headLength, diameter, length, clearLength, options) {
|
|
2839
2666
|
depreciated('PanHeadScrew', false, 'Use the jscad-hardware screw methods instead');
|
|
2840
2667
|
var head = Cylinder(headDiameter, headLength);
|
|
2841
2668
|
var thread = Cylinder(diameter, length);
|
|
2842
|
-
|
|
2843
2669
|
if (clearLength) {
|
|
2844
2670
|
var headClearSpace = Cylinder(headDiameter, clearLength);
|
|
2845
2671
|
}
|
|
2846
|
-
|
|
2847
2672
|
return Hardware.Screw(head, thread, headClearSpace, options);
|
|
2848
2673
|
},
|
|
2849
|
-
|
|
2850
2674
|
/**
|
|
2851
2675
|
* Creates a `Group` object with a Hex Head Screw.
|
|
2852
2676
|
* @param {number} headDiameter Diameter of the head of the screw
|
|
@@ -2856,18 +2680,15 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2856
2680
|
* @param {number} clearLength Length of the clearance section of the head.
|
|
2857
2681
|
* @param {object} options Screw options include orientation and clerance scale.
|
|
2858
2682
|
*/
|
|
2859
|
-
HexHeadScrew: function
|
|
2683
|
+
HexHeadScrew: function (headDiameter, headLength, diameter, length, clearLength, options) {
|
|
2860
2684
|
depreciated('HexHeadScrew', false, 'Use the jscad-hardware screw methods instead');
|
|
2861
2685
|
var head = Hexagon(headDiameter, headLength);
|
|
2862
2686
|
var thread = Cylinder(diameter, length);
|
|
2863
|
-
|
|
2864
2687
|
if (clearLength) {
|
|
2865
2688
|
var headClearSpace = Hexagon(headDiameter, clearLength);
|
|
2866
2689
|
}
|
|
2867
|
-
|
|
2868
2690
|
return Hardware.Screw(head, thread, headClearSpace, options);
|
|
2869
2691
|
},
|
|
2870
|
-
|
|
2871
2692
|
/**
|
|
2872
2693
|
* Create a Flat Head Screw
|
|
2873
2694
|
* @param {number} headDiameter head diameter
|
|
@@ -2877,44 +2698,42 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2877
2698
|
* @param {number} clearLength clearance length
|
|
2878
2699
|
* @param {object} options options
|
|
2879
2700
|
*/
|
|
2880
|
-
FlatHeadScrew: function
|
|
2701
|
+
FlatHeadScrew: function (headDiameter, headLength, diameter, length, clearLength, options) {
|
|
2881
2702
|
depreciated('FlatHeadScrew', false, 'Use the jscad-hardware screw methods instead');
|
|
2882
|
-
var head = Cone(headDiameter, diameter, headLength);
|
|
2883
|
-
|
|
2703
|
+
var head = Cone(headDiameter, diameter, headLength);
|
|
2704
|
+
// var head = Cylinder(headDiameter, headLength);
|
|
2884
2705
|
var thread = Cylinder(diameter, length);
|
|
2885
|
-
|
|
2886
2706
|
if (clearLength) {
|
|
2887
2707
|
var headClearSpace = Cylinder(headDiameter, clearLength);
|
|
2888
2708
|
}
|
|
2889
|
-
|
|
2890
2709
|
return Hardware.Screw(head, thread, headClearSpace, options);
|
|
2891
2710
|
}
|
|
2892
2711
|
};
|
|
2893
2712
|
|
|
2894
2713
|
var parts$1 = /*#__PURE__*/Object.freeze({
|
|
2895
2714
|
__proto__: null,
|
|
2896
|
-
|
|
2897
|
-
BBox: BBox,
|
|
2715
|
+
Anchor: Anchor,
|
|
2716
|
+
BBox: BBox$1,
|
|
2717
|
+
Board: Board,
|
|
2718
|
+
Cone: Cone,
|
|
2898
2719
|
Cube: Cube,
|
|
2899
|
-
RoundedCube: RoundedCube,
|
|
2900
2720
|
Cylinder: Cylinder,
|
|
2901
|
-
|
|
2721
|
+
Hardware: Hardware,
|
|
2902
2722
|
Hexagon: Hexagon,
|
|
2723
|
+
RoundedCube: RoundedCube,
|
|
2903
2724
|
Triangle: Triangle,
|
|
2904
2725
|
Tube: Tube,
|
|
2905
|
-
|
|
2906
|
-
Board: Board,
|
|
2907
|
-
Hardware: Hardware
|
|
2726
|
+
default: parts
|
|
2908
2727
|
});
|
|
2909
2728
|
|
|
2910
|
-
|
|
2729
|
+
const debug = Debug('jscadUtils:boxes');
|
|
2730
|
+
|
|
2911
2731
|
/** @typedef {import("./group").JsCadUtilsGroup} JsCadUtilsGroup */
|
|
2912
2732
|
|
|
2913
2733
|
/**
|
|
2914
2734
|
* jscad box and join utilities. This should be considered experimental,
|
|
2915
2735
|
* but there are some useful utilities here.
|
|
2916
2736
|
*/
|
|
2917
|
-
|
|
2918
2737
|
/**
|
|
2919
2738
|
* Create a [rabbet joint](https://en.wikipedia.org/wiki/Rabbet) in a CSG solid.
|
|
2920
2739
|
* This was designed for cubes, but should work on other types of objects.
|
|
@@ -2929,11 +2748,11 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2929
2748
|
* @function RabbetJoin
|
|
2930
2749
|
* @deprecated Use `Rabbet` instead.
|
|
2931
2750
|
*/
|
|
2932
|
-
|
|
2933
2751
|
function RabbetJoin(box, thickness, cutHeight) {
|
|
2934
2752
|
depreciated('RabbetJoin', true, "Use 'Rabbet' instead");
|
|
2935
2753
|
return rabbetJoin(box, thickness, cutHeight);
|
|
2936
2754
|
}
|
|
2755
|
+
|
|
2937
2756
|
/**
|
|
2938
2757
|
* Cuts a CSG object into three parts, a top and bottom of `thickness`
|
|
2939
2758
|
* height, and the remaining middle.
|
|
@@ -2942,20 +2761,20 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2942
2761
|
* @param {Number} thickness The thickness of the top and bottom parts.
|
|
2943
2762
|
* @return {JsCadUtilsGroup} A `Group` object with the `top`, `middle` and `bottom` parts.
|
|
2944
2763
|
*/
|
|
2945
|
-
|
|
2946
2764
|
function topMiddleBottom(box, thickness) {
|
|
2947
|
-
debug
|
|
2765
|
+
debug('TopMiddleBottom', box, thickness);
|
|
2948
2766
|
var bottom = box.bisect('z', thickness, {
|
|
2949
2767
|
color: true
|
|
2950
2768
|
});
|
|
2951
2769
|
var top = bottom.parts.positive.bisect('z', -thickness);
|
|
2952
2770
|
return Group('top,middle,bottom', [top.parts.positive, top.parts.negative.color('green'), bottom.parts.negative]);
|
|
2953
2771
|
}
|
|
2772
|
+
|
|
2954
2773
|
/**
|
|
2955
2774
|
* This will bisect an object using a rabett join. Returns a
|
|
2956
2775
|
* `group` object with `positive` and `negative` parts.
|
|
2957
2776
|
*
|
|
2958
|
-
* * 
|
|
2959
2778
|
* @example
|
|
2960
2779
|
*include('dist/jscad-utils.jscad');
|
|
2961
2780
|
*
|
|
@@ -2979,28 +2798,30 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2979
2798
|
* @param {Number} face Size of the join face.
|
|
2980
2799
|
* @return {JsCadUtilsGroup} A group object with `positive`, `negative` parts.
|
|
2981
2800
|
*/
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
var options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
|
|
2985
|
-
debug$3('Rabett', 'thickness', thickness, 'gap', gap, 'height', height, 'face', face);
|
|
2801
|
+
function Rabett(box, thickness, gap, height, face, options = {}) {
|
|
2802
|
+
debug('Rabett', 'thickness', thickness, 'gap', gap, 'height', height, 'face', face);
|
|
2986
2803
|
gap = gap || 0.25;
|
|
2987
2804
|
var inside = thickness - gap;
|
|
2988
|
-
var outside = -thickness + gap;
|
|
2989
|
-
|
|
2990
|
-
debug
|
|
2991
|
-
var group = Group();
|
|
2992
|
-
|
|
2993
|
-
var
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
var
|
|
3000
|
-
|
|
3001
|
-
|
|
2805
|
+
var outside = -thickness + gap;
|
|
2806
|
+
// options.color = true;
|
|
2807
|
+
debug('inside', inside, 'outside', outside);
|
|
2808
|
+
var group = Group();
|
|
2809
|
+
// debug('Rabbet top height:', height, 'options:', options);
|
|
2810
|
+
var {
|
|
2811
|
+
positive: top,
|
|
2812
|
+
negative: lower2_3rd
|
|
2813
|
+
} = box.bisect('z', height, options).parts;
|
|
2814
|
+
|
|
2815
|
+
// debug('face', face, 'height', height);
|
|
2816
|
+
var lowerBisectHeight = Math.sign(height) < 0 ? face * Math.sign(height) : height - face;
|
|
2817
|
+
// debug('Rabbet bottom height:', lowerBisectHeight, 'options:', options);
|
|
2818
|
+
var {
|
|
2819
|
+
positive: middle,
|
|
2820
|
+
negative: bottom
|
|
2821
|
+
} = lower2_3rd.bisect('z', lowerBisectHeight, options).parts;
|
|
3002
2822
|
var middleTop = middle.color('yellow').subtract(middle.color('darkred').enlarge([outside, outside, 0]));
|
|
3003
|
-
group.add(top
|
|
2823
|
+
group.add(top
|
|
2824
|
+
// .color('blue')
|
|
3004
2825
|
.union(middleTop), 'top');
|
|
3005
2826
|
var bottomOutline = middle.color('yellow').subtract(middle.color('orange').enlarge([outside, outside, 0])).enlarge([outside, outside, 0]);
|
|
3006
2827
|
group.add(bottomOutline, 'middle-top', true);
|
|
@@ -3008,6 +2829,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
3008
2829
|
group.add(bottom.color('orange').union(middle.color('green').subtract(middle.color('red').enlarge([inside, inside, 0])).subtract(middleTop)), 'bottom');
|
|
3009
2830
|
return group;
|
|
3010
2831
|
}
|
|
2832
|
+
|
|
3011
2833
|
/**
|
|
3012
2834
|
* Used on a hollow object, this will rabett out the top and/or
|
|
3013
2835
|
* bottom of the object.
|
|
@@ -3040,23 +2862,19 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
3040
2862
|
* @return {JsCadUtilsGroup} An A hollow version of the original object..
|
|
3041
2863
|
* @memberof module:Boxes
|
|
3042
2864
|
*/
|
|
3043
|
-
|
|
3044
|
-
var RabettTopBottom = function rabbetTMB(box, thickness) {
|
|
3045
|
-
var gap = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0.25;
|
|
3046
|
-
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
2865
|
+
const RabettTopBottom = function rabbetTMB(box, thickness, gap = 0.25, options = {}) {
|
|
3047
2866
|
options = Object.assign({
|
|
3048
2867
|
removableTop: true,
|
|
3049
2868
|
removableBottom: true,
|
|
3050
2869
|
topWidth: -thickness,
|
|
3051
2870
|
bottomWidth: thickness
|
|
3052
2871
|
}, options);
|
|
3053
|
-
debug
|
|
2872
|
+
debug('RabettTopBottom', box, thickness, gap, options);
|
|
3054
2873
|
var group = Group('', {
|
|
3055
2874
|
box: box
|
|
3056
2875
|
});
|
|
3057
2876
|
var inside = -thickness - gap;
|
|
3058
2877
|
var outside = -thickness + gap;
|
|
3059
|
-
|
|
3060
2878
|
if (options.removableTop) {
|
|
3061
2879
|
var top = box.bisect('z', options.topWidth, {
|
|
3062
2880
|
color: true
|
|
@@ -3064,7 +2882,6 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
3064
2882
|
group.add(top.parts.positive.enlarge([inside, inside, 0]), 'top');
|
|
3065
2883
|
if (!options.removableBottom) group.add(box.subtract(top.parts.positive.enlarge([outside, outside, 0])), 'bottom');
|
|
3066
2884
|
}
|
|
3067
|
-
|
|
3068
2885
|
if (options.removableBottom) {
|
|
3069
2886
|
var bottom = box.bisect('z', options.bottomWidth, {
|
|
3070
2887
|
color: true
|
|
@@ -3073,17 +2890,15 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
3073
2890
|
group.add(bottom.parts.negative.enlarge([inside, inside, 0]), 'bottom');
|
|
3074
2891
|
if (!options.removableTop) group.add(box.subtract(group.parts.bottomCutout), 'top');
|
|
3075
2892
|
}
|
|
3076
|
-
|
|
3077
2893
|
if (options.removableBottom && options.removableTop) {
|
|
3078
2894
|
group.add(box.subtract(union([bottom.parts.negative.enlarge([outside, outside, 0]), top.parts.positive.enlarge([outside, outside, 0])])), 'middle');
|
|
3079
2895
|
}
|
|
3080
|
-
|
|
3081
2896
|
return group;
|
|
3082
2897
|
};
|
|
3083
|
-
|
|
3084
|
-
gap = gap || 0.25;
|
|
2898
|
+
const CutOut = function cutOut(o, h, box, plug, gap) {
|
|
2899
|
+
gap = gap || 0.25;
|
|
2900
|
+
// console.log('cutOut', o.size(), h, b.size());
|
|
3085
2901
|
// var r = getRadius(o);
|
|
3086
|
-
|
|
3087
2902
|
var s = o.size();
|
|
3088
2903
|
var cutout = o.intersect(box);
|
|
3089
2904
|
var cs = o.size();
|
|
@@ -3100,9 +2915,9 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
3100
2915
|
insert: union([o, top]).intersect(box).subtract(o).enlarge([-gap, 0, 0]).union(clip.subtract(plug).enlarge(-gap, -gap, 0)).color('blue')
|
|
3101
2916
|
});
|
|
3102
2917
|
};
|
|
3103
|
-
|
|
2918
|
+
const Rectangle = function (size, thickness, cb) {
|
|
3104
2919
|
thickness = thickness || 2;
|
|
3105
|
-
var s = div(xyz2array(size), 2);
|
|
2920
|
+
var s = div$1(xyz2array(size), 2);
|
|
3106
2921
|
var r = add(s, thickness);
|
|
3107
2922
|
var box = CSG.cube({
|
|
3108
2923
|
center: r,
|
|
@@ -3111,10 +2926,12 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
3111
2926
|
center: r,
|
|
3112
2927
|
radius: s
|
|
3113
2928
|
}));
|
|
3114
|
-
if (cb) box = cb(box);
|
|
2929
|
+
if (cb) box = cb(box);
|
|
3115
2930
|
|
|
2931
|
+
// return rabbetTMB(box.color('gray'), thickness, gap, options);
|
|
3116
2932
|
return box;
|
|
3117
2933
|
};
|
|
2934
|
+
|
|
3118
2935
|
/**
|
|
3119
2936
|
* Takes a solid object and returns a hollow version with a selected
|
|
3120
2937
|
* wall thickness. This is done by reducing the object by half the
|
|
@@ -3129,8 +2946,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
3129
2946
|
* @return {CSG} An A hollow version of the original object..
|
|
3130
2947
|
* @memberof module:Boxes
|
|
3131
2948
|
*/
|
|
3132
|
-
|
|
3133
|
-
var Hollow = function Hollow(object, thickness, interiorcb, exteriorcb) {
|
|
2949
|
+
const Hollow = function (object, thickness, interiorcb, exteriorcb) {
|
|
3134
2950
|
thickness = thickness || 2;
|
|
3135
2951
|
var size = -thickness * 2;
|
|
3136
2952
|
interiorcb = interiorcb || identity;
|
|
@@ -3138,6 +2954,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
3138
2954
|
if (exteriorcb) box = exteriorcb(box);
|
|
3139
2955
|
return box;
|
|
3140
2956
|
};
|
|
2957
|
+
|
|
3141
2958
|
/**
|
|
3142
2959
|
* Create a box that surounds the object.
|
|
3143
2960
|
* @param {CSG} o The object to create a bounding box for.
|
|
@@ -3145,22 +2962,18 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
3145
2962
|
* @deprecated use parts.BBox
|
|
3146
2963
|
* @memberof module:Boxes
|
|
3147
2964
|
*/
|
|
3148
|
-
|
|
3149
|
-
var BBox$1 = function BBox(o) {
|
|
2965
|
+
const BBox = function (o) {
|
|
3150
2966
|
depreciated('BBox', true, "Use 'parts.BBox' instead");
|
|
3151
|
-
var s = div(xyz2array(o.size()), 2);
|
|
2967
|
+
var s = div$1(xyz2array(o.size()), 2);
|
|
3152
2968
|
return CSG.cube({
|
|
3153
2969
|
center: s,
|
|
3154
2970
|
radius: s
|
|
3155
2971
|
}).align(o, 'xyz');
|
|
3156
2972
|
};
|
|
3157
|
-
|
|
3158
2973
|
function getRadius(o) {
|
|
3159
|
-
return div(xyz2array(o.size()), 2);
|
|
2974
|
+
return div$1(xyz2array(o.size()), 2);
|
|
3160
2975
|
}
|
|
3161
|
-
|
|
3162
|
-
function rabbetJoin(box, thickness) {
|
|
3163
|
-
var gap = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0.25;
|
|
2976
|
+
function rabbetJoin(box, thickness, gap = 0.25) {
|
|
3164
2977
|
var r = add(getRadius(box), -thickness / 2);
|
|
3165
2978
|
r[2] = thickness / 2;
|
|
3166
2979
|
var cutter = CSG.cube({
|
|
@@ -3179,25 +2992,30 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
3179
2992
|
|
|
3180
2993
|
var Boxes = /*#__PURE__*/Object.freeze({
|
|
3181
2994
|
__proto__: null,
|
|
2995
|
+
BBox: BBox,
|
|
2996
|
+
CutOut: CutOut,
|
|
2997
|
+
Hollow: Hollow,
|
|
3182
2998
|
RabbetJoin: RabbetJoin,
|
|
3183
|
-
topMiddleBottom: topMiddleBottom,
|
|
3184
2999
|
Rabett: Rabett,
|
|
3185
3000
|
RabettTopBottom: RabettTopBottom,
|
|
3186
|
-
CutOut: CutOut,
|
|
3187
3001
|
Rectangle: Rectangle,
|
|
3188
|
-
|
|
3189
|
-
BBox: BBox$1
|
|
3002
|
+
topMiddleBottom: topMiddleBottom
|
|
3190
3003
|
});
|
|
3191
3004
|
|
|
3192
|
-
|
|
3005
|
+
/**
|
|
3006
|
+
* JsCad Utilities es6
|
|
3007
|
+
*/
|
|
3008
|
+
|
|
3009
|
+
const compatV1 = {
|
|
3010
|
+
...util,
|
|
3193
3011
|
group: Group,
|
|
3194
3012
|
init: init$1,
|
|
3195
3013
|
triangle: triUtils,
|
|
3196
|
-
array
|
|
3014
|
+
array,
|
|
3197
3015
|
parts: parts$1,
|
|
3198
|
-
Boxes
|
|
3199
|
-
Debug
|
|
3200
|
-
}
|
|
3016
|
+
Boxes,
|
|
3017
|
+
Debug
|
|
3018
|
+
};
|
|
3201
3019
|
|
|
3202
3020
|
exports.Boxes = Boxes;
|
|
3203
3021
|
exports.Debug = Debug;
|
|
@@ -3211,7 +3029,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
3211
3029
|
|
|
3212
3030
|
return exports;
|
|
3213
3031
|
|
|
3214
|
-
}({}, jsCadCSG, scadApi)
|
|
3032
|
+
})({}, jsCadCSG, scadApi);
|
|
3215
3033
|
|
|
3216
3034
|
// endinject
|
|
3217
3035
|
|