@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.
package/dist/compat.js CHANGED
@@ -43,8 +43,10 @@ function initJscadutils(_CSG, options = {}) {
43
43
  var jscadUtils = (function (exports, jsCadCSG, scadApi) {
44
44
  'use strict';
45
45
 
46
- jsCadCSG = jsCadCSG && Object.prototype.hasOwnProperty.call(jsCadCSG, 'default') ? jsCadCSG['default'] : jsCadCSG;
47
- scadApi = scadApi && Object.prototype.hasOwnProperty.call(scadApi, 'default') ? scadApi['default'] : scadApi;
46
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
47
+
48
+ var jsCadCSG__default = /*#__PURE__*/_interopDefaultLegacy(jsCadCSG);
49
+ var scadApi__default = /*#__PURE__*/_interopDefaultLegacy(scadApi);
48
50
 
49
51
  var util = /*#__PURE__*/Object.freeze({
50
52
  __proto__: null,
@@ -1013,13 +1015,13 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
1013
1015
  'default': init
1014
1016
  });
1015
1017
 
1016
- var CSG = jsCadCSG.CSG,
1017
- CAG = jsCadCSG.CAG;
1018
- var rectangular_extrude = scadApi.extrusions.rectangular_extrude;
1019
- var _scadApi$text = scadApi.text,
1018
+ var CSG = jsCadCSG__default['default'].CSG,
1019
+ CAG = jsCadCSG__default['default'].CAG;
1020
+ var rectangular_extrude = scadApi__default['default'].extrusions.rectangular_extrude;
1021
+ var _scadApi$text = scadApi__default['default'].text,
1020
1022
  vector_text = _scadApi$text.vector_text,
1021
1023
  vector_char = _scadApi$text.vector_char;
1022
- var union = scadApi.booleanOps.union;
1024
+ var union = scadApi__default['default'].booleanOps.union;
1023
1025
  init(CSG);
1024
1026
 
1025
1027
  var debug = Debug('jscadUtils:group');
@@ -1632,8 +1634,8 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
1632
1634
  * has been depricated and what to use instead.
1633
1635
  * @function depreciated
1634
1636
  * @param {string} method The name of the method being depricated.
1635
- * @param {boolean} error Throws an error if called when true.
1636
- * @param {string} message Instructions on what to use instead of the depricated method.
1637
+ * @param {boolean} [error] Throws an error if called when true.
1638
+ * @param {string} [message] Instructions on what to use instead of the depricated method.
1637
1639
  */
1638
1640
 
1639
1641
  function depreciated(method, error, message) {
@@ -2335,12 +2337,12 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
2335
2337
  return object.stretchAtPlane(normal[axis], cutDelta, distance);
2336
2338
  }
2337
2339
  /**
2338
- * Takes two CSG polygons and createds a solid of `height`.
2339
- * Similar to `CSG.extrude`, excdept you can resize either
2340
+ * Takes two CSG polygons and creates a solid of `height`.
2341
+ * Similar to `CSG.extrude`, except you can resize either
2340
2342
  * polygon.
2341
2343
  * @param {CAG} top Top polygon
2342
2344
  * @param {CAG} bottom Bottom polygon
2343
- * @param {number} height heigth of solid
2345
+ * @param {number} height height of solid
2344
2346
  * @return {CSG} generated solid
2345
2347
  */
2346
2348
 
@@ -2377,6 +2379,11 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
2377
2379
  return CSG.fromPolygons(polygons);
2378
2380
  }
2379
2381
  function slices2poly(slices, options, axis) {
2382
+ debug$1('slices2poly', slices, options, axis);
2383
+ options = Object.assign({
2384
+ twistangle: 0,
2385
+ twiststeps: 0
2386
+ }, options);
2380
2387
  var twistangle = options && parseFloat(options.twistangle) || 0;
2381
2388
  var twiststeps = options && parseInt(options.twiststeps) || CSG.defaultResolution3D;
2382
2389
 
@@ -2389,6 +2396,7 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
2389
2396
 
2390
2397
  var first$1 = first(slices);
2391
2398
  var last$1 = last(slices);
2399
+ debug$1('slices2poly first', first$1, first$1.offset, 'last', last$1);
2392
2400
  var up = first$1.offset[axis] > last$1.offset[axis]; // _toPlanePolygons only works in the 'z' axis. It's hard coded
2393
2401
  // to create the poly using 'x' and 'y'.
2394
2402
 
@@ -2487,19 +2495,21 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
2487
2495
  function reShape(object, radius, orientation, options, slicer) {
2488
2496
  options = options || {};
2489
2497
  var b = object.getBounds();
2490
- var ar = Math.abs(radius);
2498
+ var absoluteRadius = Math.abs(radius);
2491
2499
  var si = sliceParams(orientation, radius, b);
2500
+ debug$1('reShape', absoluteRadius, si);
2492
2501
  if (si.axis !== 'z') throw new Error('reShape error: CAG._toPlanePolytons only uses the "z" axis. You must use the "z" axis for now.');
2493
2502
  var cutplane = CSG.OrthoNormalBasis.GetCartesian(si.orthoNormalCartesian[0], si.orthoNormalCartesian[1]).translate(si.cutDelta);
2494
2503
  var slice = object.sectionCut(cutplane);
2495
2504
  var first = axisApply(si.axis, function () {
2496
- return si.positive ? 0 : ar;
2505
+ return si.positive ? 0 : absoluteRadius;
2497
2506
  });
2498
2507
  var last = axisApply(si.axis, function () {
2499
- return si.positive ? ar : 0;
2508
+ return si.positive ? absoluteRadius : 0;
2500
2509
  });
2501
2510
  var plane = si.positive ? cutplane.plane : cutplane.plane.flipped();
2502
- var slices = slicer(first, last, slice);
2511
+ debug$1('reShape first/last', first, last);
2512
+ var slices = slicer(first, last, slice, radius);
2503
2513
  var delta = slices2poly(slices, Object.assign(options, {
2504
2514
  si: si
2505
2515
  }), si.axis).color(options.color);
@@ -2975,23 +2985,27 @@ var jscadUtils = (function (exports, jsCadCSG, scadApi) {
2975
2985
  debug$3('Rabett', 'thickness', thickness, 'gap', gap, 'height', height, 'face', face);
2976
2986
  gap = gap || 0.25;
2977
2987
  var inside = thickness - gap;
2978
- var outside = -thickness + gap;
2979
- options.color = true;
2980
- var group = Group();
2981
- debug$3('Rabbet top height:', height, 'options:', options);
2988
+ var outside = -thickness + gap; // options.color = true;
2989
+
2990
+ debug$3('inside', inside, 'outside', outside);
2991
+ var group = Group(); // debug('Rabbet top height:', height, 'options:', options);
2992
+
2982
2993
  var _box$bisect$parts = box.bisect('z', height, options).parts,
2983
2994
  top = _box$bisect$parts.positive,
2984
- lower2_3rd = _box$bisect$parts.negative;
2985
- debug$3('face', face, 'height', height);
2986
- var lowerBisectHeight = Math.sign(height) < 0 ? face * Math.sign(height) : height - face;
2987
- debug$3('Rabbet bottom height:', lowerBisectHeight, 'options:', options);
2995
+ lower2_3rd = _box$bisect$parts.negative; // debug('face', face, 'height', height);
2996
+
2997
+ var lowerBisectHeight = Math.sign(height) < 0 ? face * Math.sign(height) : height - face; // debug('Rabbet bottom height:', lowerBisectHeight, 'options:', options);
2998
+
2988
2999
  var _lower2_3rd$bisect$pa = lower2_3rd.bisect('z', lowerBisectHeight, options).parts,
2989
3000
  middle = _lower2_3rd$bisect$pa.positive,
2990
3001
  bottom = _lower2_3rd$bisect$pa.negative;
3002
+ var middleTop = middle.color('yellow').subtract(middle.color('darkred').enlarge([outside, outside, 0]));
2991
3003
  group.add(top // .color('blue')
2992
- .union(middle.color('yellow').subtract(middle.color('darkred').enlarge([outside, outside, 0]))), 'top'); // group.add(middle.color('pink').enlarge([inside, inside, 0]), 'middle');
2993
-
2994
- group.add(bottom.color('orange').union(middle.color('green').subtract(middle.color('red').enlarge([inside, inside, 0]))), 'bottom');
3004
+ .union(middleTop), 'top');
3005
+ var bottomOutline = middle.color('yellow').subtract(middle.color('orange').enlarge([outside, outside, 0])).enlarge([outside, outside, 0]);
3006
+ group.add(bottomOutline, 'middle-top', true);
3007
+ group.add(middle.color('green').subtract(middle.color('pink').enlarge([inside, inside, 0])), 'middle-bottom', true);
3008
+ group.add(bottom.color('orange').union(middle.color('green').subtract(middle.color('red').enlarge([inside, inside, 0])).subtract(middleTop)), 'bottom');
2995
3009
  return group;
2996
3010
  }
2997
3011
  /**