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