@jwc/jscad-utils 4.8.1 → 4.8.3

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.
@@ -101,8 +101,13 @@ function initJscadutils(_CSG, options = {}) {
101
101
  });
102
102
  var jscadUtils = function(exports, jsCadCSG, scadApi) {
103
103
  "use strict";
104
- jsCadCSG = jsCadCSG && Object.prototype.hasOwnProperty.call(jsCadCSG, "default") ? jsCadCSG["default"] : jsCadCSG;
105
- scadApi = scadApi && Object.prototype.hasOwnProperty.call(scadApi, "default") ? scadApi["default"] : scadApi;
104
+ function _interopDefaultLegacy(e) {
105
+ return e && typeof e === "object" && "default" in e ? e : {
106
+ default: e
107
+ };
108
+ }
109
+ var jsCadCSG__default = _interopDefaultLegacy(jsCadCSG);
110
+ var scadApi__default = _interopDefaultLegacy(scadApi);
106
111
  var util = Object.freeze({
107
112
  __proto__: null,
108
113
  get NOZZEL_SIZE() {
@@ -349,9 +354,9 @@ function initJscadutils(_CSG, options = {}) {
349
354
  var keys = Object.keys(object);
350
355
  if (Object.getOwnPropertySymbols) {
351
356
  var symbols = Object.getOwnPropertySymbols(object);
352
- if (enumerableOnly) symbols = symbols.filter(function(sym) {
357
+ if (enumerableOnly) symbols = symbols.filter((function(sym) {
353
358
  return Object.getOwnPropertyDescriptor(object, sym).enumerable;
354
- });
359
+ }));
355
360
  keys.push.apply(keys, symbols);
356
361
  }
357
362
  return keys;
@@ -360,15 +365,15 @@ function initJscadutils(_CSG, options = {}) {
360
365
  for (var i = 1; i < arguments.length; i++) {
361
366
  var source = arguments[i] != null ? arguments[i] : {};
362
367
  if (i % 2) {
363
- ownKeys(Object(source), true).forEach(function(key) {
368
+ ownKeys(Object(source), true).forEach((function(key) {
364
369
  _defineProperty(target, key, source[key]);
365
- });
370
+ }));
366
371
  } else if (Object.getOwnPropertyDescriptors) {
367
372
  Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
368
373
  } else {
369
- ownKeys(Object(source)).forEach(function(key) {
374
+ ownKeys(Object(source)).forEach((function(key) {
370
375
  Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
371
- });
376
+ }));
372
377
  }
373
378
  }
374
379
  return target;
@@ -477,29 +482,29 @@ function initJscadutils(_CSG, options = {}) {
477
482
  solveab
478
483
  });
479
484
  var div = function div(a, f) {
480
- return a.map(function(e) {
485
+ return a.map((function(e) {
481
486
  return e / f;
482
- });
487
+ }));
483
488
  };
484
489
  var addValue = function addValue(a, f) {
485
- return a.map(function(e) {
490
+ return a.map((function(e) {
486
491
  return e + f;
487
- });
492
+ }));
488
493
  };
489
494
  var addArray = function addArray(a, f) {
490
- return a.map(function(e, i) {
495
+ return a.map((function(e, i) {
491
496
  return e + f[i];
492
- });
497
+ }));
493
498
  };
494
499
  var add = function add(a) {
495
- return Array.prototype.slice.call(arguments, 1).reduce(function(result, arg) {
500
+ return Array.prototype.slice.call(arguments, 1).reduce((function(result, arg) {
496
501
  if (Array.isArray(arg)) {
497
502
  result = addArray(result, arg);
498
503
  } else {
499
504
  result = addValue(result, arg);
500
505
  }
501
506
  return result;
502
- }, a);
507
+ }), a);
503
508
  };
504
509
  var fromxyz = function fromxyz(object) {
505
510
  return Array.isArray(object) ? object : [ object.x, object.y, object.z ];
@@ -518,9 +523,9 @@ function initJscadutils(_CSG, options = {}) {
518
523
  return a && a.length > 0 ? a[a.length - 1] : undefined;
519
524
  };
520
525
  var min = function min(a) {
521
- return a.reduce(function(result, value) {
526
+ return a.reduce((function(result, value) {
522
527
  return value < result ? value : result;
523
- }, Number.MAX_VALUE);
528
+ }), Number.MAX_VALUE);
524
529
  };
525
530
  var range = function range(a, b) {
526
531
  var result = [];
@@ -554,11 +559,11 @@ function initJscadutils(_CSG, options = {}) {
554
559
  }
555
560
  }, jscadUtilsDebug || {});
556
561
  var style = checks.options.browser ? "color:".concat(debugColors[debugCount++ % debugColors.length]) : "".concat(termColors[debugCount++ % termColors.length]);
557
- var enabled = checks.enabled.some(function checkEnabled(check) {
562
+ var enabled = checks.enabled.some((function checkEnabled(check) {
558
563
  return check.test(name);
559
- }) && !checks.disabled.some(function checkEnabled(check) {
564
+ })) && !checks.disabled.some((function checkEnabled(check) {
560
565
  return check.test(name);
561
- });
566
+ }));
562
567
  var logger = enabled ? checks.options.browser ? function() {
563
568
  var _console;
564
569
  for (var _len = arguments.length, msg = new Array(_len), _key = 0; _key < _len; _key++) {
@@ -745,9 +750,9 @@ function initJscadutils(_CSG, options = {}) {
745
750
  function color(o, r, g, b, a) {
746
751
  if (typeof r !== "string") return o.setColor(r, g, b, a);
747
752
  if (r === "") return o;
748
- var c = name2rgb(r).map(function(x) {
753
+ var c = name2rgb(r).map((function(x) {
749
754
  return x / 255;
750
- });
755
+ }));
751
756
  c[3] = g || 1;
752
757
  return o.setColor(c);
753
758
  }
@@ -849,10 +854,10 @@ function initJscadutils(_CSG, options = {}) {
849
854
  if (arguments.length === 1) {
850
855
  return this._translate(arguments[0]);
851
856
  } else {
852
- var t = Array.prototype.slice.call(arguments, 0).reduce(function(result, arg) {
857
+ var t = Array.prototype.slice.call(arguments, 0).reduce((function(result, arg) {
853
858
  result = undefined(result, arg);
854
859
  return result;
855
- }, [ 0, 0, 0 ]);
860
+ }), [ 0, 0, 0 ]);
856
861
  return this._translate(t);
857
862
  }
858
863
  };
@@ -862,9 +867,9 @@ function initJscadutils(_CSG, options = {}) {
862
867
  proto.prototype.connect = function connectTo(myConnectorName, otherConnector) {
863
868
  var mirror = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
864
869
  var normalrotation = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
865
- var myConnector = myConnectorName.split(".").reduce(function(a, v) {
870
+ var myConnector = myConnectorName.split(".").reduce((function(a, v) {
866
871
  return a[v];
867
- }, this.properties);
872
+ }), this.properties);
868
873
  if (!myConnector) {
869
874
  error("The connector '".concat(myConnectorName, "' does not exist on the object [").concat(Object.keys(this.properties).join(","), "]"), "Missing connector property");
870
875
  }
@@ -876,10 +881,10 @@ function initJscadutils(_CSG, options = {}) {
876
881
  __proto__: null,
877
882
  default: init
878
883
  });
879
- var CSG = jsCadCSG.CSG, CAG = jsCadCSG.CAG;
880
- var rectangular_extrude = scadApi.extrusions.rectangular_extrude;
881
- var _scadApi$text = scadApi.text, vector_text = _scadApi$text.vector_text, vector_char = _scadApi$text.vector_char;
882
- var union = scadApi.booleanOps.union;
884
+ var CSG = jsCadCSG__default["default"].CSG, CAG = jsCadCSG__default["default"].CAG;
885
+ var rectangular_extrude = scadApi__default["default"].extrusions.rectangular_extrude;
886
+ var _scadApi$text = scadApi__default["default"].text, vector_text = _scadApi$text.vector_text, vector_char = _scadApi$text.vector_char;
887
+ var union = scadApi__default["default"].booleanOps.union;
883
888
  init(CSG);
884
889
  var debug = Debug("jscadUtils:group");
885
890
  function JsCadUtilsGroup() {
@@ -899,9 +904,9 @@ function initJscadutils(_CSG, options = {}) {
899
904
  if (!hidden) self.names.push(name);
900
905
  self.parts[name] = object.combine(parts);
901
906
  if (subparts) {
902
- Object.keys(object.parts).forEach(function(key) {
907
+ Object.keys(object.parts).forEach((function(key) {
903
908
  self.parts[subparts + key] = object.parts[key];
904
- });
909
+ }));
905
910
  }
906
911
  } else {
907
912
  Object.assign(self.parts, object.parts);
@@ -928,9 +933,9 @@ function initJscadutils(_CSG, options = {}) {
928
933
  throw new Error("no pieces found in ".concat(self.name, " pieces: ").concat(pieces, " parts: ").concat(Object.keys(self.parts), " names: ").concat(self.names));
929
934
  }
930
935
  debug("combine", self.names, self.parts);
931
- var g = union(mapPick(self.parts, pieces, function(value, key, index, object) {
936
+ var g = union(mapPick(self.parts, pieces, (function(value, key, index, object) {
932
937
  return map ? map(value, key, index, object) : identity(value);
933
- }, self.name));
938
+ }), self.name));
934
939
  return g.subtractIf(self.holes && Array.isArray(self.holes) ? union(self.holes) : self.holes, self.holes && !options.noholes);
935
940
  } catch (err) {
936
941
  debug("combine error", this, pieces, options, err);
@@ -939,17 +944,17 @@ function initJscadutils(_CSG, options = {}) {
939
944
  };
940
945
  JsCadUtilsGroup.prototype.map = function(cb) {
941
946
  var self = this;
942
- self.parts = Object.keys(self.parts).filter(function(k) {
947
+ self.parts = Object.keys(self.parts).filter((function(k) {
943
948
  return k !== "holes";
944
- }).reduce(function(result, key) {
949
+ })).reduce((function(result, key) {
945
950
  result[key] = cb(self.parts[key], key);
946
951
  return result;
947
- }, {});
952
+ }), {});
948
953
  if (self.holes) {
949
954
  if (Array.isArray(self.holes)) {
950
- self.holes = self.holes.map(function(hole, idx) {
955
+ self.holes = self.holes.map((function(hole, idx) {
951
956
  return cb(hole, idx);
952
- });
957
+ }));
953
958
  } else {
954
959
  self.holes = cb(self.holes, "holes");
955
960
  }
@@ -965,15 +970,15 @@ function initJscadutils(_CSG, options = {}) {
965
970
  }
966
971
  if (!map) map = identity;
967
972
  var group = Group(name);
968
- Object.keys(self.parts).forEach(function(key) {
973
+ Object.keys(self.parts).forEach((function(key) {
969
974
  var part = self.parts[key];
970
975
  var hidden = self.names.indexOf(key) == -1;
971
976
  group.add(map(clone(part)), key, hidden);
972
- });
977
+ }));
973
978
  if (self.holes) {
974
- group.holes = toArray(self.holes).map(function(part) {
979
+ group.holes = toArray(self.holes).map((function(part) {
975
980
  return map(CSG.fromPolygons(part.toPolygons()), "holes");
976
- });
981
+ }));
977
982
  }
978
983
  return group;
979
984
  };
@@ -990,9 +995,9 @@ function initJscadutils(_CSG, options = {}) {
990
995
  }
991
996
  var rotationCenter = solid.centroid();
992
997
  var rotationAxis = axes[axis];
993
- self.map(function(part) {
998
+ self.map((function(part) {
994
999
  return part.rotate(rotationCenter, rotationAxis, angle);
995
- });
1000
+ }));
996
1001
  return self;
997
1002
  };
998
1003
  JsCadUtilsGroup.prototype.combineAll = function(options, map) {
@@ -1003,9 +1008,9 @@ function initJscadutils(_CSG, options = {}) {
1003
1008
  try {
1004
1009
  var self = this;
1005
1010
  var t = calcSnap(self.combine(part), to, axis, orientation, delta);
1006
- self.map(function(part) {
1011
+ self.map((function(part) {
1007
1012
  return part.translate(t);
1008
- });
1013
+ }));
1009
1014
  return self;
1010
1015
  } catch (err) {
1011
1016
  debug("snap error", this, part, to, axis, delta, err);
@@ -1018,9 +1023,9 @@ function initJscadutils(_CSG, options = {}) {
1018
1023
  var t = calcCenterWith(self.combine(part, {
1019
1024
  noholes: true
1020
1025
  }), axis, to, delta);
1021
- self.map(function(part) {
1026
+ self.map((function(part) {
1022
1027
  return part.translate(t);
1023
- });
1028
+ }));
1024
1029
  return self;
1025
1030
  } catch (err) {
1026
1031
  debug("align error", this, part, to, axis, delta, err);
@@ -1048,38 +1053,38 @@ function initJscadutils(_CSG, options = {}) {
1048
1053
  normalrotation
1049
1054
  });
1050
1055
  var self = this;
1051
- var myConnector = connectorName.split(".").reduce(function(a, v) {
1056
+ var myConnector = connectorName.split(".").reduce((function(a, v) {
1052
1057
  return a[v];
1053
- }, self.parts[partName].properties);
1058
+ }), self.parts[partName].properties);
1054
1059
  debug("toConnector", to instanceof CSG.Connector);
1055
- var toConnector = toConnectorName.split(".").reduce(function(a, v) {
1060
+ var toConnector = toConnectorName.split(".").reduce((function(a, v) {
1056
1061
  return a[v];
1057
- }, to.properties);
1062
+ }), to.properties);
1058
1063
  var matrix = myConnector.getTransformationTo(toConnector, mirror, normalrotation);
1059
1064
  debug("connectTo", matrix);
1060
- self.map(function(part) {
1065
+ self.map((function(part) {
1061
1066
  return part.transform(matrix);
1062
- });
1067
+ }));
1063
1068
  return self;
1064
1069
  };
1065
1070
  JsCadUtilsGroup.prototype.midlineTo = function midlineTo(part, axis, to) {
1066
1071
  var self = this;
1067
1072
  var size = self.combine(part).size();
1068
- var t = axisApply(axis, function(i, a) {
1073
+ var t = axisApply(axis, (function(i, a) {
1069
1074
  return to - size[a] / 2;
1070
- });
1071
- self.map(function(part) {
1075
+ }));
1076
+ self.map((function(part) {
1072
1077
  return part.translate(t);
1073
- });
1078
+ }));
1074
1079
  return self;
1075
1080
  };
1076
1081
  JsCadUtilsGroup.prototype.translate = function translate(x, y, z) {
1077
1082
  var self = this;
1078
1083
  var t = Array.isArray(x) ? x : [ x, y, z ];
1079
1084
  debug("translate", t);
1080
- self.map(function(part) {
1085
+ self.map((function(part) {
1081
1086
  return part.translate(t);
1082
- });
1087
+ }));
1083
1088
  return self;
1084
1089
  };
1085
1090
  JsCadUtilsGroup.prototype.pick = function(parts, map) {
@@ -1087,9 +1092,9 @@ function initJscadutils(_CSG, options = {}) {
1087
1092
  var p = parts && parts.length > 0 && parts.split(",") || self.names;
1088
1093
  if (!map) map = identity;
1089
1094
  var g = Group();
1090
- p.forEach(function(name) {
1095
+ p.forEach((function(name) {
1091
1096
  g.add(map(CSG.fromPolygons(self.parts[name].toPolygons()), name), name);
1092
- });
1097
+ }));
1093
1098
  return g;
1094
1099
  };
1095
1100
  JsCadUtilsGroup.prototype.array = function(parts, map) {
@@ -1098,22 +1103,22 @@ function initJscadutils(_CSG, options = {}) {
1098
1103
  var p = parts && parts.length > 0 && parts.split(",") || self.names;
1099
1104
  if (!map) map = identity;
1100
1105
  var a = [];
1101
- p.forEach(function(name) {
1106
+ p.forEach((function(name) {
1102
1107
  if (!self.parts[name]) {
1103
1108
  debug("array error", _this, parts);
1104
1109
  throw error('group::array error "'.concat(name, '" not found.\nthis: ').concat(_this, '\nparts: "').concat(parts, '"\n'), "JSCAD_UTILS_GROUP_ERROR");
1105
1110
  }
1106
1111
  a.push(map(CSG.fromPolygons(self.parts[name].toPolygons()), name));
1107
- });
1112
+ }));
1108
1113
  return a;
1109
1114
  };
1110
1115
  JsCadUtilsGroup.prototype.toArray = function(pieces) {
1111
1116
  var self = this;
1112
1117
  var piecesArray = pieces ? pieces.split(",") : self.names;
1113
- return piecesArray.map(function(piece) {
1118
+ return piecesArray.map((function(piece) {
1114
1119
  if (!self.parts[piece]) console.error("Cannot find ".concat(piece, " in ").concat(self.names));
1115
1120
  return self.parts[piece];
1116
- });
1121
+ }));
1117
1122
  };
1118
1123
  JsCadUtilsGroup.prototype.toString = function() {
1119
1124
  return '{\n name: "'.concat(this.name, '",\n names: "').concat(this.names.join(","), '", \n parts: "').concat(Object.keys(this.parts), '",\n holes: "').concat(this.holes, '"\n}');
@@ -1146,9 +1151,9 @@ function initJscadutils(_CSG, options = {}) {
1146
1151
  self.name = objectNames;
1147
1152
  } else {
1148
1153
  var objects = objectNames;
1149
- self.names = Object.keys(objects).filter(function(k) {
1154
+ self.names = Object.keys(objects).filter((function(k) {
1150
1155
  return k !== "holes";
1151
- });
1156
+ }));
1152
1157
  self.parts = Object.assign({}, objects);
1153
1158
  self.holes = objects.holes;
1154
1159
  }
@@ -1227,21 +1232,21 @@ function initJscadutils(_CSG, options = {}) {
1227
1232
  function label(text, x, y, width, height) {
1228
1233
  var l = vector_text(x || 0, y || 0, text);
1229
1234
  var o = [];
1230
- l.forEach(function(pl) {
1235
+ l.forEach((function(pl) {
1231
1236
  o.push(rectangular_extrude(pl, {
1232
1237
  w: width || 2,
1233
1238
  h: height || 2
1234
1239
  }));
1235
- });
1240
+ }));
1236
1241
  return center(union(o));
1237
1242
  }
1238
1243
  function text(text) {
1239
1244
  var l = vector_char(0, 0, text);
1240
- var _char = l.segments.reduce(function(result, segment) {
1245
+ var _char = l.segments.reduce((function(result, segment) {
1241
1246
  var path = new CSG.Path2D(segment);
1242
1247
  var cag = path.expandToCAG(2);
1243
1248
  return result ? result.union(cag) : cag;
1244
- }, undefined);
1249
+ }), undefined);
1245
1250
  return _char;
1246
1251
  }
1247
1252
  function unitCube(length, radius) {
@@ -1274,35 +1279,35 @@ function initJscadutils(_CSG, options = {}) {
1274
1279
  return result;
1275
1280
  }
1276
1281
  function zipObject(names, values) {
1277
- return names.reduce(function(result, value, idx) {
1282
+ return names.reduce((function(result, value, idx) {
1278
1283
  result[value] = values[idx];
1279
1284
  return result;
1280
- }, {});
1285
+ }), {});
1281
1286
  }
1282
1287
  function map(o, f) {
1283
- return Object.keys(o).map(function(key) {
1288
+ return Object.keys(o).map((function(key) {
1284
1289
  return f(o[key], key, o);
1285
- });
1290
+ }));
1286
1291
  }
1287
1292
  function mapValues(o, f) {
1288
- return Object.keys(o).map(function(key) {
1293
+ return Object.keys(o).map((function(key) {
1289
1294
  return f(o[key], key);
1290
- });
1295
+ }));
1291
1296
  }
1292
1297
  function pick(o, names) {
1293
- return names.reduce(function(result, name) {
1298
+ return names.reduce((function(result, name) {
1294
1299
  result[name] = o[name];
1295
1300
  return result;
1296
- }, {});
1301
+ }), {});
1297
1302
  }
1298
1303
  function mapPick(o, names, f, options) {
1299
- return names.reduce(function(result, name, index) {
1304
+ return names.reduce((function(result, name, index) {
1300
1305
  if (!o[name]) {
1301
1306
  throw new Error("".concat(name, " not found in ").concat(options.name, ": ").concat(Object.keys(o).join(",")));
1302
1307
  }
1303
1308
  result.push(f ? f(o[name], name, index, o) : o[name]);
1304
1309
  return result;
1305
- }, []);
1310
+ }), []);
1306
1311
  }
1307
1312
  function divA(a, f) {
1308
1313
  return div(a, f);
@@ -1366,9 +1371,9 @@ function initJscadutils(_CSG, options = {}) {
1366
1371
  var objectSize = size(object);
1367
1372
  var objectCentroid = centroid(object, objectSize);
1368
1373
  var idx = 0;
1369
- var t = map(objectSize, function(i) {
1374
+ var t = map(objectSize, (function(i) {
1370
1375
  return scale(i, a[idx++]);
1371
- });
1376
+ }));
1372
1377
  var new_object = object.scale(t);
1373
1378
  var new_centroid = centroid(new_object);
1374
1379
  var delta = new_centroid.minus(objectCentroid).times(-1);
@@ -1392,10 +1397,10 @@ function initJscadutils(_CSG, options = {}) {
1392
1397
  }
1393
1398
  var s = [ scale(objectSize.x, x), scale(objectSize.y, y), scale(objectSize.z, z) ];
1394
1399
  var min$1 = min(s);
1395
- return centerWith(object.scale(s.map(function(d, i) {
1400
+ return centerWith(object.scale(s.map((function(d, i) {
1396
1401
  if (a[i] === 0) return 1;
1397
1402
  return keep_aspect_ratio ? min$1 : d;
1398
- })), "xyz", object);
1403
+ }))), "xyz", object);
1399
1404
  }
1400
1405
  function shift(object, x, y, z) {
1401
1406
  var hsize = this.div(this.size(object.getBounds()), 2);
@@ -1434,9 +1439,9 @@ function initJscadutils(_CSG, options = {}) {
1434
1439
  if (side[0] === -1) {
1435
1440
  w[-1] = toxyz(withobj.centroid());
1436
1441
  }
1437
- return this.axisApply(axes, function(i, axis) {
1442
+ return this.axisApply(axes, (function(i, axis) {
1438
1443
  return w[side[0]][axis] - m[side[1]][axis];
1439
- });
1444
+ }));
1440
1445
  }
1441
1446
  function calcSnap(moveobj, withobj, axes, orientation) {
1442
1447
  var delta = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
@@ -1457,12 +1462,12 @@ function initJscadutils(_CSG, options = {}) {
1457
1462
  if (side[0] === -1) {
1458
1463
  w[-1] = withobj.centroid();
1459
1464
  }
1460
- var t = axisApply(axes, function(i, axis) {
1465
+ var t = axisApply(axes, (function(i, axis) {
1461
1466
  return w[side[0]][axis] - m[side[1]][axis];
1462
- });
1463
- return delta ? axisApply(axes, function(i) {
1467
+ }));
1468
+ return delta ? axisApply(axes, (function(i) {
1464
1469
  return t[i] + delta;
1465
- }) : t;
1470
+ })) : t;
1466
1471
  }
1467
1472
  function snap(moveobj, withobj, axis, orientation, delta) {
1468
1473
  debug$1("snap", moveobj, withobj, axis, orientation, delta);
@@ -1480,9 +1485,9 @@ function initJscadutils(_CSG, options = {}) {
1480
1485
  y: 1,
1481
1486
  z: 2
1482
1487
  };
1483
- axes.split("").forEach(function(axis) {
1488
+ axes.split("").forEach((function(axis) {
1484
1489
  retval[lookup[axis]] = valfun(lookup[axis], axis);
1485
- });
1490
+ }));
1486
1491
  return retval;
1487
1492
  }
1488
1493
  function axis2array(axes, valfun) {
@@ -1493,10 +1498,10 @@ function initJscadutils(_CSG, options = {}) {
1493
1498
  y: 1,
1494
1499
  z: 2
1495
1500
  };
1496
- axes.split("").forEach(function(axis) {
1501
+ axes.split("").forEach((function(axis) {
1497
1502
  var i = lookup[axis];
1498
1503
  a[i] = valfun(i, axis);
1499
- });
1504
+ }));
1500
1505
  return a;
1501
1506
  }
1502
1507
  function centroid(o, objectSize) {
@@ -1511,9 +1516,9 @@ function initJscadutils(_CSG, options = {}) {
1511
1516
  function calcmidlineTo(o, axis, to) {
1512
1517
  var bounds = o.getBounds();
1513
1518
  var objectSize = size(bounds);
1514
- return axisApply(axis, function(i, a) {
1519
+ return axisApply(axis, (function(i, a) {
1515
1520
  return to - objectSize[a] / 2;
1516
- });
1521
+ }));
1517
1522
  }
1518
1523
  function midlineTo(o, axis, to) {
1519
1524
  return o.translate(calcmidlineTo(o, axis, to));
@@ -1521,18 +1526,18 @@ function initJscadutils(_CSG, options = {}) {
1521
1526
  function translator(o, axis, withObj) {
1522
1527
  var objectCentroid = centroid(o);
1523
1528
  var withCentroid = centroid(withObj);
1524
- var t = axisApply(axis, function(i) {
1529
+ var t = axisApply(axis, (function(i) {
1525
1530
  return withCentroid[i] - objectCentroid[i];
1526
- });
1531
+ }));
1527
1532
  return t;
1528
1533
  }
1529
1534
  function calcCenterWith(o, axes, withObj) {
1530
1535
  var delta = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
1531
1536
  var objectCentroid = centroid(o);
1532
1537
  var withCentroid = centroid(withObj);
1533
- var t = axisApply(axes, function(i, axis) {
1538
+ var t = axisApply(axes, (function(i, axis) {
1534
1539
  return withCentroid[axis] - objectCentroid[axis];
1535
- });
1540
+ }));
1536
1541
  return delta ? add(t, delta) : t;
1537
1542
  }
1538
1543
  function centerWith(o, axis, withObj) {
@@ -1545,9 +1550,9 @@ function initJscadutils(_CSG, options = {}) {
1545
1550
  }
1546
1551
  }
1547
1552
  var dist = isNegative(offset) ? offset = size[axis] + offset : offset;
1548
- return axisApply(axis, function(i, a) {
1553
+ return axisApply(axis, (function(i, a) {
1549
1554
  return bounds[0][a] + (isEmpty(dist) ? size[axis] / 2 : dist);
1550
- });
1555
+ }));
1551
1556
  }
1552
1557
  function bisect() {
1553
1558
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
@@ -1610,11 +1615,11 @@ function initJscadutils(_CSG, options = {}) {
1610
1615
  }[[ axis, rotateaxis ].sort().join("")];
1611
1616
  var centroid = object.centroid();
1612
1617
  var rotateDelta = getDelta(objectSize, bounds, rotateOffsetAxis, rotateoffset);
1613
- var rotationCenter = options.rotationCenter || new CSG.Vector3D(axisApply("xyz", function(i, a) {
1618
+ var rotationCenter = options.rotationCenter || new CSG.Vector3D(axisApply("xyz", (function(i, a) {
1614
1619
  if (a == axis) return cutDelta[i];
1615
1620
  if (a == rotateOffsetAxis) return rotateDelta[i];
1616
1621
  return centroid[a];
1617
- }));
1622
+ })));
1618
1623
  var theRotationAxis = rotationAxes[rotateaxis];
1619
1624
  var cutplane = CSG.OrthoNormalBasis.GetCartesian(info.orthoNormalCartesian[0], info.orthoNormalCartesian[1]).translate(cutDelta).rotate(rotationCenter, theRotationAxis, angle);
1620
1625
  debug$1("bisect", debug$1.enabled && {
@@ -1673,7 +1678,7 @@ function initJscadutils(_CSG, options = {}) {
1673
1678
  }
1674
1679
  function poly2solid(top, bottom, height) {
1675
1680
  if (top.sides.length == 0) {
1676
- return new CSG();
1681
+ return new CSG;
1677
1682
  }
1678
1683
  var offsetVector = CSG.Vector3D.Create(0, 0, height);
1679
1684
  var normalVector = CSG.Vector3D.Create(0, 1, 0);
@@ -1698,6 +1703,11 @@ function initJscadutils(_CSG, options = {}) {
1698
1703
  return CSG.fromPolygons(polygons);
1699
1704
  }
1700
1705
  function slices2poly(slices, options, axis) {
1706
+ debug$1("slices2poly", slices, options, axis);
1707
+ options = Object.assign({
1708
+ twistangle: 0,
1709
+ twiststeps: 0
1710
+ }, options);
1701
1711
  var twistangle = options && parseFloat(options.twistangle) || 0;
1702
1712
  var twiststeps = options && parseInt(options.twiststeps) || CSG.defaultResolution3D;
1703
1713
  if (twistangle == 0 || twiststeps < 1) {
@@ -1707,6 +1717,7 @@ function initJscadutils(_CSG, options = {}) {
1707
1717
  var polygons = [];
1708
1718
  var first$1 = first(slices);
1709
1719
  var last$1 = last(slices);
1720
+ debug$1("slices2poly first", first$1, first$1.offset, "last", last$1);
1710
1721
  var up = first$1.offset[axis] > last$1.offset[axis];
1711
1722
  polygons = polygons.concat(first$1.poly._toPlanePolygons({
1712
1723
  translation: first$1.offset,
@@ -1725,7 +1736,7 @@ function initJscadutils(_CSG, options = {}) {
1725
1736
  return v[rotateAxis](angle * percent);
1726
1737
  };
1727
1738
  var connectorAxis = last$1.offset.minus(first$1.offset).abs();
1728
- slices.forEach(function(slice, idx) {
1739
+ slices.forEach((function(slice, idx) {
1729
1740
  if (idx < slices.length - 1) {
1730
1741
  var nextidx = idx + 1;
1731
1742
  var top = !up ? slices[nextidx] : slice;
@@ -1738,7 +1749,7 @@ function initJscadutils(_CSG, options = {}) {
1738
1749
  toConnector2: c2
1739
1750
  }));
1740
1751
  }
1741
- });
1752
+ }));
1742
1753
  return CSG.fromPolygons(polygons);
1743
1754
  }
1744
1755
  function normalVector(axis) {
@@ -1779,30 +1790,32 @@ function initJscadutils(_CSG, options = {}) {
1779
1790
  var info = dirInfo["dir" + direction];
1780
1791
  return Object.assign({
1781
1792
  axis,
1782
- cutDelta: axisApply(axis, function(i, a) {
1793
+ cutDelta: axisApply(axis, (function(i, a) {
1783
1794
  return bounds[info.sizeIdx][a] + Math.abs(radius) * info.sizeDir;
1784
- }),
1785
- moveDelta: axisApply(axis, function(i, a) {
1795
+ })),
1796
+ moveDelta: axisApply(axis, (function(i, a) {
1786
1797
  return bounds[info.sizeIdx][a] + Math.abs(radius) * info.moveDir;
1787
- })
1798
+ }))
1788
1799
  }, info, normalVector(axis));
1789
1800
  }
1790
1801
  function reShape(object, radius, orientation, options, slicer) {
1791
1802
  options = options || {};
1792
1803
  var b = object.getBounds();
1793
- var ar = Math.abs(radius);
1804
+ var absoluteRadius = Math.abs(radius);
1794
1805
  var si = sliceParams(orientation, radius, b);
1806
+ debug$1("reShape", absoluteRadius, si);
1795
1807
  if (si.axis !== "z") throw new Error('reShape error: CAG._toPlanePolytons only uses the "z" axis. You must use the "z" axis for now.');
1796
1808
  var cutplane = CSG.OrthoNormalBasis.GetCartesian(si.orthoNormalCartesian[0], si.orthoNormalCartesian[1]).translate(si.cutDelta);
1797
1809
  var slice = object.sectionCut(cutplane);
1798
- var first = axisApply(si.axis, function() {
1799
- return si.positive ? 0 : ar;
1800
- });
1801
- var last = axisApply(si.axis, function() {
1802
- return si.positive ? ar : 0;
1803
- });
1810
+ var first = axisApply(si.axis, (function() {
1811
+ return si.positive ? 0 : absoluteRadius;
1812
+ }));
1813
+ var last = axisApply(si.axis, (function() {
1814
+ return si.positive ? absoluteRadius : 0;
1815
+ }));
1804
1816
  var plane = si.positive ? cutplane.plane : cutplane.plane.flipped();
1805
- var slices = slicer(first, last, slice);
1817
+ debug$1("reShape first/last", first, last);
1818
+ var slices = slicer(first, last, slice, radius);
1806
1819
  var delta = slices2poly(slices, Object.assign(options, {
1807
1820
  si
1808
1821
  }), si.axis).color(options.color);
@@ -1810,7 +1823,7 @@ function initJscadutils(_CSG, options = {}) {
1810
1823
  return union([ options.unionOriginal ? object : remainder, delta.translate(si.moveDelta) ]);
1811
1824
  }
1812
1825
  function chamfer(object, radius, orientation, options) {
1813
- return reShape(object, radius, orientation, options, function(first, last, slice) {
1826
+ return reShape(object, radius, orientation, options, (function(first, last, slice) {
1814
1827
  return [ {
1815
1828
  poly: slice,
1816
1829
  offset: new CSG.Vector3D(first)
@@ -1818,15 +1831,15 @@ function initJscadutils(_CSG, options = {}) {
1818
1831
  poly: enlarge(slice, [ -radius * 2, -radius * 2 ]),
1819
1832
  offset: new CSG.Vector3D(last)
1820
1833
  } ];
1821
- });
1834
+ }));
1822
1835
  }
1823
1836
  function fillet(object, radius, orientation, options) {
1824
1837
  options = options || {};
1825
- return reShape(object, radius, orientation, options, function(first, last, slice) {
1838
+ return reShape(object, radius, orientation, options, (function(first, last, slice) {
1826
1839
  var v1 = new CSG.Vector3D(first);
1827
1840
  var v2 = new CSG.Vector3D(last);
1828
1841
  var res = options.resolution || CSG.defaultResolution3D;
1829
- var slices = range(0, res).map(function(i) {
1842
+ var slices = range(0, res).map((function(i) {
1830
1843
  var p = i > 0 ? i / (res - 1) : 0;
1831
1844
  var v = v1.lerp(v2, p);
1832
1845
  var size = -radius * 2 - Math.cos(Math.asin(p)) * (-radius * 2);
@@ -1834,9 +1847,9 @@ function initJscadutils(_CSG, options = {}) {
1834
1847
  poly: enlarge(slice, [ size, size ]),
1835
1848
  offset: v
1836
1849
  };
1837
- });
1850
+ }));
1838
1851
  return slices;
1839
- });
1852
+ }));
1840
1853
  }
1841
1854
  function calcRotate(part, solid, axis) {
1842
1855
  var axes = {
@@ -1856,11 +1869,11 @@ function initJscadutils(_CSG, options = {}) {
1856
1869
  return part.rotate(rotationCenter, rotationAxis, angle);
1857
1870
  }
1858
1871
  function cloneProperties(from, to) {
1859
- return Object.entries(from).reduce(function(props, _ref) {
1872
+ return Object.entries(from).reduce((function(props, _ref) {
1860
1873
  var _ref2 = _slicedToArray(_ref, 2), key = _ref2[0], value = _ref2[1];
1861
1874
  props[key] = value;
1862
1875
  return props;
1863
- }, to);
1876
+ }), to);
1864
1877
  }
1865
1878
  function clone(o) {
1866
1879
  var c = CSG.fromPolygons(o.toPolygons());
@@ -1893,10 +1906,10 @@ function initJscadutils(_CSG, options = {}) {
1893
1906
  for (var _len = arguments.length, objects = new Array(_len), _key = 0; _key < _len; _key++) {
1894
1907
  objects[_key] = arguments[_key];
1895
1908
  }
1896
- return objects.reduce(function(bbox, part) {
1909
+ return objects.reduce((function(bbox, part) {
1897
1910
  var object = bbox ? union([ bbox, box(part) ]) : part;
1898
1911
  return box(object);
1899
- }, undefined);
1912
+ }), undefined);
1900
1913
  }
1901
1914
  function Cube(width) {
1902
1915
  var r = div(fromxyz(width), 2);
@@ -2077,16 +2090,17 @@ function initJscadutils(_CSG, options = {}) {
2077
2090
  gap = gap || .25;
2078
2091
  var inside = thickness - gap;
2079
2092
  var outside = -thickness + gap;
2080
- options.color = true;
2093
+ debug$3("inside", inside, "outside", outside);
2081
2094
  var group = Group();
2082
- debug$3("Rabbet top height:", height, "options:", options);
2083
2095
  var _box$bisect$parts = box.bisect("z", height, options).parts, top = _box$bisect$parts.positive, lower2_3rd = _box$bisect$parts.negative;
2084
- debug$3("face", face, "height", height);
2085
2096
  var lowerBisectHeight = Math.sign(height) < 0 ? face * Math.sign(height) : height - face;
2086
- debug$3("Rabbet bottom height:", lowerBisectHeight, "options:", options);
2087
2097
  var _lower2_3rd$bisect$pa = lower2_3rd.bisect("z", lowerBisectHeight, options).parts, middle = _lower2_3rd$bisect$pa.positive, bottom = _lower2_3rd$bisect$pa.negative;
2088
- group.add(top.union(middle.color("yellow").subtract(middle.color("darkred").enlarge([ outside, outside, 0 ]))), "top");
2089
- group.add(bottom.color("orange").union(middle.color("green").subtract(middle.color("red").enlarge([ inside, inside, 0 ]))), "bottom");
2098
+ var middleTop = middle.color("yellow").subtract(middle.color("darkred").enlarge([ outside, outside, 0 ]));
2099
+ group.add(top.union(middleTop), "top");
2100
+ var bottomOutline = middle.color("yellow").subtract(middle.color("orange").enlarge([ outside, outside, 0 ])).enlarge([ outside, outside, 0 ]);
2101
+ group.add(bottomOutline, "middle-top", true);
2102
+ group.add(middle.color("green").subtract(middle.color("pink").enlarge([ inside, inside, 0 ])), "middle-bottom", true);
2103
+ group.add(bottom.color("orange").union(middle.color("green").subtract(middle.color("red").enlarge([ inside, inside, 0 ])).subtract(middleTop)), "bottom");
2090
2104
  return group;
2091
2105
  }
2092
2106
  var RabettTopBottom = function rabbetTMB(box, thickness) {