@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.
@@ -56,8 +56,13 @@ function initJscadutils(_CSG, options = {}) {
56
56
  });
57
57
  var jscadUtils = function(exports, jsCadCSG, scadApi) {
58
58
  "use strict";
59
- jsCadCSG = jsCadCSG && Object.prototype.hasOwnProperty.call(jsCadCSG, "default") ? jsCadCSG["default"] : jsCadCSG;
60
- scadApi = scadApi && Object.prototype.hasOwnProperty.call(scadApi, "default") ? scadApi["default"] : scadApi;
59
+ function _interopDefaultLegacy(e) {
60
+ return e && typeof e === "object" && "default" in e ? e : {
61
+ default: e
62
+ };
63
+ }
64
+ var jsCadCSG__default = _interopDefaultLegacy(jsCadCSG);
65
+ var scadApi__default = _interopDefaultLegacy(scadApi);
61
66
  var util = Object.freeze({
62
67
  __proto__: null,
63
68
  get NOZZEL_SIZE() {
@@ -304,9 +309,9 @@ function initJscadutils(_CSG, options = {}) {
304
309
  var keys = Object.keys(object);
305
310
  if (Object.getOwnPropertySymbols) {
306
311
  var symbols = Object.getOwnPropertySymbols(object);
307
- if (enumerableOnly) symbols = symbols.filter(function(sym) {
312
+ if (enumerableOnly) symbols = symbols.filter((function(sym) {
308
313
  return Object.getOwnPropertyDescriptor(object, sym).enumerable;
309
- });
314
+ }));
310
315
  keys.push.apply(keys, symbols);
311
316
  }
312
317
  return keys;
@@ -315,15 +320,15 @@ function initJscadutils(_CSG, options = {}) {
315
320
  for (var i = 1; i < arguments.length; i++) {
316
321
  var source = arguments[i] != null ? arguments[i] : {};
317
322
  if (i % 2) {
318
- ownKeys(Object(source), true).forEach(function(key) {
323
+ ownKeys(Object(source), true).forEach((function(key) {
319
324
  _defineProperty(target, key, source[key]);
320
- });
325
+ }));
321
326
  } else if (Object.getOwnPropertyDescriptors) {
322
327
  Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
323
328
  } else {
324
- ownKeys(Object(source)).forEach(function(key) {
329
+ ownKeys(Object(source)).forEach((function(key) {
325
330
  Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
326
- });
331
+ }));
327
332
  }
328
333
  }
329
334
  return target;
@@ -432,29 +437,29 @@ function initJscadutils(_CSG, options = {}) {
432
437
  solveab
433
438
  });
434
439
  var div = function div(a, f) {
435
- return a.map(function(e) {
440
+ return a.map((function(e) {
436
441
  return e / f;
437
- });
442
+ }));
438
443
  };
439
444
  var addValue = function addValue(a, f) {
440
- return a.map(function(e) {
445
+ return a.map((function(e) {
441
446
  return e + f;
442
- });
447
+ }));
443
448
  };
444
449
  var addArray = function addArray(a, f) {
445
- return a.map(function(e, i) {
450
+ return a.map((function(e, i) {
446
451
  return e + f[i];
447
- });
452
+ }));
448
453
  };
449
454
  var add = function add(a) {
450
- return Array.prototype.slice.call(arguments, 1).reduce(function(result, arg) {
455
+ return Array.prototype.slice.call(arguments, 1).reduce((function(result, arg) {
451
456
  if (Array.isArray(arg)) {
452
457
  result = addArray(result, arg);
453
458
  } else {
454
459
  result = addValue(result, arg);
455
460
  }
456
461
  return result;
457
- }, a);
462
+ }), a);
458
463
  };
459
464
  var fromxyz = function fromxyz(object) {
460
465
  return Array.isArray(object) ? object : [ object.x, object.y, object.z ];
@@ -473,9 +478,9 @@ function initJscadutils(_CSG, options = {}) {
473
478
  return a && a.length > 0 ? a[a.length - 1] : undefined;
474
479
  };
475
480
  var min = function min(a) {
476
- return a.reduce(function(result, value) {
481
+ return a.reduce((function(result, value) {
477
482
  return value < result ? value : result;
478
- }, Number.MAX_VALUE);
483
+ }), Number.MAX_VALUE);
479
484
  };
480
485
  var range = function range(a, b) {
481
486
  var result = [];
@@ -509,11 +514,11 @@ function initJscadutils(_CSG, options = {}) {
509
514
  }
510
515
  }, jscadUtilsDebug || {});
511
516
  var style = checks.options.browser ? "color:".concat(debugColors[debugCount++ % debugColors.length]) : "".concat(termColors[debugCount++ % termColors.length]);
512
- var enabled = checks.enabled.some(function checkEnabled(check) {
517
+ var enabled = checks.enabled.some((function checkEnabled(check) {
513
518
  return check.test(name);
514
- }) && !checks.disabled.some(function checkEnabled(check) {
519
+ })) && !checks.disabled.some((function checkEnabled(check) {
515
520
  return check.test(name);
516
- });
521
+ }));
517
522
  var logger = enabled ? checks.options.browser ? function() {
518
523
  var _console;
519
524
  for (var _len = arguments.length, msg = new Array(_len), _key = 0; _key < _len; _key++) {
@@ -700,9 +705,9 @@ function initJscadutils(_CSG, options = {}) {
700
705
  function color(o, r, g, b, a) {
701
706
  if (typeof r !== "string") return o.setColor(r, g, b, a);
702
707
  if (r === "") return o;
703
- var c = name2rgb(r).map(function(x) {
708
+ var c = name2rgb(r).map((function(x) {
704
709
  return x / 255;
705
- });
710
+ }));
706
711
  c[3] = g || 1;
707
712
  return o.setColor(c);
708
713
  }
@@ -804,10 +809,10 @@ function initJscadutils(_CSG, options = {}) {
804
809
  if (arguments.length === 1) {
805
810
  return this._translate(arguments[0]);
806
811
  } else {
807
- var t = Array.prototype.slice.call(arguments, 0).reduce(function(result, arg) {
812
+ var t = Array.prototype.slice.call(arguments, 0).reduce((function(result, arg) {
808
813
  result = undefined(result, arg);
809
814
  return result;
810
- }, [ 0, 0, 0 ]);
815
+ }), [ 0, 0, 0 ]);
811
816
  return this._translate(t);
812
817
  }
813
818
  };
@@ -817,9 +822,9 @@ function initJscadutils(_CSG, options = {}) {
817
822
  proto.prototype.connect = function connectTo(myConnectorName, otherConnector) {
818
823
  var mirror = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
819
824
  var normalrotation = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
820
- var myConnector = myConnectorName.split(".").reduce(function(a, v) {
825
+ var myConnector = myConnectorName.split(".").reduce((function(a, v) {
821
826
  return a[v];
822
- }, this.properties);
827
+ }), this.properties);
823
828
  if (!myConnector) {
824
829
  error("The connector '".concat(myConnectorName, "' does not exist on the object [").concat(Object.keys(this.properties).join(","), "]"), "Missing connector property");
825
830
  }
@@ -831,10 +836,10 @@ function initJscadutils(_CSG, options = {}) {
831
836
  __proto__: null,
832
837
  default: init
833
838
  });
834
- var CSG = jsCadCSG.CSG, CAG = jsCadCSG.CAG;
835
- var rectangular_extrude = scadApi.extrusions.rectangular_extrude;
836
- var _scadApi$text = scadApi.text, vector_text = _scadApi$text.vector_text, vector_char = _scadApi$text.vector_char;
837
- var union = scadApi.booleanOps.union;
839
+ var CSG = jsCadCSG__default["default"].CSG, CAG = jsCadCSG__default["default"].CAG;
840
+ var rectangular_extrude = scadApi__default["default"].extrusions.rectangular_extrude;
841
+ var _scadApi$text = scadApi__default["default"].text, vector_text = _scadApi$text.vector_text, vector_char = _scadApi$text.vector_char;
842
+ var union = scadApi__default["default"].booleanOps.union;
838
843
  init(CSG);
839
844
  var debug = Debug("jscadUtils:group");
840
845
  function JsCadUtilsGroup() {
@@ -854,9 +859,9 @@ function initJscadutils(_CSG, options = {}) {
854
859
  if (!hidden) self.names.push(name);
855
860
  self.parts[name] = object.combine(parts);
856
861
  if (subparts) {
857
- Object.keys(object.parts).forEach(function(key) {
862
+ Object.keys(object.parts).forEach((function(key) {
858
863
  self.parts[subparts + key] = object.parts[key];
859
- });
864
+ }));
860
865
  }
861
866
  } else {
862
867
  Object.assign(self.parts, object.parts);
@@ -883,9 +888,9 @@ function initJscadutils(_CSG, options = {}) {
883
888
  throw new Error("no pieces found in ".concat(self.name, " pieces: ").concat(pieces, " parts: ").concat(Object.keys(self.parts), " names: ").concat(self.names));
884
889
  }
885
890
  debug("combine", self.names, self.parts);
886
- var g = union(mapPick(self.parts, pieces, function(value, key, index, object) {
891
+ var g = union(mapPick(self.parts, pieces, (function(value, key, index, object) {
887
892
  return map ? map(value, key, index, object) : identity(value);
888
- }, self.name));
893
+ }), self.name));
889
894
  return g.subtractIf(self.holes && Array.isArray(self.holes) ? union(self.holes) : self.holes, self.holes && !options.noholes);
890
895
  } catch (err) {
891
896
  debug("combine error", this, pieces, options, err);
@@ -894,17 +899,17 @@ function initJscadutils(_CSG, options = {}) {
894
899
  };
895
900
  JsCadUtilsGroup.prototype.map = function(cb) {
896
901
  var self = this;
897
- self.parts = Object.keys(self.parts).filter(function(k) {
902
+ self.parts = Object.keys(self.parts).filter((function(k) {
898
903
  return k !== "holes";
899
- }).reduce(function(result, key) {
904
+ })).reduce((function(result, key) {
900
905
  result[key] = cb(self.parts[key], key);
901
906
  return result;
902
- }, {});
907
+ }), {});
903
908
  if (self.holes) {
904
909
  if (Array.isArray(self.holes)) {
905
- self.holes = self.holes.map(function(hole, idx) {
910
+ self.holes = self.holes.map((function(hole, idx) {
906
911
  return cb(hole, idx);
907
- });
912
+ }));
908
913
  } else {
909
914
  self.holes = cb(self.holes, "holes");
910
915
  }
@@ -920,15 +925,15 @@ function initJscadutils(_CSG, options = {}) {
920
925
  }
921
926
  if (!map) map = identity;
922
927
  var group = Group(name);
923
- Object.keys(self.parts).forEach(function(key) {
928
+ Object.keys(self.parts).forEach((function(key) {
924
929
  var part = self.parts[key];
925
930
  var hidden = self.names.indexOf(key) == -1;
926
931
  group.add(map(clone(part)), key, hidden);
927
- });
932
+ }));
928
933
  if (self.holes) {
929
- group.holes = toArray(self.holes).map(function(part) {
934
+ group.holes = toArray(self.holes).map((function(part) {
930
935
  return map(CSG.fromPolygons(part.toPolygons()), "holes");
931
- });
936
+ }));
932
937
  }
933
938
  return group;
934
939
  };
@@ -945,9 +950,9 @@ function initJscadutils(_CSG, options = {}) {
945
950
  }
946
951
  var rotationCenter = solid.centroid();
947
952
  var rotationAxis = axes[axis];
948
- self.map(function(part) {
953
+ self.map((function(part) {
949
954
  return part.rotate(rotationCenter, rotationAxis, angle);
950
- });
955
+ }));
951
956
  return self;
952
957
  };
953
958
  JsCadUtilsGroup.prototype.combineAll = function(options, map) {
@@ -958,9 +963,9 @@ function initJscadutils(_CSG, options = {}) {
958
963
  try {
959
964
  var self = this;
960
965
  var t = calcSnap(self.combine(part), to, axis, orientation, delta);
961
- self.map(function(part) {
966
+ self.map((function(part) {
962
967
  return part.translate(t);
963
- });
968
+ }));
964
969
  return self;
965
970
  } catch (err) {
966
971
  debug("snap error", this, part, to, axis, delta, err);
@@ -973,9 +978,9 @@ function initJscadutils(_CSG, options = {}) {
973
978
  var t = calcCenterWith(self.combine(part, {
974
979
  noholes: true
975
980
  }), axis, to, delta);
976
- self.map(function(part) {
981
+ self.map((function(part) {
977
982
  return part.translate(t);
978
- });
983
+ }));
979
984
  return self;
980
985
  } catch (err) {
981
986
  debug("align error", this, part, to, axis, delta, err);
@@ -1003,38 +1008,38 @@ function initJscadutils(_CSG, options = {}) {
1003
1008
  normalrotation
1004
1009
  });
1005
1010
  var self = this;
1006
- var myConnector = connectorName.split(".").reduce(function(a, v) {
1011
+ var myConnector = connectorName.split(".").reduce((function(a, v) {
1007
1012
  return a[v];
1008
- }, self.parts[partName].properties);
1013
+ }), self.parts[partName].properties);
1009
1014
  debug("toConnector", to instanceof CSG.Connector);
1010
- var toConnector = toConnectorName.split(".").reduce(function(a, v) {
1015
+ var toConnector = toConnectorName.split(".").reduce((function(a, v) {
1011
1016
  return a[v];
1012
- }, to.properties);
1017
+ }), to.properties);
1013
1018
  var matrix = myConnector.getTransformationTo(toConnector, mirror, normalrotation);
1014
1019
  debug("connectTo", matrix);
1015
- self.map(function(part) {
1020
+ self.map((function(part) {
1016
1021
  return part.transform(matrix);
1017
- });
1022
+ }));
1018
1023
  return self;
1019
1024
  };
1020
1025
  JsCadUtilsGroup.prototype.midlineTo = function midlineTo(part, axis, to) {
1021
1026
  var self = this;
1022
1027
  var size = self.combine(part).size();
1023
- var t = axisApply(axis, function(i, a) {
1028
+ var t = axisApply(axis, (function(i, a) {
1024
1029
  return to - size[a] / 2;
1025
- });
1026
- self.map(function(part) {
1030
+ }));
1031
+ self.map((function(part) {
1027
1032
  return part.translate(t);
1028
- });
1033
+ }));
1029
1034
  return self;
1030
1035
  };
1031
1036
  JsCadUtilsGroup.prototype.translate = function translate(x, y, z) {
1032
1037
  var self = this;
1033
1038
  var t = Array.isArray(x) ? x : [ x, y, z ];
1034
1039
  debug("translate", t);
1035
- self.map(function(part) {
1040
+ self.map((function(part) {
1036
1041
  return part.translate(t);
1037
- });
1042
+ }));
1038
1043
  return self;
1039
1044
  };
1040
1045
  JsCadUtilsGroup.prototype.pick = function(parts, map) {
@@ -1042,9 +1047,9 @@ function initJscadutils(_CSG, options = {}) {
1042
1047
  var p = parts && parts.length > 0 && parts.split(",") || self.names;
1043
1048
  if (!map) map = identity;
1044
1049
  var g = Group();
1045
- p.forEach(function(name) {
1050
+ p.forEach((function(name) {
1046
1051
  g.add(map(CSG.fromPolygons(self.parts[name].toPolygons()), name), name);
1047
- });
1052
+ }));
1048
1053
  return g;
1049
1054
  };
1050
1055
  JsCadUtilsGroup.prototype.array = function(parts, map) {
@@ -1053,22 +1058,22 @@ function initJscadutils(_CSG, options = {}) {
1053
1058
  var p = parts && parts.length > 0 && parts.split(",") || self.names;
1054
1059
  if (!map) map = identity;
1055
1060
  var a = [];
1056
- p.forEach(function(name) {
1061
+ p.forEach((function(name) {
1057
1062
  if (!self.parts[name]) {
1058
1063
  debug("array error", _this, parts);
1059
1064
  throw error('group::array error "'.concat(name, '" not found.\nthis: ').concat(_this, '\nparts: "').concat(parts, '"\n'), "JSCAD_UTILS_GROUP_ERROR");
1060
1065
  }
1061
1066
  a.push(map(CSG.fromPolygons(self.parts[name].toPolygons()), name));
1062
- });
1067
+ }));
1063
1068
  return a;
1064
1069
  };
1065
1070
  JsCadUtilsGroup.prototype.toArray = function(pieces) {
1066
1071
  var self = this;
1067
1072
  var piecesArray = pieces ? pieces.split(",") : self.names;
1068
- return piecesArray.map(function(piece) {
1073
+ return piecesArray.map((function(piece) {
1069
1074
  if (!self.parts[piece]) console.error("Cannot find ".concat(piece, " in ").concat(self.names));
1070
1075
  return self.parts[piece];
1071
- });
1076
+ }));
1072
1077
  };
1073
1078
  JsCadUtilsGroup.prototype.toString = function() {
1074
1079
  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}');
@@ -1101,9 +1106,9 @@ function initJscadutils(_CSG, options = {}) {
1101
1106
  self.name = objectNames;
1102
1107
  } else {
1103
1108
  var objects = objectNames;
1104
- self.names = Object.keys(objects).filter(function(k) {
1109
+ self.names = Object.keys(objects).filter((function(k) {
1105
1110
  return k !== "holes";
1106
- });
1111
+ }));
1107
1112
  self.parts = Object.assign({}, objects);
1108
1113
  self.holes = objects.holes;
1109
1114
  }
@@ -1182,21 +1187,21 @@ function initJscadutils(_CSG, options = {}) {
1182
1187
  function label(text, x, y, width, height) {
1183
1188
  var l = vector_text(x || 0, y || 0, text);
1184
1189
  var o = [];
1185
- l.forEach(function(pl) {
1190
+ l.forEach((function(pl) {
1186
1191
  o.push(rectangular_extrude(pl, {
1187
1192
  w: width || 2,
1188
1193
  h: height || 2
1189
1194
  }));
1190
- });
1195
+ }));
1191
1196
  return center(union(o));
1192
1197
  }
1193
1198
  function text(text) {
1194
1199
  var l = vector_char(0, 0, text);
1195
- var _char = l.segments.reduce(function(result, segment) {
1200
+ var _char = l.segments.reduce((function(result, segment) {
1196
1201
  var path = new CSG.Path2D(segment);
1197
1202
  var cag = path.expandToCAG(2);
1198
1203
  return result ? result.union(cag) : cag;
1199
- }, undefined);
1204
+ }), undefined);
1200
1205
  return _char;
1201
1206
  }
1202
1207
  function unitCube(length, radius) {
@@ -1229,35 +1234,35 @@ function initJscadutils(_CSG, options = {}) {
1229
1234
  return result;
1230
1235
  }
1231
1236
  function zipObject(names, values) {
1232
- return names.reduce(function(result, value, idx) {
1237
+ return names.reduce((function(result, value, idx) {
1233
1238
  result[value] = values[idx];
1234
1239
  return result;
1235
- }, {});
1240
+ }), {});
1236
1241
  }
1237
1242
  function map(o, f) {
1238
- return Object.keys(o).map(function(key) {
1243
+ return Object.keys(o).map((function(key) {
1239
1244
  return f(o[key], key, o);
1240
- });
1245
+ }));
1241
1246
  }
1242
1247
  function mapValues(o, f) {
1243
- return Object.keys(o).map(function(key) {
1248
+ return Object.keys(o).map((function(key) {
1244
1249
  return f(o[key], key);
1245
- });
1250
+ }));
1246
1251
  }
1247
1252
  function pick(o, names) {
1248
- return names.reduce(function(result, name) {
1253
+ return names.reduce((function(result, name) {
1249
1254
  result[name] = o[name];
1250
1255
  return result;
1251
- }, {});
1256
+ }), {});
1252
1257
  }
1253
1258
  function mapPick(o, names, f, options) {
1254
- return names.reduce(function(result, name, index) {
1259
+ return names.reduce((function(result, name, index) {
1255
1260
  if (!o[name]) {
1256
1261
  throw new Error("".concat(name, " not found in ").concat(options.name, ": ").concat(Object.keys(o).join(",")));
1257
1262
  }
1258
1263
  result.push(f ? f(o[name], name, index, o) : o[name]);
1259
1264
  return result;
1260
- }, []);
1265
+ }), []);
1261
1266
  }
1262
1267
  function divA(a, f) {
1263
1268
  return div(a, f);
@@ -1321,9 +1326,9 @@ function initJscadutils(_CSG, options = {}) {
1321
1326
  var objectSize = size(object);
1322
1327
  var objectCentroid = centroid(object, objectSize);
1323
1328
  var idx = 0;
1324
- var t = map(objectSize, function(i) {
1329
+ var t = map(objectSize, (function(i) {
1325
1330
  return scale(i, a[idx++]);
1326
- });
1331
+ }));
1327
1332
  var new_object = object.scale(t);
1328
1333
  var new_centroid = centroid(new_object);
1329
1334
  var delta = new_centroid.minus(objectCentroid).times(-1);
@@ -1347,10 +1352,10 @@ function initJscadutils(_CSG, options = {}) {
1347
1352
  }
1348
1353
  var s = [ scale(objectSize.x, x), scale(objectSize.y, y), scale(objectSize.z, z) ];
1349
1354
  var min$1 = min(s);
1350
- return centerWith(object.scale(s.map(function(d, i) {
1355
+ return centerWith(object.scale(s.map((function(d, i) {
1351
1356
  if (a[i] === 0) return 1;
1352
1357
  return keep_aspect_ratio ? min$1 : d;
1353
- })), "xyz", object);
1358
+ }))), "xyz", object);
1354
1359
  }
1355
1360
  function shift(object, x, y, z) {
1356
1361
  var hsize = this.div(this.size(object.getBounds()), 2);
@@ -1389,9 +1394,9 @@ function initJscadutils(_CSG, options = {}) {
1389
1394
  if (side[0] === -1) {
1390
1395
  w[-1] = toxyz(withobj.centroid());
1391
1396
  }
1392
- return this.axisApply(axes, function(i, axis) {
1397
+ return this.axisApply(axes, (function(i, axis) {
1393
1398
  return w[side[0]][axis] - m[side[1]][axis];
1394
- });
1399
+ }));
1395
1400
  }
1396
1401
  function calcSnap(moveobj, withobj, axes, orientation) {
1397
1402
  var delta = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
@@ -1412,12 +1417,12 @@ function initJscadutils(_CSG, options = {}) {
1412
1417
  if (side[0] === -1) {
1413
1418
  w[-1] = withobj.centroid();
1414
1419
  }
1415
- var t = axisApply(axes, function(i, axis) {
1420
+ var t = axisApply(axes, (function(i, axis) {
1416
1421
  return w[side[0]][axis] - m[side[1]][axis];
1417
- });
1418
- return delta ? axisApply(axes, function(i) {
1422
+ }));
1423
+ return delta ? axisApply(axes, (function(i) {
1419
1424
  return t[i] + delta;
1420
- }) : t;
1425
+ })) : t;
1421
1426
  }
1422
1427
  function snap(moveobj, withobj, axis, orientation, delta) {
1423
1428
  debug$1("snap", moveobj, withobj, axis, orientation, delta);
@@ -1435,9 +1440,9 @@ function initJscadutils(_CSG, options = {}) {
1435
1440
  y: 1,
1436
1441
  z: 2
1437
1442
  };
1438
- axes.split("").forEach(function(axis) {
1443
+ axes.split("").forEach((function(axis) {
1439
1444
  retval[lookup[axis]] = valfun(lookup[axis], axis);
1440
- });
1445
+ }));
1441
1446
  return retval;
1442
1447
  }
1443
1448
  function axis2array(axes, valfun) {
@@ -1448,10 +1453,10 @@ function initJscadutils(_CSG, options = {}) {
1448
1453
  y: 1,
1449
1454
  z: 2
1450
1455
  };
1451
- axes.split("").forEach(function(axis) {
1456
+ axes.split("").forEach((function(axis) {
1452
1457
  var i = lookup[axis];
1453
1458
  a[i] = valfun(i, axis);
1454
- });
1459
+ }));
1455
1460
  return a;
1456
1461
  }
1457
1462
  function centroid(o, objectSize) {
@@ -1466,9 +1471,9 @@ function initJscadutils(_CSG, options = {}) {
1466
1471
  function calcmidlineTo(o, axis, to) {
1467
1472
  var bounds = o.getBounds();
1468
1473
  var objectSize = size(bounds);
1469
- return axisApply(axis, function(i, a) {
1474
+ return axisApply(axis, (function(i, a) {
1470
1475
  return to - objectSize[a] / 2;
1471
- });
1476
+ }));
1472
1477
  }
1473
1478
  function midlineTo(o, axis, to) {
1474
1479
  return o.translate(calcmidlineTo(o, axis, to));
@@ -1476,18 +1481,18 @@ function initJscadutils(_CSG, options = {}) {
1476
1481
  function translator(o, axis, withObj) {
1477
1482
  var objectCentroid = centroid(o);
1478
1483
  var withCentroid = centroid(withObj);
1479
- var t = axisApply(axis, function(i) {
1484
+ var t = axisApply(axis, (function(i) {
1480
1485
  return withCentroid[i] - objectCentroid[i];
1481
- });
1486
+ }));
1482
1487
  return t;
1483
1488
  }
1484
1489
  function calcCenterWith(o, axes, withObj) {
1485
1490
  var delta = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
1486
1491
  var objectCentroid = centroid(o);
1487
1492
  var withCentroid = centroid(withObj);
1488
- var t = axisApply(axes, function(i, axis) {
1493
+ var t = axisApply(axes, (function(i, axis) {
1489
1494
  return withCentroid[axis] - objectCentroid[axis];
1490
- });
1495
+ }));
1491
1496
  return delta ? add(t, delta) : t;
1492
1497
  }
1493
1498
  function centerWith(o, axis, withObj) {
@@ -1500,9 +1505,9 @@ function initJscadutils(_CSG, options = {}) {
1500
1505
  }
1501
1506
  }
1502
1507
  var dist = isNegative(offset) ? offset = size[axis] + offset : offset;
1503
- return axisApply(axis, function(i, a) {
1508
+ return axisApply(axis, (function(i, a) {
1504
1509
  return bounds[0][a] + (isEmpty(dist) ? size[axis] / 2 : dist);
1505
- });
1510
+ }));
1506
1511
  }
1507
1512
  function bisect() {
1508
1513
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
@@ -1565,11 +1570,11 @@ function initJscadutils(_CSG, options = {}) {
1565
1570
  }[[ axis, rotateaxis ].sort().join("")];
1566
1571
  var centroid = object.centroid();
1567
1572
  var rotateDelta = getDelta(objectSize, bounds, rotateOffsetAxis, rotateoffset);
1568
- var rotationCenter = options.rotationCenter || new CSG.Vector3D(axisApply("xyz", function(i, a) {
1573
+ var rotationCenter = options.rotationCenter || new CSG.Vector3D(axisApply("xyz", (function(i, a) {
1569
1574
  if (a == axis) return cutDelta[i];
1570
1575
  if (a == rotateOffsetAxis) return rotateDelta[i];
1571
1576
  return centroid[a];
1572
- }));
1577
+ })));
1573
1578
  var theRotationAxis = rotationAxes[rotateaxis];
1574
1579
  var cutplane = CSG.OrthoNormalBasis.GetCartesian(info.orthoNormalCartesian[0], info.orthoNormalCartesian[1]).translate(cutDelta).rotate(rotationCenter, theRotationAxis, angle);
1575
1580
  debug$1("bisect", debug$1.enabled && {
@@ -1628,7 +1633,7 @@ function initJscadutils(_CSG, options = {}) {
1628
1633
  }
1629
1634
  function poly2solid(top, bottom, height) {
1630
1635
  if (top.sides.length == 0) {
1631
- return new CSG();
1636
+ return new CSG;
1632
1637
  }
1633
1638
  var offsetVector = CSG.Vector3D.Create(0, 0, height);
1634
1639
  var normalVector = CSG.Vector3D.Create(0, 1, 0);
@@ -1653,6 +1658,11 @@ function initJscadutils(_CSG, options = {}) {
1653
1658
  return CSG.fromPolygons(polygons);
1654
1659
  }
1655
1660
  function slices2poly(slices, options, axis) {
1661
+ debug$1("slices2poly", slices, options, axis);
1662
+ options = Object.assign({
1663
+ twistangle: 0,
1664
+ twiststeps: 0
1665
+ }, options);
1656
1666
  var twistangle = options && parseFloat(options.twistangle) || 0;
1657
1667
  var twiststeps = options && parseInt(options.twiststeps) || CSG.defaultResolution3D;
1658
1668
  if (twistangle == 0 || twiststeps < 1) {
@@ -1662,6 +1672,7 @@ function initJscadutils(_CSG, options = {}) {
1662
1672
  var polygons = [];
1663
1673
  var first$1 = first(slices);
1664
1674
  var last$1 = last(slices);
1675
+ debug$1("slices2poly first", first$1, first$1.offset, "last", last$1);
1665
1676
  var up = first$1.offset[axis] > last$1.offset[axis];
1666
1677
  polygons = polygons.concat(first$1.poly._toPlanePolygons({
1667
1678
  translation: first$1.offset,
@@ -1680,7 +1691,7 @@ function initJscadutils(_CSG, options = {}) {
1680
1691
  return v[rotateAxis](angle * percent);
1681
1692
  };
1682
1693
  var connectorAxis = last$1.offset.minus(first$1.offset).abs();
1683
- slices.forEach(function(slice, idx) {
1694
+ slices.forEach((function(slice, idx) {
1684
1695
  if (idx < slices.length - 1) {
1685
1696
  var nextidx = idx + 1;
1686
1697
  var top = !up ? slices[nextidx] : slice;
@@ -1693,7 +1704,7 @@ function initJscadutils(_CSG, options = {}) {
1693
1704
  toConnector2: c2
1694
1705
  }));
1695
1706
  }
1696
- });
1707
+ }));
1697
1708
  return CSG.fromPolygons(polygons);
1698
1709
  }
1699
1710
  function normalVector(axis) {
@@ -1734,30 +1745,32 @@ function initJscadutils(_CSG, options = {}) {
1734
1745
  var info = dirInfo["dir" + direction];
1735
1746
  return Object.assign({
1736
1747
  axis,
1737
- cutDelta: axisApply(axis, function(i, a) {
1748
+ cutDelta: axisApply(axis, (function(i, a) {
1738
1749
  return bounds[info.sizeIdx][a] + Math.abs(radius) * info.sizeDir;
1739
- }),
1740
- moveDelta: axisApply(axis, function(i, a) {
1750
+ })),
1751
+ moveDelta: axisApply(axis, (function(i, a) {
1741
1752
  return bounds[info.sizeIdx][a] + Math.abs(radius) * info.moveDir;
1742
- })
1753
+ }))
1743
1754
  }, info, normalVector(axis));
1744
1755
  }
1745
1756
  function reShape(object, radius, orientation, options, slicer) {
1746
1757
  options = options || {};
1747
1758
  var b = object.getBounds();
1748
- var ar = Math.abs(radius);
1759
+ var absoluteRadius = Math.abs(radius);
1749
1760
  var si = sliceParams(orientation, radius, b);
1761
+ debug$1("reShape", absoluteRadius, si);
1750
1762
  if (si.axis !== "z") throw new Error('reShape error: CAG._toPlanePolytons only uses the "z" axis. You must use the "z" axis for now.');
1751
1763
  var cutplane = CSG.OrthoNormalBasis.GetCartesian(si.orthoNormalCartesian[0], si.orthoNormalCartesian[1]).translate(si.cutDelta);
1752
1764
  var slice = object.sectionCut(cutplane);
1753
- var first = axisApply(si.axis, function() {
1754
- return si.positive ? 0 : ar;
1755
- });
1756
- var last = axisApply(si.axis, function() {
1757
- return si.positive ? ar : 0;
1758
- });
1765
+ var first = axisApply(si.axis, (function() {
1766
+ return si.positive ? 0 : absoluteRadius;
1767
+ }));
1768
+ var last = axisApply(si.axis, (function() {
1769
+ return si.positive ? absoluteRadius : 0;
1770
+ }));
1759
1771
  var plane = si.positive ? cutplane.plane : cutplane.plane.flipped();
1760
- var slices = slicer(first, last, slice);
1772
+ debug$1("reShape first/last", first, last);
1773
+ var slices = slicer(first, last, slice, radius);
1761
1774
  var delta = slices2poly(slices, Object.assign(options, {
1762
1775
  si
1763
1776
  }), si.axis).color(options.color);
@@ -1765,7 +1778,7 @@ function initJscadutils(_CSG, options = {}) {
1765
1778
  return union([ options.unionOriginal ? object : remainder, delta.translate(si.moveDelta) ]);
1766
1779
  }
1767
1780
  function chamfer(object, radius, orientation, options) {
1768
- return reShape(object, radius, orientation, options, function(first, last, slice) {
1781
+ return reShape(object, radius, orientation, options, (function(first, last, slice) {
1769
1782
  return [ {
1770
1783
  poly: slice,
1771
1784
  offset: new CSG.Vector3D(first)
@@ -1773,15 +1786,15 @@ function initJscadutils(_CSG, options = {}) {
1773
1786
  poly: enlarge(slice, [ -radius * 2, -radius * 2 ]),
1774
1787
  offset: new CSG.Vector3D(last)
1775
1788
  } ];
1776
- });
1789
+ }));
1777
1790
  }
1778
1791
  function fillet(object, radius, orientation, options) {
1779
1792
  options = options || {};
1780
- return reShape(object, radius, orientation, options, function(first, last, slice) {
1793
+ return reShape(object, radius, orientation, options, (function(first, last, slice) {
1781
1794
  var v1 = new CSG.Vector3D(first);
1782
1795
  var v2 = new CSG.Vector3D(last);
1783
1796
  var res = options.resolution || CSG.defaultResolution3D;
1784
- var slices = range(0, res).map(function(i) {
1797
+ var slices = range(0, res).map((function(i) {
1785
1798
  var p = i > 0 ? i / (res - 1) : 0;
1786
1799
  var v = v1.lerp(v2, p);
1787
1800
  var size = -radius * 2 - Math.cos(Math.asin(p)) * (-radius * 2);
@@ -1789,9 +1802,9 @@ function initJscadutils(_CSG, options = {}) {
1789
1802
  poly: enlarge(slice, [ size, size ]),
1790
1803
  offset: v
1791
1804
  };
1792
- });
1805
+ }));
1793
1806
  return slices;
1794
- });
1807
+ }));
1795
1808
  }
1796
1809
  function calcRotate(part, solid, axis) {
1797
1810
  var axes = {
@@ -1811,11 +1824,11 @@ function initJscadutils(_CSG, options = {}) {
1811
1824
  return part.rotate(rotationCenter, rotationAxis, angle);
1812
1825
  }
1813
1826
  function cloneProperties(from, to) {
1814
- return Object.entries(from).reduce(function(props, _ref) {
1827
+ return Object.entries(from).reduce((function(props, _ref) {
1815
1828
  var _ref2 = _slicedToArray(_ref, 2), key = _ref2[0], value = _ref2[1];
1816
1829
  props[key] = value;
1817
1830
  return props;
1818
- }, to);
1831
+ }), to);
1819
1832
  }
1820
1833
  function clone(o) {
1821
1834
  var c = CSG.fromPolygons(o.toPolygons());
@@ -1848,10 +1861,10 @@ function initJscadutils(_CSG, options = {}) {
1848
1861
  for (var _len = arguments.length, objects = new Array(_len), _key = 0; _key < _len; _key++) {
1849
1862
  objects[_key] = arguments[_key];
1850
1863
  }
1851
- return objects.reduce(function(bbox, part) {
1864
+ return objects.reduce((function(bbox, part) {
1852
1865
  var object = bbox ? union([ bbox, box(part) ]) : part;
1853
1866
  return box(object);
1854
- }, undefined);
1867
+ }), undefined);
1855
1868
  }
1856
1869
  function Cube(width) {
1857
1870
  var r = div(fromxyz(width), 2);
@@ -2032,16 +2045,17 @@ function initJscadutils(_CSG, options = {}) {
2032
2045
  gap = gap || .25;
2033
2046
  var inside = thickness - gap;
2034
2047
  var outside = -thickness + gap;
2035
- options.color = true;
2048
+ debug$3("inside", inside, "outside", outside);
2036
2049
  var group = Group();
2037
- debug$3("Rabbet top height:", height, "options:", options);
2038
2050
  var _box$bisect$parts = box.bisect("z", height, options).parts, top = _box$bisect$parts.positive, lower2_3rd = _box$bisect$parts.negative;
2039
- debug$3("face", face, "height", height);
2040
2051
  var lowerBisectHeight = Math.sign(height) < 0 ? face * Math.sign(height) : height - face;
2041
- debug$3("Rabbet bottom height:", lowerBisectHeight, "options:", options);
2042
2052
  var _lower2_3rd$bisect$pa = lower2_3rd.bisect("z", lowerBisectHeight, options).parts, middle = _lower2_3rd$bisect$pa.positive, bottom = _lower2_3rd$bisect$pa.negative;
2043
- group.add(top.union(middle.color("yellow").subtract(middle.color("darkred").enlarge([ outside, outside, 0 ]))), "top");
2044
- group.add(bottom.color("orange").union(middle.color("green").subtract(middle.color("red").enlarge([ inside, inside, 0 ]))), "bottom");
2053
+ var middleTop = middle.color("yellow").subtract(middle.color("darkred").enlarge([ outside, outside, 0 ]));
2054
+ group.add(top.union(middleTop), "top");
2055
+ var bottomOutline = middle.color("yellow").subtract(middle.color("orange").enlarge([ outside, outside, 0 ])).enlarge([ outside, outside, 0 ]);
2056
+ group.add(bottomOutline, "middle-top", true);
2057
+ group.add(middle.color("green").subtract(middle.color("pink").enlarge([ inside, inside, 0 ])), "middle-bottom", true);
2058
+ group.add(bottom.color("orange").union(middle.color("green").subtract(middle.color("red").enlarge([ inside, inside, 0 ])).subtract(middleTop)), "bottom");
2045
2059
  return group;
2046
2060
  }
2047
2061
  var RabettTopBottom = function rabbetTMB(box, thickness) {