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