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