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