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