@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.
@@ -74,8 +74,13 @@ function initJscadutils(_CSG, options = {}) {
74
74
  });
75
75
  var jscadUtils = function(exports, jsCadCSG, scadApi) {
76
76
  "use strict";
77
- jsCadCSG = jsCadCSG && Object.prototype.hasOwnProperty.call(jsCadCSG, "default") ? jsCadCSG["default"] : jsCadCSG;
78
- scadApi = scadApi && Object.prototype.hasOwnProperty.call(scadApi, "default") ? scadApi["default"] : scadApi;
77
+ function _interopDefaultLegacy(e) {
78
+ return e && typeof e === "object" && "default" in e ? e : {
79
+ default: e
80
+ };
81
+ }
82
+ var jsCadCSG__default = _interopDefaultLegacy(jsCadCSG);
83
+ var scadApi__default = _interopDefaultLegacy(scadApi);
79
84
  var util = Object.freeze({
80
85
  __proto__: null,
81
86
  get NOZZEL_SIZE() {
@@ -322,9 +327,9 @@ function initJscadutils(_CSG, options = {}) {
322
327
  var keys = Object.keys(object);
323
328
  if (Object.getOwnPropertySymbols) {
324
329
  var symbols = Object.getOwnPropertySymbols(object);
325
- if (enumerableOnly) symbols = symbols.filter(function(sym) {
330
+ if (enumerableOnly) symbols = symbols.filter((function(sym) {
326
331
  return Object.getOwnPropertyDescriptor(object, sym).enumerable;
327
- });
332
+ }));
328
333
  keys.push.apply(keys, symbols);
329
334
  }
330
335
  return keys;
@@ -333,15 +338,15 @@ function initJscadutils(_CSG, options = {}) {
333
338
  for (var i = 1; i < arguments.length; i++) {
334
339
  var source = arguments[i] != null ? arguments[i] : {};
335
340
  if (i % 2) {
336
- ownKeys(Object(source), true).forEach(function(key) {
341
+ ownKeys(Object(source), true).forEach((function(key) {
337
342
  _defineProperty(target, key, source[key]);
338
- });
343
+ }));
339
344
  } else if (Object.getOwnPropertyDescriptors) {
340
345
  Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
341
346
  } else {
342
- ownKeys(Object(source)).forEach(function(key) {
347
+ ownKeys(Object(source)).forEach((function(key) {
343
348
  Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
344
- });
349
+ }));
345
350
  }
346
351
  }
347
352
  return target;
@@ -450,29 +455,29 @@ function initJscadutils(_CSG, options = {}) {
450
455
  solveab
451
456
  });
452
457
  var div = function div(a, f) {
453
- return a.map(function(e) {
458
+ return a.map((function(e) {
454
459
  return e / f;
455
- });
460
+ }));
456
461
  };
457
462
  var addValue = function addValue(a, f) {
458
- return a.map(function(e) {
463
+ return a.map((function(e) {
459
464
  return e + f;
460
- });
465
+ }));
461
466
  };
462
467
  var addArray = function addArray(a, f) {
463
- return a.map(function(e, i) {
468
+ return a.map((function(e, i) {
464
469
  return e + f[i];
465
- });
470
+ }));
466
471
  };
467
472
  var add = function add(a) {
468
- return Array.prototype.slice.call(arguments, 1).reduce(function(result, arg) {
473
+ return Array.prototype.slice.call(arguments, 1).reduce((function(result, arg) {
469
474
  if (Array.isArray(arg)) {
470
475
  result = addArray(result, arg);
471
476
  } else {
472
477
  result = addValue(result, arg);
473
478
  }
474
479
  return result;
475
- }, a);
480
+ }), a);
476
481
  };
477
482
  var fromxyz = function fromxyz(object) {
478
483
  return Array.isArray(object) ? object : [ object.x, object.y, object.z ];
@@ -491,9 +496,9 @@ function initJscadutils(_CSG, options = {}) {
491
496
  return a && a.length > 0 ? a[a.length - 1] : undefined;
492
497
  };
493
498
  var min = function min(a) {
494
- return a.reduce(function(result, value) {
499
+ return a.reduce((function(result, value) {
495
500
  return value < result ? value : result;
496
- }, Number.MAX_VALUE);
501
+ }), Number.MAX_VALUE);
497
502
  };
498
503
  var range = function range(a, b) {
499
504
  var result = [];
@@ -527,11 +532,11 @@ function initJscadutils(_CSG, options = {}) {
527
532
  }
528
533
  }, jscadUtilsDebug || {});
529
534
  var style = checks.options.browser ? "color:".concat(debugColors[debugCount++ % debugColors.length]) : "".concat(termColors[debugCount++ % termColors.length]);
530
- var enabled = checks.enabled.some(function checkEnabled(check) {
535
+ var enabled = checks.enabled.some((function checkEnabled(check) {
531
536
  return check.test(name);
532
- }) && !checks.disabled.some(function checkEnabled(check) {
537
+ })) && !checks.disabled.some((function checkEnabled(check) {
533
538
  return check.test(name);
534
- });
539
+ }));
535
540
  var logger = enabled ? checks.options.browser ? function() {
536
541
  var _console;
537
542
  for (var _len = arguments.length, msg = new Array(_len), _key = 0; _key < _len; _key++) {
@@ -718,9 +723,9 @@ function initJscadutils(_CSG, options = {}) {
718
723
  function color(o, r, g, b, a) {
719
724
  if (typeof r !== "string") return o.setColor(r, g, b, a);
720
725
  if (r === "") return o;
721
- var c = name2rgb(r).map(function(x) {
726
+ var c = name2rgb(r).map((function(x) {
722
727
  return x / 255;
723
- });
728
+ }));
724
729
  c[3] = g || 1;
725
730
  return o.setColor(c);
726
731
  }
@@ -822,10 +827,10 @@ function initJscadutils(_CSG, options = {}) {
822
827
  if (arguments.length === 1) {
823
828
  return this._translate(arguments[0]);
824
829
  } else {
825
- var t = Array.prototype.slice.call(arguments, 0).reduce(function(result, arg) {
830
+ var t = Array.prototype.slice.call(arguments, 0).reduce((function(result, arg) {
826
831
  result = undefined(result, arg);
827
832
  return result;
828
- }, [ 0, 0, 0 ]);
833
+ }), [ 0, 0, 0 ]);
829
834
  return this._translate(t);
830
835
  }
831
836
  };
@@ -835,9 +840,9 @@ function initJscadutils(_CSG, options = {}) {
835
840
  proto.prototype.connect = function connectTo(myConnectorName, otherConnector) {
836
841
  var mirror = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
837
842
  var normalrotation = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
838
- var myConnector = myConnectorName.split(".").reduce(function(a, v) {
843
+ var myConnector = myConnectorName.split(".").reduce((function(a, v) {
839
844
  return a[v];
840
- }, this.properties);
845
+ }), this.properties);
841
846
  if (!myConnector) {
842
847
  error("The connector '".concat(myConnectorName, "' does not exist on the object [").concat(Object.keys(this.properties).join(","), "]"), "Missing connector property");
843
848
  }
@@ -849,10 +854,10 @@ function initJscadutils(_CSG, options = {}) {
849
854
  __proto__: null,
850
855
  default: init
851
856
  });
852
- var CSG = jsCadCSG.CSG, CAG = jsCadCSG.CAG;
853
- var rectangular_extrude = scadApi.extrusions.rectangular_extrude;
854
- var _scadApi$text = scadApi.text, vector_text = _scadApi$text.vector_text, vector_char = _scadApi$text.vector_char;
855
- var union = scadApi.booleanOps.union;
857
+ var CSG = jsCadCSG__default["default"].CSG, CAG = jsCadCSG__default["default"].CAG;
858
+ var rectangular_extrude = scadApi__default["default"].extrusions.rectangular_extrude;
859
+ var _scadApi$text = scadApi__default["default"].text, vector_text = _scadApi$text.vector_text, vector_char = _scadApi$text.vector_char;
860
+ var union = scadApi__default["default"].booleanOps.union;
856
861
  init(CSG);
857
862
  var debug = Debug("jscadUtils:group");
858
863
  function JsCadUtilsGroup() {
@@ -872,9 +877,9 @@ function initJscadutils(_CSG, options = {}) {
872
877
  if (!hidden) self.names.push(name);
873
878
  self.parts[name] = object.combine(parts);
874
879
  if (subparts) {
875
- Object.keys(object.parts).forEach(function(key) {
880
+ Object.keys(object.parts).forEach((function(key) {
876
881
  self.parts[subparts + key] = object.parts[key];
877
- });
882
+ }));
878
883
  }
879
884
  } else {
880
885
  Object.assign(self.parts, object.parts);
@@ -901,9 +906,9 @@ function initJscadutils(_CSG, options = {}) {
901
906
  throw new Error("no pieces found in ".concat(self.name, " pieces: ").concat(pieces, " parts: ").concat(Object.keys(self.parts), " names: ").concat(self.names));
902
907
  }
903
908
  debug("combine", self.names, self.parts);
904
- var g = union(mapPick(self.parts, pieces, function(value, key, index, object) {
909
+ var g = union(mapPick(self.parts, pieces, (function(value, key, index, object) {
905
910
  return map ? map(value, key, index, object) : identity(value);
906
- }, self.name));
911
+ }), self.name));
907
912
  return g.subtractIf(self.holes && Array.isArray(self.holes) ? union(self.holes) : self.holes, self.holes && !options.noholes);
908
913
  } catch (err) {
909
914
  debug("combine error", this, pieces, options, err);
@@ -912,17 +917,17 @@ function initJscadutils(_CSG, options = {}) {
912
917
  };
913
918
  JsCadUtilsGroup.prototype.map = function(cb) {
914
919
  var self = this;
915
- self.parts = Object.keys(self.parts).filter(function(k) {
920
+ self.parts = Object.keys(self.parts).filter((function(k) {
916
921
  return k !== "holes";
917
- }).reduce(function(result, key) {
922
+ })).reduce((function(result, key) {
918
923
  result[key] = cb(self.parts[key], key);
919
924
  return result;
920
- }, {});
925
+ }), {});
921
926
  if (self.holes) {
922
927
  if (Array.isArray(self.holes)) {
923
- self.holes = self.holes.map(function(hole, idx) {
928
+ self.holes = self.holes.map((function(hole, idx) {
924
929
  return cb(hole, idx);
925
- });
930
+ }));
926
931
  } else {
927
932
  self.holes = cb(self.holes, "holes");
928
933
  }
@@ -938,15 +943,15 @@ function initJscadutils(_CSG, options = {}) {
938
943
  }
939
944
  if (!map) map = identity;
940
945
  var group = Group(name);
941
- Object.keys(self.parts).forEach(function(key) {
946
+ Object.keys(self.parts).forEach((function(key) {
942
947
  var part = self.parts[key];
943
948
  var hidden = self.names.indexOf(key) == -1;
944
949
  group.add(map(clone(part)), key, hidden);
945
- });
950
+ }));
946
951
  if (self.holes) {
947
- group.holes = toArray(self.holes).map(function(part) {
952
+ group.holes = toArray(self.holes).map((function(part) {
948
953
  return map(CSG.fromPolygons(part.toPolygons()), "holes");
949
- });
954
+ }));
950
955
  }
951
956
  return group;
952
957
  };
@@ -963,9 +968,9 @@ function initJscadutils(_CSG, options = {}) {
963
968
  }
964
969
  var rotationCenter = solid.centroid();
965
970
  var rotationAxis = axes[axis];
966
- self.map(function(part) {
971
+ self.map((function(part) {
967
972
  return part.rotate(rotationCenter, rotationAxis, angle);
968
- });
973
+ }));
969
974
  return self;
970
975
  };
971
976
  JsCadUtilsGroup.prototype.combineAll = function(options, map) {
@@ -976,9 +981,9 @@ function initJscadutils(_CSG, options = {}) {
976
981
  try {
977
982
  var self = this;
978
983
  var t = calcSnap(self.combine(part), to, axis, orientation, delta);
979
- self.map(function(part) {
984
+ self.map((function(part) {
980
985
  return part.translate(t);
981
- });
986
+ }));
982
987
  return self;
983
988
  } catch (err) {
984
989
  debug("snap error", this, part, to, axis, delta, err);
@@ -991,9 +996,9 @@ function initJscadutils(_CSG, options = {}) {
991
996
  var t = calcCenterWith(self.combine(part, {
992
997
  noholes: true
993
998
  }), axis, to, delta);
994
- self.map(function(part) {
999
+ self.map((function(part) {
995
1000
  return part.translate(t);
996
- });
1001
+ }));
997
1002
  return self;
998
1003
  } catch (err) {
999
1004
  debug("align error", this, part, to, axis, delta, err);
@@ -1021,38 +1026,38 @@ function initJscadutils(_CSG, options = {}) {
1021
1026
  normalrotation
1022
1027
  });
1023
1028
  var self = this;
1024
- var myConnector = connectorName.split(".").reduce(function(a, v) {
1029
+ var myConnector = connectorName.split(".").reduce((function(a, v) {
1025
1030
  return a[v];
1026
- }, self.parts[partName].properties);
1031
+ }), self.parts[partName].properties);
1027
1032
  debug("toConnector", to instanceof CSG.Connector);
1028
- var toConnector = toConnectorName.split(".").reduce(function(a, v) {
1033
+ var toConnector = toConnectorName.split(".").reduce((function(a, v) {
1029
1034
  return a[v];
1030
- }, to.properties);
1035
+ }), to.properties);
1031
1036
  var matrix = myConnector.getTransformationTo(toConnector, mirror, normalrotation);
1032
1037
  debug("connectTo", matrix);
1033
- self.map(function(part) {
1038
+ self.map((function(part) {
1034
1039
  return part.transform(matrix);
1035
- });
1040
+ }));
1036
1041
  return self;
1037
1042
  };
1038
1043
  JsCadUtilsGroup.prototype.midlineTo = function midlineTo(part, axis, to) {
1039
1044
  var self = this;
1040
1045
  var size = self.combine(part).size();
1041
- var t = axisApply(axis, function(i, a) {
1046
+ var t = axisApply(axis, (function(i, a) {
1042
1047
  return to - size[a] / 2;
1043
- });
1044
- self.map(function(part) {
1048
+ }));
1049
+ self.map((function(part) {
1045
1050
  return part.translate(t);
1046
- });
1051
+ }));
1047
1052
  return self;
1048
1053
  };
1049
1054
  JsCadUtilsGroup.prototype.translate = function translate(x, y, z) {
1050
1055
  var self = this;
1051
1056
  var t = Array.isArray(x) ? x : [ x, y, z ];
1052
1057
  debug("translate", t);
1053
- self.map(function(part) {
1058
+ self.map((function(part) {
1054
1059
  return part.translate(t);
1055
- });
1060
+ }));
1056
1061
  return self;
1057
1062
  };
1058
1063
  JsCadUtilsGroup.prototype.pick = function(parts, map) {
@@ -1060,9 +1065,9 @@ function initJscadutils(_CSG, options = {}) {
1060
1065
  var p = parts && parts.length > 0 && parts.split(",") || self.names;
1061
1066
  if (!map) map = identity;
1062
1067
  var g = Group();
1063
- p.forEach(function(name) {
1068
+ p.forEach((function(name) {
1064
1069
  g.add(map(CSG.fromPolygons(self.parts[name].toPolygons()), name), name);
1065
- });
1070
+ }));
1066
1071
  return g;
1067
1072
  };
1068
1073
  JsCadUtilsGroup.prototype.array = function(parts, map) {
@@ -1071,22 +1076,22 @@ function initJscadutils(_CSG, options = {}) {
1071
1076
  var p = parts && parts.length > 0 && parts.split(",") || self.names;
1072
1077
  if (!map) map = identity;
1073
1078
  var a = [];
1074
- p.forEach(function(name) {
1079
+ p.forEach((function(name) {
1075
1080
  if (!self.parts[name]) {
1076
1081
  debug("array error", _this, parts);
1077
1082
  throw error('group::array error "'.concat(name, '" not found.\nthis: ').concat(_this, '\nparts: "').concat(parts, '"\n'), "JSCAD_UTILS_GROUP_ERROR");
1078
1083
  }
1079
1084
  a.push(map(CSG.fromPolygons(self.parts[name].toPolygons()), name));
1080
- });
1085
+ }));
1081
1086
  return a;
1082
1087
  };
1083
1088
  JsCadUtilsGroup.prototype.toArray = function(pieces) {
1084
1089
  var self = this;
1085
1090
  var piecesArray = pieces ? pieces.split(",") : self.names;
1086
- return piecesArray.map(function(piece) {
1091
+ return piecesArray.map((function(piece) {
1087
1092
  if (!self.parts[piece]) console.error("Cannot find ".concat(piece, " in ").concat(self.names));
1088
1093
  return self.parts[piece];
1089
- });
1094
+ }));
1090
1095
  };
1091
1096
  JsCadUtilsGroup.prototype.toString = function() {
1092
1097
  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}');
@@ -1119,9 +1124,9 @@ function initJscadutils(_CSG, options = {}) {
1119
1124
  self.name = objectNames;
1120
1125
  } else {
1121
1126
  var objects = objectNames;
1122
- self.names = Object.keys(objects).filter(function(k) {
1127
+ self.names = Object.keys(objects).filter((function(k) {
1123
1128
  return k !== "holes";
1124
- });
1129
+ }));
1125
1130
  self.parts = Object.assign({}, objects);
1126
1131
  self.holes = objects.holes;
1127
1132
  }
@@ -1200,21 +1205,21 @@ function initJscadutils(_CSG, options = {}) {
1200
1205
  function label(text, x, y, width, height) {
1201
1206
  var l = vector_text(x || 0, y || 0, text);
1202
1207
  var o = [];
1203
- l.forEach(function(pl) {
1208
+ l.forEach((function(pl) {
1204
1209
  o.push(rectangular_extrude(pl, {
1205
1210
  w: width || 2,
1206
1211
  h: height || 2
1207
1212
  }));
1208
- });
1213
+ }));
1209
1214
  return center(union(o));
1210
1215
  }
1211
1216
  function text(text) {
1212
1217
  var l = vector_char(0, 0, text);
1213
- var _char = l.segments.reduce(function(result, segment) {
1218
+ var _char = l.segments.reduce((function(result, segment) {
1214
1219
  var path = new CSG.Path2D(segment);
1215
1220
  var cag = path.expandToCAG(2);
1216
1221
  return result ? result.union(cag) : cag;
1217
- }, undefined);
1222
+ }), undefined);
1218
1223
  return _char;
1219
1224
  }
1220
1225
  function unitCube(length, radius) {
@@ -1247,35 +1252,35 @@ function initJscadutils(_CSG, options = {}) {
1247
1252
  return result;
1248
1253
  }
1249
1254
  function zipObject(names, values) {
1250
- return names.reduce(function(result, value, idx) {
1255
+ return names.reduce((function(result, value, idx) {
1251
1256
  result[value] = values[idx];
1252
1257
  return result;
1253
- }, {});
1258
+ }), {});
1254
1259
  }
1255
1260
  function map(o, f) {
1256
- return Object.keys(o).map(function(key) {
1261
+ return Object.keys(o).map((function(key) {
1257
1262
  return f(o[key], key, o);
1258
- });
1263
+ }));
1259
1264
  }
1260
1265
  function mapValues(o, f) {
1261
- return Object.keys(o).map(function(key) {
1266
+ return Object.keys(o).map((function(key) {
1262
1267
  return f(o[key], key);
1263
- });
1268
+ }));
1264
1269
  }
1265
1270
  function pick(o, names) {
1266
- return names.reduce(function(result, name) {
1271
+ return names.reduce((function(result, name) {
1267
1272
  result[name] = o[name];
1268
1273
  return result;
1269
- }, {});
1274
+ }), {});
1270
1275
  }
1271
1276
  function mapPick(o, names, f, options) {
1272
- return names.reduce(function(result, name, index) {
1277
+ return names.reduce((function(result, name, index) {
1273
1278
  if (!o[name]) {
1274
1279
  throw new Error("".concat(name, " not found in ").concat(options.name, ": ").concat(Object.keys(o).join(",")));
1275
1280
  }
1276
1281
  result.push(f ? f(o[name], name, index, o) : o[name]);
1277
1282
  return result;
1278
- }, []);
1283
+ }), []);
1279
1284
  }
1280
1285
  function divA(a, f) {
1281
1286
  return div(a, f);
@@ -1339,9 +1344,9 @@ function initJscadutils(_CSG, options = {}) {
1339
1344
  var objectSize = size(object);
1340
1345
  var objectCentroid = centroid(object, objectSize);
1341
1346
  var idx = 0;
1342
- var t = map(objectSize, function(i) {
1347
+ var t = map(objectSize, (function(i) {
1343
1348
  return scale(i, a[idx++]);
1344
- });
1349
+ }));
1345
1350
  var new_object = object.scale(t);
1346
1351
  var new_centroid = centroid(new_object);
1347
1352
  var delta = new_centroid.minus(objectCentroid).times(-1);
@@ -1365,10 +1370,10 @@ function initJscadutils(_CSG, options = {}) {
1365
1370
  }
1366
1371
  var s = [ scale(objectSize.x, x), scale(objectSize.y, y), scale(objectSize.z, z) ];
1367
1372
  var min$1 = min(s);
1368
- return centerWith(object.scale(s.map(function(d, i) {
1373
+ return centerWith(object.scale(s.map((function(d, i) {
1369
1374
  if (a[i] === 0) return 1;
1370
1375
  return keep_aspect_ratio ? min$1 : d;
1371
- })), "xyz", object);
1376
+ }))), "xyz", object);
1372
1377
  }
1373
1378
  function shift(object, x, y, z) {
1374
1379
  var hsize = this.div(this.size(object.getBounds()), 2);
@@ -1407,9 +1412,9 @@ function initJscadutils(_CSG, options = {}) {
1407
1412
  if (side[0] === -1) {
1408
1413
  w[-1] = toxyz(withobj.centroid());
1409
1414
  }
1410
- return this.axisApply(axes, function(i, axis) {
1415
+ return this.axisApply(axes, (function(i, axis) {
1411
1416
  return w[side[0]][axis] - m[side[1]][axis];
1412
- });
1417
+ }));
1413
1418
  }
1414
1419
  function calcSnap(moveobj, withobj, axes, orientation) {
1415
1420
  var delta = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
@@ -1430,12 +1435,12 @@ function initJscadutils(_CSG, options = {}) {
1430
1435
  if (side[0] === -1) {
1431
1436
  w[-1] = withobj.centroid();
1432
1437
  }
1433
- var t = axisApply(axes, function(i, axis) {
1438
+ var t = axisApply(axes, (function(i, axis) {
1434
1439
  return w[side[0]][axis] - m[side[1]][axis];
1435
- });
1436
- return delta ? axisApply(axes, function(i) {
1440
+ }));
1441
+ return delta ? axisApply(axes, (function(i) {
1437
1442
  return t[i] + delta;
1438
- }) : t;
1443
+ })) : t;
1439
1444
  }
1440
1445
  function snap(moveobj, withobj, axis, orientation, delta) {
1441
1446
  debug$1("snap", moveobj, withobj, axis, orientation, delta);
@@ -1453,9 +1458,9 @@ function initJscadutils(_CSG, options = {}) {
1453
1458
  y: 1,
1454
1459
  z: 2
1455
1460
  };
1456
- axes.split("").forEach(function(axis) {
1461
+ axes.split("").forEach((function(axis) {
1457
1462
  retval[lookup[axis]] = valfun(lookup[axis], axis);
1458
- });
1463
+ }));
1459
1464
  return retval;
1460
1465
  }
1461
1466
  function axis2array(axes, valfun) {
@@ -1466,10 +1471,10 @@ function initJscadutils(_CSG, options = {}) {
1466
1471
  y: 1,
1467
1472
  z: 2
1468
1473
  };
1469
- axes.split("").forEach(function(axis) {
1474
+ axes.split("").forEach((function(axis) {
1470
1475
  var i = lookup[axis];
1471
1476
  a[i] = valfun(i, axis);
1472
- });
1477
+ }));
1473
1478
  return a;
1474
1479
  }
1475
1480
  function centroid(o, objectSize) {
@@ -1484,9 +1489,9 @@ function initJscadutils(_CSG, options = {}) {
1484
1489
  function calcmidlineTo(o, axis, to) {
1485
1490
  var bounds = o.getBounds();
1486
1491
  var objectSize = size(bounds);
1487
- return axisApply(axis, function(i, a) {
1492
+ return axisApply(axis, (function(i, a) {
1488
1493
  return to - objectSize[a] / 2;
1489
- });
1494
+ }));
1490
1495
  }
1491
1496
  function midlineTo(o, axis, to) {
1492
1497
  return o.translate(calcmidlineTo(o, axis, to));
@@ -1494,18 +1499,18 @@ function initJscadutils(_CSG, options = {}) {
1494
1499
  function translator(o, axis, withObj) {
1495
1500
  var objectCentroid = centroid(o);
1496
1501
  var withCentroid = centroid(withObj);
1497
- var t = axisApply(axis, function(i) {
1502
+ var t = axisApply(axis, (function(i) {
1498
1503
  return withCentroid[i] - objectCentroid[i];
1499
- });
1504
+ }));
1500
1505
  return t;
1501
1506
  }
1502
1507
  function calcCenterWith(o, axes, withObj) {
1503
1508
  var delta = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
1504
1509
  var objectCentroid = centroid(o);
1505
1510
  var withCentroid = centroid(withObj);
1506
- var t = axisApply(axes, function(i, axis) {
1511
+ var t = axisApply(axes, (function(i, axis) {
1507
1512
  return withCentroid[axis] - objectCentroid[axis];
1508
- });
1513
+ }));
1509
1514
  return delta ? add(t, delta) : t;
1510
1515
  }
1511
1516
  function centerWith(o, axis, withObj) {
@@ -1518,9 +1523,9 @@ function initJscadutils(_CSG, options = {}) {
1518
1523
  }
1519
1524
  }
1520
1525
  var dist = isNegative(offset) ? offset = size[axis] + offset : offset;
1521
- return axisApply(axis, function(i, a) {
1526
+ return axisApply(axis, (function(i, a) {
1522
1527
  return bounds[0][a] + (isEmpty(dist) ? size[axis] / 2 : dist);
1523
- });
1528
+ }));
1524
1529
  }
1525
1530
  function bisect() {
1526
1531
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
@@ -1583,11 +1588,11 @@ function initJscadutils(_CSG, options = {}) {
1583
1588
  }[[ axis, rotateaxis ].sort().join("")];
1584
1589
  var centroid = object.centroid();
1585
1590
  var rotateDelta = getDelta(objectSize, bounds, rotateOffsetAxis, rotateoffset);
1586
- var rotationCenter = options.rotationCenter || new CSG.Vector3D(axisApply("xyz", function(i, a) {
1591
+ var rotationCenter = options.rotationCenter || new CSG.Vector3D(axisApply("xyz", (function(i, a) {
1587
1592
  if (a == axis) return cutDelta[i];
1588
1593
  if (a == rotateOffsetAxis) return rotateDelta[i];
1589
1594
  return centroid[a];
1590
- }));
1595
+ })));
1591
1596
  var theRotationAxis = rotationAxes[rotateaxis];
1592
1597
  var cutplane = CSG.OrthoNormalBasis.GetCartesian(info.orthoNormalCartesian[0], info.orthoNormalCartesian[1]).translate(cutDelta).rotate(rotationCenter, theRotationAxis, angle);
1593
1598
  debug$1("bisect", debug$1.enabled && {
@@ -1646,7 +1651,7 @@ function initJscadutils(_CSG, options = {}) {
1646
1651
  }
1647
1652
  function poly2solid(top, bottom, height) {
1648
1653
  if (top.sides.length == 0) {
1649
- return new CSG();
1654
+ return new CSG;
1650
1655
  }
1651
1656
  var offsetVector = CSG.Vector3D.Create(0, 0, height);
1652
1657
  var normalVector = CSG.Vector3D.Create(0, 1, 0);
@@ -1671,6 +1676,11 @@ function initJscadutils(_CSG, options = {}) {
1671
1676
  return CSG.fromPolygons(polygons);
1672
1677
  }
1673
1678
  function slices2poly(slices, options, axis) {
1679
+ debug$1("slices2poly", slices, options, axis);
1680
+ options = Object.assign({
1681
+ twistangle: 0,
1682
+ twiststeps: 0
1683
+ }, options);
1674
1684
  var twistangle = options && parseFloat(options.twistangle) || 0;
1675
1685
  var twiststeps = options && parseInt(options.twiststeps) || CSG.defaultResolution3D;
1676
1686
  if (twistangle == 0 || twiststeps < 1) {
@@ -1680,6 +1690,7 @@ function initJscadutils(_CSG, options = {}) {
1680
1690
  var polygons = [];
1681
1691
  var first$1 = first(slices);
1682
1692
  var last$1 = last(slices);
1693
+ debug$1("slices2poly first", first$1, first$1.offset, "last", last$1);
1683
1694
  var up = first$1.offset[axis] > last$1.offset[axis];
1684
1695
  polygons = polygons.concat(first$1.poly._toPlanePolygons({
1685
1696
  translation: first$1.offset,
@@ -1698,7 +1709,7 @@ function initJscadutils(_CSG, options = {}) {
1698
1709
  return v[rotateAxis](angle * percent);
1699
1710
  };
1700
1711
  var connectorAxis = last$1.offset.minus(first$1.offset).abs();
1701
- slices.forEach(function(slice, idx) {
1712
+ slices.forEach((function(slice, idx) {
1702
1713
  if (idx < slices.length - 1) {
1703
1714
  var nextidx = idx + 1;
1704
1715
  var top = !up ? slices[nextidx] : slice;
@@ -1711,7 +1722,7 @@ function initJscadutils(_CSG, options = {}) {
1711
1722
  toConnector2: c2
1712
1723
  }));
1713
1724
  }
1714
- });
1725
+ }));
1715
1726
  return CSG.fromPolygons(polygons);
1716
1727
  }
1717
1728
  function normalVector(axis) {
@@ -1752,30 +1763,32 @@ function initJscadutils(_CSG, options = {}) {
1752
1763
  var info = dirInfo["dir" + direction];
1753
1764
  return Object.assign({
1754
1765
  axis,
1755
- cutDelta: axisApply(axis, function(i, a) {
1766
+ cutDelta: axisApply(axis, (function(i, a) {
1756
1767
  return bounds[info.sizeIdx][a] + Math.abs(radius) * info.sizeDir;
1757
- }),
1758
- moveDelta: axisApply(axis, function(i, a) {
1768
+ })),
1769
+ moveDelta: axisApply(axis, (function(i, a) {
1759
1770
  return bounds[info.sizeIdx][a] + Math.abs(radius) * info.moveDir;
1760
- })
1771
+ }))
1761
1772
  }, info, normalVector(axis));
1762
1773
  }
1763
1774
  function reShape(object, radius, orientation, options, slicer) {
1764
1775
  options = options || {};
1765
1776
  var b = object.getBounds();
1766
- var ar = Math.abs(radius);
1777
+ var absoluteRadius = Math.abs(radius);
1767
1778
  var si = sliceParams(orientation, radius, b);
1779
+ debug$1("reShape", absoluteRadius, si);
1768
1780
  if (si.axis !== "z") throw new Error('reShape error: CAG._toPlanePolytons only uses the "z" axis. You must use the "z" axis for now.');
1769
1781
  var cutplane = CSG.OrthoNormalBasis.GetCartesian(si.orthoNormalCartesian[0], si.orthoNormalCartesian[1]).translate(si.cutDelta);
1770
1782
  var slice = object.sectionCut(cutplane);
1771
- var first = axisApply(si.axis, function() {
1772
- return si.positive ? 0 : ar;
1773
- });
1774
- var last = axisApply(si.axis, function() {
1775
- return si.positive ? ar : 0;
1776
- });
1783
+ var first = axisApply(si.axis, (function() {
1784
+ return si.positive ? 0 : absoluteRadius;
1785
+ }));
1786
+ var last = axisApply(si.axis, (function() {
1787
+ return si.positive ? absoluteRadius : 0;
1788
+ }));
1777
1789
  var plane = si.positive ? cutplane.plane : cutplane.plane.flipped();
1778
- var slices = slicer(first, last, slice);
1790
+ debug$1("reShape first/last", first, last);
1791
+ var slices = slicer(first, last, slice, radius);
1779
1792
  var delta = slices2poly(slices, Object.assign(options, {
1780
1793
  si
1781
1794
  }), si.axis).color(options.color);
@@ -1783,7 +1796,7 @@ function initJscadutils(_CSG, options = {}) {
1783
1796
  return union([ options.unionOriginal ? object : remainder, delta.translate(si.moveDelta) ]);
1784
1797
  }
1785
1798
  function chamfer(object, radius, orientation, options) {
1786
- return reShape(object, radius, orientation, options, function(first, last, slice) {
1799
+ return reShape(object, radius, orientation, options, (function(first, last, slice) {
1787
1800
  return [ {
1788
1801
  poly: slice,
1789
1802
  offset: new CSG.Vector3D(first)
@@ -1791,15 +1804,15 @@ function initJscadutils(_CSG, options = {}) {
1791
1804
  poly: enlarge(slice, [ -radius * 2, -radius * 2 ]),
1792
1805
  offset: new CSG.Vector3D(last)
1793
1806
  } ];
1794
- });
1807
+ }));
1795
1808
  }
1796
1809
  function fillet(object, radius, orientation, options) {
1797
1810
  options = options || {};
1798
- return reShape(object, radius, orientation, options, function(first, last, slice) {
1811
+ return reShape(object, radius, orientation, options, (function(first, last, slice) {
1799
1812
  var v1 = new CSG.Vector3D(first);
1800
1813
  var v2 = new CSG.Vector3D(last);
1801
1814
  var res = options.resolution || CSG.defaultResolution3D;
1802
- var slices = range(0, res).map(function(i) {
1815
+ var slices = range(0, res).map((function(i) {
1803
1816
  var p = i > 0 ? i / (res - 1) : 0;
1804
1817
  var v = v1.lerp(v2, p);
1805
1818
  var size = -radius * 2 - Math.cos(Math.asin(p)) * (-radius * 2);
@@ -1807,9 +1820,9 @@ function initJscadutils(_CSG, options = {}) {
1807
1820
  poly: enlarge(slice, [ size, size ]),
1808
1821
  offset: v
1809
1822
  };
1810
- });
1823
+ }));
1811
1824
  return slices;
1812
- });
1825
+ }));
1813
1826
  }
1814
1827
  function calcRotate(part, solid, axis) {
1815
1828
  var axes = {
@@ -1829,11 +1842,11 @@ function initJscadutils(_CSG, options = {}) {
1829
1842
  return part.rotate(rotationCenter, rotationAxis, angle);
1830
1843
  }
1831
1844
  function cloneProperties(from, to) {
1832
- return Object.entries(from).reduce(function(props, _ref) {
1845
+ return Object.entries(from).reduce((function(props, _ref) {
1833
1846
  var _ref2 = _slicedToArray(_ref, 2), key = _ref2[0], value = _ref2[1];
1834
1847
  props[key] = value;
1835
1848
  return props;
1836
- }, to);
1849
+ }), to);
1837
1850
  }
1838
1851
  function clone(o) {
1839
1852
  var c = CSG.fromPolygons(o.toPolygons());
@@ -1866,10 +1879,10 @@ function initJscadutils(_CSG, options = {}) {
1866
1879
  for (var _len = arguments.length, objects = new Array(_len), _key = 0; _key < _len; _key++) {
1867
1880
  objects[_key] = arguments[_key];
1868
1881
  }
1869
- return objects.reduce(function(bbox, part) {
1882
+ return objects.reduce((function(bbox, part) {
1870
1883
  var object = bbox ? union([ bbox, box(part) ]) : part;
1871
1884
  return box(object);
1872
- }, undefined);
1885
+ }), undefined);
1873
1886
  }
1874
1887
  function Cube(width) {
1875
1888
  var r = div(fromxyz(width), 2);
@@ -2050,16 +2063,17 @@ function initJscadutils(_CSG, options = {}) {
2050
2063
  gap = gap || .25;
2051
2064
  var inside = thickness - gap;
2052
2065
  var outside = -thickness + gap;
2053
- options.color = true;
2066
+ debug$3("inside", inside, "outside", outside);
2054
2067
  var group = Group();
2055
- debug$3("Rabbet top height:", height, "options:", options);
2056
2068
  var _box$bisect$parts = box.bisect("z", height, options).parts, top = _box$bisect$parts.positive, lower2_3rd = _box$bisect$parts.negative;
2057
- debug$3("face", face, "height", height);
2058
2069
  var lowerBisectHeight = Math.sign(height) < 0 ? face * Math.sign(height) : height - face;
2059
- debug$3("Rabbet bottom height:", lowerBisectHeight, "options:", options);
2060
2070
  var _lower2_3rd$bisect$pa = lower2_3rd.bisect("z", lowerBisectHeight, options).parts, middle = _lower2_3rd$bisect$pa.positive, bottom = _lower2_3rd$bisect$pa.negative;
2061
- group.add(top.union(middle.color("yellow").subtract(middle.color("darkred").enlarge([ outside, outside, 0 ]))), "top");
2062
- group.add(bottom.color("orange").union(middle.color("green").subtract(middle.color("red").enlarge([ inside, inside, 0 ]))), "bottom");
2071
+ var middleTop = middle.color("yellow").subtract(middle.color("darkred").enlarge([ outside, outside, 0 ]));
2072
+ group.add(top.union(middleTop), "top");
2073
+ var bottomOutline = middle.color("yellow").subtract(middle.color("orange").enlarge([ outside, outside, 0 ])).enlarge([ outside, outside, 0 ]);
2074
+ group.add(bottomOutline, "middle-top", true);
2075
+ group.add(middle.color("green").subtract(middle.color("pink").enlarge([ inside, inside, 0 ])), "middle-bottom", true);
2076
+ group.add(bottom.color("orange").union(middle.color("green").subtract(middle.color("red").enlarge([ inside, inside, 0 ])).subtract(middleTop)), "bottom");
2063
2077
  return group;
2064
2078
  }
2065
2079
  var RabettTopBottom = function rabbetTMB(box, thickness) {