geometric-library 1.3.0 → 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 +49 -23
  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} +6 -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} +5 -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} +3 -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
package/README.md CHANGED
@@ -4,57 +4,83 @@ A Node based, visually agnostic implementation of geometric functions, both abst
4
4
 
5
5
  ## Prerequisites
6
6
 
7
- This library assumes you already have basic knowledge of concepts pertaining to algebra and geometry, including:
7
+ This library assumes you already have basic knowledge of geometric concepts, including:
8
8
 
9
9
  - **Abstracts**: magnitude, direction, position, coordinate, vector, point, figure, angle
10
10
  - **Figures**: line, curve, ellipse, polygon
11
11
  - **Transformations**: rotation, translation, reflection, scaling
12
12
  - **Units**: radian, degree
13
13
 
14
- ## Usage
15
-
16
- You may install this library into your JavaScript or TypeScript project using the following command:
14
+ ## Installation
17
15
 
18
16
  ```sh
19
17
  npm install geometric-library
20
18
  ```
21
19
 
22
- You may then `import` any of the classes listed in the **API** section and use them at your own discretion.
20
+ ## Importing (ESM)
23
21
 
24
- If you're using TypeScript for your project you can also `import` types and interfaces for all the exported functionalities, which is very much recommended as it will make your life easier in terms of understading how everything works.
22
+ ```javascript
23
+ import { Point, Line, Vector, Angle } from 'geometric-library';
24
+ ```
25
25
 
26
- ## API
26
+ ## Importing (CommonJS)
27
27
 
28
- The types and interfaces exported from [./src/types/index.ts](./src/types/index.ts) should give you a pretty good idea of how to use any of the functionalities included in this library.
28
+ ```javascript
29
+ const { Point, Line, Vector, Angle } = require('geometric-library');
30
+ ```
29
31
 
30
- The following classes are available:
32
+ ## TypeScript Types
31
33
 
32
- (Abstracts) `Flag` `Magnitude` `Angle` `Vector` `Point` `Figure`
34
+ If you're using TypeScript, you can import types and interfaces for all exported functionalities:
33
35
 
34
- (Figures) `Line` `Polygon` `QuadraticBezierCurve` `CubicBezierCurve` `ArcCurve` `Ellipse` `Circle`
36
+ ```typescript
37
+ import { IPoint, TPointValues, ILine, TLineValues } from 'geometric-library';
38
+ ```
35
39
 
36
- ## Dependencies
40
+ This is recommended as it will help you understand how everything works and provides full type safety.
37
41
 
38
- JavaScript is bad at math. Don't hate me for saying it, it's actually a pretty well known fact that JavaScript just struggles with algebra, especially when it involves floating point numbers. Here's one of the many articles about it if you want to learn more: [Why JavaScript is Bad At Math](https://javascript.plainenglish.io/why-javascript-is-bad-at-math-9b8247640caa) (by Alexandra Langton).
42
+ ## Quick Example
39
43
 
40
- Though there are ways to combat these issues natively, for this library I chose to use an abstraction of [Decimal.js](https://mikemcl.github.io/decimal.js/), which does just that pretty efficiently.
44
+ ```typescript
45
+ import { Point, Vector, Line, Angle } from 'geometric-library';
41
46
 
42
- As it is an intrinsic dependency so you don't have to install anything yourself.
47
+ // Create two points and a line between them
48
+ const pointA = new Point([0, 0]);
49
+ const pointB = new Point([5, 5]);
50
+ const line = new Line([pointA, pointB]);
51
+
52
+ // Check line properties
53
+ console.log(line.slope); // 1
54
+ console.log(line.yIntercept); // 0
55
+
56
+ // Transform with chaining
57
+ const vector = new Vector([2, 3]);
58
+ const angle = new Angle(90, 'degrees');
59
+ pointA.translate(vector).rotate(angle);
60
+ ```
61
+
62
+ ## Dependencies
43
63
 
44
- ## Contributing
64
+ ### Decimal.js
45
65
 
46
- This project is open to contribution.
66
+ JavaScript has well-documented issues with floating-point arithmetic. This library uses [Decimal.js](https://mikemcl.github.io/decimal.js/) under the hood (via the `Calculator` utility class) to handle precision correctly.
47
67
 
48
- If you have a bug to report please open an issue so it can be tracked and addressed as soon as possible. Do include information about how to reproduce the bug, the expected result and the actual result.
68
+ You do **not** need to install Decimal.js separately - it is included as a dependency of this library. All math operations are routed through `Calculator`, which applies epsilon-based rounding (1e-8) to eliminate floating-point artifacts.
49
69
 
50
- If there's a missing feature feel free to open an issue as well detailing the feature request and its value to the project and its users.
70
+ ## Documentation
51
71
 
52
- If you already have an idea of how to fix an issue or implement a feature, please also feel free to directly contribute by opening a pull request with the changes. Though the project includes some automated scripts for linting, cleaning, building, testing and deploying the code, please do try to adhere to the existing standards in terms of naming, directory structure and SOLID principles.
72
+ - **API Reference**
73
+ - [Abstracts](./docs/api/abstracts.md) - Flag, Angle, Magnitude, Vector, Point, Figure
74
+ - [Figures](./docs/api/figures.md) - Line, Polygon, Ellipse, Circle, QuadraticBezierCurve, CubicBezierCurve, ArcCurve
75
+ - [Utilities](./docs/api/utilities.md) - Calculator, coordinateOrigin, xAxis, yAxis, PI2
76
+ - [Types](./docs/api/types.md) - All interfaces and type definitions
77
+ - **[Architecture](./docs/architecture.md)** - Design decisions, patterns, class hierarchy
78
+ - **[Contributing](./docs/contributing.md)** - Bug reports, PRs, coding standards
53
79
 
54
- ## TO DO
80
+ ## References
55
81
 
56
- - Add a complete documentation of all the functionalities made available.
57
- - Add examples.
82
+ - [Intro to Bezier curves](https://iquilezles.org/articles/bezierbbox) by [Inigo Quilez](https://iquilezles.org/).
83
+ - [Arc Implementation Notes](https://www.w3.org/TR/SVG/implnote.html#ArcImplementationNotes) from the [SVG 2 Specification](https://www.w3.org/TR/SVG).
58
84
 
59
85
  ## License
60
86
 
@@ -1,18 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Angle = void 0;
4
- const Calculator_1 = require("../utilities/Calculator");
5
- const PI2 = +Calculator_1.Calculator.mul(Math.PI, 2);
4
+ const calculator_1 = require("../../utilities/calculator");
6
5
  class Angle {
6
+ kind = 'angle';
7
7
  _radians;
8
8
  constructor(value, unit) {
9
9
  this._radians = unit === 'radians' ? value : Angle.toRadians(value);
10
10
  }
11
11
  get cos() {
12
- return +Calculator_1.Calculator.cos(this.radians);
12
+ return +calculator_1.Calculator.cos(this.radians);
13
13
  }
14
14
  get cot() {
15
- return +Calculator_1.Calculator.div(1, this.tan);
15
+ return +calculator_1.Calculator.div(1, this.tan);
16
16
  }
17
17
  get degrees() {
18
18
  return Angle.toDegrees(this.radians);
@@ -21,16 +21,16 @@ class Angle {
21
21
  return this._radians;
22
22
  }
23
23
  get sin() {
24
- return +Calculator_1.Calculator.sin(this.radians);
24
+ return +calculator_1.Calculator.sin(this.radians);
25
25
  }
26
26
  get tan() {
27
- return +Calculator_1.Calculator.tan(this.radians);
27
+ return +calculator_1.Calculator.tan(this.radians);
28
28
  }
29
29
  static toDegrees(radians) {
30
- return +Calculator_1.Calculator.mul(radians, 180).div(Math.PI);
30
+ return +calculator_1.Calculator.mul(radians, 180).div(Math.PI);
31
31
  }
32
32
  static toRadians(degrees) {
33
- return +Calculator_1.Calculator.mul(degrees, Math.PI).div(180);
33
+ return +calculator_1.Calculator.mul(degrees, Math.PI).div(180);
34
34
  }
35
35
  clone() {
36
36
  return new Angle(this.radians, 'radians');
@@ -38,10 +38,10 @@ class Angle {
38
38
  normalize() {
39
39
  const { radians } = this;
40
40
  if (radians < 0) {
41
- this._radians = +Calculator_1.Calculator.add(radians, PI2);
41
+ this._radians = +calculator_1.Calculator.add(radians, calculator_1.Calculator.PI2);
42
42
  }
43
43
  else if (radians > 0) {
44
- this._radians = +Calculator_1.Calculator.mod(radians, PI2);
44
+ this._radians = +calculator_1.Calculator.mod(radians, calculator_1.Calculator.PI2);
45
45
  }
46
46
  return this;
47
47
  }
@@ -50,7 +50,7 @@ class Angle {
50
50
  return this;
51
51
  }
52
52
  scale(factor) {
53
- this._radians = +Calculator_1.Calculator.mul(this.radians, factor);
53
+ this._radians = +calculator_1.Calculator.mul(this.radians, factor);
54
54
  return this;
55
55
  }
56
56
  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("./Angle"), exports);
18
+ __exportStar(require("./Angle.types"), exports);
@@ -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,12 +1,16 @@
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;
9
10
  }
11
+ get value() {
12
+ return this._value;
13
+ }
10
14
  clone() {
11
15
  return new Magnitude(+this);
12
16
  }
@@ -15,7 +19,7 @@ class Magnitude {
15
19
  return this;
16
20
  }
17
21
  scale(factor) {
18
- this._value = +Calculator_1.Calculator.mul(+this, factor);
22
+ this._value = +calculator_1.Calculator.mul(+this, factor);
19
23
  return this;
20
24
  }
21
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);