makerjs 0.17.3 → 0.17.5

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.
@@ -39,7 +39,7 @@ and limitations under the License.
39
39
  * author: Dan Marshall / Microsoft Corporation
40
40
  * maintainers: Dan Marshall <danmar@microsoft.com>
41
41
  * homepage: https://maker.js.org
42
- * version: 0.17.3
42
+ * version: 0.17.5
43
43
  *
44
44
  * browserify:
45
45
  * license: MIT (http://opensource.org/licenses/MIT)
@@ -4104,8 +4104,21 @@ var MakerJs;
4104
4104
  //lines are both vertical, see if x are the same
4105
4105
  return MakerJs.round(slopeA.line.origin[0] - slopeB.line.origin[0]) == 0;
4106
4106
  }
4107
- //lines are parallel, but not vertical, see if y-intercept is the same
4108
- return MakerJs.round(slopeA.yIntercept - slopeB.yIntercept, .00001) == 0;
4107
+ //lines are parallel, but not vertical
4108
+ //create array of slopes
4109
+ var slopes = [slopeA, slopeB];
4110
+ //get angle of each line
4111
+ var angles = slopes.map(function (s) { return MakerJs.angle.toDegrees(Math.atan(s.slope)); });
4112
+ //create an array of each line cloned
4113
+ var lines = slopes.map(function (s) { return MakerJs.path.clone(s.line); });
4114
+ //use the first line as the rotation origin
4115
+ var origin = lines[0].origin;
4116
+ //rotate each line to flat
4117
+ lines.forEach(function (l, i) { return MakerJs.path.rotate(l, -angles[i], origin); });
4118
+ //get average y-intercept of each line
4119
+ var averageYs = lines.map(function (l) { return (l.origin[1] + l.end[1]) / 2; });
4120
+ //see if y-intercept is the same
4121
+ return MakerJs.round(averageYs[0] - averageYs[1], .00001) == 0;
4109
4122
  }
4110
4123
  measure.isSlopeEqual = isSlopeEqual;
4111
4124
  /**
@@ -8384,10 +8397,12 @@ var MakerJs;
8384
8397
  cpa.sort(function (a, b) { return a.xRatio - b.xRatio; });
8385
8398
  var first = cpa[0];
8386
8399
  var last = cpa[cpa.length - 1];
8387
- var min = first.xRatio;
8388
- var max = last.xRatio;
8389
- var span = max - min;
8390
- cpa.forEach(function (cp) { return cp.xRatio = (cp.xRatio - min) / span; });
8400
+ if (cpa.length > 1) {
8401
+ var min = first.xRatio;
8402
+ var max = last.xRatio;
8403
+ var span = max - min;
8404
+ cpa.forEach(function (cp) { return cp.xRatio = (cp.xRatio - min) / span; });
8405
+ }
8391
8406
  return {
8392
8407
  cpa: cpa,
8393
8408
  firstX: xMap[first.childId],
@@ -8440,7 +8455,7 @@ var MakerJs;
8440
8455
  var result = getChildPlacement(parentModel, baseline);
8441
8456
  var cpa = result.cpa;
8442
8457
  var chosenPath = onPath;
8443
- if (contain) {
8458
+ if (contain && cpa.length > 1) {
8444
8459
  //see if we need to clip
8445
8460
  var onPathLength = MakerJs.measure.pathLength(onPath);
8446
8461
  if (result.firstX + result.lastX < onPathLength) {
@@ -8502,35 +8517,52 @@ var MakerJs;
8502
8517
  var result = getChildPlacement(parentModel, baseline);
8503
8518
  var cpa = result.cpa;
8504
8519
  var chainLength = onChain.pathLength;
8505
- if (contain)
8506
- chainLength -= result.firstX + result.lastX;
8507
- var absolutes = cpa.map(function (cp) { return (reversed ? 1 - cp.xRatio : cp.xRatio) * chainLength; });
8508
- var relatives;
8509
- if (reversed)
8510
- absolutes.reverse();
8511
- relatives = absolutes.map(function (ab, i) { return Math.abs(ab - (i == 0 ? 0 : absolutes[i - 1])); });
8512
- if (contain) {
8513
- relatives[0] += reversed ? result.lastX : result.firstX;
8520
+ var points;
8521
+ if (cpa.length > 1) {
8522
+ if (contain)
8523
+ chainLength -= result.firstX + result.lastX;
8524
+ var absolutes = cpa.map(function (cp) { return (reversed ? 1 - cp.xRatio : cp.xRatio) * chainLength; });
8525
+ var relatives;
8526
+ if (reversed)
8527
+ absolutes.reverse();
8528
+ relatives = absolutes.map(function (ab, i) { return Math.abs(ab - (i == 0 ? 0 : absolutes[i - 1])); });
8529
+ if (contain) {
8530
+ relatives[0] += reversed ? result.lastX : result.firstX;
8531
+ }
8532
+ else {
8533
+ relatives.shift();
8534
+ }
8535
+ //chain.toPoints always follows the chain in its order, from beginning to end. This is why we needed to contort the points input
8536
+ points = MakerJs.chain.toPoints(onChain, relatives);
8537
+ if (points.length < cpa.length) {
8538
+ //add last point of chain, since our distances exceeded the chain
8539
+ var endLink = onChain.links[onChain.links.length - 1];
8540
+ points.push(endLink.endPoints[endLink.reversed ? 0 : 1]);
8541
+ }
8542
+ if (contain)
8543
+ points.shift(); //delete the first point which is the beginning of the chain
8514
8544
  }
8515
8545
  else {
8516
- relatives.shift();
8546
+ //get the first point and the middle point of the chain
8547
+ points = MakerJs.chain.toPoints(onChain, 0.5 * chainLength);
8548
+ points.length = 2;
8549
+ //add the last point of the chain
8550
+ points.push(onChain.links[onChain.links.length - 1].endPoints[onChain.links[onChain.links.length - 1].reversed ? 0 : 1]);
8517
8551
  }
8518
- //chain.toPoints always follows the chain in its order, from beginning to end. This is why we needed to contort the points input
8519
- var points = MakerJs.chain.toPoints(onChain, relatives);
8520
- if (points.length < cpa.length) {
8521
- //add last point of chain, since our distances exceeded the chain
8522
- var endLink = onChain.links[onChain.links.length - 1];
8523
- points.push(endLink.endPoints[endLink.reversed ? 0 : 1]);
8524
- }
8525
- if (contain)
8526
- points.shift(); //delete the first point which is the beginning of the chain
8527
8552
  if (reversed)
8528
8553
  points.reverse();
8529
8554
  var angles = miterAngles(points, -90);
8530
- cpa.forEach(function (cp, i) {
8531
- cp.angle = angles[i];
8532
- cp.origin = points[i];
8533
- });
8555
+ if (cpa.length > 1) {
8556
+ cpa.forEach(function (cp, i) {
8557
+ cp.angle = angles[i];
8558
+ cp.origin = points[i];
8559
+ });
8560
+ }
8561
+ else {
8562
+ //use the middle point
8563
+ cpa[0].angle = angles[1];
8564
+ cpa[0].origin = points[1];
8565
+ }
8534
8566
  moveAndRotate(parentModel, cpa, rotated);
8535
8567
  return parentModel;
8536
8568
  }
@@ -10286,6 +10318,6 @@ var MakerJs;
10286
10318
  ];
10287
10319
  })(models = MakerJs.models || (MakerJs.models = {}));
10288
10320
  })(MakerJs || (MakerJs = {}));
10289
- MakerJs.version = "0.17.3";
10321
+ MakerJs.version = "0.17.5";
10290
10322
 
10291
10323
  },{"clone":2,"graham_scan":3,"kdbush":4}]},{},[]);
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- // Type definitions for Maker.js 0.17.3
1
+ // Type definitions for Maker.js 0.17.5
2
2
  // Project: https://github.com/Microsoft/maker.js
3
3
  // Definitions by: Dan Marshall <https://github.com/danmarshall>
4
4
  // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
package/dist/index.js CHANGED
@@ -3687,8 +3687,21 @@ var MakerJs;
3687
3687
  //lines are both vertical, see if x are the same
3688
3688
  return MakerJs.round(slopeA.line.origin[0] - slopeB.line.origin[0]) == 0;
3689
3689
  }
3690
- //lines are parallel, but not vertical, see if y-intercept is the same
3691
- return MakerJs.round(slopeA.yIntercept - slopeB.yIntercept, .00001) == 0;
3690
+ //lines are parallel, but not vertical
3691
+ //create array of slopes
3692
+ var slopes = [slopeA, slopeB];
3693
+ //get angle of each line
3694
+ var angles = slopes.map(function (s) { return MakerJs.angle.toDegrees(Math.atan(s.slope)); });
3695
+ //create an array of each line cloned
3696
+ var lines = slopes.map(function (s) { return MakerJs.path.clone(s.line); });
3697
+ //use the first line as the rotation origin
3698
+ var origin = lines[0].origin;
3699
+ //rotate each line to flat
3700
+ lines.forEach(function (l, i) { return MakerJs.path.rotate(l, -angles[i], origin); });
3701
+ //get average y-intercept of each line
3702
+ var averageYs = lines.map(function (l) { return (l.origin[1] + l.end[1]) / 2; });
3703
+ //see if y-intercept is the same
3704
+ return MakerJs.round(averageYs[0] - averageYs[1], .00001) == 0;
3692
3705
  }
3693
3706
  measure.isSlopeEqual = isSlopeEqual;
3694
3707
  /**
@@ -7967,10 +7980,12 @@ var MakerJs;
7967
7980
  cpa.sort(function (a, b) { return a.xRatio - b.xRatio; });
7968
7981
  var first = cpa[0];
7969
7982
  var last = cpa[cpa.length - 1];
7970
- var min = first.xRatio;
7971
- var max = last.xRatio;
7972
- var span = max - min;
7973
- cpa.forEach(function (cp) { return cp.xRatio = (cp.xRatio - min) / span; });
7983
+ if (cpa.length > 1) {
7984
+ var min = first.xRatio;
7985
+ var max = last.xRatio;
7986
+ var span = max - min;
7987
+ cpa.forEach(function (cp) { return cp.xRatio = (cp.xRatio - min) / span; });
7988
+ }
7974
7989
  return {
7975
7990
  cpa: cpa,
7976
7991
  firstX: xMap[first.childId],
@@ -8023,7 +8038,7 @@ var MakerJs;
8023
8038
  var result = getChildPlacement(parentModel, baseline);
8024
8039
  var cpa = result.cpa;
8025
8040
  var chosenPath = onPath;
8026
- if (contain) {
8041
+ if (contain && cpa.length > 1) {
8027
8042
  //see if we need to clip
8028
8043
  var onPathLength = MakerJs.measure.pathLength(onPath);
8029
8044
  if (result.firstX + result.lastX < onPathLength) {
@@ -8085,35 +8100,52 @@ var MakerJs;
8085
8100
  var result = getChildPlacement(parentModel, baseline);
8086
8101
  var cpa = result.cpa;
8087
8102
  var chainLength = onChain.pathLength;
8088
- if (contain)
8089
- chainLength -= result.firstX + result.lastX;
8090
- var absolutes = cpa.map(function (cp) { return (reversed ? 1 - cp.xRatio : cp.xRatio) * chainLength; });
8091
- var relatives;
8092
- if (reversed)
8093
- absolutes.reverse();
8094
- relatives = absolutes.map(function (ab, i) { return Math.abs(ab - (i == 0 ? 0 : absolutes[i - 1])); });
8095
- if (contain) {
8096
- relatives[0] += reversed ? result.lastX : result.firstX;
8103
+ var points;
8104
+ if (cpa.length > 1) {
8105
+ if (contain)
8106
+ chainLength -= result.firstX + result.lastX;
8107
+ var absolutes = cpa.map(function (cp) { return (reversed ? 1 - cp.xRatio : cp.xRatio) * chainLength; });
8108
+ var relatives;
8109
+ if (reversed)
8110
+ absolutes.reverse();
8111
+ relatives = absolutes.map(function (ab, i) { return Math.abs(ab - (i == 0 ? 0 : absolutes[i - 1])); });
8112
+ if (contain) {
8113
+ relatives[0] += reversed ? result.lastX : result.firstX;
8114
+ }
8115
+ else {
8116
+ relatives.shift();
8117
+ }
8118
+ //chain.toPoints always follows the chain in its order, from beginning to end. This is why we needed to contort the points input
8119
+ points = MakerJs.chain.toPoints(onChain, relatives);
8120
+ if (points.length < cpa.length) {
8121
+ //add last point of chain, since our distances exceeded the chain
8122
+ var endLink = onChain.links[onChain.links.length - 1];
8123
+ points.push(endLink.endPoints[endLink.reversed ? 0 : 1]);
8124
+ }
8125
+ if (contain)
8126
+ points.shift(); //delete the first point which is the beginning of the chain
8097
8127
  }
8098
8128
  else {
8099
- relatives.shift();
8129
+ //get the first point and the middle point of the chain
8130
+ points = MakerJs.chain.toPoints(onChain, 0.5 * chainLength);
8131
+ points.length = 2;
8132
+ //add the last point of the chain
8133
+ points.push(onChain.links[onChain.links.length - 1].endPoints[onChain.links[onChain.links.length - 1].reversed ? 0 : 1]);
8100
8134
  }
8101
- //chain.toPoints always follows the chain in its order, from beginning to end. This is why we needed to contort the points input
8102
- var points = MakerJs.chain.toPoints(onChain, relatives);
8103
- if (points.length < cpa.length) {
8104
- //add last point of chain, since our distances exceeded the chain
8105
- var endLink = onChain.links[onChain.links.length - 1];
8106
- points.push(endLink.endPoints[endLink.reversed ? 0 : 1]);
8107
- }
8108
- if (contain)
8109
- points.shift(); //delete the first point which is the beginning of the chain
8110
8135
  if (reversed)
8111
8136
  points.reverse();
8112
8137
  var angles = miterAngles(points, -90);
8113
- cpa.forEach(function (cp, i) {
8114
- cp.angle = angles[i];
8115
- cp.origin = points[i];
8116
- });
8138
+ if (cpa.length > 1) {
8139
+ cpa.forEach(function (cp, i) {
8140
+ cp.angle = angles[i];
8141
+ cp.origin = points[i];
8142
+ });
8143
+ }
8144
+ else {
8145
+ //use the middle point
8146
+ cpa[0].angle = angles[1];
8147
+ cpa[0].origin = points[1];
8148
+ }
8117
8149
  moveAndRotate(parentModel, cpa, rotated);
8118
8150
  return parentModel;
8119
8151
  }
@@ -9869,5 +9901,5 @@ var MakerJs;
9869
9901
  ];
9870
9902
  })(models = MakerJs.models || (MakerJs.models = {}));
9871
9903
  })(MakerJs || (MakerJs = {}));
9872
- MakerJs.version = "0.17.3";
9904
+ MakerJs.version = "0.17.5";
9873
9905
  var Bezier = require('bezier-js');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "makerjs",
3
- "version": "0.17.3",
3
+ "version": "0.17.5",
4
4
  "description": "Maker.js, a Microsoft Garage project, is a JavaScript library for creating and sharing modular line drawings for CNC and laser cutters.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",