geometric-library 1.3.1 → 1.4.0

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.
Files changed (143) hide show
  1. package/README.md +39 -430
  2. package/dist/cjs/abstracts/{Angle.js → angle/Angle.js} +11 -11
  3. package/dist/cjs/abstracts/angle/Angle.types.js +2 -0
  4. package/dist/cjs/abstracts/angle/index.js +18 -0
  5. package/dist/cjs/abstracts/{Figure.js → figure/Figure.js} +45 -30
  6. package/dist/cjs/abstracts/figure/Figure.types.js +2 -0
  7. package/dist/cjs/abstracts/figure/index.js +18 -0
  8. package/dist/cjs/abstracts/{Flag.js → flag/Flag.js} +1 -0
  9. package/dist/cjs/abstracts/flag/Flag.types.js +2 -0
  10. package/dist/cjs/abstracts/flag/index.js +18 -0
  11. package/dist/cjs/abstracts/index.js +22 -0
  12. package/dist/cjs/abstracts/{Magnitude.js → magnitude/Magnitude.js} +3 -2
  13. package/dist/cjs/abstracts/magnitude/Magnitude.types.js +2 -0
  14. package/dist/cjs/abstracts/magnitude/index.js +18 -0
  15. package/dist/cjs/abstracts/{Point.js → point/Point.js} +8 -7
  16. package/dist/cjs/abstracts/point/Point.types.js +2 -0
  17. package/dist/cjs/abstracts/point/index.js +18 -0
  18. package/dist/cjs/abstracts/{Vector.js → vector/Vector.js} +16 -15
  19. package/dist/cjs/abstracts/vector/Vector.types.js +2 -0
  20. package/dist/cjs/abstracts/vector/index.js +18 -0
  21. package/dist/cjs/figures/arc-curve/ArcCurve.js +174 -0
  22. package/dist/cjs/figures/arc-curve/ArcCurve.types.js +2 -0
  23. package/dist/cjs/figures/arc-curve/index.js +18 -0
  24. package/dist/cjs/figures/{Circle.js → circle/Circle.js} +8 -9
  25. package/dist/cjs/figures/circle/Circle.types.js +2 -0
  26. package/dist/cjs/figures/circle/index.js +18 -0
  27. package/dist/cjs/figures/{CubicBezierCurve.js → cubic-bezier-curve/CubicBezierCurve.js} +22 -17
  28. package/dist/cjs/figures/cubic-bezier-curve/CubicBezierCurve.types.js +2 -0
  29. package/dist/cjs/figures/cubic-bezier-curve/index.js +18 -0
  30. package/dist/cjs/figures/ellipse/Ellipse.js +129 -0
  31. package/dist/cjs/figures/ellipse/Ellipse.types.js +2 -0
  32. package/dist/cjs/figures/ellipse/index.js +18 -0
  33. package/dist/cjs/figures/index.js +23 -0
  34. package/dist/cjs/figures/{Line.js → line/Line.js} +78 -59
  35. package/dist/cjs/figures/line/Line.types.js +2 -0
  36. package/dist/cjs/figures/line/index.js +18 -0
  37. package/dist/cjs/figures/polygon/Polygon.js +51 -0
  38. package/dist/cjs/figures/polygon/Polygon.types.js +2 -0
  39. package/dist/cjs/figures/polygon/index.js +18 -0
  40. package/dist/cjs/figures/{QuadraticBezierCurve.js → quadratic-bezier-curve/QuadraticBezierCurve.js} +12 -8
  41. package/dist/cjs/figures/quadratic-bezier-curve/QuadraticBezierCurve.types.js +2 -0
  42. package/dist/cjs/figures/quadratic-bezier-curve/index.js +18 -0
  43. package/dist/cjs/index.js +2 -29
  44. package/dist/cjs/utilities/{Calculator.js → calculator/Calculator.js} +9 -1
  45. package/dist/cjs/utilities/calculator/index.js +17 -0
  46. package/dist/cjs/utilities/index.js +20 -8
  47. package/dist/esm/abstracts/{Angle.js → angle/Angle.js} +4 -4
  48. package/dist/esm/abstracts/angle/Angle.types.js +1 -0
  49. package/dist/esm/abstracts/angle/index.js +2 -0
  50. package/dist/esm/abstracts/{Figure.js → figure/Figure.js} +37 -22
  51. package/dist/esm/abstracts/figure/Figure.types.js +1 -0
  52. package/dist/esm/abstracts/figure/index.js +2 -0
  53. package/dist/esm/abstracts/{Flag.js → flag/Flag.js} +1 -0
  54. package/dist/esm/abstracts/flag/Flag.types.js +1 -0
  55. package/dist/esm/abstracts/flag/index.js +2 -0
  56. package/dist/esm/abstracts/index.js +6 -0
  57. package/dist/esm/abstracts/{Magnitude.js → magnitude/Magnitude.js} +2 -1
  58. package/dist/esm/abstracts/magnitude/Magnitude.types.js +1 -0
  59. package/dist/esm/abstracts/magnitude/index.js +2 -0
  60. package/dist/esm/abstracts/{Point.js → point/Point.js} +2 -1
  61. package/dist/esm/abstracts/point/Point.types.js +1 -0
  62. package/dist/esm/abstracts/point/index.js +2 -0
  63. package/dist/esm/abstracts/{Vector.js → vector/Vector.js} +3 -2
  64. package/dist/esm/abstracts/vector/Vector.types.js +1 -0
  65. package/dist/esm/abstracts/vector/index.js +2 -0
  66. package/dist/esm/figures/{ArcCurve.js → arc-curve/ArcCurve.js} +50 -8
  67. package/dist/esm/figures/arc-curve/ArcCurve.types.js +1 -0
  68. package/dist/esm/figures/arc-curve/index.js +2 -0
  69. package/dist/esm/figures/{Circle.js → circle/Circle.js} +3 -4
  70. package/dist/esm/figures/circle/Circle.types.js +1 -0
  71. package/dist/esm/figures/circle/index.js +2 -0
  72. package/dist/esm/figures/{CubicBezierCurve.js → cubic-bezier-curve/CubicBezierCurve.js} +11 -6
  73. package/dist/esm/figures/cubic-bezier-curve/CubicBezierCurve.types.js +1 -0
  74. package/dist/esm/figures/cubic-bezier-curve/index.js +2 -0
  75. package/dist/esm/figures/{Ellipse.js → ellipse/Ellipse.js} +24 -6
  76. package/dist/esm/figures/ellipse/Ellipse.types.js +1 -0
  77. package/dist/esm/figures/ellipse/index.js +2 -0
  78. package/dist/esm/figures/index.js +7 -0
  79. package/dist/esm/figures/{Line.js → line/Line.js} +57 -38
  80. package/dist/esm/figures/line/Line.types.js +1 -0
  81. package/dist/esm/figures/line/index.js +2 -0
  82. package/dist/esm/figures/polygon/Polygon.js +47 -0
  83. package/dist/esm/figures/polygon/Polygon.types.js +1 -0
  84. package/dist/esm/figures/polygon/index.js +2 -0
  85. package/dist/esm/figures/{QuadraticBezierCurve.js → quadratic-bezier-curve/QuadraticBezierCurve.js} +7 -3
  86. package/dist/esm/figures/quadratic-bezier-curve/QuadraticBezierCurve.types.js +1 -0
  87. package/dist/esm/figures/quadratic-bezier-curve/index.js +2 -0
  88. package/dist/esm/index.js +2 -14
  89. package/dist/esm/utilities/{Calculator.js → calculator/Calculator.js} +9 -1
  90. package/dist/esm/utilities/calculator/index.js +1 -0
  91. package/dist/esm/utilities/index.js +4 -6
  92. package/dist/types/abstracts/{Angle.d.ts → angle/Angle.d.ts} +2 -1
  93. package/dist/types/abstracts/angle/Angle.types.d.ts +16 -0
  94. package/dist/types/abstracts/angle/index.d.ts +2 -0
  95. package/dist/types/abstracts/{Figure.d.ts → figure/Figure.d.ts} +4 -4
  96. package/dist/types/abstracts/figure/Figure.types.d.ts +14 -0
  97. package/dist/types/abstracts/figure/index.d.ts +2 -0
  98. package/dist/types/abstracts/{Flag.d.ts → flag/Flag.d.ts} +2 -1
  99. package/dist/types/abstracts/flag/Flag.types.d.ts +8 -0
  100. package/dist/types/abstracts/flag/index.d.ts +2 -0
  101. package/dist/types/abstracts/index.d.ts +6 -0
  102. package/dist/types/abstracts/{Magnitude.d.ts → magnitude/Magnitude.d.ts} +2 -1
  103. package/dist/types/abstracts/magnitude/Magnitude.types.d.ts +8 -0
  104. package/dist/types/abstracts/magnitude/index.d.ts +2 -0
  105. package/dist/types/abstracts/{Point.d.ts → point/Point.d.ts} +2 -1
  106. package/dist/types/abstracts/point/Point.types.d.ts +13 -0
  107. package/dist/types/abstracts/point/index.d.ts +2 -0
  108. package/dist/types/abstracts/{Vector.d.ts → vector/Vector.d.ts} +3 -1
  109. package/dist/types/abstracts/vector/Vector.types.d.ts +19 -0
  110. package/dist/types/abstracts/vector/index.d.ts +2 -0
  111. package/dist/types/figures/{ArcCurve.d.ts → arc-curve/ArcCurve.d.ts} +7 -2
  112. package/dist/types/figures/arc-curve/ArcCurve.types.d.ts +11 -0
  113. package/dist/types/figures/arc-curve/index.d.ts +2 -0
  114. package/dist/types/figures/{Circle.d.ts → circle/Circle.d.ts} +3 -2
  115. package/dist/types/figures/circle/Circle.types.d.ts +9 -0
  116. package/dist/types/figures/circle/index.d.ts +2 -0
  117. package/dist/types/figures/{CubicBezierCurve.d.ts → cubic-bezier-curve/CubicBezierCurve.d.ts} +4 -2
  118. package/dist/types/figures/cubic-bezier-curve/CubicBezierCurve.types.d.ts +8 -0
  119. package/dist/types/figures/cubic-bezier-curve/index.d.ts +2 -0
  120. package/dist/types/figures/{Ellipse.d.ts → ellipse/Ellipse.d.ts} +5 -2
  121. package/dist/types/figures/ellipse/Ellipse.types.d.ts +16 -0
  122. package/dist/types/figures/ellipse/index.d.ts +2 -0
  123. package/dist/types/figures/index.d.ts +7 -0
  124. package/dist/types/figures/{Line.d.ts → line/Line.d.ts} +6 -4
  125. package/dist/types/figures/line/Line.types.d.ts +30 -0
  126. package/dist/types/figures/line/index.d.ts +2 -0
  127. package/dist/types/figures/polygon/Polygon.d.ts +17 -0
  128. package/dist/types/figures/polygon/Polygon.types.d.ts +8 -0
  129. package/dist/types/figures/polygon/index.d.ts +2 -0
  130. package/dist/types/figures/{QuadraticBezierCurve.d.ts → quadratic-bezier-curve/QuadraticBezierCurve.d.ts} +4 -2
  131. package/dist/types/figures/quadratic-bezier-curve/QuadraticBezierCurve.types.d.ts +8 -0
  132. package/dist/types/figures/quadratic-bezier-curve/index.d.ts +2 -0
  133. package/dist/types/index.d.ts +2 -14
  134. package/dist/types/types/index.d.ts +0 -129
  135. package/dist/types/utilities/{Calculator.d.ts → calculator/Calculator.d.ts} +4 -0
  136. package/dist/types/utilities/calculator/index.d.ts +1 -0
  137. package/dist/types/utilities/index.d.ts +2 -4
  138. package/package.json +24 -18
  139. package/dist/cjs/figures/ArcCurve.js +0 -132
  140. package/dist/cjs/figures/Ellipse.js +0 -111
  141. package/dist/cjs/figures/Polygon.js +0 -17
  142. package/dist/esm/figures/Polygon.js +0 -13
  143. package/dist/types/figures/Polygon.d.ts +0 -7
@@ -1,10 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Figure = void 0;
4
- const Calculator_1 = require("../utilities/Calculator");
5
- const Magnitude_1 = require("./Magnitude");
6
- const Point_1 = require("./Point");
7
- const Vector_1 = require("./Vector");
4
+ const _abstracts_1 = require("..");
5
+ const calculator_1 = require("../../utilities/calculator");
8
6
  class Figure {
9
7
  angles = [];
10
8
  isRelative = false;
@@ -22,23 +20,22 @@ class Figure {
22
20
  get values() {
23
21
  return this._values;
24
22
  }
25
- /**
26
- * @todo Figure out a better way to type narrow than iterating again.
27
- */
28
23
  set values(values) {
29
24
  this._values = values;
30
25
  const [points, vectors, magnitudes, angles] = values.reduce((result, value) => {
31
- if (value instanceof Point_1.Point) {
32
- result[0].push(value);
33
- }
34
- if (value instanceof Vector_1.Vector) {
35
- result[1].push(value);
36
- }
37
- if (value instanceof Magnitude_1.Magnitude) {
38
- result[2].push(value);
39
- }
40
- if (typeof value === 'object' && 'radians' in value) {
41
- result[3].push(value);
26
+ switch (value.kind) {
27
+ case 'point':
28
+ result[0].push(value);
29
+ break;
30
+ case 'vector':
31
+ result[1].push(value);
32
+ break;
33
+ case 'magnitude':
34
+ result[2].push(value);
35
+ break;
36
+ case 'angle':
37
+ result[3].push(value);
38
+ break;
42
39
  }
43
40
  return result;
44
41
  }, [[], [], [], []]);
@@ -57,10 +54,10 @@ class Figure {
57
54
  values[1].push(point.y);
58
55
  return values;
59
56
  }, [[], []]);
60
- const xMax = +Calculator_1.Calculator.max(xValues);
61
- const xMin = +Calculator_1.Calculator.min(xValues);
62
- const yMax = +Calculator_1.Calculator.max(yValues);
63
- const yMin = +Calculator_1.Calculator.min(yValues);
57
+ const xMax = +calculator_1.Calculator.max(xValues);
58
+ const xMin = +calculator_1.Calculator.min(xValues);
59
+ const yMax = +calculator_1.Calculator.max(yValues);
60
+ const yMin = +calculator_1.Calculator.min(yValues);
64
61
  return { xMax, xMin, yMax, yMin };
65
62
  }
66
63
  static getNoPointsErrorMessage(name, property = false) {
@@ -77,10 +74,13 @@ class Figure {
77
74
  point.reflect(perpendicularRoot);
78
75
  });
79
76
  vectors.forEach((vector) => {
80
- vector.reflect({
81
- x: !about.isHorizontal,
82
- y: !about.isVertical
83
- });
77
+ const referenceProjection = about.getPerpendicularProjection(points[0]);
78
+ const referencePoint = points[0].clone().reflect(referenceProjection);
79
+ const endPoint = points[0].clone().translate(vector);
80
+ const endProjection = about.getPerpendicularProjection(endPoint);
81
+ const positionalPoint = endPoint.reflect(endProjection);
82
+ const reflectedVector = new _abstracts_1.Vector([referencePoint, positionalPoint]);
83
+ vector.replace(reflectedVector);
84
84
  });
85
85
  return this;
86
86
  }
@@ -106,21 +106,21 @@ class Figure {
106
106
  vectors.forEach((vector) => {
107
107
  const referencePoint = points[0].clone().rotate(phi, about);
108
108
  const positionalPoint = points[0].clone().translate(vector).rotate(phi, about);
109
- const rotatedVector = new Vector_1.Vector([referencePoint, positionalPoint]);
109
+ const rotatedVector = new _abstracts_1.Vector([referencePoint, positionalPoint]);
110
110
  vector.replace(rotatedVector);
111
111
  });
112
112
  angles.forEach((angle) => {
113
- angle.replace(+Calculator_1.Calculator.add(+angle, +phi), 'radians').normalize();
113
+ angle.replace(+calculator_1.Calculator.add(+angle, +phi), 'radians').normalize();
114
114
  });
115
115
  return this;
116
116
  }
117
- scale(factor, about = new Point_1.Point([0, 0])) {
117
+ scale(factor, about = new _abstracts_1.Point([0, 0])) {
118
118
  const { points, vectors, magnitudes } = this;
119
119
  if (!points) {
120
120
  throw new Error(Figure.getNoPointsErrorMessage('scale'));
121
121
  }
122
122
  points.forEach((point) => {
123
- const positionalVector = new Vector_1.Vector([about, point]);
123
+ const positionalVector = new _abstracts_1.Vector([about, point]);
124
124
  const scaledPositionalVector = positionalVector.clone().scale(factor);
125
125
  const scaledPoint = about.clone().translate(scaledPositionalVector);
126
126
  point.replace(scaledPoint);
@@ -133,6 +133,21 @@ class Figure {
133
133
  });
134
134
  return this;
135
135
  }
136
+ scaleXY(factorX, factorY, about = new _abstracts_1.Point([0, 0])) {
137
+ const { points, vectors } = this;
138
+ if (!points) {
139
+ throw new Error(Figure.getNoPointsErrorMessage('scaleXY'));
140
+ }
141
+ points.forEach((point) => {
142
+ const scaledX = +calculator_1.Calculator.add(about.x, calculator_1.Calculator.sub(point.x, about.x).mul(factorX));
143
+ const scaledY = +calculator_1.Calculator.add(about.y, calculator_1.Calculator.sub(point.y, about.y).mul(factorY));
144
+ point.replace(new _abstracts_1.Point([scaledX, scaledY]));
145
+ });
146
+ vectors.forEach((vector) => {
147
+ vector.replace(new _abstracts_1.Vector([+calculator_1.Calculator.mul(vector.dx, factorX), +calculator_1.Calculator.mul(vector.dy, factorY)]));
148
+ });
149
+ return this;
150
+ }
136
151
  translate(vector) {
137
152
  const { points } = this;
138
153
  if (!points) {
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./Figure"), exports);
18
+ __exportStar(require("./Figure.types"), exports);
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Flag = void 0;
4
4
  class Flag {
5
+ kind = 'flag';
5
6
  _value;
6
7
  constructor(value) {
7
8
  this._value = value;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./Flag"), exports);
18
+ __exportStar(require("./Flag.types"), exports);
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./angle"), exports);
18
+ __exportStar(require("./figure"), exports);
19
+ __exportStar(require("./flag"), exports);
20
+ __exportStar(require("./magnitude"), exports);
21
+ __exportStar(require("./point"), exports);
22
+ __exportStar(require("./vector"), exports);
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Magnitude = void 0;
4
- const Calculator_1 = require("../utilities/Calculator");
4
+ const calculator_1 = require("../../utilities/calculator");
5
5
  class Magnitude {
6
+ kind = 'magnitude';
6
7
  _value;
7
8
  constructor(value) {
8
9
  this._value = value;
@@ -18,7 +19,7 @@ class Magnitude {
18
19
  return this;
19
20
  }
20
21
  scale(factor) {
21
- this._value = +Calculator_1.Calculator.mul(+this, factor);
22
+ this._value = +calculator_1.Calculator.mul(+this, factor);
22
23
  return this;
23
24
  }
24
25
  valueOf() {
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./Magnitude"), exports);
18
+ __exportStar(require("./Magnitude.types"), exports);
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Point = void 0;
4
- const Calculator_1 = require("../utilities/Calculator");
4
+ const calculator_1 = require("../../utilities/calculator");
5
5
  class Point {
6
+ kind = 'point';
6
7
  _x;
7
8
  _y;
8
9
  constructor([x, y]) {
@@ -24,8 +25,8 @@ class Point {
24
25
  }
25
26
  reflect(about) {
26
27
  const { x, y } = this;
27
- this._x = +Calculator_1.Calculator.sub(about.x, x).mul(2).add(x);
28
- this._y = +Calculator_1.Calculator.sub(about.y, y).mul(2).add(y);
28
+ this._x = +calculator_1.Calculator.sub(about.x, x).mul(2).add(x);
29
+ this._y = +calculator_1.Calculator.sub(about.y, y).mul(2).add(y);
29
30
  return this;
30
31
  }
31
32
  replace(point) {
@@ -34,16 +35,16 @@ class Point {
34
35
  return this;
35
36
  }
36
37
  rotate(phi, about = new Point([0, 0])) {
37
- const dx = Calculator_1.Calculator.sub(this.x, about.x);
38
- const dy = Calculator_1.Calculator.sub(this.y, about.y);
38
+ const dx = calculator_1.Calculator.sub(this.x, about.x);
39
+ const dy = calculator_1.Calculator.sub(this.y, about.y);
39
40
  this._x = +dx.mul(phi.cos).sub(dy.mul(phi.sin)).add(about.x);
40
41
  this._y = +dy.mul(phi.cos).add(dx.mul(phi.sin)).add(about.y);
41
42
  return this;
42
43
  }
43
44
  translate(vector) {
44
45
  const { x, y } = this;
45
- this._x = +Calculator_1.Calculator.add(x, vector.dx);
46
- this._y = +Calculator_1.Calculator.add(y, vector.dy);
46
+ this._x = +calculator_1.Calculator.add(x, vector.dx);
47
+ this._y = +calculator_1.Calculator.add(y, vector.dy);
47
48
  return this;
48
49
  }
49
50
  }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./Point"), exports);
18
+ __exportStar(require("./Point.types"), exports);
@@ -1,17 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Vector = void 0;
4
- const Calculator_1 = require("../utilities/Calculator");
5
- const Angle_1 = require("./Angle");
4
+ const _abstracts_1 = require("..");
5
+ const calculator_1 = require("../../utilities/calculator");
6
6
  class Vector {
7
+ kind = 'vector';
7
8
  _dx;
8
9
  _dy;
9
10
  constructor(values) {
10
11
  const fromPoints = values.some((value) => typeof value !== 'number');
11
12
  if (fromPoints) {
12
13
  const [P1, P2] = values;
13
- this._dx = +Calculator_1.Calculator.sub(P2.x, P1.x);
14
- this._dy = +Calculator_1.Calculator.sub(P2.y, P1.y);
14
+ this._dx = +calculator_1.Calculator.sub(P2.x, P1.x);
15
+ this._dy = +calculator_1.Calculator.sub(P2.y, P1.y);
15
16
  return;
16
17
  }
17
18
  const [dx, dy] = values;
@@ -26,7 +27,7 @@ class Vector {
26
27
  }
27
28
  get magnitude() {
28
29
  const { dx, dy } = this;
29
- return +Calculator_1.Calculator.pow(dx, 2).add(Calculator_1.Calculator.pow(dy, 2)).sqrt();
30
+ return +calculator_1.Calculator.pow(dx, 2).add(calculator_1.Calculator.pow(dy, 2)).sqrt();
30
31
  }
31
32
  get values() {
32
33
  return [this.dx, this.dy];
@@ -35,10 +36,10 @@ class Vector {
35
36
  const dotProd = this.dotProduct(vector);
36
37
  const magV1 = this.magnitude;
37
38
  const magV2 = vector.magnitude;
38
- const magProd = Calculator_1.Calculator.mul(magV1, magV2);
39
- const cosAngle = Calculator_1.Calculator.div(dotProd, magProd);
39
+ const magProd = calculator_1.Calculator.mul(magV1, magV2);
40
+ const cosAngle = calculator_1.Calculator.div(dotProd, magProd);
40
41
  const angle = cosAngle.acos();
41
- return new Angle_1.Angle(+angle, 'radians');
42
+ return new _abstracts_1.Angle(+angle, 'radians');
42
43
  }
43
44
  clone() {
44
45
  const { dx, dy } = this;
@@ -46,11 +47,11 @@ class Vector {
46
47
  }
47
48
  dotProduct(vector) {
48
49
  const { dx, dy } = this;
49
- return +Calculator_1.Calculator.mul(dx, vector.dx).add(Calculator_1.Calculator.mul(dy, vector.dy));
50
+ return +calculator_1.Calculator.mul(dx, vector.dx).add(calculator_1.Calculator.mul(dy, vector.dy));
50
51
  }
51
52
  reflect({ x, y }) {
52
- this._dx = x ? +Calculator_1.Calculator.neg(this.dx) : this.dx;
53
- this._dy = y ? +Calculator_1.Calculator.neg(this.dy) : this.dy;
53
+ this._dx = x ? +calculator_1.Calculator.neg(this.dx) : this.dx;
54
+ this._dy = y ? +calculator_1.Calculator.neg(this.dy) : this.dy;
54
55
  return this;
55
56
  }
56
57
  replace(vector) {
@@ -60,14 +61,14 @@ class Vector {
60
61
  }
61
62
  rotate(phi) {
62
63
  const { dx, dy } = this;
63
- this._dx = +Calculator_1.Calculator.mul(phi.cos, dx).sub(Calculator_1.Calculator.mul(phi.sin, dy));
64
- this._dy = +Calculator_1.Calculator.mul(phi.sin, dx).add(Calculator_1.Calculator.mul(phi.cos, dy));
64
+ this._dx = +calculator_1.Calculator.mul(phi.cos, dx).sub(calculator_1.Calculator.mul(phi.sin, dy));
65
+ this._dy = +calculator_1.Calculator.mul(phi.sin, dx).add(calculator_1.Calculator.mul(phi.cos, dy));
65
66
  return this;
66
67
  }
67
68
  scale(factor) {
68
69
  const { dx, dy } = this;
69
- this._dx = +Calculator_1.Calculator.mul(dx, factor);
70
- this._dy = +Calculator_1.Calculator.mul(dy, factor);
70
+ this._dx = +calculator_1.Calculator.mul(dx, factor);
71
+ this._dy = +calculator_1.Calculator.mul(dy, factor);
71
72
  return this;
72
73
  }
73
74
  }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./Vector"), exports);
18
+ __exportStar(require("./Vector.types"), exports);
@@ -0,0 +1,174 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ArcCurve = void 0;
4
+ const _abstracts_1 = require("../../abstracts");
5
+ const CubicBezierCurve_1 = require("../cubic-bezier-curve/CubicBezierCurve");
6
+ const Ellipse_1 = require("../ellipse/Ellipse");
7
+ const calculator_1 = require("../../utilities/calculator");
8
+ class ArcCurve extends _abstracts_1.Figure {
9
+ ellipse;
10
+ largeArcFlag;
11
+ phi;
12
+ rx;
13
+ ry;
14
+ sweepFlag;
15
+ constructor(values) {
16
+ super(values);
17
+ const [, rx, ry, phi, largeArcFlag, sweepFlag] = values;
18
+ this.rx = rx;
19
+ this.ry = ry;
20
+ this.phi = phi;
21
+ this.largeArcFlag = largeArcFlag;
22
+ this.sweepFlag = sweepFlag;
23
+ this.adjustRadii();
24
+ const center = this.computeCenter();
25
+ this.ellipse = new Ellipse_1.Ellipse([center, rx, ry, phi]);
26
+ }
27
+ get boundingBox() {
28
+ const { P0, P1 } = this;
29
+ const points = [P0, P1, ...this.criticalPoints];
30
+ return _abstracts_1.Figure.computeBoundingBox(points);
31
+ }
32
+ get center() {
33
+ return this.ellipse.center;
34
+ }
35
+ get criticalPoints() {
36
+ const { ellipse } = this;
37
+ const [minTheta, maxTheta] = this.computeThetaRange();
38
+ return ellipse.criticalPoints.filter((point) => {
39
+ const { P0, P1 } = this;
40
+ if ((calculator_1.Calculator.isEqual(point.x, P0.x) && calculator_1.Calculator.isEqual(point.y, P0.y)) || (calculator_1.Calculator.isEqual(point.x, P1.x) && calculator_1.Calculator.isEqual(point.y, P1.y))) {
41
+ return false;
42
+ }
43
+ const theta = ellipse.computeThetaForPoint(point);
44
+ return +theta >= +minTheta && +theta <= +maxTheta;
45
+ });
46
+ }
47
+ get P0() {
48
+ return this.points[0];
49
+ }
50
+ get P1() {
51
+ if (this.isRelative) {
52
+ return this.P0.clone().translate(this.vectors[0]);
53
+ }
54
+ return this.points[1];
55
+ }
56
+ clone() {
57
+ const values = this.values.map((value) => (typeof value === 'object' && 'clone' in value ? value.clone() : /* v8 ignore next */ value));
58
+ return new ArcCurve(values);
59
+ }
60
+ reflect(about) {
61
+ super.reflect(about);
62
+ this.sweepFlag.invert();
63
+ return this;
64
+ }
65
+ toCubicBezierCurves() {
66
+ const [minTheta, maxTheta] = this.computeThetaRange();
67
+ const p0Theta = this.ellipse.computeThetaForPoint(this.P0);
68
+ const p0IsMin = calculator_1.Calculator.isEqual(+p0Theta.radians, +minTheta.radians);
69
+ const span = +calculator_1.Calculator.sub(maxTheta.radians, minTheta.radians);
70
+ const halfPi = Math.PI / 2;
71
+ const numSegments = Math.max(1, Math.ceil(span / halfPi));
72
+ const segmentAngle = span / numSegments;
73
+ const curves = [];
74
+ for (let i = 0; i < numSegments; i++) {
75
+ let t1Rad;
76
+ let t2Rad;
77
+ if (p0IsMin) {
78
+ t1Rad = +calculator_1.Calculator.add(minTheta.radians, calculator_1.Calculator.mul(segmentAngle, i));
79
+ t2Rad = +calculator_1.Calculator.add(minTheta.radians, calculator_1.Calculator.mul(segmentAngle, i + 1));
80
+ }
81
+ else {
82
+ t1Rad = +calculator_1.Calculator.sub(maxTheta.radians, calculator_1.Calculator.mul(segmentAngle, i));
83
+ t2Rad = +calculator_1.Calculator.sub(maxTheta.radians, calculator_1.Calculator.mul(segmentAngle, i + 1));
84
+ }
85
+ curves.push(this.computeBezierSegment(new _abstracts_1.Angle(t1Rad, 'radians'), new _abstracts_1.Angle(t2Rad, 'radians')));
86
+ }
87
+ return curves;
88
+ }
89
+ adjustRadii() {
90
+ const { rx, ry } = this;
91
+ const P0_prime = this.computeP0Prime();
92
+ const { x: x1_prime, y: y1_prime } = P0_prime;
93
+ const rx_sq = calculator_1.Calculator.pow(+rx, 2);
94
+ const ry_sq = calculator_1.Calculator.pow(+ry, 2);
95
+ const x1_prime_sq = calculator_1.Calculator.pow(x1_prime, 2);
96
+ const y1_prime_sq = calculator_1.Calculator.pow(y1_prime, 2);
97
+ const radii_check = x1_prime_sq.div(rx_sq).add(y1_prime_sq.div(ry_sq));
98
+ if (+radii_check > 1) {
99
+ rx.replace(+calculator_1.Calculator.mul(+rx, radii_check.sqrt()));
100
+ ry.replace(+calculator_1.Calculator.mul(+ry, radii_check.sqrt()));
101
+ }
102
+ }
103
+ computeBezierSegment(theta1, theta2) {
104
+ const { ellipse } = this;
105
+ const alpha = +calculator_1.Calculator.sub(theta2.radians, theta1.radians);
106
+ const k = +calculator_1.Calculator.mul(4, calculator_1.Calculator.tan(calculator_1.Calculator.div(alpha, 4))).div(3);
107
+ const p0 = ellipse.computePointForTheta(theta1);
108
+ const p3 = ellipse.computePointForTheta(theta2);
109
+ const [t1x, t1y] = this.computeTangentForTheta(theta1);
110
+ const [t2x, t2y] = this.computeTangentForTheta(theta2);
111
+ const p1 = new _abstracts_1.Point([+calculator_1.Calculator.add(p0.x, calculator_1.Calculator.mul(k, t1x)), +calculator_1.Calculator.add(p0.y, calculator_1.Calculator.mul(k, t1y))]);
112
+ const p2 = new _abstracts_1.Point([+calculator_1.Calculator.sub(p3.x, calculator_1.Calculator.mul(k, t2x)), +calculator_1.Calculator.sub(p3.y, calculator_1.Calculator.mul(k, t2y))]);
113
+ return new CubicBezierCurve_1.CubicBezierCurve([p0, p1, p2, p3]);
114
+ }
115
+ computeCenter() {
116
+ const { P0, P1, phi } = this;
117
+ const center_prime = this.computeCenterPrime();
118
+ const { x: x1, y: y1 } = P0;
119
+ const { x: x2, y: y2 } = P1;
120
+ const { x: cx_prime, y: cy_prime } = center_prime;
121
+ const dx = calculator_1.Calculator.add(x1, x2).div(2);
122
+ const dy = calculator_1.Calculator.add(y1, y2).div(2);
123
+ const cx = calculator_1.Calculator.mul(phi.cos, cx_prime).sub(calculator_1.Calculator.mul(phi.sin, cy_prime)).add(dx);
124
+ const cy = calculator_1.Calculator.mul(phi.sin, cx_prime).add(calculator_1.Calculator.mul(phi.cos, cy_prime)).add(dy);
125
+ return new _abstracts_1.Point([+cx, +cy]);
126
+ }
127
+ computeCenterPrime() {
128
+ const { largeArcFlag, sweepFlag, rx, ry } = this;
129
+ const P0_prime = this.computeP0Prime();
130
+ const { x: x1_prime, y: y1_prime } = P0_prime;
131
+ const rx_sq = calculator_1.Calculator.pow(+rx, 2);
132
+ const ry_sq = calculator_1.Calculator.pow(+ry, 2);
133
+ const x1_prime_sq = calculator_1.Calculator.pow(x1_prime, 2);
134
+ const y1_prime_sq = calculator_1.Calculator.pow(y1_prime, 2);
135
+ const sign = new calculator_1.Calculator(+largeArcFlag === +sweepFlag ? -1 : 1);
136
+ let sq = rx_sq
137
+ .mul(ry_sq)
138
+ .sub(rx_sq.mul(y1_prime_sq))
139
+ .sub(ry_sq.mul(x1_prime_sq))
140
+ .div(rx_sq.mul(y1_prime_sq).add(ry_sq.mul(x1_prime_sq)));
141
+ sq = +sq < 0 ? /* v8 ignore next */ new calculator_1.Calculator(0) : sq;
142
+ const coef = sign.mul(sq.sqrt());
143
+ const cx_prime = coef.mul(calculator_1.Calculator.mul(+rx, y1_prime).div(+ry));
144
+ const cy_prime = coef.mul(calculator_1.Calculator.mul(+ry, x1_prime).div(+rx).neg());
145
+ return new _abstracts_1.Point([+cx_prime, +cy_prime]);
146
+ }
147
+ computeP0Prime() {
148
+ const { P0, P1, phi } = this;
149
+ const { x: x1, y: y1 } = P0;
150
+ const { x: x2, y: y2 } = P1;
151
+ const mx = calculator_1.Calculator.sub(x1, x2).div(2);
152
+ const my = calculator_1.Calculator.sub(y1, y2).div(2);
153
+ const x1_prime = calculator_1.Calculator.mul(phi.cos, mx).add(calculator_1.Calculator.mul(phi.sin, my));
154
+ const y1_prime = calculator_1.Calculator.mul(phi.sin, mx).neg().add(calculator_1.Calculator.mul(phi.cos, my));
155
+ return new _abstracts_1.Point([+x1_prime, +y1_prime]);
156
+ }
157
+ computeTangentForTheta(theta) {
158
+ const { phi, rx, ry } = this.ellipse;
159
+ const tx = +calculator_1.Calculator.neg(calculator_1.Calculator.mul(+rx, theta.sin).mul(phi.cos)).sub(calculator_1.Calculator.mul(+ry, theta.cos).mul(phi.sin));
160
+ const ty = +calculator_1.Calculator.neg(calculator_1.Calculator.mul(+rx, theta.sin).mul(phi.sin)).add(calculator_1.Calculator.mul(+ry, theta.cos).mul(phi.cos));
161
+ return [tx, ty];
162
+ }
163
+ computeThetaRange() {
164
+ const { P0, P1, ellipse, sweepFlag } = this;
165
+ const theta1 = ellipse.computeThetaForPoint(P0);
166
+ const theta2 = ellipse.computeThetaForPoint(P1);
167
+ if (calculator_1.Calculator.isNearZero(+theta2) && !sweepFlag.value) {
168
+ theta2.replace(360, 'degrees');
169
+ }
170
+ const thetaRange = [theta1, theta2].sort((a, b) => +calculator_1.Calculator.sub(a.radians, b.radians));
171
+ return thetaRange;
172
+ }
173
+ }
174
+ exports.ArcCurve = ArcCurve;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./ArcCurve"), exports);
18
+ __exportStar(require("./ArcCurve.types"), exports);
@@ -1,15 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Circle = void 0;
4
- const Calculator_1 = require("../utilities/Calculator");
5
- const Ellipse_1 = require("./Ellipse");
6
- const Point_1 = require("../abstracts/Point");
7
- const Angle_1 = require("../abstracts/Angle");
4
+ const _abstracts_1 = require("../../abstracts");
5
+ const Ellipse_1 = require("../ellipse/Ellipse");
6
+ const calculator_1 = require("../../utilities/calculator");
8
7
  class Circle extends Ellipse_1.Ellipse {
9
8
  _radius;
10
9
  constructor(values) {
11
10
  const [center, radius] = values;
12
- const phi = new Angle_1.Angle(0, 'radians'); // Always 0 since circles don't change with rotation.
11
+ const phi = new _abstracts_1.Angle(0, 'radians'); // Always 0 since circles don't change with rotation.
13
12
  super([center, radius, radius.clone(), phi]);
14
13
  this._radius = radius;
15
14
  }
@@ -33,10 +32,10 @@ class Circle extends Ellipse_1.Ellipse {
33
32
  computeCriticalPoints(ellipse = this) {
34
33
  const { center, rx } = ellipse;
35
34
  const radius = rx;
36
- const first = new Point_1.Point([center.x, +Calculator_1.Calculator.add(center.y, +radius)]);
37
- const second = new Point_1.Point([+Calculator_1.Calculator.add(center.x, +radius), center.y]);
38
- const third = new Point_1.Point([center.x, +Calculator_1.Calculator.sub(center.y, +radius)]);
39
- const fourth = new Point_1.Point([+Calculator_1.Calculator.sub(center.x, +radius), center.y]);
35
+ const first = new _abstracts_1.Point([center.x, +calculator_1.Calculator.add(center.y, +radius)]);
36
+ const second = new _abstracts_1.Point([+calculator_1.Calculator.add(center.x, +radius), center.y]);
37
+ const third = new _abstracts_1.Point([center.x, +calculator_1.Calculator.sub(center.y, +radius)]);
38
+ const fourth = new _abstracts_1.Point([+calculator_1.Calculator.sub(center.x, +radius), center.y]);
40
39
  return [first, second, third, fourth];
41
40
  }
42
41
  }