@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/examples/size.jscad
CHANGED
|
@@ -146,7 +146,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
146
146
|
return divxyz;
|
|
147
147
|
},
|
|
148
148
|
get div() {
|
|
149
|
-
return div
|
|
149
|
+
return div;
|
|
150
150
|
},
|
|
151
151
|
get mulxyz() {
|
|
152
152
|
return mulxyz;
|
|
@@ -278,104 +278,98 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
278
278
|
return addConnector;
|
|
279
279
|
}
|
|
280
280
|
});
|
|
281
|
-
function
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
keys.push.apply(keys, symbols);
|
|
315
|
-
}
|
|
316
|
-
return keys;
|
|
317
|
-
}
|
|
318
|
-
function _objectSpread2(target) {
|
|
319
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
320
|
-
var source = arguments[i] != null ? arguments[i] : {};
|
|
321
|
-
if (i % 2) {
|
|
322
|
-
ownKeys(Object(source), true).forEach((function(key) {
|
|
323
|
-
_defineProperty(target, key, source[key]);
|
|
324
|
-
}));
|
|
325
|
-
} else if (Object.getOwnPropertyDescriptors) {
|
|
326
|
-
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
327
|
-
} else {
|
|
328
|
-
ownKeys(Object(source)).forEach((function(key) {
|
|
329
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
330
|
-
}));
|
|
281
|
+
function _arrayLikeToArray(r, a) {
|
|
282
|
+
(null == a || a > r.length) && (a = r.length);
|
|
283
|
+
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
284
|
+
return n;
|
|
285
|
+
}
|
|
286
|
+
function _arrayWithHoles(r) {
|
|
287
|
+
if (Array.isArray(r)) return r;
|
|
288
|
+
}
|
|
289
|
+
function _defineProperty(e, r, t) {
|
|
290
|
+
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
291
|
+
value: t,
|
|
292
|
+
enumerable: !0,
|
|
293
|
+
configurable: !0,
|
|
294
|
+
writable: !0
|
|
295
|
+
}) : e[r] = t, e;
|
|
296
|
+
}
|
|
297
|
+
function _iterableToArrayLimit(r, l) {
|
|
298
|
+
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
299
|
+
if (null != t) {
|
|
300
|
+
var e, n, i, u, a = [], f = !0, o = !1;
|
|
301
|
+
try {
|
|
302
|
+
if (i = (t = t.call(r)).next, 0 === l) {
|
|
303
|
+
if (Object(t) !== t) return;
|
|
304
|
+
f = !1;
|
|
305
|
+
} else for (;!(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0) ;
|
|
306
|
+
} catch (r) {
|
|
307
|
+
o = !0, n = r;
|
|
308
|
+
} finally {
|
|
309
|
+
try {
|
|
310
|
+
if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
|
|
311
|
+
} finally {
|
|
312
|
+
if (o) throw n;
|
|
313
|
+
}
|
|
331
314
|
}
|
|
315
|
+
return a;
|
|
332
316
|
}
|
|
333
|
-
return target;
|
|
334
317
|
}
|
|
335
|
-
function
|
|
336
|
-
|
|
337
|
-
}
|
|
338
|
-
function _arrayWithHoles(arr) {
|
|
339
|
-
if (Array.isArray(arr)) return arr;
|
|
318
|
+
function _nonIterableRest() {
|
|
319
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
340
320
|
}
|
|
341
|
-
function
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
|
|
349
|
-
_arr.push(_s.value);
|
|
350
|
-
if (i && _arr.length === i) break;
|
|
351
|
-
}
|
|
352
|
-
} catch (err) {
|
|
353
|
-
_d = true;
|
|
354
|
-
_e = err;
|
|
355
|
-
} finally {
|
|
356
|
-
try {
|
|
357
|
-
if (!_n && _i["return"] != null) _i["return"]();
|
|
358
|
-
} finally {
|
|
359
|
-
if (_d) throw _e;
|
|
360
|
-
}
|
|
321
|
+
function ownKeys(e, r) {
|
|
322
|
+
var t = Object.keys(e);
|
|
323
|
+
if (Object.getOwnPropertySymbols) {
|
|
324
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
325
|
+
r && (o = o.filter(function(r) {
|
|
326
|
+
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
327
|
+
})), t.push.apply(t, o);
|
|
361
328
|
}
|
|
362
|
-
return
|
|
329
|
+
return t;
|
|
363
330
|
}
|
|
364
|
-
function
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
331
|
+
function _objectSpread2(e) {
|
|
332
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
333
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
334
|
+
r % 2 ? ownKeys(Object(t), !0).forEach(function(r) {
|
|
335
|
+
_defineProperty(e, r, t[r]);
|
|
336
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r) {
|
|
337
|
+
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
return e;
|
|
341
|
+
}
|
|
342
|
+
function _slicedToArray(r, e) {
|
|
343
|
+
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
|
|
344
|
+
}
|
|
345
|
+
function _toPrimitive(t, r) {
|
|
346
|
+
if ("object" != typeof t || !t) return t;
|
|
347
|
+
var e = t[Symbol.toPrimitive];
|
|
348
|
+
if (void 0 !== e) {
|
|
349
|
+
var i = e.call(t, r || "default");
|
|
350
|
+
if ("object" != typeof i) return i;
|
|
351
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
352
|
+
}
|
|
353
|
+
return ("string" === r ? String : Number)(t);
|
|
371
354
|
}
|
|
372
|
-
function
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
return arr2;
|
|
355
|
+
function _toPropertyKey(t) {
|
|
356
|
+
var i = _toPrimitive(t, "string");
|
|
357
|
+
return "symbol" == typeof i ? i : i + "";
|
|
376
358
|
}
|
|
377
|
-
function
|
|
378
|
-
|
|
359
|
+
function _typeof(o) {
|
|
360
|
+
"@babel/helpers - typeof";
|
|
361
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
362
|
+
return typeof o;
|
|
363
|
+
} : function(o) {
|
|
364
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
365
|
+
}, _typeof(o);
|
|
366
|
+
}
|
|
367
|
+
function _unsupportedIterableToArray(r, a) {
|
|
368
|
+
if (r) {
|
|
369
|
+
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
370
|
+
var t = {}.toString.call(r).slice(8, -1);
|
|
371
|
+
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;
|
|
372
|
+
}
|
|
379
373
|
}
|
|
380
374
|
var toRadians = function toRadians(deg) {
|
|
381
375
|
return deg / 180 * Math.PI;
|
|
@@ -435,30 +429,30 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
435
429
|
solve90ac,
|
|
436
430
|
solveab
|
|
437
431
|
});
|
|
438
|
-
var div = function div(a, f) {
|
|
439
|
-
return a.map(
|
|
432
|
+
var div$1 = function div(a, f) {
|
|
433
|
+
return a.map(function(e) {
|
|
440
434
|
return e / f;
|
|
441
|
-
})
|
|
435
|
+
});
|
|
442
436
|
};
|
|
443
437
|
var addValue = function addValue(a, f) {
|
|
444
|
-
return a.map(
|
|
438
|
+
return a.map(function(e) {
|
|
445
439
|
return e + f;
|
|
446
|
-
})
|
|
440
|
+
});
|
|
447
441
|
};
|
|
448
442
|
var addArray = function addArray(a, f) {
|
|
449
|
-
return a.map(
|
|
443
|
+
return a.map(function(e, i) {
|
|
450
444
|
return e + f[i];
|
|
451
|
-
})
|
|
445
|
+
});
|
|
452
446
|
};
|
|
453
447
|
var add = function add(a) {
|
|
454
|
-
return Array.prototype.slice.call(arguments, 1).reduce(
|
|
448
|
+
return Array.prototype.slice.call(arguments, 1).reduce(function(result, arg) {
|
|
455
449
|
if (Array.isArray(arg)) {
|
|
456
450
|
result = addArray(result, arg);
|
|
457
451
|
} else {
|
|
458
452
|
result = addValue(result, arg);
|
|
459
453
|
}
|
|
460
454
|
return result;
|
|
461
|
-
}
|
|
455
|
+
}, a);
|
|
462
456
|
};
|
|
463
457
|
var fromxyz = function fromxyz(object) {
|
|
464
458
|
return Array.isArray(object) ? object : [ object.x, object.y, object.z ];
|
|
@@ -477,9 +471,9 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
477
471
|
return a && a.length > 0 ? a[a.length - 1] : undefined;
|
|
478
472
|
};
|
|
479
473
|
var min = function min(a) {
|
|
480
|
-
return a.reduce(
|
|
474
|
+
return a.reduce(function(result, value) {
|
|
481
475
|
return value < result ? value : result;
|
|
482
|
-
}
|
|
476
|
+
}, Number.MAX_VALUE);
|
|
483
477
|
};
|
|
484
478
|
var range = function range(a, b) {
|
|
485
479
|
var result = [];
|
|
@@ -490,7 +484,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
490
484
|
};
|
|
491
485
|
var array = Object.freeze({
|
|
492
486
|
__proto__: null,
|
|
493
|
-
div,
|
|
487
|
+
div: div$1,
|
|
494
488
|
addValue,
|
|
495
489
|
addArray,
|
|
496
490
|
add,
|
|
@@ -513,11 +507,11 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
513
507
|
}
|
|
514
508
|
}, jscadUtilsDebug || {});
|
|
515
509
|
var style = checks.options.browser ? "color:".concat(debugColors[debugCount++ % debugColors.length]) : "".concat(termColors[debugCount++ % termColors.length]);
|
|
516
|
-
var enabled = checks.enabled.some(
|
|
510
|
+
var enabled = checks.enabled.some(function checkEnabled(check) {
|
|
517
511
|
return check.test(name);
|
|
518
|
-
})
|
|
512
|
+
}) && !checks.disabled.some(function checkEnabled(check) {
|
|
519
513
|
return check.test(name);
|
|
520
|
-
})
|
|
514
|
+
});
|
|
521
515
|
var logger = enabled ? checks.options.browser ? function() {
|
|
522
516
|
var _console;
|
|
523
517
|
for (var _len = arguments.length, msg = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
@@ -704,9 +698,9 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
704
698
|
function color(o, r, g, b, a) {
|
|
705
699
|
if (typeof r !== "string") return o.setColor(r, g, b, a);
|
|
706
700
|
if (r === "") return o;
|
|
707
|
-
var c = name2rgb(r).map(
|
|
701
|
+
var c = name2rgb(r).map(function(x) {
|
|
708
702
|
return x / 255;
|
|
709
|
-
})
|
|
703
|
+
});
|
|
710
704
|
c[3] = g || 1;
|
|
711
705
|
return o.setColor(c);
|
|
712
706
|
}
|
|
@@ -808,10 +802,10 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
808
802
|
if (arguments.length === 1) {
|
|
809
803
|
return this._translate(arguments[0]);
|
|
810
804
|
} else {
|
|
811
|
-
var t = Array.prototype.slice.call(arguments, 0).reduce(
|
|
805
|
+
var t = Array.prototype.slice.call(arguments, 0).reduce(function(result, arg) {
|
|
812
806
|
result = undefined(result, arg);
|
|
813
807
|
return result;
|
|
814
|
-
}
|
|
808
|
+
}, [ 0, 0, 0 ]);
|
|
815
809
|
return this._translate(t);
|
|
816
810
|
}
|
|
817
811
|
};
|
|
@@ -821,9 +815,9 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
821
815
|
proto.prototype.connect = function connectTo(myConnectorName, otherConnector) {
|
|
822
816
|
var mirror = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
823
817
|
var normalrotation = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
824
|
-
var myConnector = myConnectorName.split(".").reduce(
|
|
818
|
+
var myConnector = myConnectorName.split(".").reduce(function(a, v) {
|
|
825
819
|
return a[v];
|
|
826
|
-
}
|
|
820
|
+
}, this.properties);
|
|
827
821
|
if (!myConnector) {
|
|
828
822
|
error("The connector '".concat(myConnectorName, "' does not exist on the object [").concat(Object.keys(this.properties).join(","), "]"), "Missing connector property");
|
|
829
823
|
}
|
|
@@ -840,7 +834,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
840
834
|
var _scadApi$text = scadApi__default["default"].text, vector_text = _scadApi$text.vector_text, vector_char = _scadApi$text.vector_char;
|
|
841
835
|
var union = scadApi__default["default"].booleanOps.union;
|
|
842
836
|
init(CSG);
|
|
843
|
-
var debug = Debug("jscadUtils:group");
|
|
837
|
+
var debug$3 = Debug("jscadUtils:group");
|
|
844
838
|
function JsCadUtilsGroup() {
|
|
845
839
|
var names = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
846
840
|
var parts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
@@ -851,16 +845,16 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
851
845
|
this.holes = holes;
|
|
852
846
|
}
|
|
853
847
|
JsCadUtilsGroup.prototype.add = function(object, name, hidden, subparts, parts) {
|
|
854
|
-
debug("add", object, name, hidden, subparts, parts);
|
|
848
|
+
debug$3("add", object, name, hidden, subparts, parts);
|
|
855
849
|
var self = this;
|
|
856
850
|
if (object.parts) {
|
|
857
851
|
if (name) {
|
|
858
852
|
if (!hidden) self.names.push(name);
|
|
859
853
|
self.parts[name] = object.combine(parts);
|
|
860
854
|
if (subparts) {
|
|
861
|
-
Object.keys(object.parts).forEach(
|
|
855
|
+
Object.keys(object.parts).forEach(function(key) {
|
|
862
856
|
self.parts[subparts + key] = object.parts[key];
|
|
863
|
-
})
|
|
857
|
+
});
|
|
864
858
|
}
|
|
865
859
|
} else {
|
|
866
860
|
Object.assign(self.parts, object.parts);
|
|
@@ -886,29 +880,30 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
886
880
|
if (pieces.length === 0) {
|
|
887
881
|
throw new Error("no pieces found in ".concat(self.name, " pieces: ").concat(pieces, " parts: ").concat(Object.keys(self.parts), " names: ").concat(self.names));
|
|
888
882
|
}
|
|
889
|
-
debug("combine", self.names, self.parts);
|
|
890
|
-
var g = union(mapPick(self.parts, pieces,
|
|
883
|
+
debug$3("combine", self.names, self.parts);
|
|
884
|
+
var g = union(mapPick(self.parts, pieces, function(value, key, index, object) {
|
|
885
|
+
debug$3("combine mapPick", value, key, object);
|
|
891
886
|
return map ? map(value, key, index, object) : identity(value);
|
|
892
|
-
}
|
|
887
|
+
}, self.name));
|
|
893
888
|
return g.subtractIf(self.holes && Array.isArray(self.holes) ? union(self.holes) : self.holes, self.holes && !options.noholes);
|
|
894
889
|
} catch (err) {
|
|
895
|
-
debug("combine error", this, pieces, options, err);
|
|
890
|
+
debug$3("combine error", this, pieces, options, err);
|
|
896
891
|
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");
|
|
897
892
|
}
|
|
898
893
|
};
|
|
899
894
|
JsCadUtilsGroup.prototype.map = function(cb) {
|
|
900
895
|
var self = this;
|
|
901
|
-
self.parts = Object.keys(self.parts).filter(
|
|
896
|
+
self.parts = Object.keys(self.parts).filter(function(k) {
|
|
902
897
|
return k !== "holes";
|
|
903
|
-
})
|
|
898
|
+
}).reduce(function(result, key) {
|
|
904
899
|
result[key] = cb(self.parts[key], key);
|
|
905
900
|
return result;
|
|
906
|
-
}
|
|
901
|
+
}, {});
|
|
907
902
|
if (self.holes) {
|
|
908
903
|
if (Array.isArray(self.holes)) {
|
|
909
|
-
self.holes = self.holes.map(
|
|
904
|
+
self.holes = self.holes.map(function(hole, idx) {
|
|
910
905
|
return cb(hole, idx);
|
|
911
|
-
})
|
|
906
|
+
});
|
|
912
907
|
} else {
|
|
913
908
|
self.holes = cb(self.holes, "holes");
|
|
914
909
|
}
|
|
@@ -916,7 +911,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
916
911
|
return self;
|
|
917
912
|
};
|
|
918
913
|
JsCadUtilsGroup.prototype.clone = function(name, map) {
|
|
919
|
-
debug("clone", name, _typeof(name), map);
|
|
914
|
+
debug$3("clone", name, _typeof(name), map);
|
|
920
915
|
var self = this;
|
|
921
916
|
if (typeof name == "function") {
|
|
922
917
|
map = name;
|
|
@@ -924,15 +919,15 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
924
919
|
}
|
|
925
920
|
if (!map) map = identity;
|
|
926
921
|
var group = Group(name);
|
|
927
|
-
Object.keys(self.parts).forEach(
|
|
922
|
+
Object.keys(self.parts).forEach(function(key) {
|
|
928
923
|
var part = self.parts[key];
|
|
929
924
|
var hidden = self.names.indexOf(key) == -1;
|
|
930
925
|
group.add(map(clone(part)), key, hidden);
|
|
931
|
-
})
|
|
926
|
+
});
|
|
932
927
|
if (self.holes) {
|
|
933
|
-
group.holes = toArray(self.holes).map(
|
|
928
|
+
group.holes = toArray(self.holes).map(function(part) {
|
|
934
929
|
return map(CSG.fromPolygons(part.toPolygons()), "holes");
|
|
935
|
-
})
|
|
930
|
+
});
|
|
936
931
|
}
|
|
937
932
|
return group;
|
|
938
933
|
};
|
|
@@ -949,9 +944,9 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
949
944
|
}
|
|
950
945
|
var rotationCenter = solid.centroid();
|
|
951
946
|
var rotationAxis = axes[axis];
|
|
952
|
-
self.map(
|
|
947
|
+
self.map(function(part) {
|
|
953
948
|
return part.rotate(rotationCenter, rotationAxis, angle);
|
|
954
|
-
})
|
|
949
|
+
});
|
|
955
950
|
return self;
|
|
956
951
|
};
|
|
957
952
|
JsCadUtilsGroup.prototype.combineAll = function(options, map) {
|
|
@@ -962,12 +957,12 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
962
957
|
try {
|
|
963
958
|
var self = this;
|
|
964
959
|
var t = calcSnap(self.combine(part), to, axis, orientation, delta);
|
|
965
|
-
self.map(
|
|
960
|
+
self.map(function(part) {
|
|
966
961
|
return part.translate(t);
|
|
967
|
-
})
|
|
962
|
+
});
|
|
968
963
|
return self;
|
|
969
964
|
} catch (err) {
|
|
970
|
-
debug("snap error", this, part, to, axis, delta, err);
|
|
965
|
+
debug$3("snap error", this, part, to, axis, delta, err);
|
|
971
966
|
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");
|
|
972
967
|
}
|
|
973
968
|
};
|
|
@@ -977,12 +972,12 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
977
972
|
var t = calcCenterWith(self.combine(part, {
|
|
978
973
|
noholes: true
|
|
979
974
|
}), axis, to, delta);
|
|
980
|
-
self.map(
|
|
975
|
+
self.map(function(part) {
|
|
981
976
|
return part.translate(t);
|
|
982
|
-
})
|
|
977
|
+
});
|
|
983
978
|
return self;
|
|
984
979
|
} catch (err) {
|
|
985
|
-
debug("align error", this, part, to, axis, delta, err);
|
|
980
|
+
debug$3("align error", this, part, to, axis, delta, err);
|
|
986
981
|
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");
|
|
987
982
|
}
|
|
988
983
|
};
|
|
@@ -998,7 +993,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
998
993
|
JsCadUtilsGroup.prototype.connectTo = function connectTo(partName, connectorName, to, toConnectorName) {
|
|
999
994
|
var mirror = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
|
|
1000
995
|
var normalrotation = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 0;
|
|
1001
|
-
debug("connectTo", {
|
|
996
|
+
debug$3("connectTo", {
|
|
1002
997
|
partName,
|
|
1003
998
|
connectorName,
|
|
1004
999
|
to,
|
|
@@ -1007,38 +1002,38 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1007
1002
|
normalrotation
|
|
1008
1003
|
});
|
|
1009
1004
|
var self = this;
|
|
1010
|
-
var myConnector = connectorName.split(".").reduce(
|
|
1005
|
+
var myConnector = connectorName.split(".").reduce(function(a, v) {
|
|
1011
1006
|
return a[v];
|
|
1012
|
-
}
|
|
1013
|
-
debug("toConnector", to instanceof CSG.Connector);
|
|
1014
|
-
var toConnector = toConnectorName.split(".").reduce(
|
|
1007
|
+
}, self.parts[partName].properties);
|
|
1008
|
+
debug$3("toConnector", to instanceof CSG.Connector);
|
|
1009
|
+
var toConnector = toConnectorName.split(".").reduce(function(a, v) {
|
|
1015
1010
|
return a[v];
|
|
1016
|
-
}
|
|
1011
|
+
}, to.properties);
|
|
1017
1012
|
var matrix = myConnector.getTransformationTo(toConnector, mirror, normalrotation);
|
|
1018
|
-
debug("connectTo", matrix);
|
|
1019
|
-
self.map(
|
|
1013
|
+
debug$3("connectTo", matrix);
|
|
1014
|
+
self.map(function(part) {
|
|
1020
1015
|
return part.transform(matrix);
|
|
1021
|
-
})
|
|
1016
|
+
});
|
|
1022
1017
|
return self;
|
|
1023
1018
|
};
|
|
1024
1019
|
JsCadUtilsGroup.prototype.midlineTo = function midlineTo(part, axis, to) {
|
|
1025
1020
|
var self = this;
|
|
1026
1021
|
var size = self.combine(part).size();
|
|
1027
|
-
var t = axisApply(axis,
|
|
1022
|
+
var t = axisApply(axis, function(i, a) {
|
|
1028
1023
|
return to - size[a] / 2;
|
|
1029
|
-
})
|
|
1030
|
-
self.map(
|
|
1024
|
+
});
|
|
1025
|
+
self.map(function(part) {
|
|
1031
1026
|
return part.translate(t);
|
|
1032
|
-
})
|
|
1027
|
+
});
|
|
1033
1028
|
return self;
|
|
1034
1029
|
};
|
|
1035
1030
|
JsCadUtilsGroup.prototype.translate = function translate(x, y, z) {
|
|
1036
1031
|
var self = this;
|
|
1037
1032
|
var t = Array.isArray(x) ? x : [ x, y, z ];
|
|
1038
|
-
debug("translate", t);
|
|
1039
|
-
self.map(
|
|
1033
|
+
debug$3("translate", t);
|
|
1034
|
+
self.map(function(part) {
|
|
1040
1035
|
return part.translate(t);
|
|
1041
|
-
})
|
|
1036
|
+
});
|
|
1042
1037
|
return self;
|
|
1043
1038
|
};
|
|
1044
1039
|
JsCadUtilsGroup.prototype.pick = function(parts, map) {
|
|
@@ -1046,9 +1041,9 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1046
1041
|
var p = parts && parts.length > 0 && parts.split(",") || self.names;
|
|
1047
1042
|
if (!map) map = identity;
|
|
1048
1043
|
var g = Group();
|
|
1049
|
-
p.forEach(
|
|
1044
|
+
p.forEach(function(name) {
|
|
1050
1045
|
g.add(map(CSG.fromPolygons(self.parts[name].toPolygons()), name), name);
|
|
1051
|
-
})
|
|
1046
|
+
});
|
|
1052
1047
|
return g;
|
|
1053
1048
|
};
|
|
1054
1049
|
JsCadUtilsGroup.prototype.array = function(parts, map) {
|
|
@@ -1057,32 +1052,32 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1057
1052
|
var p = parts && parts.length > 0 && parts.split(",") || self.names;
|
|
1058
1053
|
if (!map) map = identity;
|
|
1059
1054
|
var a = [];
|
|
1060
|
-
p.forEach(
|
|
1055
|
+
p.forEach(function(name) {
|
|
1061
1056
|
if (!self.parts[name]) {
|
|
1062
|
-
debug("array error", _this, parts);
|
|
1057
|
+
debug$3("array error", _this, parts);
|
|
1063
1058
|
throw error('group::array error "'.concat(name, '" not found.\nthis: ').concat(_this, '\nparts: "').concat(parts, '"\n'), "JSCAD_UTILS_GROUP_ERROR");
|
|
1064
1059
|
}
|
|
1065
1060
|
a.push(map(CSG.fromPolygons(self.parts[name].toPolygons()), name));
|
|
1066
|
-
})
|
|
1061
|
+
});
|
|
1067
1062
|
return a;
|
|
1068
1063
|
};
|
|
1069
1064
|
JsCadUtilsGroup.prototype.toArray = function(pieces) {
|
|
1070
1065
|
var self = this;
|
|
1071
1066
|
var piecesArray = pieces ? pieces.split(",") : self.names;
|
|
1072
|
-
return piecesArray.map(
|
|
1067
|
+
return piecesArray.map(function(piece) {
|
|
1073
1068
|
if (!self.parts[piece]) console.error("Cannot find ".concat(piece, " in ").concat(self.names));
|
|
1074
1069
|
return self.parts[piece];
|
|
1075
|
-
})
|
|
1070
|
+
});
|
|
1076
1071
|
};
|
|
1077
1072
|
JsCadUtilsGroup.prototype.toString = function() {
|
|
1078
|
-
return '{\n name: "'.concat(this.name, '",\n names: "').concat(this.names.join(","), '", \n parts: "').concat(Object.keys(this.parts), '",\n holes:
|
|
1073
|
+
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}");
|
|
1079
1074
|
};
|
|
1080
1075
|
JsCadUtilsGroup.prototype.setName = function(name) {
|
|
1081
1076
|
this.name = name;
|
|
1082
1077
|
return this;
|
|
1083
1078
|
};
|
|
1084
1079
|
function Group(objectNames, addObjects) {
|
|
1085
|
-
debug("Group", objectNames, addObjects);
|
|
1080
|
+
debug$3("Group", objectNames, addObjects);
|
|
1086
1081
|
var self = {
|
|
1087
1082
|
name: "",
|
|
1088
1083
|
names: [],
|
|
@@ -1105,9 +1100,9 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1105
1100
|
self.name = objectNames;
|
|
1106
1101
|
} else {
|
|
1107
1102
|
var objects = objectNames;
|
|
1108
|
-
self.names = Object.keys(objects).filter(
|
|
1103
|
+
self.names = Object.keys(objects).filter(function(k) {
|
|
1109
1104
|
return k !== "holes";
|
|
1110
|
-
})
|
|
1105
|
+
});
|
|
1111
1106
|
self.parts = Object.assign({}, objects);
|
|
1112
1107
|
self.holes = objects.holes;
|
|
1113
1108
|
}
|
|
@@ -1115,7 +1110,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1115
1110
|
}
|
|
1116
1111
|
return new JsCadUtilsGroup(self.names, self.parts, self.holes);
|
|
1117
1112
|
}
|
|
1118
|
-
var debug$
|
|
1113
|
+
var debug$2 = Debug("jscadUtils:util");
|
|
1119
1114
|
var NOZZEL_SIZE = .4;
|
|
1120
1115
|
var nearest = {
|
|
1121
1116
|
under: function under(desired) {
|
|
@@ -1150,7 +1145,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1150
1145
|
return ((n = +n) || 1 / n) < 0;
|
|
1151
1146
|
}
|
|
1152
1147
|
function print(msg, o) {
|
|
1153
|
-
debug$
|
|
1148
|
+
debug$2(msg, JSON.stringify(o.getBounds()), JSON.stringify(this.size(o.getBounds())));
|
|
1154
1149
|
}
|
|
1155
1150
|
function jscadToString(o) {
|
|
1156
1151
|
if (_typeof(o) == "object") {
|
|
@@ -1186,21 +1181,21 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1186
1181
|
function label(text, x, y, width, height) {
|
|
1187
1182
|
var l = vector_text(x || 0, y || 0, text);
|
|
1188
1183
|
var o = [];
|
|
1189
|
-
l.forEach(
|
|
1184
|
+
l.forEach(function(pl) {
|
|
1190
1185
|
o.push(rectangular_extrude(pl, {
|
|
1191
1186
|
w: width || 2,
|
|
1192
1187
|
h: height || 2
|
|
1193
1188
|
}));
|
|
1194
|
-
})
|
|
1189
|
+
});
|
|
1195
1190
|
return center(union(o));
|
|
1196
1191
|
}
|
|
1197
1192
|
function text(text) {
|
|
1198
1193
|
var l = vector_char(0, 0, text);
|
|
1199
|
-
var _char = l.segments.reduce(
|
|
1194
|
+
var _char = l.segments.reduce(function(result, segment) {
|
|
1200
1195
|
var path = new CSG.Path2D(segment);
|
|
1201
1196
|
var cag = path.expandToCAG(2);
|
|
1202
1197
|
return result ? result.union(cag) : cag;
|
|
1203
|
-
}
|
|
1198
|
+
}, undefined);
|
|
1204
1199
|
return _char;
|
|
1205
1200
|
}
|
|
1206
1201
|
function unitCube(length, radius) {
|
|
@@ -1211,7 +1206,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1211
1206
|
});
|
|
1212
1207
|
}
|
|
1213
1208
|
function unitAxis(length, radius, centroid) {
|
|
1214
|
-
debug$
|
|
1209
|
+
debug$2("unitAxis", length, radius, centroid);
|
|
1215
1210
|
centroid = centroid || [ 0, 0, 0 ];
|
|
1216
1211
|
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) ]);
|
|
1217
1212
|
unitaxis.properties.origin = new CSG.Connector([ 0, 0, 0 ], [ 1, 0, 0 ], [ 0, 1, 0 ]);
|
|
@@ -1233,38 +1228,38 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1233
1228
|
return result;
|
|
1234
1229
|
}
|
|
1235
1230
|
function zipObject(names, values) {
|
|
1236
|
-
return names.reduce(
|
|
1231
|
+
return names.reduce(function(result, value, idx) {
|
|
1237
1232
|
result[value] = values[idx];
|
|
1238
1233
|
return result;
|
|
1239
|
-
}
|
|
1234
|
+
}, {});
|
|
1240
1235
|
}
|
|
1241
1236
|
function map(o, f) {
|
|
1242
|
-
return Object.keys(o).map(
|
|
1237
|
+
return Object.keys(o).map(function(key) {
|
|
1243
1238
|
return f(o[key], key, o);
|
|
1244
|
-
})
|
|
1239
|
+
});
|
|
1245
1240
|
}
|
|
1246
1241
|
function mapValues(o, f) {
|
|
1247
|
-
return Object.keys(o).map(
|
|
1242
|
+
return Object.keys(o).map(function(key) {
|
|
1248
1243
|
return f(o[key], key);
|
|
1249
|
-
})
|
|
1244
|
+
});
|
|
1250
1245
|
}
|
|
1251
1246
|
function pick(o, names) {
|
|
1252
|
-
return names.reduce(
|
|
1247
|
+
return names.reduce(function(result, name) {
|
|
1253
1248
|
result[name] = o[name];
|
|
1254
1249
|
return result;
|
|
1255
|
-
}
|
|
1250
|
+
}, {});
|
|
1256
1251
|
}
|
|
1257
1252
|
function mapPick(o, names, f, options) {
|
|
1258
|
-
return names.reduce(
|
|
1253
|
+
return names.reduce(function(result, name, index) {
|
|
1259
1254
|
if (!o[name]) {
|
|
1260
1255
|
throw new Error("".concat(name, " not found in ").concat(options.name, ": ").concat(Object.keys(o).join(",")));
|
|
1261
1256
|
}
|
|
1262
1257
|
result.push(f ? f(o[name], name, index, o) : o[name]);
|
|
1263
1258
|
return result;
|
|
1264
|
-
}
|
|
1259
|
+
}, []);
|
|
1265
1260
|
}
|
|
1266
1261
|
function divA(a, f) {
|
|
1267
|
-
return div(a, f);
|
|
1262
|
+
return div$1(a, f);
|
|
1268
1263
|
}
|
|
1269
1264
|
function divxyz(size, x, y, z) {
|
|
1270
1265
|
return {
|
|
@@ -1273,7 +1268,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1273
1268
|
z: size.z / z
|
|
1274
1269
|
};
|
|
1275
1270
|
}
|
|
1276
|
-
function div
|
|
1271
|
+
function div(size, d) {
|
|
1277
1272
|
return this.divxyz(size, d, d, d);
|
|
1278
1273
|
}
|
|
1279
1274
|
function mulxyz(size, x, y, z) {
|
|
@@ -1325,9 +1320,9 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1325
1320
|
var objectSize = size(object);
|
|
1326
1321
|
var objectCentroid = centroid(object, objectSize);
|
|
1327
1322
|
var idx = 0;
|
|
1328
|
-
var t = map(objectSize,
|
|
1323
|
+
var t = map(objectSize, function(i) {
|
|
1329
1324
|
return scale(i, a[idx++]);
|
|
1330
|
-
})
|
|
1325
|
+
});
|
|
1331
1326
|
var new_object = object.scale(t);
|
|
1332
1327
|
var new_centroid = centroid(new_object);
|
|
1333
1328
|
var delta = new_centroid.minus(objectCentroid).times(-1);
|
|
@@ -1351,10 +1346,10 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1351
1346
|
}
|
|
1352
1347
|
var s = [ scale(objectSize.x, x), scale(objectSize.y, y), scale(objectSize.z, z) ];
|
|
1353
1348
|
var min$1 = min(s);
|
|
1354
|
-
return centerWith(object.scale(s.map(
|
|
1349
|
+
return centerWith(object.scale(s.map(function(d, i) {
|
|
1355
1350
|
if (a[i] === 0) return 1;
|
|
1356
1351
|
return keep_aspect_ratio ? min$1 : d;
|
|
1357
|
-
}))
|
|
1352
|
+
})), "xyz", object);
|
|
1358
1353
|
}
|
|
1359
1354
|
function shift(object, x, y, z) {
|
|
1360
1355
|
var hsize = this.div(this.size(object.getBounds()), 2);
|
|
@@ -1393,9 +1388,9 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1393
1388
|
if (side[0] === -1) {
|
|
1394
1389
|
w[-1] = toxyz(withobj.centroid());
|
|
1395
1390
|
}
|
|
1396
|
-
return this.axisApply(axes,
|
|
1391
|
+
return this.axisApply(axes, function(i, axis) {
|
|
1397
1392
|
return w[side[0]][axis] - m[side[1]][axis];
|
|
1398
|
-
})
|
|
1393
|
+
});
|
|
1399
1394
|
}
|
|
1400
1395
|
function calcSnap(moveobj, withobj, axes, orientation) {
|
|
1401
1396
|
var delta = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
|
|
@@ -1416,15 +1411,15 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1416
1411
|
if (side[0] === -1) {
|
|
1417
1412
|
w[-1] = withobj.centroid();
|
|
1418
1413
|
}
|
|
1419
|
-
var t = axisApply(axes,
|
|
1414
|
+
var t = axisApply(axes, function(i, axis) {
|
|
1420
1415
|
return w[side[0]][axis] - m[side[1]][axis];
|
|
1421
|
-
})
|
|
1422
|
-
return delta ? axisApply(axes,
|
|
1416
|
+
});
|
|
1417
|
+
return delta ? axisApply(axes, function(i) {
|
|
1423
1418
|
return t[i] + delta;
|
|
1424
|
-
})
|
|
1419
|
+
}) : t;
|
|
1425
1420
|
}
|
|
1426
1421
|
function snap(moveobj, withobj, axis, orientation, delta) {
|
|
1427
|
-
debug$
|
|
1422
|
+
debug$2("snap", moveobj, withobj, axis, orientation, delta);
|
|
1428
1423
|
var t = calcSnap(moveobj, withobj, axis, orientation, delta);
|
|
1429
1424
|
return moveobj.translate(t);
|
|
1430
1425
|
}
|
|
@@ -1432,16 +1427,16 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1432
1427
|
return moveobj.translate(calcFlush(moveobj, withobj, axis, mside, wside));
|
|
1433
1428
|
}
|
|
1434
1429
|
function axisApply(axes, valfun, a) {
|
|
1435
|
-
debug$
|
|
1430
|
+
debug$2("axisApply", axes, valfun, a);
|
|
1436
1431
|
var retval = a || [ 0, 0, 0 ];
|
|
1437
1432
|
var lookup = {
|
|
1438
1433
|
x: 0,
|
|
1439
1434
|
y: 1,
|
|
1440
1435
|
z: 2
|
|
1441
1436
|
};
|
|
1442
|
-
axes.split("").forEach(
|
|
1437
|
+
axes.split("").forEach(function(axis) {
|
|
1443
1438
|
retval[lookup[axis]] = valfun(lookup[axis], axis);
|
|
1444
|
-
})
|
|
1439
|
+
});
|
|
1445
1440
|
return retval;
|
|
1446
1441
|
}
|
|
1447
1442
|
function axis2array(axes, valfun) {
|
|
@@ -1452,10 +1447,10 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1452
1447
|
y: 1,
|
|
1453
1448
|
z: 2
|
|
1454
1449
|
};
|
|
1455
|
-
axes.split("").forEach(
|
|
1450
|
+
axes.split("").forEach(function(axis) {
|
|
1456
1451
|
var i = lookup[axis];
|
|
1457
1452
|
a[i] = valfun(i, axis);
|
|
1458
|
-
})
|
|
1453
|
+
});
|
|
1459
1454
|
return a;
|
|
1460
1455
|
}
|
|
1461
1456
|
function centroid(o, objectSize) {
|
|
@@ -1470,9 +1465,9 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1470
1465
|
function calcmidlineTo(o, axis, to) {
|
|
1471
1466
|
var bounds = o.getBounds();
|
|
1472
1467
|
var objectSize = size(bounds);
|
|
1473
|
-
return axisApply(axis,
|
|
1468
|
+
return axisApply(axis, function(i, a) {
|
|
1474
1469
|
return to - objectSize[a] / 2;
|
|
1475
|
-
})
|
|
1470
|
+
});
|
|
1476
1471
|
}
|
|
1477
1472
|
function midlineTo(o, axis, to) {
|
|
1478
1473
|
return o.translate(calcmidlineTo(o, axis, to));
|
|
@@ -1480,18 +1475,18 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1480
1475
|
function translator(o, axis, withObj) {
|
|
1481
1476
|
var objectCentroid = centroid(o);
|
|
1482
1477
|
var withCentroid = centroid(withObj);
|
|
1483
|
-
var t = axisApply(axis,
|
|
1478
|
+
var t = axisApply(axis, function(i) {
|
|
1484
1479
|
return withCentroid[i] - objectCentroid[i];
|
|
1485
|
-
})
|
|
1480
|
+
});
|
|
1486
1481
|
return t;
|
|
1487
1482
|
}
|
|
1488
1483
|
function calcCenterWith(o, axes, withObj) {
|
|
1489
1484
|
var delta = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
1490
1485
|
var objectCentroid = centroid(o);
|
|
1491
1486
|
var withCentroid = centroid(withObj);
|
|
1492
|
-
var t = axisApply(axes,
|
|
1487
|
+
var t = axisApply(axes, function(i, axis) {
|
|
1493
1488
|
return withCentroid[axis] - objectCentroid[axis];
|
|
1494
|
-
})
|
|
1489
|
+
});
|
|
1495
1490
|
return delta ? add(t, delta) : t;
|
|
1496
1491
|
}
|
|
1497
1492
|
function centerWith(o, axis, withObj) {
|
|
@@ -1504,9 +1499,9 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1504
1499
|
}
|
|
1505
1500
|
}
|
|
1506
1501
|
var dist = isNegative(offset) ? offset = size[axis] + offset : offset;
|
|
1507
|
-
return axisApply(axis,
|
|
1502
|
+
return axisApply(axis, function(i, a) {
|
|
1508
1503
|
return bounds[0][a] + (isEmpty(dist) ? size[axis] / 2 : dist);
|
|
1509
|
-
})
|
|
1504
|
+
});
|
|
1510
1505
|
}
|
|
1511
1506
|
function bisect() {
|
|
1512
1507
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
@@ -1569,14 +1564,14 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1569
1564
|
}[[ axis, rotateaxis ].sort().join("")];
|
|
1570
1565
|
var centroid = object.centroid();
|
|
1571
1566
|
var rotateDelta = getDelta(objectSize, bounds, rotateOffsetAxis, rotateoffset);
|
|
1572
|
-
var rotationCenter = options.rotationCenter || new CSG.Vector3D(axisApply("xyz",
|
|
1567
|
+
var rotationCenter = options.rotationCenter || new CSG.Vector3D(axisApply("xyz", function(i, a) {
|
|
1573
1568
|
if (a == axis) return cutDelta[i];
|
|
1574
1569
|
if (a == rotateOffsetAxis) return rotateDelta[i];
|
|
1575
1570
|
return centroid[a];
|
|
1576
|
-
}))
|
|
1571
|
+
}));
|
|
1577
1572
|
var theRotationAxis = rotationAxes[rotateaxis];
|
|
1578
1573
|
var cutplane = CSG.OrthoNormalBasis.GetCartesian(info.orthoNormalCartesian[0], info.orthoNormalCartesian[1]).translate(cutDelta).rotate(rotationCenter, theRotationAxis, angle);
|
|
1579
|
-
debug$
|
|
1574
|
+
debug$2("bisect", debug$2.enabled && {
|
|
1580
1575
|
axis,
|
|
1581
1576
|
offset,
|
|
1582
1577
|
angle,
|
|
@@ -1657,21 +1652,18 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1657
1652
|
return CSG.fromPolygons(polygons);
|
|
1658
1653
|
}
|
|
1659
1654
|
function slices2poly(slices, options, axis) {
|
|
1660
|
-
debug$
|
|
1655
|
+
debug$2("slices2poly", slices, options, axis);
|
|
1661
1656
|
options = Object.assign({
|
|
1662
1657
|
twistangle: 0,
|
|
1663
1658
|
twiststeps: 0
|
|
1664
1659
|
}, options);
|
|
1665
1660
|
var twistangle = options && parseFloat(options.twistangle) || 0;
|
|
1666
|
-
|
|
1667
|
-
if (twistangle == 0 || twiststeps < 1) {
|
|
1668
|
-
twiststeps = 1;
|
|
1669
|
-
}
|
|
1661
|
+
options && parseInt(options.twiststeps) || CSG.defaultResolution3D;
|
|
1670
1662
|
var normalVector = options.si.normalVector;
|
|
1671
1663
|
var polygons = [];
|
|
1672
1664
|
var first$1 = first(slices);
|
|
1673
1665
|
var last$1 = last(slices);
|
|
1674
|
-
debug$
|
|
1666
|
+
debug$2("slices2poly first", first$1, first$1.offset, "last", last$1);
|
|
1675
1667
|
var up = first$1.offset[axis] > last$1.offset[axis];
|
|
1676
1668
|
polygons = polygons.concat(first$1.poly._toPlanePolygons({
|
|
1677
1669
|
translation: first$1.offset,
|
|
@@ -1690,7 +1682,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1690
1682
|
return v[rotateAxis](angle * percent);
|
|
1691
1683
|
};
|
|
1692
1684
|
var connectorAxis = last$1.offset.minus(first$1.offset).abs();
|
|
1693
|
-
slices.forEach(
|
|
1685
|
+
slices.forEach(function(slice, idx) {
|
|
1694
1686
|
if (idx < slices.length - 1) {
|
|
1695
1687
|
var nextidx = idx + 1;
|
|
1696
1688
|
var top = !up ? slices[nextidx] : slice;
|
|
@@ -1703,7 +1695,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1703
1695
|
toConnector2: c2
|
|
1704
1696
|
}));
|
|
1705
1697
|
}
|
|
1706
|
-
})
|
|
1698
|
+
});
|
|
1707
1699
|
return CSG.fromPolygons(polygons);
|
|
1708
1700
|
}
|
|
1709
1701
|
function normalVector(axis) {
|
|
@@ -1744,12 +1736,12 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1744
1736
|
var info = dirInfo["dir" + direction];
|
|
1745
1737
|
return Object.assign({
|
|
1746
1738
|
axis,
|
|
1747
|
-
cutDelta: axisApply(axis,
|
|
1739
|
+
cutDelta: axisApply(axis, function(i, a) {
|
|
1748
1740
|
return bounds[info.sizeIdx][a] + Math.abs(radius) * info.sizeDir;
|
|
1749
|
-
})
|
|
1750
|
-
moveDelta: axisApply(axis,
|
|
1741
|
+
}),
|
|
1742
|
+
moveDelta: axisApply(axis, function(i, a) {
|
|
1751
1743
|
return bounds[info.sizeIdx][a] + Math.abs(radius) * info.moveDir;
|
|
1752
|
-
})
|
|
1744
|
+
})
|
|
1753
1745
|
}, info, normalVector(axis));
|
|
1754
1746
|
}
|
|
1755
1747
|
function reShape(object, radius, orientation, options, slicer) {
|
|
@@ -1757,18 +1749,18 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1757
1749
|
var b = object.getBounds();
|
|
1758
1750
|
var absoluteRadius = Math.abs(radius);
|
|
1759
1751
|
var si = sliceParams(orientation, radius, b);
|
|
1760
|
-
debug$
|
|
1752
|
+
debug$2("reShape", absoluteRadius, si);
|
|
1761
1753
|
if (si.axis !== "z") throw new Error('reShape error: CAG._toPlanePolytons only uses the "z" axis. You must use the "z" axis for now.');
|
|
1762
1754
|
var cutplane = CSG.OrthoNormalBasis.GetCartesian(si.orthoNormalCartesian[0], si.orthoNormalCartesian[1]).translate(si.cutDelta);
|
|
1763
1755
|
var slice = object.sectionCut(cutplane);
|
|
1764
|
-
var first = axisApply(si.axis,
|
|
1756
|
+
var first = axisApply(si.axis, function() {
|
|
1765
1757
|
return si.positive ? 0 : absoluteRadius;
|
|
1766
|
-
})
|
|
1767
|
-
var last = axisApply(si.axis,
|
|
1758
|
+
});
|
|
1759
|
+
var last = axisApply(si.axis, function() {
|
|
1768
1760
|
return si.positive ? absoluteRadius : 0;
|
|
1769
|
-
})
|
|
1761
|
+
});
|
|
1770
1762
|
var plane = si.positive ? cutplane.plane : cutplane.plane.flipped();
|
|
1771
|
-
debug$
|
|
1763
|
+
debug$2("reShape first/last", first, last);
|
|
1772
1764
|
var slices = slicer(first, last, slice, radius);
|
|
1773
1765
|
var delta = slices2poly(slices, Object.assign(options, {
|
|
1774
1766
|
si
|
|
@@ -1777,7 +1769,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1777
1769
|
return union([ options.unionOriginal ? object : remainder, delta.translate(si.moveDelta) ]);
|
|
1778
1770
|
}
|
|
1779
1771
|
function chamfer(object, radius, orientation, options) {
|
|
1780
|
-
return reShape(object, radius, orientation, options,
|
|
1772
|
+
return reShape(object, radius, orientation, options, function(first, last, slice) {
|
|
1781
1773
|
return [ {
|
|
1782
1774
|
poly: slice,
|
|
1783
1775
|
offset: new CSG.Vector3D(first)
|
|
@@ -1785,15 +1777,15 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1785
1777
|
poly: enlarge(slice, [ -radius * 2, -radius * 2 ]),
|
|
1786
1778
|
offset: new CSG.Vector3D(last)
|
|
1787
1779
|
} ];
|
|
1788
|
-
})
|
|
1780
|
+
});
|
|
1789
1781
|
}
|
|
1790
1782
|
function fillet(object, radius, orientation, options) {
|
|
1791
1783
|
options = options || {};
|
|
1792
|
-
return reShape(object, radius, orientation, options,
|
|
1784
|
+
return reShape(object, radius, orientation, options, function(first, last, slice) {
|
|
1793
1785
|
var v1 = new CSG.Vector3D(first);
|
|
1794
1786
|
var v2 = new CSG.Vector3D(last);
|
|
1795
1787
|
var res = options.resolution || CSG.defaultResolution3D;
|
|
1796
|
-
var slices = range(0, res).map(
|
|
1788
|
+
var slices = range(0, res).map(function(i) {
|
|
1797
1789
|
var p = i > 0 ? i / (res - 1) : 0;
|
|
1798
1790
|
var v = v1.lerp(v2, p);
|
|
1799
1791
|
var size = -radius * 2 - Math.cos(Math.asin(p)) * (-radius * 2);
|
|
@@ -1801,9 +1793,9 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1801
1793
|
poly: enlarge(slice, [ size, size ]),
|
|
1802
1794
|
offset: v
|
|
1803
1795
|
};
|
|
1804
|
-
})
|
|
1796
|
+
});
|
|
1805
1797
|
return slices;
|
|
1806
|
-
})
|
|
1798
|
+
});
|
|
1807
1799
|
}
|
|
1808
1800
|
function calcRotate(part, solid, axis) {
|
|
1809
1801
|
var axes = {
|
|
@@ -1823,16 +1815,16 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1823
1815
|
return part.rotate(rotationCenter, rotationAxis, angle);
|
|
1824
1816
|
}
|
|
1825
1817
|
function cloneProperties(from, to) {
|
|
1826
|
-
return Object.entries(from).reduce(
|
|
1818
|
+
return Object.entries(from).reduce(function(props, _ref) {
|
|
1827
1819
|
var _ref2 = _slicedToArray(_ref, 2), key = _ref2[0], value = _ref2[1];
|
|
1828
1820
|
props[key] = value;
|
|
1829
1821
|
return props;
|
|
1830
|
-
}
|
|
1822
|
+
}, to);
|
|
1831
1823
|
}
|
|
1832
1824
|
function clone(o) {
|
|
1833
1825
|
var c = CSG.fromPolygons(o.toPolygons());
|
|
1834
1826
|
cloneProperties(o, c);
|
|
1835
|
-
debug$
|
|
1827
|
+
debug$2("clone", o, c, CSG);
|
|
1836
1828
|
return c;
|
|
1837
1829
|
}
|
|
1838
1830
|
function addConnector(object, name) {
|
|
@@ -1842,15 +1834,15 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1842
1834
|
object.properties[name] = new CSG.Connector(point, axis, normal);
|
|
1843
1835
|
return object;
|
|
1844
1836
|
}
|
|
1845
|
-
var debug$
|
|
1837
|
+
var debug$1 = Debug("jscadUtils:parts");
|
|
1846
1838
|
var parts = {
|
|
1847
|
-
BBox,
|
|
1839
|
+
BBox: BBox$1,
|
|
1848
1840
|
Cube,
|
|
1849
1841
|
RoundedCube,
|
|
1850
1842
|
Cylinder,
|
|
1851
1843
|
Cone
|
|
1852
1844
|
};
|
|
1853
|
-
function BBox() {
|
|
1845
|
+
function BBox$1() {
|
|
1854
1846
|
function box(object) {
|
|
1855
1847
|
return CSG.cube({
|
|
1856
1848
|
center: object.centroid(),
|
|
@@ -1860,13 +1852,13 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1860
1852
|
for (var _len = arguments.length, objects = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1861
1853
|
objects[_key] = arguments[_key];
|
|
1862
1854
|
}
|
|
1863
|
-
return objects.reduce(
|
|
1855
|
+
return objects.reduce(function(bbox, part) {
|
|
1864
1856
|
var object = bbox ? union([ bbox, box(part) ]) : part;
|
|
1865
1857
|
return box(object);
|
|
1866
|
-
}
|
|
1858
|
+
}, undefined);
|
|
1867
1859
|
}
|
|
1868
1860
|
function Cube(width) {
|
|
1869
|
-
var r = div(fromxyz(width), 2);
|
|
1861
|
+
var r = div$1(fromxyz(width), 2);
|
|
1870
1862
|
return CSG.cube({
|
|
1871
1863
|
center: r,
|
|
1872
1864
|
radius: r
|
|
@@ -1881,7 +1873,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1881
1873
|
} else {
|
|
1882
1874
|
var r = [ x / 2, y / 2 ];
|
|
1883
1875
|
}
|
|
1884
|
-
debug$
|
|
1876
|
+
debug$1("RoundedCube", size$1, r, thickness, corner_radius);
|
|
1885
1877
|
var roundedcube = CAG.roundedRectangle({
|
|
1886
1878
|
center: [ r[0], r[1], 0 ],
|
|
1887
1879
|
radius: r,
|
|
@@ -1894,7 +1886,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1894
1886
|
}
|
|
1895
1887
|
function Cylinder(diameter, height) {
|
|
1896
1888
|
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1897
|
-
debug$
|
|
1889
|
+
debug$1("parts.Cylinder", diameter, height, options);
|
|
1898
1890
|
options = Object.assign({
|
|
1899
1891
|
start: [ 0, 0, 0 ],
|
|
1900
1892
|
end: [ 0, 0, height ],
|
|
@@ -1905,7 +1897,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1905
1897
|
}
|
|
1906
1898
|
function Cone(diameter1, diameter2, height) {
|
|
1907
1899
|
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
1908
|
-
debug$
|
|
1900
|
+
debug$1("parts.Cone", diameter1, diameter2, height, options);
|
|
1909
1901
|
return CSG.cylinder(Object.assign({
|
|
1910
1902
|
start: [ 0, 0, 0 ],
|
|
1911
1903
|
end: [ 0, 0, height ],
|
|
@@ -1915,7 +1907,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
1915
1907
|
}, options));
|
|
1916
1908
|
}
|
|
1917
1909
|
function Hexagon(diameter, height) {
|
|
1918
|
-
debug$
|
|
1910
|
+
debug$1("hexagon", diameter, height);
|
|
1919
1911
|
var radius = diameter / 2;
|
|
1920
1912
|
var sqrt3 = Math.sqrt(3) / 2;
|
|
1921
1913
|
var hex = CAG.fromPoints([ [ radius, 0 ], [ radius / 2, radius * sqrt3 ], [ -radius / 2, radius * sqrt3 ], [ -radius, 0 ], [ -radius / 2, -radius * sqrt3 ], [ radius / 2, -radius * sqrt3 ] ]);
|
|
@@ -2013,7 +2005,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2013
2005
|
var parts$1 = Object.freeze({
|
|
2014
2006
|
__proto__: null,
|
|
2015
2007
|
default: parts,
|
|
2016
|
-
BBox,
|
|
2008
|
+
BBox: BBox$1,
|
|
2017
2009
|
Cube,
|
|
2018
2010
|
RoundedCube,
|
|
2019
2011
|
Cylinder,
|
|
@@ -2025,13 +2017,13 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2025
2017
|
Board,
|
|
2026
2018
|
Hardware
|
|
2027
2019
|
});
|
|
2028
|
-
var debug
|
|
2020
|
+
var debug = Debug("jscadUtils:boxes");
|
|
2029
2021
|
function RabbetJoin(box, thickness, cutHeight) {
|
|
2030
2022
|
depreciated("RabbetJoin", true, "Use 'Rabbet' instead");
|
|
2031
2023
|
return rabbetJoin(box, thickness, cutHeight);
|
|
2032
2024
|
}
|
|
2033
2025
|
function topMiddleBottom(box, thickness) {
|
|
2034
|
-
debug
|
|
2026
|
+
debug("TopMiddleBottom", box, thickness);
|
|
2035
2027
|
var bottom = box.bisect("z", thickness, {
|
|
2036
2028
|
color: true
|
|
2037
2029
|
});
|
|
@@ -2040,11 +2032,11 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2040
2032
|
}
|
|
2041
2033
|
function Rabett(box, thickness, gap, height, face) {
|
|
2042
2034
|
var options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
|
|
2043
|
-
debug
|
|
2035
|
+
debug("Rabett", "thickness", thickness, "gap", gap, "height", height, "face", face);
|
|
2044
2036
|
gap = gap || .25;
|
|
2045
2037
|
var inside = thickness - gap;
|
|
2046
2038
|
var outside = -thickness + gap;
|
|
2047
|
-
debug
|
|
2039
|
+
debug("inside", inside, "outside", outside);
|
|
2048
2040
|
var group = Group();
|
|
2049
2041
|
var _box$bisect$parts = box.bisect("z", height, options).parts, top = _box$bisect$parts.positive, lower2_3rd = _box$bisect$parts.negative;
|
|
2050
2042
|
var lowerBisectHeight = Math.sign(height) < 0 ? face * Math.sign(height) : height - face;
|
|
@@ -2066,7 +2058,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2066
2058
|
topWidth: -thickness,
|
|
2067
2059
|
bottomWidth: thickness
|
|
2068
2060
|
}, options);
|
|
2069
|
-
debug
|
|
2061
|
+
debug("RabettTopBottom", box, thickness, gap, options);
|
|
2070
2062
|
var group = Group("", {
|
|
2071
2063
|
box
|
|
2072
2064
|
});
|
|
@@ -2112,7 +2104,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2112
2104
|
};
|
|
2113
2105
|
var Rectangle = function Rectangle(size, thickness, cb) {
|
|
2114
2106
|
thickness = thickness || 2;
|
|
2115
|
-
var s = div(xyz2array(size), 2);
|
|
2107
|
+
var s = div$1(xyz2array(size), 2);
|
|
2116
2108
|
var r = add(s, thickness);
|
|
2117
2109
|
var box = CSG.cube({
|
|
2118
2110
|
center: r,
|
|
@@ -2132,16 +2124,16 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2132
2124
|
if (exteriorcb) box = exteriorcb(box);
|
|
2133
2125
|
return box;
|
|
2134
2126
|
};
|
|
2135
|
-
var BBox
|
|
2127
|
+
var BBox = function BBox(o) {
|
|
2136
2128
|
depreciated("BBox", true, "Use 'parts.BBox' instead");
|
|
2137
|
-
var s = div(xyz2array(o.size()), 2);
|
|
2129
|
+
var s = div$1(xyz2array(o.size()), 2);
|
|
2138
2130
|
return CSG.cube({
|
|
2139
2131
|
center: s,
|
|
2140
2132
|
radius: s
|
|
2141
2133
|
}).align(o, "xyz");
|
|
2142
2134
|
};
|
|
2143
2135
|
function getRadius(o) {
|
|
2144
|
-
return div(xyz2array(o.size()), 2);
|
|
2136
|
+
return div$1(xyz2array(o.size()), 2);
|
|
2145
2137
|
}
|
|
2146
2138
|
function rabbetJoin(box, thickness) {
|
|
2147
2139
|
var gap = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : .25;
|
|
@@ -2169,7 +2161,7 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2169
2161
|
CutOut,
|
|
2170
2162
|
Rectangle,
|
|
2171
2163
|
Hollow,
|
|
2172
|
-
BBox
|
|
2164
|
+
BBox
|
|
2173
2165
|
});
|
|
2174
2166
|
var compatV1 = _objectSpread2(_objectSpread2({}, util), {}, {
|
|
2175
2167
|
group: Group,
|
|
@@ -2189,6 +2181,9 @@ function initJscadutils(_CSG, options = {}) {
|
|
|
2189
2181
|
exports.parts = parts$1;
|
|
2190
2182
|
exports.triUtils = triUtils;
|
|
2191
2183
|
exports.util = util;
|
|
2184
|
+
Object.defineProperty(exports, "__esModule", {
|
|
2185
|
+
value: true
|
|
2186
|
+
});
|
|
2192
2187
|
return exports;
|
|
2193
2188
|
}({}, jsCadCSG, scadApi);
|
|
2194
2189
|
const debug = jscadUtils.Debug("jscadUtils:initJscadutils");
|