@jwc/jscad-utils 4.8.4 → 4.9.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 +349 -480
- package/dist/examples/bisect.jscad +254 -259
- package/dist/examples/boxes.jscad +254 -259
- package/dist/examples/chamfer.jscad +254 -259
- package/dist/examples/fillet.jscad +254 -259
- package/dist/examples/fit.jscad +254 -259
- package/dist/examples/groups.jscad +254 -259
- package/dist/examples/midlineTo.jscad +254 -259
- package/dist/examples/parts-hexagon.jscad +254 -259
- package/dist/examples/rabett-tb.jscad +254 -259
- package/dist/examples/rabett.jscad +254 -259
- package/dist/examples/rabett2.jscad +254 -259
- package/dist/examples/retraction-test.jscad +254 -259
- package/dist/examples/size.jscad +254 -259
- package/dist/examples/snap.jscad +254 -259
- package/dist/examples/text.jscad +254 -259
- package/dist/examples/wedge.jscad +254 -259
- package/dist/index.js +349 -480
- package/package.json +4 -12
- package/src/boxes.js +1 -1
- package/src/util.js +11 -11
package/dist/compat.js
CHANGED
|
@@ -77,7 +77,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
77
77
|
get mapPick () { return mapPick; },
|
|
78
78
|
get divA () { return divA; },
|
|
79
79
|
get divxyz () { return divxyz; },
|
|
80
|
-
get div () { return div
|
|
80
|
+
get div () { return div; },
|
|
81
81
|
get mulxyz () { return mulxyz; },
|
|
82
82
|
get mul () { return mul; },
|
|
83
83
|
get xyz2array () { return xyz2array; },
|
|
@@ -123,125 +123,105 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
123
123
|
get addConnector () { return addConnector; }
|
|
124
124
|
});
|
|
125
125
|
|
|
126
|
-
function
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
126
|
+
function _arrayLikeToArray(r, a) {
|
|
127
|
+
(null == a || a > r.length) && (a = r.length);
|
|
128
|
+
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
129
|
+
return n;
|
|
130
|
+
}
|
|
131
|
+
function _arrayWithHoles(r) {
|
|
132
|
+
if (Array.isArray(r)) return r;
|
|
133
|
+
}
|
|
134
|
+
function _defineProperty(e, r, t) {
|
|
135
|
+
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
136
|
+
value: t,
|
|
137
|
+
enumerable: !0,
|
|
138
|
+
configurable: !0,
|
|
139
|
+
writable: !0
|
|
140
|
+
}) : e[r] = t, e;
|
|
141
|
+
}
|
|
142
|
+
function _iterableToArrayLimit(r, l) {
|
|
143
|
+
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
144
|
+
if (null != t) {
|
|
145
|
+
var e,
|
|
146
|
+
n,
|
|
147
|
+
i,
|
|
148
|
+
u,
|
|
149
|
+
a = [],
|
|
150
|
+
f = !0,
|
|
151
|
+
o = !1;
|
|
152
|
+
try {
|
|
153
|
+
if (i = (t = t.call(r)).next, 0 === l) {
|
|
154
|
+
if (Object(t) !== t) return;
|
|
155
|
+
f = !1;
|
|
156
|
+
} else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
|
|
157
|
+
} catch (r) {
|
|
158
|
+
o = !0, n = r;
|
|
159
|
+
} finally {
|
|
160
|
+
try {
|
|
161
|
+
if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
|
|
162
|
+
} finally {
|
|
163
|
+
if (o) throw n;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return a;
|
|
137
167
|
}
|
|
138
|
-
|
|
139
|
-
return _typeof(obj);
|
|
140
168
|
}
|
|
141
|
-
|
|
142
|
-
|
|
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;
|
|
169
|
+
function _nonIterableRest() {
|
|
170
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
155
171
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
var keys = Object.keys(object);
|
|
159
|
-
|
|
172
|
+
function ownKeys(e, r) {
|
|
173
|
+
var t = Object.keys(e);
|
|
160
174
|
if (Object.getOwnPropertySymbols) {
|
|
161
|
-
var
|
|
162
|
-
|
|
163
|
-
return Object.getOwnPropertyDescriptor(
|
|
164
|
-
});
|
|
165
|
-
keys.push.apply(keys, symbols);
|
|
175
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
176
|
+
r && (o = o.filter(function (r) {
|
|
177
|
+
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
178
|
+
})), t.push.apply(t, o);
|
|
166
179
|
}
|
|
167
|
-
|
|
168
|
-
return keys;
|
|
180
|
+
return t;
|
|
169
181
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
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
|
-
}
|
|
182
|
+
function _objectSpread2(e) {
|
|
183
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
184
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
185
|
+
r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
|
|
186
|
+
_defineProperty(e, r, t[r]);
|
|
187
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
|
|
188
|
+
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
189
|
+
});
|
|
186
190
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
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
|
-
}
|
|
191
|
+
return e;
|
|
192
|
+
}
|
|
193
|
+
function _slicedToArray(r, e) {
|
|
194
|
+
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
|
|
195
|
+
}
|
|
196
|
+
function _toPrimitive(t, r) {
|
|
197
|
+
if ("object" != typeof t || !t) return t;
|
|
198
|
+
var e = t[Symbol.toPrimitive];
|
|
199
|
+
if (void 0 !== e) {
|
|
200
|
+
var i = e.call(t, r || "default");
|
|
201
|
+
if ("object" != typeof i) return i;
|
|
202
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
221
203
|
}
|
|
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);
|
|
204
|
+
return ("string" === r ? String : Number)(t);
|
|
233
205
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
239
|
-
|
|
240
|
-
return arr2;
|
|
206
|
+
function _toPropertyKey(t) {
|
|
207
|
+
var i = _toPrimitive(t, "string");
|
|
208
|
+
return "symbol" == typeof i ? i : i + "";
|
|
241
209
|
}
|
|
210
|
+
function _typeof(o) {
|
|
211
|
+
"@babel/helpers - typeof";
|
|
242
212
|
|
|
243
|
-
|
|
244
|
-
|
|
213
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
|
|
214
|
+
return typeof o;
|
|
215
|
+
} : function (o) {
|
|
216
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
217
|
+
}, _typeof(o);
|
|
218
|
+
}
|
|
219
|
+
function _unsupportedIterableToArray(r, a) {
|
|
220
|
+
if (r) {
|
|
221
|
+
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
222
|
+
var t = {}.toString.call(r).slice(8, -1);
|
|
223
|
+
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
|
|
224
|
+
}
|
|
245
225
|
}
|
|
246
226
|
|
|
247
227
|
/** @module triangle */
|
|
@@ -254,15 +234,16 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
254
234
|
var toRadians = function toRadians(deg) {
|
|
255
235
|
return deg / 180 * Math.PI;
|
|
256
236
|
};
|
|
237
|
+
|
|
257
238
|
/**
|
|
258
239
|
* Convert radians to degrees.
|
|
259
240
|
* @param {Number} rad value in radians
|
|
260
241
|
* @return {Number} value in degrees
|
|
261
242
|
*/
|
|
262
|
-
|
|
263
243
|
var toDegrees = function toDegrees(rad) {
|
|
264
244
|
return rad * (180 / Math.PI);
|
|
265
245
|
};
|
|
246
|
+
|
|
266
247
|
/**
|
|
267
248
|
* Solve a 90 degree triangle from two points.
|
|
268
249
|
* @param {Number} p1.x Point 1 x coordinate
|
|
@@ -271,7 +252,6 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
271
252
|
* @param {Number} p2.y Point 2 y coordinate
|
|
272
253
|
* @return {Object} A triangle object {A,B,C,a,b,c}
|
|
273
254
|
*/
|
|
274
|
-
|
|
275
255
|
var solve = function solve(p1, p2) {
|
|
276
256
|
var r = {
|
|
277
257
|
c: 90,
|
|
@@ -279,12 +259,13 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
279
259
|
B: Math.abs(p2.y - p1.y)
|
|
280
260
|
};
|
|
281
261
|
var brad = Math.atan2(r.B, r.A);
|
|
282
|
-
r.b = this.toDegrees(brad);
|
|
283
|
-
|
|
262
|
+
r.b = this.toDegrees(brad);
|
|
263
|
+
// r.C = Math.sqrt(Math.pow(r.B, 2) + Math.pow(r.A, 2));
|
|
284
264
|
r.C = r.B / Math.sin(brad);
|
|
285
265
|
r.a = 90 - r.b;
|
|
286
266
|
return r;
|
|
287
267
|
};
|
|
268
|
+
|
|
288
269
|
/**
|
|
289
270
|
* Solve a partial triangle object. Angles are in degrees.
|
|
290
271
|
* Angle `C` is set to 90 degrees. Requires a Side and an
|
|
@@ -313,43 +294,48 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
313
294
|
* @param {Number} r.c Length of side `c`
|
|
314
295
|
* @return {Object} A solved triangle object {A,B,C,a,b,c}
|
|
315
296
|
*/
|
|
316
|
-
|
|
317
297
|
var solve90SA = function solve90SA(r) {
|
|
318
298
|
r = Object.assign(r, {
|
|
319
299
|
C: 90
|
|
320
300
|
});
|
|
321
301
|
r.A = r.A || 90 - r.B;
|
|
322
302
|
r.B = r.B || 90 - r.A;
|
|
323
|
-
var arad = toRadians(r.A);
|
|
303
|
+
var arad = toRadians(r.A);
|
|
304
|
+
|
|
305
|
+
// sinA = a/c
|
|
324
306
|
// a = c * sinA
|
|
325
307
|
// tanA = a/b
|
|
326
308
|
// a = b * tanA
|
|
309
|
+
r.a = r.a || (r.c ? r.c * Math.sin(arad) : r.b * Math.tan(arad));
|
|
327
310
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
r.c = r.c || r.a / Math.sin(arad); // tanA = a/b
|
|
311
|
+
// sinA = a/c
|
|
312
|
+
r.c = r.c || r.a / Math.sin(arad);
|
|
331
313
|
|
|
314
|
+
// tanA = a/b
|
|
332
315
|
r.b = r.b || r.a / Math.tan(arad);
|
|
333
316
|
return r;
|
|
334
317
|
};
|
|
335
318
|
var solve90ac = function solve90ac(r) {
|
|
336
319
|
r = Object.assign(r, {
|
|
337
320
|
C: 90
|
|
338
|
-
});
|
|
339
|
-
// a = arcsin(a/c)
|
|
321
|
+
});
|
|
340
322
|
|
|
323
|
+
// sinA = a/c
|
|
324
|
+
// a = arcsin(a/c)
|
|
341
325
|
var arad = Math.asin(r.a / r.c);
|
|
342
326
|
r.A = toDegrees(arad);
|
|
343
|
-
r.B = 90 - r.A;
|
|
327
|
+
r.B = 90 - r.A;
|
|
328
|
+
|
|
329
|
+
// tanA = a/b
|
|
344
330
|
// r.b = r.a / Math.tan(arad);
|
|
345
331
|
// or
|
|
346
332
|
// a*a + b*b = c*c
|
|
347
333
|
// b*b = c*c - a*a
|
|
348
334
|
// b = sqr(c*c - a*a)
|
|
349
|
-
|
|
350
335
|
r.b = Math.sqrt(Math.pow(r.c, 2) - Math.pow(r.a, 2));
|
|
351
336
|
return r;
|
|
352
337
|
};
|
|
338
|
+
|
|
353
339
|
/**
|
|
354
340
|
* @function solveab
|
|
355
341
|
* Solve a partial right triangle object from two sides (a and b). Angles are in degrees.
|
|
@@ -368,16 +354,18 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
368
354
|
* @param {Number} r.b Length of side `b`
|
|
369
355
|
* @return {Object} A solved triangle object {A,B,C,a,b,c}
|
|
370
356
|
*/
|
|
371
|
-
|
|
372
357
|
function solveab(r) {
|
|
373
358
|
r = Object.assign(r, {
|
|
374
359
|
C: 90
|
|
375
|
-
});
|
|
360
|
+
});
|
|
376
361
|
|
|
377
|
-
|
|
362
|
+
// c = sqr(a*a + b*b)
|
|
363
|
+
r.c = Math.sqrt(Math.pow(r.a, 2) + Math.pow(r.b, 2));
|
|
378
364
|
|
|
379
|
-
|
|
365
|
+
// A = arcsin(a/c)
|
|
366
|
+
r.A = toDegrees(Math.asin(r.a / r.c));
|
|
380
367
|
|
|
368
|
+
// B = arcsin(b/c);
|
|
381
369
|
r.B = toDegrees(Math.asin(r.b / r.c));
|
|
382
370
|
return r;
|
|
383
371
|
}
|
|
@@ -404,11 +392,12 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
404
392
|
* @param {Number} f
|
|
405
393
|
* @memberof! array
|
|
406
394
|
*/
|
|
407
|
-
var div = function div(a, f) {
|
|
395
|
+
var div$1 = function div(a, f) {
|
|
408
396
|
return a.map(function (e) {
|
|
409
397
|
return e / f;
|
|
410
398
|
});
|
|
411
399
|
};
|
|
400
|
+
|
|
412
401
|
/**
|
|
413
402
|
* Adds a value to each element of an array of numbers.
|
|
414
403
|
* @function addValue
|
|
@@ -416,12 +405,12 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
416
405
|
* @param {Number} f A value to add to each element of the original array.
|
|
417
406
|
* @return {Array} A new array with the values added together.
|
|
418
407
|
*/
|
|
419
|
-
|
|
420
408
|
var addValue = function addValue(a, f) {
|
|
421
409
|
return a.map(function (e) {
|
|
422
410
|
return e + f;
|
|
423
411
|
});
|
|
424
412
|
};
|
|
413
|
+
|
|
425
414
|
/**
|
|
426
415
|
* Adds two arrays together. The shorter array must be the first argument.
|
|
427
416
|
*
|
|
@@ -430,19 +419,18 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
430
419
|
* @param {Array} f Another array of numbers, if
|
|
431
420
|
* @return {Array} A new array with the two values added together.
|
|
432
421
|
*/
|
|
433
|
-
|
|
434
422
|
var addArray = function addArray(a, f) {
|
|
435
423
|
return a.map(function (e, i) {
|
|
436
424
|
return e + f[i];
|
|
437
425
|
});
|
|
438
426
|
};
|
|
427
|
+
|
|
439
428
|
/**
|
|
440
429
|
* Adds a value or array to another array.
|
|
441
430
|
* @function add
|
|
442
431
|
* @param {Array} a An array of numbers .
|
|
443
432
|
* @return {Array} A new array with the two values added together.
|
|
444
433
|
*/
|
|
445
|
-
|
|
446
434
|
var add = function add(a) {
|
|
447
435
|
return Array.prototype.slice.call(arguments, 1).reduce(function (result, arg) {
|
|
448
436
|
if (Array.isArray(arg)) {
|
|
@@ -450,17 +438,16 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
450
438
|
} else {
|
|
451
439
|
result = addValue(result, arg);
|
|
452
440
|
}
|
|
453
|
-
|
|
454
441
|
return result;
|
|
455
442
|
}, a);
|
|
456
443
|
};
|
|
444
|
+
|
|
457
445
|
/**
|
|
458
446
|
* Converts an object with x, y, and z properties into
|
|
459
447
|
* an array, or an array if passed an array.
|
|
460
448
|
* @function fromxyz
|
|
461
449
|
* @param {Object|Array} object
|
|
462
450
|
*/
|
|
463
|
-
|
|
464
451
|
var fromxyz = function fromxyz(object) {
|
|
465
452
|
return Array.isArray(object) ? object : [object.x, object.y, object.z];
|
|
466
453
|
};
|
|
@@ -471,37 +458,38 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
471
458
|
z: a[2]
|
|
472
459
|
};
|
|
473
460
|
};
|
|
461
|
+
|
|
474
462
|
/**
|
|
475
463
|
* Returns the first value of an array.
|
|
476
464
|
* @function first
|
|
477
465
|
* @param {Array} a An array of numbers.
|
|
478
466
|
* @return {Number} The value of the first element of the array or undefined.
|
|
479
467
|
*/
|
|
480
|
-
|
|
481
468
|
var first = function first(a) {
|
|
482
469
|
return a ? a[0] : undefined;
|
|
483
470
|
};
|
|
471
|
+
|
|
484
472
|
/**
|
|
485
473
|
* @function last
|
|
486
474
|
* @param {Array} a An array of numbers.
|
|
487
475
|
* @return {Number} The value of the last element of the array or undefined.
|
|
488
476
|
*/
|
|
489
|
-
|
|
490
477
|
var last = function last(a) {
|
|
491
478
|
return a && a.length > 0 ? a[a.length - 1] : undefined;
|
|
492
479
|
};
|
|
480
|
+
|
|
493
481
|
/**
|
|
494
482
|
* Finds the minimum value of an array.
|
|
495
483
|
* @function min
|
|
496
484
|
* @param {Array} a An array of numbers.
|
|
497
485
|
* @return {Number} The minimum value in an array of numbers.
|
|
498
486
|
*/
|
|
499
|
-
|
|
500
487
|
var min = function min(a) {
|
|
501
488
|
return a.reduce(function (result, value) {
|
|
502
489
|
return value < result ? value : result;
|
|
503
490
|
}, Number.MAX_VALUE);
|
|
504
491
|
};
|
|
492
|
+
|
|
505
493
|
/**
|
|
506
494
|
* Creates a array of numbers given the start and end points.
|
|
507
495
|
* @function range
|
|
@@ -509,20 +497,17 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
509
497
|
* @param {Number} b The ending value.
|
|
510
498
|
* @return {Array} An array of values from `a` to `b`.
|
|
511
499
|
*/
|
|
512
|
-
|
|
513
500
|
var range = function range(a, b) {
|
|
514
501
|
var result = [];
|
|
515
|
-
|
|
516
502
|
for (var i = a; i < b; i++) {
|
|
517
503
|
result.push(i);
|
|
518
504
|
}
|
|
519
|
-
|
|
520
505
|
return result;
|
|
521
506
|
};
|
|
522
507
|
|
|
523
508
|
var array = /*#__PURE__*/Object.freeze({
|
|
524
509
|
__proto__: null,
|
|
525
|
-
div: div,
|
|
510
|
+
div: div$1,
|
|
526
511
|
addValue: addValue,
|
|
527
512
|
addArray: addArray,
|
|
528
513
|
add: add,
|
|
@@ -535,9 +520,11 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
535
520
|
});
|
|
536
521
|
|
|
537
522
|
/* globals jscadUtilsDebug */
|
|
523
|
+
|
|
538
524
|
var debugColors = ['#e41a1c', '#377eb8', '#4daf4a', '#984ea3', '#ff7f00', '#ffff33', '#a65628', '#f781bf', '#999999'];
|
|
539
525
|
var 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
526
|
var debugCount = 0;
|
|
527
|
+
|
|
541
528
|
/**
|
|
542
529
|
* Creates a function that uses `console.log` with a styled name. The name
|
|
543
530
|
* is checked against the `jscadUtilsDebug` settings `enabled` and `disabled` list.
|
|
@@ -556,7 +543,6 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
556
543
|
* @param {String} name The name of the debug function.
|
|
557
544
|
* @return {Function} A debug function if enabled otherwise an empty function.
|
|
558
545
|
*/
|
|
559
|
-
|
|
560
546
|
var Debug = function Debug(name) {
|
|
561
547
|
var checks = Object.assign({
|
|
562
548
|
enabled: [],
|
|
@@ -573,19 +559,15 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
573
559
|
});
|
|
574
560
|
var logger = enabled ? checks.options.browser ? function () {
|
|
575
561
|
var _console;
|
|
576
|
-
|
|
577
562
|
for (var _len = arguments.length, msg = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
578
563
|
msg[_key] = arguments[_key];
|
|
579
564
|
}
|
|
580
|
-
|
|
581
565
|
(_console = console).log.apply(_console, ['%c%s', style, name].concat(msg));
|
|
582
566
|
} : function () {
|
|
583
567
|
var _console2;
|
|
584
|
-
|
|
585
568
|
for (var _len2 = arguments.length, msg = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
586
569
|
msg[_key2] = arguments[_key2];
|
|
587
570
|
}
|
|
588
|
-
|
|
589
571
|
(_console2 = console).log.apply(_console2, ["".concat(name)].concat(msg));
|
|
590
572
|
} : function () {
|
|
591
573
|
return undefined;
|
|
@@ -764,7 +746,6 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
764
746
|
}
|
|
765
747
|
function hex2rgb(h) {
|
|
766
748
|
h = h.replace(/^\#/, '');
|
|
767
|
-
|
|
768
749
|
if (h.length === 6) {
|
|
769
750
|
return [parseInt(h.substr(0, 2), 16), parseInt(h.substr(2, 2), 16), parseInt(h.substr(4, 2), 16)];
|
|
770
751
|
}
|
|
@@ -777,13 +758,13 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
777
758
|
function color(o, r, g, b, a) {
|
|
778
759
|
if (typeof r !== 'string') return o.setColor(r, g, b, a);
|
|
779
760
|
if (r === '') return o; // shortcut for no color
|
|
780
|
-
|
|
781
761
|
var c = name2rgb(r).map(function (x) {
|
|
782
762
|
return x / 255;
|
|
783
763
|
});
|
|
784
764
|
c[3] = g || 1.0;
|
|
785
765
|
return o.setColor(c);
|
|
786
766
|
}
|
|
767
|
+
|
|
787
768
|
/**
|
|
788
769
|
* Initialize the Color utility. This adds a `.color()` prototype to the `CSG` object.
|
|
789
770
|
* @param {CSG} CSG The global `CSG` object
|
|
@@ -793,6 +774,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
793
774
|
// init: function init(proto) {
|
|
794
775
|
// // if (proto.setColor) {
|
|
795
776
|
// var _setColor = proto.setColor; // eslint-disable-line no-unused-vars
|
|
777
|
+
|
|
796
778
|
// /**
|
|
797
779
|
// * Set the color of a CSG object using a css color name. Also accepts the normal `setColor()` values.
|
|
798
780
|
// * @example
|
|
@@ -831,139 +813,108 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
831
813
|
* @param {proto} proto The global `proto` object
|
|
832
814
|
* @augments proto
|
|
833
815
|
*/
|
|
834
|
-
|
|
835
816
|
function init(proto) {
|
|
836
817
|
/**
|
|
837
818
|
* Short circut out if the prototypes have alrady been added.
|
|
838
819
|
*/
|
|
839
|
-
if (proto.prototype._jscadutilsinit) return;
|
|
820
|
+
if (proto.prototype._jscadutilsinit) return;
|
|
840
821
|
|
|
822
|
+
// Colors.init(proto);
|
|
841
823
|
proto.prototype.color = function (r, g, b, a) {
|
|
842
824
|
if (!r) return this; // shortcut empty color values to do nothing.
|
|
843
|
-
|
|
844
825
|
return color(this, r, g, b, a);
|
|
845
826
|
};
|
|
846
|
-
|
|
847
827
|
proto.prototype.flush = function flush$1(to, axis, mside, wside) {
|
|
848
828
|
return flush(this, to, axis, mside, wside);
|
|
849
829
|
};
|
|
850
|
-
|
|
851
830
|
proto.prototype.snap = function snap$1(to, axis, orientation, delta) {
|
|
852
831
|
return snap(this, to, axis, orientation, delta);
|
|
853
832
|
};
|
|
854
|
-
|
|
855
833
|
proto.prototype.calcSnap = function calcSnap$1(to, axis, orientation, delta) {
|
|
856
834
|
return calcSnap(this, to, axis, orientation, delta);
|
|
857
835
|
};
|
|
858
|
-
|
|
859
836
|
proto.prototype.midlineTo = function midlineTo$1(axis, to) {
|
|
860
837
|
return midlineTo(this, axis, to);
|
|
861
838
|
};
|
|
862
|
-
|
|
863
839
|
proto.prototype.calcmidlineTo = function midlineTo(axis, to) {
|
|
864
840
|
return calcmidlineTo(this, axis, to);
|
|
865
841
|
};
|
|
866
|
-
|
|
867
842
|
proto.prototype.centerWith = function centerWith$1(axis, to) {
|
|
868
843
|
depreciated('centerWith', true, 'Use align instead.');
|
|
869
844
|
return centerWith(this, axis, to);
|
|
870
845
|
};
|
|
871
|
-
|
|
872
846
|
if (proto.center) echo('proto already has .center');
|
|
873
|
-
|
|
874
847
|
proto.prototype.center = function center(axis) {
|
|
875
848
|
// console.log('center', axis, this.getBounds());
|
|
876
849
|
return centerWith(this, axis || 'xyz', unitCube());
|
|
877
850
|
};
|
|
878
|
-
|
|
879
851
|
proto.prototype.calcCenter = function centerWith(axis) {
|
|
880
852
|
return calcCenterWith(this, axis || 'xyz', unitCube(), 0);
|
|
881
853
|
};
|
|
882
|
-
|
|
883
854
|
proto.prototype.align = function align(to, axis) {
|
|
884
855
|
// console.log('align', to.getBounds(), axis);
|
|
885
856
|
return centerWith(this, axis, to);
|
|
886
857
|
};
|
|
887
|
-
|
|
888
858
|
proto.prototype.calcAlign = function calcAlign(to, axis, delta) {
|
|
889
859
|
return calcCenterWith(this, axis, to, delta);
|
|
890
860
|
};
|
|
891
|
-
|
|
892
861
|
proto.prototype.enlarge = function enlarge$1(x, y, z) {
|
|
893
862
|
return enlarge(this, x, y, z);
|
|
894
863
|
};
|
|
895
|
-
|
|
896
864
|
proto.prototype.fit = function fit$1(x, y, z, a) {
|
|
897
865
|
return fit(this, x, y, z, a);
|
|
898
866
|
};
|
|
899
|
-
|
|
900
867
|
if (proto.size) echo('proto already has .size');
|
|
901
|
-
|
|
902
868
|
proto.prototype.size = function () {
|
|
903
869
|
return size(this.getBounds());
|
|
904
870
|
};
|
|
905
|
-
|
|
906
871
|
proto.prototype.centroid = function () {
|
|
907
872
|
return centroid(this);
|
|
908
873
|
};
|
|
909
|
-
|
|
910
874
|
proto.prototype.Zero = function zero$1() {
|
|
911
875
|
return zero(this);
|
|
912
876
|
};
|
|
913
|
-
|
|
914
877
|
proto.prototype.Center = function Center(axes) {
|
|
915
878
|
return this.align(unitCube(), axes || 'xy');
|
|
916
879
|
};
|
|
917
|
-
|
|
918
880
|
proto.Vector2D.prototype.map = function Vector2D_map(cb) {
|
|
919
881
|
return new proto.Vector2D(cb(this.x), cb(this.y));
|
|
920
882
|
};
|
|
921
|
-
|
|
922
883
|
proto.prototype.fillet = function fillet$1(radius, orientation, options) {
|
|
923
884
|
return fillet(this, radius, orientation, options);
|
|
924
885
|
};
|
|
925
|
-
|
|
926
886
|
proto.prototype.chamfer = function chamfer$1(radius, orientation, options) {
|
|
927
887
|
return chamfer(this, radius, orientation, options);
|
|
928
888
|
};
|
|
929
|
-
|
|
930
889
|
proto.prototype.bisect = function bisect$1() {
|
|
931
890
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
932
891
|
args[_key] = arguments[_key];
|
|
933
892
|
}
|
|
934
|
-
|
|
935
893
|
return bisect.apply(util, [this].concat(args));
|
|
936
894
|
};
|
|
937
|
-
|
|
938
895
|
proto.prototype.slice = function slice$1() {
|
|
939
896
|
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
940
897
|
args[_key2] = arguments[_key2];
|
|
941
898
|
}
|
|
942
|
-
|
|
943
899
|
return slice.apply(util, [this].concat(args));
|
|
944
900
|
};
|
|
945
|
-
|
|
946
901
|
proto.prototype.wedge = function wedge$1() {
|
|
947
902
|
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
948
903
|
args[_key3] = arguments[_key3];
|
|
949
904
|
}
|
|
950
|
-
|
|
951
905
|
return wedge.apply(util, [this].concat(args));
|
|
952
906
|
};
|
|
953
|
-
|
|
954
907
|
proto.prototype.stretch = function stretch$1(axis, distance, offset) {
|
|
955
908
|
return stretch(this, axis, distance, offset);
|
|
956
909
|
};
|
|
957
|
-
|
|
958
910
|
proto.prototype.unionIf = function unionIf(object, condition) {
|
|
959
911
|
return condition ? this.union(result(this, object)) : this;
|
|
960
912
|
};
|
|
961
|
-
|
|
962
913
|
proto.prototype.subtractIf = function subtractIf(object, condition) {
|
|
963
914
|
return condition ? this.subtract(result(this, object)) : this;
|
|
964
915
|
};
|
|
965
|
-
|
|
966
916
|
proto.prototype._translate = proto.prototype.translate;
|
|
917
|
+
|
|
967
918
|
/**
|
|
968
919
|
* This modifies the normal `proto.translate` method to accept
|
|
969
920
|
* multiple translations, adding the translations together.
|
|
@@ -971,7 +922,6 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
971
922
|
* a short circut is applied when only one parameter is given.
|
|
972
923
|
* @return {proto} The resulting object.
|
|
973
924
|
*/
|
|
974
|
-
|
|
975
925
|
proto.prototype.translate = function translate() {
|
|
976
926
|
if (arguments.length === 1) {
|
|
977
927
|
return this._translate(arguments[0]);
|
|
@@ -980,34 +930,33 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
980
930
|
// console.log('arg', arg);
|
|
981
931
|
result = undefined(result, arg);
|
|
982
932
|
return result;
|
|
983
|
-
}, [0, 0, 0]);
|
|
933
|
+
}, [0, 0, 0]);
|
|
984
934
|
|
|
935
|
+
// console.log('translate', t);
|
|
985
936
|
return this._translate(t);
|
|
986
937
|
}
|
|
987
938
|
};
|
|
988
|
-
|
|
989
939
|
proto.prototype.addConnector = function addConnector$1(name, point, axis, normal) {
|
|
990
940
|
return addConnector(this, name, point, axis, normal);
|
|
991
941
|
};
|
|
992
|
-
|
|
993
942
|
proto.prototype.connect = function connectTo(myConnectorName, otherConnector) {
|
|
994
943
|
var mirror = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
995
944
|
var normalrotation = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
996
945
|
var myConnector = myConnectorName.split('.').reduce(function (a, v) {
|
|
997
946
|
return a[v];
|
|
998
947
|
}, this.properties);
|
|
948
|
+
|
|
999
949
|
/**
|
|
1000
950
|
* Check for missing property.
|
|
1001
951
|
*/
|
|
1002
|
-
|
|
1003
952
|
if (!myConnector) {
|
|
1004
953
|
error("The connector '".concat(myConnectorName, "' does not exist on the object [").concat(Object.keys(this.properties).join(','), "]"), 'Missing connector property');
|
|
1005
954
|
}
|
|
1006
|
-
|
|
1007
955
|
return this.connectTo(myConnector, otherConnector, mirror, normalrotation);
|
|
1008
956
|
};
|
|
957
|
+
proto.prototype._jscadutilsinit = true;
|
|
1009
958
|
|
|
1010
|
-
|
|
959
|
+
// console.trace('init', proto.prototype);
|
|
1011
960
|
}
|
|
1012
961
|
|
|
1013
962
|
var init$1 = /*#__PURE__*/Object.freeze({
|
|
@@ -1015,16 +964,17 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1015
964
|
'default': init
|
|
1016
965
|
});
|
|
1017
966
|
|
|
1018
|
-
var CSG = jsCadCSG__default[
|
|
1019
|
-
|
|
1020
|
-
var rectangular_extrude = scadApi__default[
|
|
1021
|
-
var _scadApi$text = scadApi__default[
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
var union = scadApi__default[
|
|
967
|
+
var CSG = jsCadCSG__default["default"].CSG,
|
|
968
|
+
CAG = jsCadCSG__default["default"].CAG;
|
|
969
|
+
var rectangular_extrude = scadApi__default["default"].extrusions.rectangular_extrude;
|
|
970
|
+
var _scadApi$text = scadApi__default["default"].text,
|
|
971
|
+
vector_text = _scadApi$text.vector_text,
|
|
972
|
+
vector_char = _scadApi$text.vector_char;
|
|
973
|
+
var union = scadApi__default["default"].booleanOps.union;
|
|
1025
974
|
init(CSG);
|
|
1026
975
|
|
|
1027
|
-
var debug = Debug('jscadUtils:group');
|
|
976
|
+
var debug$3 = Debug('jscadUtils:group');
|
|
977
|
+
|
|
1028
978
|
/**
|
|
1029
979
|
* @function JsCadUtilsGroup
|
|
1030
980
|
* @param {string[]} names An array of object names in the group.
|
|
@@ -1032,7 +982,6 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1032
982
|
* @param {CSG[]} holes An array of CSG objects that will be subtracted after combination.
|
|
1033
983
|
* @namespace JsCadUtilsGroup
|
|
1034
984
|
*/
|
|
1035
|
-
|
|
1036
985
|
function JsCadUtilsGroup() {
|
|
1037
986
|
var names = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
1038
987
|
var parts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
@@ -1042,6 +991,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1042
991
|
this.parts = parts;
|
|
1043
992
|
this.holes = holes;
|
|
1044
993
|
}
|
|
994
|
+
|
|
1045
995
|
/**
|
|
1046
996
|
* Add a CSG object to the current group.
|
|
1047
997
|
* @param {CSG|JsCadUtilsGroup} object Object to add the parts dictionary.
|
|
@@ -1052,17 +1002,14 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1052
1002
|
* @function add
|
|
1053
1003
|
* @memberof! JsCadUtilsGroup
|
|
1054
1004
|
*/
|
|
1055
|
-
|
|
1056
1005
|
JsCadUtilsGroup.prototype.add = function (object, name, hidden, subparts, parts) {
|
|
1057
|
-
debug('add', object, name, hidden, subparts, parts);
|
|
1006
|
+
debug$3('add', object, name, hidden, subparts, parts);
|
|
1058
1007
|
var self = this;
|
|
1059
|
-
|
|
1060
1008
|
if (object.parts) {
|
|
1061
1009
|
if (name) {
|
|
1062
1010
|
// add the combined part
|
|
1063
1011
|
if (!hidden) self.names.push(name);
|
|
1064
1012
|
self.parts[name] = object.combine(parts);
|
|
1065
|
-
|
|
1066
1013
|
if (subparts) {
|
|
1067
1014
|
Object.keys(object.parts).forEach(function (key) {
|
|
1068
1015
|
self.parts[subparts + key] = object.parts[key];
|
|
@@ -1076,9 +1023,9 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1076
1023
|
if (!hidden) self.names.push(name);
|
|
1077
1024
|
self.parts[name] = object;
|
|
1078
1025
|
}
|
|
1079
|
-
|
|
1080
1026
|
return self;
|
|
1081
1027
|
};
|
|
1028
|
+
|
|
1082
1029
|
/**
|
|
1083
1030
|
* @function combine
|
|
1084
1031
|
* @param {String} [pieces] The parts to combine, if empty, then all named parts.
|
|
@@ -1086,45 +1033,39 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1086
1033
|
* @param {Function} map A function that is run before unioning the parts together.
|
|
1087
1034
|
* @return {CSG} A single `CSG` object of the unioned parts.
|
|
1088
1035
|
*/
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
1036
|
JsCadUtilsGroup.prototype.combine = function (pieces) {
|
|
1092
1037
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1093
1038
|
var map = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function (x) {
|
|
1094
1039
|
return x;
|
|
1095
1040
|
};
|
|
1096
|
-
|
|
1097
1041
|
try {
|
|
1098
1042
|
var self = this;
|
|
1099
1043
|
options = Object.assign({
|
|
1100
1044
|
noholes: false
|
|
1101
1045
|
}, options);
|
|
1102
1046
|
pieces = pieces ? pieces.split(',') : self.names;
|
|
1103
|
-
|
|
1104
1047
|
if (pieces.length === 0) {
|
|
1105
1048
|
throw new Error("no pieces found in ".concat(self.name, " pieces: ").concat(pieces, " parts: ").concat(Object.keys(self.parts), " names: ").concat(self.names));
|
|
1106
1049
|
}
|
|
1107
|
-
|
|
1108
|
-
debug('combine', self.names, self.parts);
|
|
1050
|
+
debug$3('combine', self.names, self.parts);
|
|
1109
1051
|
var g = union(mapPick(self.parts, pieces, function (value, key, index, object) {
|
|
1110
|
-
|
|
1052
|
+
debug$3('combine mapPick', value, key, object);
|
|
1111
1053
|
return map ? map(value, key, index, object) : identity(value);
|
|
1112
1054
|
}, self.name));
|
|
1113
1055
|
return g.subtractIf(self.holes && Array.isArray(self.holes) ? union(self.holes) : self.holes, self.holes && !options.noholes);
|
|
1114
1056
|
} catch (err) {
|
|
1115
|
-
debug('combine error', this, pieces, options, err);
|
|
1057
|
+
debug$3('combine error', this, pieces, options, err);
|
|
1116
1058
|
throw error("group::combine error \"".concat(err.message || err.toString(), "\"\nthis: ").concat(this, "\npieces: \"").concat(pieces, "\"\noptions: ").concat(JSON.stringify(options, null, 2), "\nstack: ").concat(err.stack, "\n"), 'JSCAD_UTILS_GROUP_ERROR');
|
|
1117
1059
|
}
|
|
1118
1060
|
};
|
|
1061
|
+
|
|
1119
1062
|
/**
|
|
1120
1063
|
* Apply a function to each element in the group.
|
|
1121
|
-
* @param {Function} cb Callback
|
|
1064
|
+
* @param {Function} cb Callback function applied to each part.
|
|
1122
1065
|
* It is called with the parameters `(value, key)`
|
|
1123
1066
|
* @return {Object} Returns this object so it can be chained
|
|
1124
1067
|
* @function map
|
|
1125
1068
|
*/
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
1069
|
JsCadUtilsGroup.prototype.map = function (cb) {
|
|
1129
1070
|
var self = this;
|
|
1130
1071
|
self.parts = Object.keys(self.parts).filter(function (k) {
|
|
@@ -1133,7 +1074,6 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1133
1074
|
result[key] = cb(self.parts[key], key);
|
|
1134
1075
|
return result;
|
|
1135
1076
|
}, {});
|
|
1136
|
-
|
|
1137
1077
|
if (self.holes) {
|
|
1138
1078
|
if (Array.isArray(self.holes)) {
|
|
1139
1079
|
self.holes = self.holes.map(function (hole, idx) {
|
|
@@ -1143,9 +1083,9 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1143
1083
|
self.holes = cb(self.holes, 'holes');
|
|
1144
1084
|
}
|
|
1145
1085
|
}
|
|
1146
|
-
|
|
1147
1086
|
return self;
|
|
1148
1087
|
};
|
|
1088
|
+
|
|
1149
1089
|
/**
|
|
1150
1090
|
* Clone a group into a new group.
|
|
1151
1091
|
* @function clone
|
|
@@ -1153,47 +1093,41 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1153
1093
|
* @param {Function} [map] A function called on each part.
|
|
1154
1094
|
* @return {JsCadUtilsGroup} The new group.
|
|
1155
1095
|
*/
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
1096
|
JsCadUtilsGroup.prototype.clone = function (name, map) {
|
|
1159
|
-
debug('clone', name, _typeof(name), map);
|
|
1097
|
+
debug$3('clone', name, _typeof(name), map);
|
|
1160
1098
|
var self = this;
|
|
1161
1099
|
/**
|
|
1162
1100
|
* For backwards compatibility
|
|
1163
1101
|
*/
|
|
1164
|
-
|
|
1165
1102
|
if (typeof name == 'function') {
|
|
1166
1103
|
map = name;
|
|
1167
1104
|
name = undefined;
|
|
1168
1105
|
}
|
|
1106
|
+
if (!map) map = identity;
|
|
1169
1107
|
|
|
1170
|
-
|
|
1171
|
-
|
|
1108
|
+
// console.warn('clone() has been refactored');
|
|
1172
1109
|
var group = Group(name);
|
|
1173
1110
|
Object.keys(self.parts).forEach(function (key) {
|
|
1174
1111
|
var part = self.parts[key];
|
|
1175
1112
|
var hidden = self.names.indexOf(key) == -1;
|
|
1176
1113
|
group.add(map(clone(part)), key, hidden);
|
|
1177
1114
|
});
|
|
1178
|
-
|
|
1179
1115
|
if (self.holes) {
|
|
1180
1116
|
group.holes = toArray(self.holes).map(function (part) {
|
|
1181
1117
|
return map(CSG.fromPolygons(part.toPolygons()), 'holes');
|
|
1182
1118
|
});
|
|
1183
1119
|
}
|
|
1184
|
-
|
|
1185
1120
|
return group;
|
|
1186
1121
|
};
|
|
1122
|
+
|
|
1187
1123
|
/**
|
|
1188
1124
|
* Rotate the group around a solids centroid. This mutates the group.
|
|
1189
1125
|
* @param {CSG|String} solid The solid to rotate the group around
|
|
1190
1126
|
* @param {String} axis Axis to rotate
|
|
1191
1127
|
* @param {Number} angle Angle in degrees
|
|
1192
|
-
* @return {JsCadUtilsGroup} The
|
|
1128
|
+
* @return {JsCadUtilsGroup} The rotated group.
|
|
1193
1129
|
* @function rotate
|
|
1194
1130
|
*/
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
1131
|
JsCadUtilsGroup.prototype.rotate = function (solid, axis, angle) {
|
|
1198
1132
|
var self = this;
|
|
1199
1133
|
var axes = {
|
|
@@ -1201,12 +1135,10 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1201
1135
|
y: [0, 1, 0],
|
|
1202
1136
|
z: [0, 0, 1]
|
|
1203
1137
|
};
|
|
1204
|
-
|
|
1205
1138
|
if (typeof solid === 'string') {
|
|
1206
1139
|
var _names = solid;
|
|
1207
1140
|
solid = self.combine(_names);
|
|
1208
1141
|
}
|
|
1209
|
-
|
|
1210
1142
|
var rotationCenter = solid.centroid();
|
|
1211
1143
|
var rotationAxis = axes[axis];
|
|
1212
1144
|
self.map(function (part) {
|
|
@@ -1214,6 +1146,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1214
1146
|
});
|
|
1215
1147
|
return self;
|
|
1216
1148
|
};
|
|
1149
|
+
|
|
1217
1150
|
/**
|
|
1218
1151
|
* Combines all parts, named and unnamed.
|
|
1219
1152
|
* @function combineAll
|
|
@@ -1221,12 +1154,11 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1221
1154
|
* @param {Function} map A function run on each part before unioning.
|
|
1222
1155
|
* @return {CSG} A `CSG` object of all combined parts.
|
|
1223
1156
|
*/
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
1157
|
JsCadUtilsGroup.prototype.combineAll = function (options, map) {
|
|
1227
1158
|
var self = this;
|
|
1228
1159
|
return self.combine(Object.keys(self.parts).join(','), options, map);
|
|
1229
1160
|
};
|
|
1161
|
+
|
|
1230
1162
|
/**
|
|
1231
1163
|
* Snaps a named part of a group to another `CSG` objects
|
|
1232
1164
|
* bounding box.
|
|
@@ -1238,22 +1170,21 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1238
1170
|
* @param {Number} [delta=0] An offset to apply with the snap, in millimeters.
|
|
1239
1171
|
* @return {JsCadUtilsGroup} The group after snapping all parts to the `to` object.
|
|
1240
1172
|
*/
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
1173
|
JsCadUtilsGroup.prototype.snap = function snap(part, to, axis, orientation, delta) {
|
|
1244
1174
|
try {
|
|
1245
|
-
var self = this;
|
|
1246
|
-
|
|
1175
|
+
var self = this;
|
|
1176
|
+
// debug(', self);
|
|
1247
1177
|
var t = calcSnap(self.combine(part), to, axis, orientation, delta);
|
|
1248
1178
|
self.map(function (part) {
|
|
1249
1179
|
return part.translate(t);
|
|
1250
1180
|
});
|
|
1251
1181
|
return self;
|
|
1252
1182
|
} catch (err) {
|
|
1253
|
-
debug('snap error', this, part, to, axis, delta, err);
|
|
1183
|
+
debug$3('snap error', this, part, to, axis, delta, err);
|
|
1254
1184
|
throw error("group::snap error \"".concat(err.message || err.toString(), "\"\nthis: ").concat(this, "\npart: \"").concat(part, "\"\nto: ").concat(to, "\naxis: \"").concat(axis, "\"\norientation: \"").concat(orientation, "\"\ndelta: \"").concat(delta, "\"\nstack: ").concat(err.stack, "\n"), 'JSCAD_UTILS_GROUP_ERROR');
|
|
1255
1185
|
}
|
|
1256
1186
|
};
|
|
1187
|
+
|
|
1257
1188
|
/**
|
|
1258
1189
|
* Aligns all parts in a group to another `CSG` object.
|
|
1259
1190
|
* @function align
|
|
@@ -1264,45 +1195,40 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1264
1195
|
* @return {JsCadUtilsGroup} The group after aligning all parts to the `to` object.
|
|
1265
1196
|
|
|
1266
1197
|
*/
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
1198
|
JsCadUtilsGroup.prototype.align = function align(part, to, axis, delta) {
|
|
1270
1199
|
try {
|
|
1271
1200
|
var self = this;
|
|
1272
1201
|
var t = calcCenterWith(self.combine(part, {
|
|
1273
1202
|
noholes: true
|
|
1274
1203
|
}), axis, to, delta);
|
|
1275
|
-
self.map(function (part
|
|
1276
|
-
/*, name */
|
|
1277
|
-
) {
|
|
1204
|
+
self.map(function (part /*, name */) {
|
|
1278
1205
|
return part.translate(t);
|
|
1279
|
-
});
|
|
1206
|
+
});
|
|
1207
|
+
|
|
1208
|
+
// if (self.holes)
|
|
1280
1209
|
// self.holes = util.ifArray(self.holes, function(hole) {
|
|
1281
1210
|
// return hole.translate(t);
|
|
1282
1211
|
// });
|
|
1283
1212
|
|
|
1284
1213
|
return self;
|
|
1285
1214
|
} catch (err) {
|
|
1286
|
-
debug('align error', this, part, to, axis, delta, err);
|
|
1215
|
+
debug$3('align error', this, part, to, axis, delta, err);
|
|
1287
1216
|
throw error("group::align error \"".concat(err.message || err.toString(), "\"\nthis: ").concat(this, "\npart: \"").concat(part, "\"\nto: ").concat(to, "\naxis: \"").concat(axis, "\"\ndelta: \"").concat(delta, "\"\nstack: ").concat(err.stack, "\n"), 'JSCAD_UTILS_GROUP_ERROR');
|
|
1288
1217
|
}
|
|
1289
1218
|
};
|
|
1290
|
-
|
|
1291
1219
|
JsCadUtilsGroup.prototype.center = function center(part) {
|
|
1292
1220
|
var self = this;
|
|
1293
1221
|
return self.align(part, unitCube(), 'xyz');
|
|
1294
1222
|
};
|
|
1295
|
-
|
|
1296
1223
|
JsCadUtilsGroup.prototype.zero = function zero(part) {
|
|
1297
1224
|
var self = this;
|
|
1298
1225
|
var bounds = self.parts[part].getBounds();
|
|
1299
1226
|
return self.translate([0, 0, -bounds[0].z]);
|
|
1300
1227
|
};
|
|
1301
|
-
|
|
1302
1228
|
JsCadUtilsGroup.prototype.connectTo = function connectTo(partName, connectorName, to, toConnectorName) {
|
|
1303
1229
|
var mirror = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
|
|
1304
1230
|
var normalrotation = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 0;
|
|
1305
|
-
debug('connectTo', {
|
|
1231
|
+
debug$3('connectTo', {
|
|
1306
1232
|
partName: partName,
|
|
1307
1233
|
connectorName: connectorName,
|
|
1308
1234
|
to: to,
|
|
@@ -1314,17 +1240,18 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1314
1240
|
var myConnector = connectorName.split('.').reduce(function (a, v) {
|
|
1315
1241
|
return a[v];
|
|
1316
1242
|
}, self.parts[partName].properties);
|
|
1317
|
-
debug('toConnector', to instanceof CSG.Connector);
|
|
1243
|
+
debug$3('toConnector', to instanceof CSG.Connector);
|
|
1318
1244
|
var toConnector = toConnectorName.split('.').reduce(function (a, v) {
|
|
1319
1245
|
return a[v];
|
|
1320
1246
|
}, to.properties);
|
|
1321
1247
|
var matrix = myConnector.getTransformationTo(toConnector, mirror, normalrotation);
|
|
1322
|
-
debug('connectTo', matrix);
|
|
1248
|
+
debug$3('connectTo', matrix);
|
|
1323
1249
|
self.map(function (part) {
|
|
1324
1250
|
return part.transform(matrix);
|
|
1325
1251
|
});
|
|
1326
1252
|
return self;
|
|
1327
1253
|
};
|
|
1254
|
+
|
|
1328
1255
|
/**
|
|
1329
1256
|
* @function midlineTo
|
|
1330
1257
|
* @param {String} part Comma separated list of parts in the group to align.
|
|
@@ -1332,48 +1259,50 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1332
1259
|
* @param {String} axis An axis string to align on can be any combination of `x`, `y`, or `z`.
|
|
1333
1260
|
* @return {JsCadUtilsGroup} The group after aligning all parts to the `to` object.
|
|
1334
1261
|
*/
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
1262
|
JsCadUtilsGroup.prototype.midlineTo = function midlineTo(part, axis, to) {
|
|
1338
1263
|
var self = this;
|
|
1339
1264
|
var size = self.combine(part).size();
|
|
1340
1265
|
var t = axisApply(axis, function (i, a) {
|
|
1341
1266
|
return to - size[a] / 2;
|
|
1342
|
-
});
|
|
1267
|
+
});
|
|
1268
|
+
// debug(' part, t);
|
|
1343
1269
|
// var t = util.calcCenterWith(self.combine(part), axis, to, delta);
|
|
1344
|
-
|
|
1345
1270
|
self.map(function (part) {
|
|
1346
1271
|
return part.translate(t);
|
|
1347
|
-
});
|
|
1272
|
+
});
|
|
1273
|
+
|
|
1274
|
+
// if (self.holes)
|
|
1348
1275
|
// self.holes = util.ifArray(self.holes, function(hole) {
|
|
1349
1276
|
// return hole.translate(t);
|
|
1350
1277
|
// });
|
|
1351
1278
|
|
|
1352
1279
|
return self;
|
|
1353
1280
|
};
|
|
1281
|
+
|
|
1354
1282
|
/**
|
|
1355
|
-
* Translates a group by a given
|
|
1283
|
+
* Translates a group by a given amount
|
|
1356
1284
|
* @function translate
|
|
1357
1285
|
* @param {Number|Array} x The `x` value or an array of x, y and z.
|
|
1358
1286
|
* @param {Number} [y] The `y` value.
|
|
1359
1287
|
* @param {Number} [z] The `z` value.
|
|
1360
1288
|
* @return {JsCadUtilsGroup} The translated group.
|
|
1361
1289
|
*/
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
1290
|
JsCadUtilsGroup.prototype.translate = function translate(x, y, z) {
|
|
1365
1291
|
var self = this;
|
|
1366
1292
|
var t = Array.isArray(x) ? x : [x, y, z];
|
|
1367
|
-
debug('translate', t);
|
|
1293
|
+
debug$3('translate', t);
|
|
1368
1294
|
self.map(function (part) {
|
|
1369
1295
|
return part.translate(t);
|
|
1370
|
-
});
|
|
1296
|
+
});
|
|
1297
|
+
|
|
1298
|
+
// if (self.holes)
|
|
1371
1299
|
// self.holes = util.ifArray(self.holes, function(hole) {
|
|
1372
1300
|
// return hole.translate(t);
|
|
1373
1301
|
// });
|
|
1374
1302
|
|
|
1375
1303
|
return self;
|
|
1376
1304
|
};
|
|
1305
|
+
|
|
1377
1306
|
/**
|
|
1378
1307
|
* Returns a new group from the list of parts.
|
|
1379
1308
|
* @function pick
|
|
@@ -1381,8 +1310,6 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1381
1310
|
* @param {function} map A function run on each part as its added to the new group.
|
|
1382
1311
|
* @return {JsCadUtilsGroup} The new group with the picked parts.
|
|
1383
1312
|
*/
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
1313
|
JsCadUtilsGroup.prototype.pick = function (parts, map) {
|
|
1387
1314
|
var self = this;
|
|
1388
1315
|
var p = parts && parts.length > 0 && parts.split(',') || self.names;
|
|
@@ -1393,32 +1320,30 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1393
1320
|
});
|
|
1394
1321
|
return g;
|
|
1395
1322
|
};
|
|
1323
|
+
|
|
1396
1324
|
/**
|
|
1397
1325
|
* Converts a group into an array of `CSG` objects.
|
|
1398
1326
|
* @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.
|
|
1327
|
+
* @param {String} [parts] A comma separated list of parts it include in the new array.
|
|
1328
|
+
* @param {Function} [map] A function run on each part as its added to the new array.
|
|
1401
1329
|
* @return {Array} An array of `CSG` objects
|
|
1402
1330
|
*/
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
1331
|
JsCadUtilsGroup.prototype.array = function (parts, map) {
|
|
1406
1332
|
var _this = this;
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1333
|
+
var self = this;
|
|
1334
|
+
// try {
|
|
1410
1335
|
var p = parts && parts.length > 0 && parts.split(',') || self.names;
|
|
1411
1336
|
if (!map) map = identity;
|
|
1412
1337
|
var a = [];
|
|
1413
1338
|
p.forEach(function (name) {
|
|
1414
1339
|
if (!self.parts[name]) {
|
|
1415
|
-
debug('array error', _this, parts);
|
|
1340
|
+
debug$3('array error', _this, parts);
|
|
1416
1341
|
throw error("group::array error \"".concat(name, "\" not found.\nthis: ").concat(_this, "\nparts: \"").concat(parts, "\"\n"), 'JSCAD_UTILS_GROUP_ERROR');
|
|
1417
1342
|
}
|
|
1418
|
-
|
|
1419
1343
|
a.push(map(CSG.fromPolygons(self.parts[name].toPolygons()), name));
|
|
1420
1344
|
});
|
|
1421
|
-
return a;
|
|
1345
|
+
return a;
|
|
1346
|
+
// } catch (err) {
|
|
1422
1347
|
// debug('array error', this, parts, err);
|
|
1423
1348
|
// throw error(
|
|
1424
1349
|
// `group::array error "${err.message || err.toString()}"
|
|
@@ -1430,6 +1355,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1430
1355
|
// );
|
|
1431
1356
|
// }
|
|
1432
1357
|
};
|
|
1358
|
+
|
|
1433
1359
|
/**
|
|
1434
1360
|
* Converts all pieces or the picked pieces of a group into an array of `CSG`
|
|
1435
1361
|
* objects.
|
|
@@ -1438,8 +1364,6 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1438
1364
|
* @return {Array} An array of `CSG` objects.
|
|
1439
1365
|
* @deprecated Use `array` instead of `toArray`.
|
|
1440
1366
|
*/
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
1367
|
JsCadUtilsGroup.prototype.toArray = function (pieces) {
|
|
1444
1368
|
var self = this;
|
|
1445
1369
|
var piecesArray = pieces ? pieces.split(',') : self.names;
|
|
@@ -1448,15 +1372,14 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1448
1372
|
return self.parts[piece];
|
|
1449
1373
|
});
|
|
1450
1374
|
};
|
|
1451
|
-
|
|
1452
1375
|
JsCadUtilsGroup.prototype.toString = function () {
|
|
1453
|
-
return "{\n name: \"".concat(this.name, "\",\n names: \"").concat(this.names.join(','), "\", \n parts: \"").concat(Object.keys(this.parts), "\",\n holes:
|
|
1376
|
+
return "{\n name: \"".concat(this.name, "\",\n names: \"").concat(this.names.join(','), "\", \n parts: \"").concat(Object.keys(this.parts), "\",\n holes: ").concat(Array.isArray(this.holes) ? this.holes.length : this.holes ? 1 : 0, "\n}");
|
|
1454
1377
|
};
|
|
1455
|
-
|
|
1456
1378
|
JsCadUtilsGroup.prototype.setName = function (name) {
|
|
1457
1379
|
this.name = name;
|
|
1458
1380
|
return this;
|
|
1459
1381
|
};
|
|
1382
|
+
|
|
1460
1383
|
/**
|
|
1461
1384
|
* Creates a `group` object given a comma separated
|
|
1462
1385
|
* list of names, and an array or object. If an object
|
|
@@ -1465,29 +1388,25 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1465
1388
|
*
|
|
1466
1389
|
* You can call the `combine()` function with a list of parts you want combined into one.
|
|
1467
1390
|
*
|
|
1468
|
-
* The `map()`
|
|
1391
|
+
* The `map()` function allows you to modify each part
|
|
1469
1392
|
* contained in the group object.
|
|
1470
1393
|
*
|
|
1471
1394
|
* @param {string | object} [objectNames] Comma separated list of part names.
|
|
1472
1395
|
* @param {array | object} [addObjects] Array or object of parts. If Array, the names list is used as names for each part.
|
|
1473
1396
|
* @return {JsCadUtilsGroup} An object that has a parts dictionary, a `combine()` and `map()` function.
|
|
1474
1397
|
*/
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
1398
|
function Group(objectNames, addObjects) {
|
|
1478
|
-
debug('Group', objectNames, addObjects);
|
|
1399
|
+
debug$3('Group', objectNames, addObjects);
|
|
1479
1400
|
var self = {
|
|
1480
1401
|
name: '',
|
|
1481
1402
|
names: [],
|
|
1482
1403
|
parts: {}
|
|
1483
1404
|
};
|
|
1484
|
-
|
|
1485
1405
|
if (objectNames) {
|
|
1486
1406
|
if (addObjects) {
|
|
1487
1407
|
var names = objectNames;
|
|
1488
1408
|
var objects = addObjects;
|
|
1489
1409
|
self.names = names && names.length > 0 && names.split(',') || [];
|
|
1490
|
-
|
|
1491
1410
|
if (Array.isArray(objects)) {
|
|
1492
1411
|
self.parts = zipObject(self.names, objects);
|
|
1493
1412
|
} else if (objects instanceof CSG) {
|
|
@@ -1503,7 +1422,6 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1503
1422
|
self.name = objectNames;
|
|
1504
1423
|
} else {
|
|
1505
1424
|
var objects = objectNames; // eslint-disable-line no-redeclare
|
|
1506
|
-
|
|
1507
1425
|
self.names = Object.keys(objects).filter(function (k) {
|
|
1508
1426
|
return k !== 'holes';
|
|
1509
1427
|
});
|
|
@@ -1512,11 +1430,11 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1512
1430
|
}
|
|
1513
1431
|
}
|
|
1514
1432
|
}
|
|
1515
|
-
|
|
1516
1433
|
return new JsCadUtilsGroup(self.names, self.parts, self.holes);
|
|
1517
1434
|
}
|
|
1518
1435
|
|
|
1519
|
-
var debug$
|
|
1436
|
+
var debug$2 = Debug('jscadUtils:util');
|
|
1437
|
+
// import utilInit from '../src/add-prototype';
|
|
1520
1438
|
// utilInit(CSG);
|
|
1521
1439
|
// console.trace('CSG', CSG.prototype);
|
|
1522
1440
|
|
|
@@ -1535,7 +1453,6 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1535
1453
|
var nozzie = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
1536
1454
|
return (Math.floor(desired / nozzel) + nozzie) * nozzel;
|
|
1537
1455
|
},
|
|
1538
|
-
|
|
1539
1456
|
/**
|
|
1540
1457
|
* Returns the largest number that is a multipel of the
|
|
1541
1458
|
* nozzel size, just over the desired value.
|
|
@@ -1550,6 +1467,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1550
1467
|
return (Math.ceil(desired / nozzel) + nozzie) * nozzel;
|
|
1551
1468
|
}
|
|
1552
1469
|
};
|
|
1470
|
+
|
|
1553
1471
|
/**
|
|
1554
1472
|
* A function that reutrns the first argument. Useful when
|
|
1555
1473
|
* passing in a callback to modify something, and you want a
|
|
@@ -1558,10 +1476,10 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1558
1476
|
* @return {object} the first parameter passed into the function.
|
|
1559
1477
|
* @function identity
|
|
1560
1478
|
*/
|
|
1561
|
-
|
|
1562
1479
|
function identity(solid) {
|
|
1563
1480
|
return solid;
|
|
1564
1481
|
}
|
|
1482
|
+
|
|
1565
1483
|
/**
|
|
1566
1484
|
* If `f` is a funciton, it is executed with `object` as the
|
|
1567
1485
|
* parameter. This is used in `CSG.unionIf` and `CSG.subtractIf`,
|
|
@@ -1573,7 +1491,6 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1573
1491
|
* @return {object} the result of the function or the object.
|
|
1574
1492
|
* @function result
|
|
1575
1493
|
*/
|
|
1576
|
-
|
|
1577
1494
|
function result(object, f) {
|
|
1578
1495
|
if (typeof f === 'function') {
|
|
1579
1496
|
return f.call(object);
|
|
@@ -1581,6 +1498,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1581
1498
|
return f;
|
|
1582
1499
|
}
|
|
1583
1500
|
}
|
|
1501
|
+
|
|
1584
1502
|
/**
|
|
1585
1503
|
* Returns target object with default values assigned. If values already exist, they are not set.
|
|
1586
1504
|
* @param {object} target The target object to return.
|
|
@@ -1589,7 +1507,6 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1589
1507
|
* @function defaults
|
|
1590
1508
|
* @depricated
|
|
1591
1509
|
*/
|
|
1592
|
-
|
|
1593
1510
|
function defaults(target, defaults) {
|
|
1594
1511
|
depreciated('defaults', true, 'use Object.assign instead');
|
|
1595
1512
|
return Object.assign(defaults, target);
|
|
@@ -1600,6 +1517,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1600
1517
|
function isNegative(n) {
|
|
1601
1518
|
return ((n = +n) || 1 / n) < 0;
|
|
1602
1519
|
}
|
|
1520
|
+
|
|
1603
1521
|
/**
|
|
1604
1522
|
* Print a message and CSG object bounds and size to the conosle.
|
|
1605
1523
|
* @param {String} msg Message to print
|
|
@@ -1607,9 +1525,8 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1607
1525
|
* @function
|
|
1608
1526
|
* @depricated use Debug instead
|
|
1609
1527
|
*/
|
|
1610
|
-
|
|
1611
1528
|
function print(msg, o) {
|
|
1612
|
-
debug$
|
|
1529
|
+
debug$2(msg, JSON.stringify(o.getBounds()), JSON.stringify(this.size(o.getBounds())));
|
|
1613
1530
|
}
|
|
1614
1531
|
function jscadToString(o) {
|
|
1615
1532
|
if (_typeof(o) == 'object') {
|
|
@@ -1623,12 +1540,12 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1623
1540
|
}
|
|
1624
1541
|
function error(msg, name, error) {
|
|
1625
1542
|
if (console && console.error) console.error(msg, error); // eslint-disable-line no-console
|
|
1626
|
-
|
|
1627
1543
|
var err = new Error(msg);
|
|
1628
1544
|
err.name = name || 'JSCAD_UTILS_ERROR';
|
|
1629
1545
|
err._error = error;
|
|
1630
1546
|
throw err;
|
|
1631
1547
|
}
|
|
1548
|
+
|
|
1632
1549
|
/**
|
|
1633
1550
|
* Shows a warning or error message. Used to indicate a method
|
|
1634
1551
|
* has been depricated and what to use instead.
|
|
@@ -1637,41 +1554,38 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1637
1554
|
* @param {boolean} [error] Throws an error if called when true.
|
|
1638
1555
|
* @param {string} [message] Instructions on what to use instead of the depricated method.
|
|
1639
1556
|
*/
|
|
1640
|
-
|
|
1641
1557
|
function depreciated(method, error, message) {
|
|
1642
|
-
var msg = method + ' is depreciated.' + (' ' + message || '');
|
|
1643
|
-
|
|
1558
|
+
var msg = method + ' is depreciated.' + (' ' + message || '');
|
|
1559
|
+
// eslint-disable-next-line no-console
|
|
1644
1560
|
if (!error && console && console.error) console[error ? 'error' : 'warn'](msg); // eslint-disable-line no-console
|
|
1645
|
-
|
|
1646
1561
|
if (error) {
|
|
1647
1562
|
var err = new Error(msg);
|
|
1648
1563
|
err.name = 'JSCAD_UTILS_DEPRECATED';
|
|
1649
1564
|
throw err;
|
|
1650
1565
|
}
|
|
1651
1566
|
}
|
|
1567
|
+
|
|
1652
1568
|
/**
|
|
1653
1569
|
* Convert an imperial `inch` to metric `mm`.
|
|
1654
1570
|
* @param {Number} x Value in inches
|
|
1655
1571
|
* @return {Number} Result in mm
|
|
1656
1572
|
* @function inch
|
|
1657
1573
|
*/
|
|
1658
|
-
|
|
1659
1574
|
function inch(x) {
|
|
1660
1575
|
return x * 25.4;
|
|
1661
1576
|
}
|
|
1577
|
+
|
|
1662
1578
|
/**
|
|
1663
1579
|
* Convert metric `cm` to imperial `inch`.
|
|
1664
1580
|
* @param {Number} x Value in cm
|
|
1665
1581
|
* @return {Number} Result in inches
|
|
1666
1582
|
* @function cm
|
|
1667
1583
|
*/
|
|
1668
|
-
|
|
1669
1584
|
function cm(x) {
|
|
1670
1585
|
return x / 25.4;
|
|
1671
1586
|
}
|
|
1672
1587
|
function label(text, x, y, width, height) {
|
|
1673
1588
|
var l = vector_text(x || 0, y || 0, text); // l contains a list of polylines to draw
|
|
1674
|
-
|
|
1675
1589
|
var o = [];
|
|
1676
1590
|
l.forEach(function (pl) {
|
|
1677
1591
|
// pl = polyline (not closed)
|
|
@@ -1679,22 +1593,20 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1679
1593
|
w: width || 2,
|
|
1680
1594
|
h: height || 2
|
|
1681
1595
|
})); // extrude it to 3D
|
|
1682
|
-
});
|
|
1596
|
+
});
|
|
1597
|
+
// console.trace('label', Object.getPrototypeOf(union(o)));
|
|
1683
1598
|
// var foo = union(o);
|
|
1684
1599
|
// console.trace('typeof', typeof foo);
|
|
1685
|
-
|
|
1686
1600
|
return center(union(o));
|
|
1687
1601
|
}
|
|
1688
1602
|
function text(text) {
|
|
1689
1603
|
var l = vector_char(0, 0, text); // l contains a list of polylines to draw
|
|
1690
|
-
|
|
1691
1604
|
var _char = l.segments.reduce(function (result, segment) {
|
|
1692
1605
|
var path = new CSG.Path2D(segment);
|
|
1693
|
-
var cag = path.expandToCAG(2);
|
|
1694
|
-
|
|
1606
|
+
var cag = path.expandToCAG(2);
|
|
1607
|
+
// debug('reduce', result, segment, path, cag);
|
|
1695
1608
|
return result ? result.union(cag) : cag;
|
|
1696
1609
|
}, undefined);
|
|
1697
|
-
|
|
1698
1610
|
return _char;
|
|
1699
1611
|
}
|
|
1700
1612
|
function unitCube(length, radius) {
|
|
@@ -1705,7 +1617,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1705
1617
|
});
|
|
1706
1618
|
}
|
|
1707
1619
|
function unitAxis(length, radius, centroid) {
|
|
1708
|
-
debug$
|
|
1620
|
+
debug$2('unitAxis', length, radius, centroid);
|
|
1709
1621
|
centroid = centroid || [0, 0, 0];
|
|
1710
1622
|
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
1623
|
unitaxis.properties.origin = new CSG.Connector([0, 0, 0], [1, 0, 0], [0, 1, 0]);
|
|
@@ -1717,6 +1629,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1717
1629
|
function ifArray(a, cb) {
|
|
1718
1630
|
return Array.isArray(a) ? a.map(cb) : cb(a);
|
|
1719
1631
|
}
|
|
1632
|
+
|
|
1720
1633
|
/**
|
|
1721
1634
|
* Returns an array of positions along an object on a given axis.
|
|
1722
1635
|
* @param {CSG} object The object to calculate the segments on.
|
|
@@ -1725,16 +1638,13 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1725
1638
|
* @return {Array} An array of segment positions.
|
|
1726
1639
|
* @function segment
|
|
1727
1640
|
*/
|
|
1728
|
-
|
|
1729
1641
|
function segment(object, segments, axis) {
|
|
1730
1642
|
var size = object.size()[axis];
|
|
1731
1643
|
var width = size / segments;
|
|
1732
1644
|
var result = [];
|
|
1733
|
-
|
|
1734
1645
|
for (var i = width; i < size; i += width) {
|
|
1735
1646
|
result.push(i);
|
|
1736
1647
|
}
|
|
1737
|
-
|
|
1738
1648
|
return result;
|
|
1739
1649
|
}
|
|
1740
1650
|
function zipObject(names, values) {
|
|
@@ -1743,6 +1653,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1743
1653
|
return result;
|
|
1744
1654
|
}, {});
|
|
1745
1655
|
}
|
|
1656
|
+
|
|
1746
1657
|
/**
|
|
1747
1658
|
* Object map function, returns an array of the object mapped into an array.
|
|
1748
1659
|
* @param {object} o Object to map
|
|
@@ -1750,7 +1661,6 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1750
1661
|
* @return {array} an array of the mapped object.
|
|
1751
1662
|
* @function map
|
|
1752
1663
|
*/
|
|
1753
|
-
|
|
1754
1664
|
function map(o, f) {
|
|
1755
1665
|
return Object.keys(o).map(function (key) {
|
|
1756
1666
|
return f(o[key], key, o);
|
|
@@ -1772,13 +1682,12 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1772
1682
|
if (!o[name]) {
|
|
1773
1683
|
throw new Error("".concat(name, " not found in ").concat(options.name, ": ").concat(Object.keys(o).join(',')));
|
|
1774
1684
|
}
|
|
1775
|
-
|
|
1776
1685
|
result.push(f ? f(o[name], name, index, o) : o[name]);
|
|
1777
1686
|
return result;
|
|
1778
1687
|
}, []);
|
|
1779
1688
|
}
|
|
1780
1689
|
function divA(a, f) {
|
|
1781
|
-
return div(a, f);
|
|
1690
|
+
return div$1(a, f);
|
|
1782
1691
|
}
|
|
1783
1692
|
function divxyz(size, x, y, z) {
|
|
1784
1693
|
return {
|
|
@@ -1787,7 +1696,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1787
1696
|
z: size.z / z
|
|
1788
1697
|
};
|
|
1789
1698
|
}
|
|
1790
|
-
function div
|
|
1699
|
+
function div(size, d) {
|
|
1791
1700
|
return this.divxyz(size, d, d, d);
|
|
1792
1701
|
}
|
|
1793
1702
|
function mulxyz(size, x, y, z) {
|
|
@@ -1808,18 +1717,19 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1808
1717
|
y: [0, 1, 0],
|
|
1809
1718
|
z: [0, 0, 1]
|
|
1810
1719
|
};
|
|
1720
|
+
|
|
1811
1721
|
/**
|
|
1812
1722
|
* Returns a `Vector3D` with the size of the object.
|
|
1813
1723
|
* @param {CSG} o A `CSG` like object or an array of `CSG.Vector3D` objects (the result of getBounds()).
|
|
1814
1724
|
* @return {CSG.Vector3D} Vector3d with the size of the object
|
|
1815
1725
|
* @function size
|
|
1816
1726
|
*/
|
|
1817
|
-
|
|
1818
1727
|
function size(o) {
|
|
1819
1728
|
var bbox = o.getBounds ? o.getBounds() : o;
|
|
1820
1729
|
var foo = bbox[1].minus(bbox[0]);
|
|
1821
1730
|
return foo;
|
|
1822
1731
|
}
|
|
1732
|
+
|
|
1823
1733
|
/**
|
|
1824
1734
|
* Returns a scale factor (0.0-1.0) for an object
|
|
1825
1735
|
* that will resize it by a value in size units instead
|
|
@@ -1829,7 +1739,6 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1829
1739
|
* @return {number} Scale factor
|
|
1830
1740
|
* @function scale
|
|
1831
1741
|
*/
|
|
1832
|
-
|
|
1833
1742
|
function scale(size, value) {
|
|
1834
1743
|
if (value == 0) return 1;
|
|
1835
1744
|
return 1 + 100 / (size / value) / 100;
|
|
@@ -1846,6 +1755,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1846
1755
|
objectSize = objectSize || size(object.getBounds());
|
|
1847
1756
|
return object.translate([-objectSize.x / 2, 0, 0]);
|
|
1848
1757
|
}
|
|
1758
|
+
|
|
1849
1759
|
/**
|
|
1850
1760
|
* Enlarge an object by scale units, while keeping the same
|
|
1851
1761
|
* centroid. For example `enlarge(mycsg, 1, 1, 1)` enlarges
|
|
@@ -1857,16 +1767,13 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1857
1767
|
* @return {CSG} [description]
|
|
1858
1768
|
* @function enlarge
|
|
1859
1769
|
*/
|
|
1860
|
-
|
|
1861
1770
|
function enlarge(object, x, y, z) {
|
|
1862
1771
|
var a;
|
|
1863
|
-
|
|
1864
1772
|
if (Array.isArray(x)) {
|
|
1865
1773
|
a = x;
|
|
1866
1774
|
} else {
|
|
1867
1775
|
a = [x, y || x, z || x];
|
|
1868
1776
|
}
|
|
1869
|
-
|
|
1870
1777
|
var objectSize = size(object);
|
|
1871
1778
|
var objectCentroid = centroid(object, objectSize);
|
|
1872
1779
|
var idx = 0;
|
|
@@ -1874,11 +1781,13 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1874
1781
|
return scale(i, a[idx++]);
|
|
1875
1782
|
});
|
|
1876
1783
|
var new_object = object.scale(t);
|
|
1877
|
-
var new_centroid = centroid(new_object);
|
|
1784
|
+
var new_centroid = centroid(new_object);
|
|
1878
1785
|
|
|
1786
|
+
/// Calculate the difference between the original centroid and the new
|
|
1879
1787
|
var delta = new_centroid.minus(objectCentroid).times(-1);
|
|
1880
1788
|
return new_object.translate(delta);
|
|
1881
1789
|
}
|
|
1790
|
+
|
|
1882
1791
|
/**
|
|
1883
1792
|
* Fit an object inside a bounding box. Often used
|
|
1884
1793
|
* with text labels.
|
|
@@ -1890,10 +1799,8 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1890
1799
|
* @return {CSG} [description]
|
|
1891
1800
|
* @function fit
|
|
1892
1801
|
*/
|
|
1893
|
-
|
|
1894
1802
|
function fit(object, x, y, z, keep_aspect_ratio) {
|
|
1895
1803
|
var a;
|
|
1896
|
-
|
|
1897
1804
|
if (Array.isArray(x)) {
|
|
1898
1805
|
a = x;
|
|
1899
1806
|
keep_aspect_ratio = y;
|
|
@@ -1903,19 +1810,15 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1903
1810
|
} else {
|
|
1904
1811
|
a = [x, y, z];
|
|
1905
1812
|
}
|
|
1906
|
-
|
|
1907
1813
|
var objectSize = size(object.getBounds());
|
|
1908
|
-
|
|
1909
1814
|
function scale(size, value) {
|
|
1910
1815
|
if (value == 0) return 1;
|
|
1911
1816
|
return value / size;
|
|
1912
1817
|
}
|
|
1913
|
-
|
|
1914
1818
|
var s = [scale(objectSize.x, x), scale(objectSize.y, y), scale(objectSize.z, z)];
|
|
1915
1819
|
var min$1 = min(s);
|
|
1916
1820
|
return centerWith(object.scale(s.map(function (d, i) {
|
|
1917
1821
|
if (a[i] === 0) return 1; // don't scale when value is zero
|
|
1918
|
-
|
|
1919
1822
|
return keep_aspect_ratio ? min$1 : d;
|
|
1920
1823
|
})), 'xyz', object);
|
|
1921
1824
|
}
|
|
@@ -1945,7 +1848,6 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1945
1848
|
function calcFlush(moveobj, withobj, axes, mside, wside) {
|
|
1946
1849
|
depreciated('calcFlush', false, 'Use calcSnap instead.');
|
|
1947
1850
|
var side;
|
|
1948
|
-
|
|
1949
1851
|
if (mside === 0 || mside === 1) {
|
|
1950
1852
|
// wside = wside !== undefined ? wside : mside;
|
|
1951
1853
|
side = [wside !== undefined ? wside : mside, mside];
|
|
@@ -1953,14 +1855,13 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1953
1855
|
side = flushSide[mside];
|
|
1954
1856
|
if (!side) error('invalid side: ' + mside);
|
|
1955
1857
|
}
|
|
1956
|
-
|
|
1957
1858
|
var m = moveobj.getBounds();
|
|
1958
|
-
var w = withobj.getBounds();
|
|
1859
|
+
var w = withobj.getBounds();
|
|
1959
1860
|
|
|
1861
|
+
// Add centroid if needed
|
|
1960
1862
|
if (side[0] === -1) {
|
|
1961
1863
|
w[-1] = toxyz(withobj.centroid());
|
|
1962
1864
|
}
|
|
1963
|
-
|
|
1964
1865
|
return this.axisApply(axes, function (i, axis) {
|
|
1965
1866
|
return w[side[0]][axis] - m[side[1]][axis];
|
|
1966
1867
|
});
|
|
@@ -1968,7 +1869,6 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1968
1869
|
function calcSnap(moveobj, withobj, axes, orientation) {
|
|
1969
1870
|
var delta = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
|
|
1970
1871
|
var side = flushSide[orientation];
|
|
1971
|
-
|
|
1972
1872
|
if (!side) {
|
|
1973
1873
|
var fix = {
|
|
1974
1874
|
'01': 'outside+',
|
|
@@ -1980,14 +1880,13 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1980
1880
|
};
|
|
1981
1881
|
error('calcSnap: invalid side: ' + orientation + ' should be ' + fix['' + orientation + delta]);
|
|
1982
1882
|
}
|
|
1983
|
-
|
|
1984
1883
|
var m = moveobj.getBounds();
|
|
1985
|
-
var w = withobj.getBounds();
|
|
1884
|
+
var w = withobj.getBounds();
|
|
1986
1885
|
|
|
1886
|
+
// Add centroid if needed
|
|
1987
1887
|
if (side[0] === -1) {
|
|
1988
1888
|
w[-1] = withobj.centroid();
|
|
1989
1889
|
}
|
|
1990
|
-
|
|
1991
1890
|
var t = axisApply(axes, function (i, axis) {
|
|
1992
1891
|
return w[side[0]][axis] - m[side[1]][axis];
|
|
1993
1892
|
});
|
|
@@ -1996,10 +1895,11 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
1996
1895
|
}) : t;
|
|
1997
1896
|
}
|
|
1998
1897
|
function snap(moveobj, withobj, axis, orientation, delta) {
|
|
1999
|
-
debug$
|
|
1898
|
+
debug$2('snap', moveobj, withobj, axis, orientation, delta);
|
|
2000
1899
|
var t = calcSnap(moveobj, withobj, axis, orientation, delta);
|
|
2001
1900
|
return moveobj.translate(t);
|
|
2002
1901
|
}
|
|
1902
|
+
|
|
2003
1903
|
/**
|
|
2004
1904
|
* Moves an object flush with another object
|
|
2005
1905
|
* @param {CSG} moveobj Object to move
|
|
@@ -2009,12 +1909,11 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2009
1909
|
* @param {Number} wside 0 or 1
|
|
2010
1910
|
* @return {CSG} [description]
|
|
2011
1911
|
*/
|
|
2012
|
-
|
|
2013
1912
|
function flush(moveobj, withobj, axis, mside, wside) {
|
|
2014
1913
|
return moveobj.translate(calcFlush(moveobj, withobj, axis, mside, wside));
|
|
2015
1914
|
}
|
|
2016
1915
|
function axisApply(axes, valfun, a) {
|
|
2017
|
-
debug$
|
|
1916
|
+
debug$2('axisApply', axes, valfun, a);
|
|
2018
1917
|
var retval = a || [0, 0, 0];
|
|
2019
1918
|
var lookup = {
|
|
2020
1919
|
x: 0,
|
|
@@ -2049,6 +1948,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2049
1948
|
error("centroid error o:".concat(jscadToString(o), " objectSize: ").concat(objectSize), undefined, err);
|
|
2050
1949
|
}
|
|
2051
1950
|
}
|
|
1951
|
+
|
|
2052
1952
|
/**
|
|
2053
1953
|
* Calculates the transform array to move the midline of an object
|
|
2054
1954
|
* by value. This is useful when you have a diagram that provides
|
|
@@ -2059,7 +1959,6 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2059
1959
|
* @param {Number} to Value to move the midline of the object to.
|
|
2060
1960
|
* @return {Number[]} The tranform array needed to move the object.
|
|
2061
1961
|
*/
|
|
2062
|
-
|
|
2063
1962
|
function calcmidlineTo(o, axis, to) {
|
|
2064
1963
|
var bounds = o.getBounds();
|
|
2065
1964
|
var objectSize = size(bounds);
|
|
@@ -2072,8 +1971,8 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2072
1971
|
}
|
|
2073
1972
|
function translator(o, axis, withObj) {
|
|
2074
1973
|
var objectCentroid = centroid(o);
|
|
2075
|
-
var withCentroid = centroid(withObj);
|
|
2076
|
-
|
|
1974
|
+
var withCentroid = centroid(withObj);
|
|
1975
|
+
// echo('centerWith', centroid, withCentroid);
|
|
2077
1976
|
var t = axisApply(axis, function (i) {
|
|
2078
1977
|
return withCentroid[i] - objectCentroid[i];
|
|
2079
1978
|
});
|
|
@@ -2091,6 +1990,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2091
1990
|
function centerWith(o, axis, withObj) {
|
|
2092
1991
|
return o.translate(calcCenterWith(o, axis, withObj));
|
|
2093
1992
|
}
|
|
1993
|
+
|
|
2094
1994
|
/**
|
|
2095
1995
|
* Given an size, bounds and an axis, a Point
|
|
2096
1996
|
* along the axis will be returned. If no `offset`
|
|
@@ -2105,21 +2005,20 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2105
2005
|
* @param {Boolean} [nonzero] When true, no offset values under 1e-4 are allowed.
|
|
2106
2006
|
* @return {Point} The point along the axis.
|
|
2107
2007
|
*/
|
|
2108
|
-
|
|
2109
2008
|
function getDelta(size, bounds, axis, offset, nonzero) {
|
|
2110
2009
|
if (!isEmpty(offset) && nonzero) {
|
|
2111
2010
|
if (Math.abs(offset) < 1e-4) {
|
|
2112
2011
|
offset = 1e-4 * (isNegative(offset) ? -1 : 1);
|
|
2113
2012
|
}
|
|
2114
|
-
}
|
|
2013
|
+
}
|
|
2014
|
+
// if the offset is negative, then it's an offset from
|
|
2115
2015
|
// the positive side of the axis
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
2016
|
var dist = isNegative(offset) ? offset = size[axis] + offset : offset;
|
|
2119
2017
|
return axisApply(axis, function (i, a) {
|
|
2120
2018
|
return bounds[0][a] + (isEmpty(dist) ? size[axis] / 2 : dist);
|
|
2121
2019
|
});
|
|
2122
2020
|
}
|
|
2021
|
+
|
|
2123
2022
|
/**
|
|
2124
2023
|
* Cut an object into two pieces, along a given axis. The offset
|
|
2125
2024
|
* allows you to move the cut plane along the cut axis. For example,
|
|
@@ -2129,7 +2028,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2129
2028
|
*
|
|
2130
2029
|
* You can angle the cut plane and position the rotation point.
|
|
2131
2030
|
*
|
|
2132
|
-
* 
|
|
2133
2032
|
* @param {CSG} object object to bisect
|
|
2134
2033
|
* @param {string} axis axis to cut along
|
|
2135
2034
|
* @param {number} [offset] offset to cut at
|
|
@@ -2142,27 +2041,24 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2142
2041
|
* @param {CSG.Vector3D} [options.rotationCenter]
|
|
2143
2042
|
* @return {JsCadUtilsGroup} Returns a group object with a parts object.
|
|
2144
2043
|
*/
|
|
2145
|
-
|
|
2146
2044
|
function bisect() {
|
|
2147
2045
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
2148
2046
|
args[_key] = arguments[_key];
|
|
2149
2047
|
}
|
|
2150
|
-
|
|
2151
2048
|
if (args.length < 2) {
|
|
2152
2049
|
error('bisect requries an object and an axis', 'JSCAD_UTILS_INVALID_ARGS');
|
|
2153
2050
|
}
|
|
2154
|
-
|
|
2155
2051
|
var object = args[0];
|
|
2156
2052
|
var axis = args[1];
|
|
2157
2053
|
var offset,
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2054
|
+
angle = 0,
|
|
2055
|
+
rotateaxis,
|
|
2056
|
+
rotateoffset,
|
|
2057
|
+
options = {};
|
|
2058
|
+
|
|
2162
2059
|
/**
|
|
2163
2060
|
* Allow the options object to include the parameters.
|
|
2164
2061
|
*/
|
|
2165
|
-
|
|
2166
2062
|
for (var i = 2; i < args.length; i++) {
|
|
2167
2063
|
if (args[i] instanceof Object) {
|
|
2168
2064
|
options = args[i];
|
|
@@ -2175,26 +2071,21 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2175
2071
|
case 2:
|
|
2176
2072
|
offset = args[i];
|
|
2177
2073
|
break;
|
|
2178
|
-
|
|
2179
2074
|
case 3:
|
|
2180
2075
|
angle = args[i];
|
|
2181
2076
|
break;
|
|
2182
|
-
|
|
2183
2077
|
case 4:
|
|
2184
2078
|
rotateaxis = args[i];
|
|
2185
2079
|
break;
|
|
2186
|
-
|
|
2187
2080
|
case 5:
|
|
2188
2081
|
rotateoffset = args[i];
|
|
2189
2082
|
break;
|
|
2190
|
-
|
|
2191
2083
|
case 6:
|
|
2192
2084
|
options = args[i];
|
|
2193
2085
|
break;
|
|
2194
2086
|
}
|
|
2195
2087
|
}
|
|
2196
2088
|
}
|
|
2197
|
-
|
|
2198
2089
|
options = Object.assign({
|
|
2199
2090
|
addRotationCenter: false
|
|
2200
2091
|
}, options);
|
|
@@ -2222,7 +2113,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2222
2113
|
}));
|
|
2223
2114
|
var theRotationAxis = rotationAxes[rotateaxis];
|
|
2224
2115
|
var cutplane = CSG.OrthoNormalBasis.GetCartesian(info.orthoNormalCartesian[0], info.orthoNormalCartesian[1]).translate(cutDelta).rotate(rotationCenter, theRotationAxis, angle);
|
|
2225
|
-
debug$
|
|
2116
|
+
debug$2('bisect', debug$2.enabled && {
|
|
2226
2117
|
axis: axis,
|
|
2227
2118
|
offset: offset,
|
|
2228
2119
|
angle: angle,
|
|
@@ -2250,7 +2141,6 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2250
2141
|
* @param {CSG.Vector3D} [options.rotationCenter] The location of the rotation center, defaults to [0,0,0].
|
|
2251
2142
|
* @return {JsCadUtilsGroup} A group with a positive and negative CSG object.
|
|
2252
2143
|
*/
|
|
2253
|
-
|
|
2254
2144
|
function slice(object) {
|
|
2255
2145
|
var angle = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 15;
|
|
2256
2146
|
var axis = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'x';
|
|
@@ -2262,22 +2152,22 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2262
2152
|
var info = normalVector(axis);
|
|
2263
2153
|
var rotationCenter = options.rotationCenter || new CSG.Vector3D(0, 0, 0);
|
|
2264
2154
|
var theRotationAxis = rotationAxes[rotateaxis];
|
|
2265
|
-
var cutplane = CSG.OrthoNormalBasis.GetCartesian(info.orthoNormalCartesian[0], info.orthoNormalCartesian[1])
|
|
2155
|
+
var cutplane = CSG.OrthoNormalBasis.GetCartesian(info.orthoNormalCartesian[0], info.orthoNormalCartesian[1])
|
|
2156
|
+
// .translate(cutDelta)
|
|
2266
2157
|
.rotate(rotationCenter, theRotationAxis, angle);
|
|
2267
2158
|
var g = Group('negative,positive', [object.cutByPlane(cutplane.plane).color(options.color && 'red'), object.cutByPlane(cutplane.plane.flipped()).color(options.color && 'blue')]);
|
|
2268
|
-
|
|
2269
2159
|
if (options.addRotationCenter) {
|
|
2270
2160
|
var objectSize = size(object);
|
|
2271
2161
|
g.add(unitAxis(objectSize.length() + 10, 0.1, rotationCenter), 'rotationCenter');
|
|
2272
2162
|
}
|
|
2273
|
-
|
|
2274
2163
|
return g;
|
|
2275
2164
|
}
|
|
2165
|
+
|
|
2276
2166
|
/**
|
|
2277
2167
|
* Creates a `JsCadUtilsGroup` object that has `body` and `wedge` objects. The `wedge` object
|
|
2278
2168
|
* is created by radially cutting the object from the `start` to the `end` angle.
|
|
2279
2169
|
*
|
|
2280
|
-
* 
|
|
2281
2171
|
*
|
|
2282
2172
|
*
|
|
2283
2173
|
* @example
|
|
@@ -2305,7 +2195,6 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2305
2195
|
* @param {'x'|'y'|'z'} axis The axis to cut the wedge in.
|
|
2306
2196
|
* @return {JsCadUtilsGroup} A group object with a `body` and `wedge` parts.
|
|
2307
2197
|
*/
|
|
2308
|
-
|
|
2309
2198
|
function wedge(object, start, end, axis) {
|
|
2310
2199
|
var a = slice(object, start, axis);
|
|
2311
2200
|
var b = slice(a.parts.positive, end, axis);
|
|
@@ -2314,6 +2203,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2314
2203
|
wedge: b.parts.negative.color('red')
|
|
2315
2204
|
});
|
|
2316
2205
|
}
|
|
2206
|
+
|
|
2317
2207
|
/**
|
|
2318
2208
|
* Wraps the `stretchAtPlane` call using the same
|
|
2319
2209
|
* logic as `bisect`.
|
|
@@ -2323,7 +2213,6 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2323
2213
|
* @param {Number} offset Offset along the axis to cut the object
|
|
2324
2214
|
* @return {CSG} The stretched object.
|
|
2325
2215
|
*/
|
|
2326
|
-
|
|
2327
2216
|
function stretch(object, axis, distance, offset) {
|
|
2328
2217
|
var normal = {
|
|
2329
2218
|
x: [1, 0, 0],
|
|
@@ -2332,10 +2221,11 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2332
2221
|
};
|
|
2333
2222
|
var bounds = object.getBounds();
|
|
2334
2223
|
var objectSize = size(object);
|
|
2335
|
-
var cutDelta = getDelta(objectSize, bounds, axis, offset, true);
|
|
2336
|
-
|
|
2224
|
+
var cutDelta = getDelta(objectSize, bounds, axis, offset, true);
|
|
2225
|
+
// debug('stretch.cutDelta', cutDelta, normal[axis]);
|
|
2337
2226
|
return object.stretchAtPlane(normal[axis], cutDelta, distance);
|
|
2338
2227
|
}
|
|
2228
|
+
|
|
2339
2229
|
/**
|
|
2340
2230
|
* Takes two CSG polygons and creates a solid of `height`.
|
|
2341
2231
|
* Similar to `CSG.extrude`, except you can resize either
|
|
@@ -2345,18 +2235,16 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2345
2235
|
* @param {number} height height of solid
|
|
2346
2236
|
* @return {CSG} generated solid
|
|
2347
2237
|
*/
|
|
2348
|
-
|
|
2349
2238
|
function poly2solid(top, bottom, height) {
|
|
2350
2239
|
if (top.sides.length == 0) {
|
|
2351
2240
|
// empty!
|
|
2352
2241
|
return new CSG();
|
|
2353
|
-
}
|
|
2354
|
-
|
|
2355
|
-
|
|
2242
|
+
}
|
|
2243
|
+
// var offsetVector = CSG.parseOptionAs3DVector(options, "offset", [0, 0, 10]);
|
|
2356
2244
|
var offsetVector = CSG.Vector3D.Create(0, 0, height);
|
|
2357
2245
|
var normalVector = CSG.Vector3D.Create(0, 1, 0);
|
|
2358
|
-
var polygons = [];
|
|
2359
|
-
|
|
2246
|
+
var polygons = [];
|
|
2247
|
+
// bottom and top
|
|
2360
2248
|
polygons = polygons.concat(bottom._toPlanePolygons({
|
|
2361
2249
|
translation: [0, 0, 0],
|
|
2362
2250
|
normalVector: normalVector,
|
|
@@ -2366,40 +2254,38 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2366
2254
|
translation: offsetVector,
|
|
2367
2255
|
normalVector: normalVector,
|
|
2368
2256
|
flipped: offsetVector.z < 0
|
|
2369
|
-
}));
|
|
2370
|
-
|
|
2257
|
+
}));
|
|
2258
|
+
// walls
|
|
2371
2259
|
var c1 = new CSG.Connector(offsetVector.times(0), [0, 0, offsetVector.z], normalVector);
|
|
2372
2260
|
var c2 = new CSG.Connector(offsetVector, [0, 0, offsetVector.z], normalVector);
|
|
2373
2261
|
polygons = polygons.concat(bottom._toWallPolygons({
|
|
2374
2262
|
cag: top,
|
|
2375
2263
|
toConnector1: c1,
|
|
2376
2264
|
toConnector2: c2
|
|
2377
|
-
}));
|
|
2265
|
+
}));
|
|
2266
|
+
// }
|
|
2378
2267
|
|
|
2379
2268
|
return CSG.fromPolygons(polygons);
|
|
2380
2269
|
}
|
|
2381
2270
|
function slices2poly(slices, options, axis) {
|
|
2382
|
-
debug$
|
|
2271
|
+
debug$2('slices2poly', slices, options, axis);
|
|
2383
2272
|
options = Object.assign({
|
|
2384
2273
|
twistangle: 0,
|
|
2385
2274
|
twiststeps: 0
|
|
2386
2275
|
}, options);
|
|
2387
2276
|
var twistangle = options && parseFloat(options.twistangle) || 0;
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
if (twistangle == 0 || twiststeps < 1) {
|
|
2391
|
-
twiststeps = 1;
|
|
2392
|
-
}
|
|
2393
|
-
|
|
2277
|
+
options && parseInt(options.twiststeps) || CSG.defaultResolution3D;
|
|
2394
2278
|
var normalVector = options.si.normalVector;
|
|
2395
|
-
var polygons = [];
|
|
2279
|
+
var polygons = [];
|
|
2396
2280
|
|
|
2281
|
+
// bottom and top
|
|
2397
2282
|
var first$1 = first(slices);
|
|
2398
2283
|
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'.
|
|
2284
|
+
debug$2('slices2poly first', first$1, first$1.offset, 'last', last$1);
|
|
2285
|
+
var up = first$1.offset[axis] > last$1.offset[axis];
|
|
2402
2286
|
|
|
2287
|
+
// _toPlanePolygons only works in the 'z' axis. It's hard coded
|
|
2288
|
+
// to create the poly using 'x' and 'y'.
|
|
2403
2289
|
polygons = polygons.concat(first$1.poly._toPlanePolygons({
|
|
2404
2290
|
translation: first$1.offset,
|
|
2405
2291
|
normalVector: normalVector,
|
|
@@ -2410,24 +2296,27 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2410
2296
|
translation: last$1.offset,
|
|
2411
2297
|
normalVector: normalVector[rotateAxis](twistangle),
|
|
2412
2298
|
flipped: up
|
|
2413
|
-
}));
|
|
2299
|
+
}));
|
|
2414
2300
|
|
|
2301
|
+
// rotate with quick short circut
|
|
2415
2302
|
var rotate = twistangle === 0 ? function rotateZero(v) {
|
|
2416
2303
|
return v;
|
|
2417
2304
|
} : function rotate(v, angle, percent) {
|
|
2418
2305
|
return v[rotateAxis](angle * percent);
|
|
2419
|
-
};
|
|
2420
|
-
|
|
2421
|
-
var connectorAxis = last$1.offset.minus(first$1.offset).abs(); // debug('connectorAxis', connectorAxis);
|
|
2306
|
+
};
|
|
2422
2307
|
|
|
2308
|
+
// walls
|
|
2309
|
+
var connectorAxis = last$1.offset.minus(first$1.offset).abs();
|
|
2310
|
+
// debug('connectorAxis', connectorAxis);
|
|
2423
2311
|
slices.forEach(function (slice, idx) {
|
|
2424
2312
|
if (idx < slices.length - 1) {
|
|
2425
2313
|
var nextidx = idx + 1;
|
|
2426
2314
|
var top = !up ? slices[nextidx] : slice;
|
|
2427
2315
|
var bottom = up ? slices[nextidx] : slice;
|
|
2428
2316
|
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));
|
|
2317
|
+
var c2 = new CSG.Connector(top.offset, connectorAxis, rotate(normalVector, twistangle, nextidx / slices.length));
|
|
2430
2318
|
|
|
2319
|
+
// debug('slices2poly.slices', c1.point, c2.point);
|
|
2431
2320
|
polygons = polygons.concat(bottom.poly._toWallPolygons({
|
|
2432
2321
|
cag: top.poly,
|
|
2433
2322
|
toConnector1: c1,
|
|
@@ -2482,7 +2371,9 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2482
2371
|
return bounds[info.sizeIdx][a] + Math.abs(radius) * info.moveDir;
|
|
2483
2372
|
})
|
|
2484
2373
|
}, info, normalVector(axis));
|
|
2485
|
-
}
|
|
2374
|
+
}
|
|
2375
|
+
|
|
2376
|
+
// export function solidFromSlices(slices, heights) {
|
|
2486
2377
|
// var si = {
|
|
2487
2378
|
// axis: 'z',
|
|
2488
2379
|
// cutDelta: {},
|
|
@@ -2497,7 +2388,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2497
2388
|
var b = object.getBounds();
|
|
2498
2389
|
var absoluteRadius = Math.abs(radius);
|
|
2499
2390
|
var si = sliceParams(orientation, radius, b);
|
|
2500
|
-
debug$
|
|
2391
|
+
debug$2('reShape', absoluteRadius, si);
|
|
2501
2392
|
if (si.axis !== 'z') throw new Error('reShape error: CAG._toPlanePolytons only uses the "z" axis. You must use the "z" axis for now.');
|
|
2502
2393
|
var cutplane = CSG.OrthoNormalBasis.GetCartesian(si.orthoNormalCartesian[0], si.orthoNormalCartesian[1]).translate(si.cutDelta);
|
|
2503
2394
|
var slice = object.sectionCut(cutplane);
|
|
@@ -2508,7 +2399,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2508
2399
|
return si.positive ? absoluteRadius : 0;
|
|
2509
2400
|
});
|
|
2510
2401
|
var plane = si.positive ? cutplane.plane : cutplane.plane.flipped();
|
|
2511
|
-
debug$
|
|
2402
|
+
debug$2('reShape first/last', first, last);
|
|
2512
2403
|
var slices = slicer(first, last, slice, radius);
|
|
2513
2404
|
var delta = slices2poly(slices, Object.assign(options, {
|
|
2514
2405
|
si: si
|
|
@@ -2545,9 +2436,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2545
2436
|
return slices;
|
|
2546
2437
|
});
|
|
2547
2438
|
}
|
|
2548
|
-
function calcRotate(part, solid, axis
|
|
2549
|
-
/* , angle */
|
|
2550
|
-
) {
|
|
2439
|
+
function calcRotate(part, solid, axis /* , angle */) {
|
|
2551
2440
|
var axes = {
|
|
2552
2441
|
x: [1, 0, 0],
|
|
2553
2442
|
y: [0, 1, 0],
|
|
@@ -2562,29 +2451,26 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2562
2451
|
}
|
|
2563
2452
|
function rotateAround(part, solid, axis, angle) {
|
|
2564
2453
|
var _calcRotate = calcRotate(part, solid, axis),
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2454
|
+
rotationCenter = _calcRotate.rotationCenter,
|
|
2455
|
+
rotationAxis = _calcRotate.rotationAxis;
|
|
2568
2456
|
return part.rotate(rotationCenter, rotationAxis, angle);
|
|
2569
2457
|
}
|
|
2570
|
-
|
|
2571
2458
|
function cloneProperties(from, to) {
|
|
2572
2459
|
return Object.entries(from).reduce(function (props, _ref) {
|
|
2573
2460
|
var _ref2 = _slicedToArray(_ref, 2),
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2461
|
+
key = _ref2[0],
|
|
2462
|
+
value = _ref2[1];
|
|
2577
2463
|
props[key] = value;
|
|
2578
2464
|
return props;
|
|
2579
2465
|
}, to);
|
|
2580
2466
|
}
|
|
2581
|
-
|
|
2582
2467
|
function clone(o) {
|
|
2583
2468
|
var c = CSG.fromPolygons(o.toPolygons());
|
|
2584
2469
|
cloneProperties(o, c);
|
|
2585
|
-
debug$
|
|
2470
|
+
debug$2('clone', o, c, CSG);
|
|
2586
2471
|
return c;
|
|
2587
2472
|
}
|
|
2473
|
+
|
|
2588
2474
|
/**
|
|
2589
2475
|
* @function addConnector
|
|
2590
2476
|
* @param {CSG} object The object to add the connector to.
|
|
@@ -2594,7 +2480,6 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2594
2480
|
* @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
2481
|
* @return {CSG} The CSG object with the new connector added.
|
|
2596
2482
|
*/
|
|
2597
|
-
|
|
2598
2483
|
function addConnector(object, name) {
|
|
2599
2484
|
var point = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [0, 0, 0];
|
|
2600
2485
|
var axis = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [1, 0, 0];
|
|
@@ -2603,14 +2488,15 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2603
2488
|
return object;
|
|
2604
2489
|
}
|
|
2605
2490
|
|
|
2606
|
-
var debug$
|
|
2491
|
+
var debug$1 = Debug('jscadUtils:parts');
|
|
2607
2492
|
var parts = {
|
|
2608
|
-
BBox: BBox,
|
|
2493
|
+
BBox: BBox$1,
|
|
2609
2494
|
Cube: Cube,
|
|
2610
2495
|
RoundedCube: RoundedCube,
|
|
2611
2496
|
Cylinder: Cylinder,
|
|
2612
2497
|
Cone: Cone
|
|
2613
2498
|
};
|
|
2499
|
+
|
|
2614
2500
|
/**
|
|
2615
2501
|
* Returns a CSG cube object with the same extent of all
|
|
2616
2502
|
* parameters objects passed in.
|
|
@@ -2618,37 +2504,35 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2618
2504
|
* @param {CSG} ...objects Any number of CSG objects to create a bounding box for.
|
|
2619
2505
|
* @return {CSG} A box with the size of the extents of all of the passed in objects
|
|
2620
2506
|
*/
|
|
2621
|
-
|
|
2622
|
-
function BBox() {
|
|
2507
|
+
function BBox$1() {
|
|
2623
2508
|
function box(object) {
|
|
2624
2509
|
return CSG.cube({
|
|
2625
2510
|
center: object.centroid(),
|
|
2626
2511
|
radius: object.size().dividedBy(2)
|
|
2627
2512
|
});
|
|
2628
2513
|
}
|
|
2629
|
-
|
|
2630
2514
|
for (var _len = arguments.length, objects = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
2631
2515
|
objects[_key] = arguments[_key];
|
|
2632
2516
|
}
|
|
2633
|
-
|
|
2634
2517
|
return objects.reduce(function (bbox, part) {
|
|
2635
2518
|
var object = bbox ? union([bbox, box(part)]) : part;
|
|
2636
2519
|
return box(object);
|
|
2637
2520
|
}, undefined);
|
|
2638
2521
|
}
|
|
2639
2522
|
function Cube(width) {
|
|
2640
|
-
var r = div(fromxyz(width), 2);
|
|
2523
|
+
var r = div$1(fromxyz(width), 2);
|
|
2641
2524
|
return CSG.cube({
|
|
2642
2525
|
center: r,
|
|
2643
2526
|
radius: r
|
|
2644
2527
|
});
|
|
2645
|
-
}
|
|
2528
|
+
}
|
|
2529
|
+
|
|
2530
|
+
// export function Sphere(diameter) {
|
|
2646
2531
|
// return CSG.sphere({
|
|
2647
2532
|
// cener: [0, 0, 0],
|
|
2648
2533
|
// radius: diameter / 2
|
|
2649
2534
|
// });
|
|
2650
2535
|
// }
|
|
2651
|
-
|
|
2652
2536
|
/**
|
|
2653
2537
|
* Creates a cube with the `x` and `y` corners rounded. The `z` faces are flat.
|
|
2654
2538
|
* Intended to create circut boards and similar objects.
|
|
@@ -2660,7 +2544,6 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2660
2544
|
* @param {Number} [corner_radius] Radius of the corners.
|
|
2661
2545
|
* @return {CSG} A csg rounded cube.
|
|
2662
2546
|
*/
|
|
2663
|
-
|
|
2664
2547
|
function RoundedCube(x, y, thickness, corner_radius) {
|
|
2665
2548
|
if (x.getBounds) {
|
|
2666
2549
|
var size$1 = size(x.getBounds());
|
|
@@ -2670,8 +2553,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2670
2553
|
} else {
|
|
2671
2554
|
var r = [x / 2, y / 2]; // eslint-disable-line no-redeclare
|
|
2672
2555
|
}
|
|
2673
|
-
|
|
2674
|
-
debug$2('RoundedCube', size$1, r, thickness, corner_radius);
|
|
2556
|
+
debug$1('RoundedCube', size$1, r, thickness, corner_radius);
|
|
2675
2557
|
var roundedcube = CAG.roundedRectangle({
|
|
2676
2558
|
center: [r[0], r[1], 0],
|
|
2677
2559
|
radius: r,
|
|
@@ -2682,6 +2564,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2682
2564
|
});
|
|
2683
2565
|
return roundedcube;
|
|
2684
2566
|
}
|
|
2567
|
+
|
|
2685
2568
|
/**
|
|
2686
2569
|
* A Cylinder primative located at the origin.
|
|
2687
2570
|
* @param {Number} diameter Diameter of the cylinder
|
|
@@ -2690,10 +2573,9 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2690
2573
|
* @param {number} [options.resolution] The number of segments to create in 360 degrees of rotation.
|
|
2691
2574
|
* @return {CSG} A CSG Cylinder
|
|
2692
2575
|
*/
|
|
2693
|
-
|
|
2694
2576
|
function Cylinder(diameter, height) {
|
|
2695
2577
|
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
2696
|
-
debug$
|
|
2578
|
+
debug$1('parts.Cylinder', diameter, height, options);
|
|
2697
2579
|
options = Object.assign({
|
|
2698
2580
|
start: [0, 0, 0],
|
|
2699
2581
|
end: [0, 0, height],
|
|
@@ -2702,6 +2584,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2702
2584
|
}, options);
|
|
2703
2585
|
return CSG.cylinder(options);
|
|
2704
2586
|
}
|
|
2587
|
+
|
|
2705
2588
|
/**
|
|
2706
2589
|
* Creats a cone.
|
|
2707
2590
|
* @function Cone
|
|
@@ -2711,10 +2594,9 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2711
2594
|
* @param {Object} options Additional options passed to `CSG.cylinder`.
|
|
2712
2595
|
* @return {CSG} A CSG cone object.
|
|
2713
2596
|
*/
|
|
2714
|
-
|
|
2715
2597
|
function Cone(diameter1, diameter2, height) {
|
|
2716
2598
|
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
2717
|
-
debug$
|
|
2599
|
+
debug$1('parts.Cone', diameter1, diameter2, height, options);
|
|
2718
2600
|
return CSG.cylinder(Object.assign({
|
|
2719
2601
|
start: [0, 0, 0],
|
|
2720
2602
|
end: [0, 0, height],
|
|
@@ -2723,14 +2605,14 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2723
2605
|
resolution: CSG.defaultResolution2D
|
|
2724
2606
|
}, options));
|
|
2725
2607
|
}
|
|
2608
|
+
|
|
2726
2609
|
/**
|
|
2727
2610
|
* Creates a hexagon.
|
|
2728
2611
|
* @param {number} diameter Outside diameter of the hexagon
|
|
2729
2612
|
* @param {number} height height of the hexagon
|
|
2730
2613
|
*/
|
|
2731
|
-
|
|
2732
2614
|
function Hexagon(diameter, height) {
|
|
2733
|
-
debug$
|
|
2615
|
+
debug$1('hexagon', diameter, height);
|
|
2734
2616
|
var radius = diameter / 2;
|
|
2735
2617
|
var sqrt3 = Math.sqrt(3) / 2;
|
|
2736
2618
|
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 +2620,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2738
2620
|
offset: [0, 0, height]
|
|
2739
2621
|
});
|
|
2740
2622
|
}
|
|
2623
|
+
|
|
2741
2624
|
/**
|
|
2742
2625
|
* Creats a 3 sided prisim
|
|
2743
2626
|
* @function Triangle
|
|
@@ -2745,7 +2628,6 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2745
2628
|
* @param {Number} height The height of the prisim.
|
|
2746
2629
|
* @return {CSG} A prisim object.
|
|
2747
2630
|
*/
|
|
2748
|
-
|
|
2749
2631
|
function Triangle(base, height) {
|
|
2750
2632
|
var radius = base / 2;
|
|
2751
2633
|
var tri = CAG.fromPoints([[-radius, 0], [radius, 0], [0, Math.sin(30) * radius]]);
|
|
@@ -2753,6 +2635,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2753
2635
|
offset: [0, 0, height]
|
|
2754
2636
|
});
|
|
2755
2637
|
}
|
|
2638
|
+
|
|
2756
2639
|
/**
|
|
2757
2640
|
* Create a tube
|
|
2758
2641
|
* @param {Number} outsideDiameter Outside diameter of the tube.
|
|
@@ -2764,16 +2647,15 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2764
2647
|
* @param {number} [insideOptions.resolution] The resolution option determines the number of segments to create in 360 degrees of rotation.
|
|
2765
2648
|
* @returns {CSG} A CSG Tube
|
|
2766
2649
|
*/
|
|
2767
|
-
|
|
2768
2650
|
function Tube(outsideDiameter, insideDiameter, height, outsideOptions, insideOptions) {
|
|
2769
2651
|
return Cylinder(outsideDiameter, height, outsideOptions).subtract(Cylinder(insideDiameter, height, insideOptions || outsideOptions));
|
|
2770
2652
|
}
|
|
2653
|
+
|
|
2771
2654
|
/**
|
|
2772
2655
|
*
|
|
2773
2656
|
* @param {Number} width
|
|
2774
2657
|
* @param {Number} height
|
|
2775
2658
|
*/
|
|
2776
|
-
|
|
2777
2659
|
function Anchor() {
|
|
2778
2660
|
var width = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 10;
|
|
2779
2661
|
var height = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10;
|
|
@@ -2818,14 +2700,11 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2818
2700
|
head: head.color('gray'),
|
|
2819
2701
|
thread: thread.snap(head, 'z', orientation.head).color('silver')
|
|
2820
2702
|
});
|
|
2821
|
-
|
|
2822
2703
|
if (headClearSpace) {
|
|
2823
2704
|
group.add(headClearSpace.enlarge(options.clearance).snap(head, 'z', orientation.clear).color('red'), 'headClearSpace', true);
|
|
2824
2705
|
}
|
|
2825
|
-
|
|
2826
2706
|
return group;
|
|
2827
2707
|
},
|
|
2828
|
-
|
|
2829
2708
|
/**
|
|
2830
2709
|
* Creates a `Group` object with a Pan Head Screw.
|
|
2831
2710
|
* @param {number} headDiameter Diameter of the head of the screw
|
|
@@ -2839,14 +2718,11 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2839
2718
|
depreciated('PanHeadScrew', false, 'Use the jscad-hardware screw methods instead');
|
|
2840
2719
|
var head = Cylinder(headDiameter, headLength);
|
|
2841
2720
|
var thread = Cylinder(diameter, length);
|
|
2842
|
-
|
|
2843
2721
|
if (clearLength) {
|
|
2844
2722
|
var headClearSpace = Cylinder(headDiameter, clearLength);
|
|
2845
2723
|
}
|
|
2846
|
-
|
|
2847
2724
|
return Hardware.Screw(head, thread, headClearSpace, options);
|
|
2848
2725
|
},
|
|
2849
|
-
|
|
2850
2726
|
/**
|
|
2851
2727
|
* Creates a `Group` object with a Hex Head Screw.
|
|
2852
2728
|
* @param {number} headDiameter Diameter of the head of the screw
|
|
@@ -2860,14 +2736,11 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2860
2736
|
depreciated('HexHeadScrew', false, 'Use the jscad-hardware screw methods instead');
|
|
2861
2737
|
var head = Hexagon(headDiameter, headLength);
|
|
2862
2738
|
var thread = Cylinder(diameter, length);
|
|
2863
|
-
|
|
2864
2739
|
if (clearLength) {
|
|
2865
2740
|
var headClearSpace = Hexagon(headDiameter, clearLength);
|
|
2866
2741
|
}
|
|
2867
|
-
|
|
2868
2742
|
return Hardware.Screw(head, thread, headClearSpace, options);
|
|
2869
2743
|
},
|
|
2870
|
-
|
|
2871
2744
|
/**
|
|
2872
2745
|
* Create a Flat Head Screw
|
|
2873
2746
|
* @param {number} headDiameter head diameter
|
|
@@ -2879,14 +2752,12 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2879
2752
|
*/
|
|
2880
2753
|
FlatHeadScrew: function FlatHeadScrew(headDiameter, headLength, diameter, length, clearLength, options) {
|
|
2881
2754
|
depreciated('FlatHeadScrew', false, 'Use the jscad-hardware screw methods instead');
|
|
2882
|
-
var head = Cone(headDiameter, diameter, headLength);
|
|
2883
|
-
|
|
2755
|
+
var head = Cone(headDiameter, diameter, headLength);
|
|
2756
|
+
// var head = Cylinder(headDiameter, headLength);
|
|
2884
2757
|
var thread = Cylinder(diameter, length);
|
|
2885
|
-
|
|
2886
2758
|
if (clearLength) {
|
|
2887
2759
|
var headClearSpace = Cylinder(headDiameter, clearLength);
|
|
2888
2760
|
}
|
|
2889
|
-
|
|
2890
2761
|
return Hardware.Screw(head, thread, headClearSpace, options);
|
|
2891
2762
|
}
|
|
2892
2763
|
};
|
|
@@ -2894,7 +2765,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2894
2765
|
var parts$1 = /*#__PURE__*/Object.freeze({
|
|
2895
2766
|
__proto__: null,
|
|
2896
2767
|
'default': parts,
|
|
2897
|
-
BBox: BBox,
|
|
2768
|
+
BBox: BBox$1,
|
|
2898
2769
|
Cube: Cube,
|
|
2899
2770
|
RoundedCube: RoundedCube,
|
|
2900
2771
|
Cylinder: Cylinder,
|
|
@@ -2907,14 +2778,14 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2907
2778
|
Hardware: Hardware
|
|
2908
2779
|
});
|
|
2909
2780
|
|
|
2910
|
-
var debug
|
|
2781
|
+
var debug = Debug('jscadUtils:boxes');
|
|
2782
|
+
|
|
2911
2783
|
/** @typedef {import("./group").JsCadUtilsGroup} JsCadUtilsGroup */
|
|
2912
2784
|
|
|
2913
2785
|
/**
|
|
2914
2786
|
* jscad box and join utilities. This should be considered experimental,
|
|
2915
2787
|
* but there are some useful utilities here.
|
|
2916
2788
|
*/
|
|
2917
|
-
|
|
2918
2789
|
/**
|
|
2919
2790
|
* Create a [rabbet joint](https://en.wikipedia.org/wiki/Rabbet) in a CSG solid.
|
|
2920
2791
|
* This was designed for cubes, but should work on other types of objects.
|
|
@@ -2929,11 +2800,11 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2929
2800
|
* @function RabbetJoin
|
|
2930
2801
|
* @deprecated Use `Rabbet` instead.
|
|
2931
2802
|
*/
|
|
2932
|
-
|
|
2933
2803
|
function RabbetJoin(box, thickness, cutHeight) {
|
|
2934
2804
|
depreciated('RabbetJoin', true, "Use 'Rabbet' instead");
|
|
2935
2805
|
return rabbetJoin(box, thickness, cutHeight);
|
|
2936
2806
|
}
|
|
2807
|
+
|
|
2937
2808
|
/**
|
|
2938
2809
|
* Cuts a CSG object into three parts, a top and bottom of `thickness`
|
|
2939
2810
|
* height, and the remaining middle.
|
|
@@ -2942,20 +2813,20 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2942
2813
|
* @param {Number} thickness The thickness of the top and bottom parts.
|
|
2943
2814
|
* @return {JsCadUtilsGroup} A `Group` object with the `top`, `middle` and `bottom` parts.
|
|
2944
2815
|
*/
|
|
2945
|
-
|
|
2946
2816
|
function topMiddleBottom(box, thickness) {
|
|
2947
|
-
debug
|
|
2817
|
+
debug('TopMiddleBottom', box, thickness);
|
|
2948
2818
|
var bottom = box.bisect('z', thickness, {
|
|
2949
2819
|
color: true
|
|
2950
2820
|
});
|
|
2951
2821
|
var top = bottom.parts.positive.bisect('z', -thickness);
|
|
2952
2822
|
return Group('top,middle,bottom', [top.parts.positive, top.parts.negative.color('green'), bottom.parts.negative]);
|
|
2953
2823
|
}
|
|
2824
|
+
|
|
2954
2825
|
/**
|
|
2955
2826
|
* This will bisect an object using a rabett join. Returns a
|
|
2956
2827
|
* `group` object with `positive` and `negative` parts.
|
|
2957
2828
|
*
|
|
2958
|
-
* * 
|
|
2959
2830
|
* @example
|
|
2960
2831
|
*include('dist/jscad-utils.jscad');
|
|
2961
2832
|
*
|
|
@@ -2979,28 +2850,29 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
2979
2850
|
* @param {Number} face Size of the join face.
|
|
2980
2851
|
* @return {JsCadUtilsGroup} A group object with `positive`, `negative` parts.
|
|
2981
2852
|
*/
|
|
2982
|
-
|
|
2983
2853
|
function Rabett(box, thickness, gap, height, face) {
|
|
2984
2854
|
var options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
|
|
2985
|
-
debug
|
|
2855
|
+
debug('Rabett', 'thickness', thickness, 'gap', gap, 'height', height, 'face', face);
|
|
2986
2856
|
gap = gap || 0.25;
|
|
2987
2857
|
var inside = thickness - gap;
|
|
2988
|
-
var outside = -thickness + gap;
|
|
2989
|
-
|
|
2990
|
-
debug
|
|
2991
|
-
var group = Group();
|
|
2992
|
-
|
|
2858
|
+
var outside = -thickness + gap;
|
|
2859
|
+
// options.color = true;
|
|
2860
|
+
debug('inside', inside, 'outside', outside);
|
|
2861
|
+
var group = Group();
|
|
2862
|
+
// debug('Rabbet top height:', height, 'options:', options);
|
|
2993
2863
|
var _box$bisect$parts = box.bisect('z', height, options).parts,
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
var lowerBisectHeight = Math.sign(height) < 0 ? face * Math.sign(height) : height - face; // debug('Rabbet bottom height:', lowerBisectHeight, 'options:', options);
|
|
2864
|
+
top = _box$bisect$parts.positive,
|
|
2865
|
+
lower2_3rd = _box$bisect$parts.negative;
|
|
2998
2866
|
|
|
2867
|
+
// debug('face', face, 'height', height);
|
|
2868
|
+
var lowerBisectHeight = Math.sign(height) < 0 ? face * Math.sign(height) : height - face;
|
|
2869
|
+
// debug('Rabbet bottom height:', lowerBisectHeight, 'options:', options);
|
|
2999
2870
|
var _lower2_3rd$bisect$pa = lower2_3rd.bisect('z', lowerBisectHeight, options).parts,
|
|
3000
|
-
|
|
3001
|
-
|
|
2871
|
+
middle = _lower2_3rd$bisect$pa.positive,
|
|
2872
|
+
bottom = _lower2_3rd$bisect$pa.negative;
|
|
3002
2873
|
var middleTop = middle.color('yellow').subtract(middle.color('darkred').enlarge([outside, outside, 0]));
|
|
3003
|
-
group.add(top
|
|
2874
|
+
group.add(top
|
|
2875
|
+
// .color('blue')
|
|
3004
2876
|
.union(middleTop), 'top');
|
|
3005
2877
|
var bottomOutline = middle.color('yellow').subtract(middle.color('orange').enlarge([outside, outside, 0])).enlarge([outside, outside, 0]);
|
|
3006
2878
|
group.add(bottomOutline, 'middle-top', true);
|
|
@@ -3008,6 +2880,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
3008
2880
|
group.add(bottom.color('orange').union(middle.color('green').subtract(middle.color('red').enlarge([inside, inside, 0])).subtract(middleTop)), 'bottom');
|
|
3009
2881
|
return group;
|
|
3010
2882
|
}
|
|
2883
|
+
|
|
3011
2884
|
/**
|
|
3012
2885
|
* Used on a hollow object, this will rabett out the top and/or
|
|
3013
2886
|
* bottom of the object.
|
|
@@ -3040,7 +2913,6 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
3040
2913
|
* @return {JsCadUtilsGroup} An A hollow version of the original object..
|
|
3041
2914
|
* @memberof module:Boxes
|
|
3042
2915
|
*/
|
|
3043
|
-
|
|
3044
2916
|
var RabettTopBottom = function rabbetTMB(box, thickness) {
|
|
3045
2917
|
var gap = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0.25;
|
|
3046
2918
|
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
@@ -3050,13 +2922,12 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
3050
2922
|
topWidth: -thickness,
|
|
3051
2923
|
bottomWidth: thickness
|
|
3052
2924
|
}, options);
|
|
3053
|
-
debug
|
|
2925
|
+
debug('RabettTopBottom', box, thickness, gap, options);
|
|
3054
2926
|
var group = Group('', {
|
|
3055
2927
|
box: box
|
|
3056
2928
|
});
|
|
3057
2929
|
var inside = -thickness - gap;
|
|
3058
2930
|
var outside = -thickness + gap;
|
|
3059
|
-
|
|
3060
2931
|
if (options.removableTop) {
|
|
3061
2932
|
var top = box.bisect('z', options.topWidth, {
|
|
3062
2933
|
color: true
|
|
@@ -3064,7 +2935,6 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
3064
2935
|
group.add(top.parts.positive.enlarge([inside, inside, 0]), 'top');
|
|
3065
2936
|
if (!options.removableBottom) group.add(box.subtract(top.parts.positive.enlarge([outside, outside, 0])), 'bottom');
|
|
3066
2937
|
}
|
|
3067
|
-
|
|
3068
2938
|
if (options.removableBottom) {
|
|
3069
2939
|
var bottom = box.bisect('z', options.bottomWidth, {
|
|
3070
2940
|
color: true
|
|
@@ -3073,17 +2943,15 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
3073
2943
|
group.add(bottom.parts.negative.enlarge([inside, inside, 0]), 'bottom');
|
|
3074
2944
|
if (!options.removableTop) group.add(box.subtract(group.parts.bottomCutout), 'top');
|
|
3075
2945
|
}
|
|
3076
|
-
|
|
3077
2946
|
if (options.removableBottom && options.removableTop) {
|
|
3078
2947
|
group.add(box.subtract(union([bottom.parts.negative.enlarge([outside, outside, 0]), top.parts.positive.enlarge([outside, outside, 0])])), 'middle');
|
|
3079
2948
|
}
|
|
3080
|
-
|
|
3081
2949
|
return group;
|
|
3082
2950
|
};
|
|
3083
2951
|
var CutOut = function cutOut(o, h, box, plug, gap) {
|
|
3084
|
-
gap = gap || 0.25;
|
|
2952
|
+
gap = gap || 0.25;
|
|
2953
|
+
// console.log('cutOut', o.size(), h, b.size());
|
|
3085
2954
|
// var r = getRadius(o);
|
|
3086
|
-
|
|
3087
2955
|
var s = o.size();
|
|
3088
2956
|
var cutout = o.intersect(box);
|
|
3089
2957
|
var cs = o.size();
|
|
@@ -3102,7 +2970,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
3102
2970
|
};
|
|
3103
2971
|
var Rectangle = function Rectangle(size, thickness, cb) {
|
|
3104
2972
|
thickness = thickness || 2;
|
|
3105
|
-
var s = div(xyz2array(size), 2);
|
|
2973
|
+
var s = div$1(xyz2array(size), 2);
|
|
3106
2974
|
var r = add(s, thickness);
|
|
3107
2975
|
var box = CSG.cube({
|
|
3108
2976
|
center: r,
|
|
@@ -3111,10 +2979,12 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
3111
2979
|
center: r,
|
|
3112
2980
|
radius: s
|
|
3113
2981
|
}));
|
|
3114
|
-
if (cb) box = cb(box);
|
|
2982
|
+
if (cb) box = cb(box);
|
|
3115
2983
|
|
|
2984
|
+
// return rabbetTMB(box.color('gray'), thickness, gap, options);
|
|
3116
2985
|
return box;
|
|
3117
2986
|
};
|
|
2987
|
+
|
|
3118
2988
|
/**
|
|
3119
2989
|
* Takes a solid object and returns a hollow version with a selected
|
|
3120
2990
|
* wall thickness. This is done by reducing the object by half the
|
|
@@ -3129,7 +2999,6 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
3129
2999
|
* @return {CSG} An A hollow version of the original object..
|
|
3130
3000
|
* @memberof module:Boxes
|
|
3131
3001
|
*/
|
|
3132
|
-
|
|
3133
3002
|
var Hollow = function Hollow(object, thickness, interiorcb, exteriorcb) {
|
|
3134
3003
|
thickness = thickness || 2;
|
|
3135
3004
|
var size = -thickness * 2;
|
|
@@ -3138,6 +3007,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
3138
3007
|
if (exteriorcb) box = exteriorcb(box);
|
|
3139
3008
|
return box;
|
|
3140
3009
|
};
|
|
3010
|
+
|
|
3141
3011
|
/**
|
|
3142
3012
|
* Create a box that surounds the object.
|
|
3143
3013
|
* @param {CSG} o The object to create a bounding box for.
|
|
@@ -3145,20 +3015,17 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
3145
3015
|
* @deprecated use parts.BBox
|
|
3146
3016
|
* @memberof module:Boxes
|
|
3147
3017
|
*/
|
|
3148
|
-
|
|
3149
|
-
var BBox$1 = function BBox(o) {
|
|
3018
|
+
var BBox = function BBox(o) {
|
|
3150
3019
|
depreciated('BBox', true, "Use 'parts.BBox' instead");
|
|
3151
|
-
var s = div(xyz2array(o.size()), 2);
|
|
3020
|
+
var s = div$1(xyz2array(o.size()), 2);
|
|
3152
3021
|
return CSG.cube({
|
|
3153
3022
|
center: s,
|
|
3154
3023
|
radius: s
|
|
3155
3024
|
}).align(o, 'xyz');
|
|
3156
3025
|
};
|
|
3157
|
-
|
|
3158
3026
|
function getRadius(o) {
|
|
3159
|
-
return div(xyz2array(o.size()), 2);
|
|
3027
|
+
return div$1(xyz2array(o.size()), 2);
|
|
3160
3028
|
}
|
|
3161
|
-
|
|
3162
3029
|
function rabbetJoin(box, thickness) {
|
|
3163
3030
|
var gap = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0.25;
|
|
3164
3031
|
var r = add(getRadius(box), -thickness / 2);
|
|
@@ -3186,7 +3053,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
3186
3053
|
CutOut: CutOut,
|
|
3187
3054
|
Rectangle: Rectangle,
|
|
3188
3055
|
Hollow: Hollow,
|
|
3189
|
-
BBox: BBox
|
|
3056
|
+
BBox: BBox
|
|
3190
3057
|
});
|
|
3191
3058
|
|
|
3192
3059
|
var compatV1 = _objectSpread2(_objectSpread2({}, util), {}, {
|
|
@@ -3209,9 +3076,11 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
|
|
|
3209
3076
|
exports.triUtils = triUtils;
|
|
3210
3077
|
exports.util = util;
|
|
3211
3078
|
|
|
3079
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3080
|
+
|
|
3212
3081
|
return exports;
|
|
3213
3082
|
|
|
3214
|
-
}({}, jsCadCSG, scadApi)
|
|
3083
|
+
})({}, jsCadCSG, scadApi);
|
|
3215
3084
|
|
|
3216
3085
|
// endinject
|
|
3217
3086
|
|