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