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.
- package/README.md +49 -23
- package/dist/cjs/abstracts/{Angle.js → angle/Angle.js} +11 -11
- package/dist/cjs/abstracts/angle/Angle.types.js +2 -0
- package/dist/cjs/abstracts/angle/index.js +18 -0
- package/dist/cjs/abstracts/{Figure.js → figure/Figure.js} +45 -30
- package/dist/cjs/abstracts/figure/Figure.types.js +2 -0
- package/dist/cjs/abstracts/figure/index.js +18 -0
- package/dist/cjs/abstracts/{Flag.js → flag/Flag.js} +1 -0
- package/dist/cjs/abstracts/flag/Flag.types.js +2 -0
- package/dist/cjs/abstracts/flag/index.js +18 -0
- package/dist/cjs/abstracts/index.js +22 -0
- package/dist/cjs/abstracts/{Magnitude.js → magnitude/Magnitude.js} +6 -2
- package/dist/cjs/abstracts/magnitude/Magnitude.types.js +2 -0
- package/dist/cjs/abstracts/magnitude/index.js +18 -0
- package/dist/cjs/abstracts/{Point.js → point/Point.js} +8 -7
- package/dist/cjs/abstracts/point/Point.types.js +2 -0
- package/dist/cjs/abstracts/point/index.js +18 -0
- package/dist/cjs/abstracts/{Vector.js → vector/Vector.js} +16 -15
- package/dist/cjs/abstracts/vector/Vector.types.js +2 -0
- package/dist/cjs/abstracts/vector/index.js +18 -0
- package/dist/cjs/figures/arc-curve/ArcCurve.js +174 -0
- package/dist/cjs/figures/arc-curve/ArcCurve.types.js +2 -0
- package/dist/cjs/figures/arc-curve/index.js +18 -0
- package/dist/cjs/figures/{Circle.js → circle/Circle.js} +8 -9
- package/dist/cjs/figures/circle/Circle.types.js +2 -0
- package/dist/cjs/figures/circle/index.js +18 -0
- package/dist/cjs/figures/{CubicBezierCurve.js → cubic-bezier-curve/CubicBezierCurve.js} +22 -17
- package/dist/cjs/figures/cubic-bezier-curve/CubicBezierCurve.types.js +2 -0
- package/dist/cjs/figures/cubic-bezier-curve/index.js +18 -0
- package/dist/cjs/figures/ellipse/Ellipse.js +129 -0
- package/dist/cjs/figures/ellipse/Ellipse.types.js +2 -0
- package/dist/cjs/figures/ellipse/index.js +18 -0
- package/dist/cjs/figures/index.js +23 -0
- package/dist/cjs/figures/{Line.js → line/Line.js} +78 -59
- package/dist/cjs/figures/line/Line.types.js +2 -0
- package/dist/cjs/figures/line/index.js +18 -0
- package/dist/cjs/figures/polygon/Polygon.js +51 -0
- package/dist/cjs/figures/polygon/Polygon.types.js +2 -0
- package/dist/cjs/figures/polygon/index.js +18 -0
- package/dist/cjs/figures/{QuadraticBezierCurve.js → quadratic-bezier-curve/QuadraticBezierCurve.js} +12 -8
- package/dist/cjs/figures/quadratic-bezier-curve/QuadraticBezierCurve.types.js +2 -0
- package/dist/cjs/figures/quadratic-bezier-curve/index.js +18 -0
- package/dist/cjs/index.js +2 -29
- package/dist/cjs/utilities/{Calculator.js → calculator/Calculator.js} +9 -1
- package/dist/cjs/utilities/calculator/index.js +17 -0
- package/dist/cjs/utilities/index.js +20 -8
- package/dist/esm/abstracts/{Angle.js → angle/Angle.js} +4 -4
- package/dist/esm/abstracts/angle/Angle.types.js +1 -0
- package/dist/esm/abstracts/angle/index.js +2 -0
- package/dist/esm/abstracts/{Figure.js → figure/Figure.js} +37 -22
- package/dist/esm/abstracts/figure/Figure.types.js +1 -0
- package/dist/esm/abstracts/figure/index.js +2 -0
- package/dist/esm/abstracts/{Flag.js → flag/Flag.js} +1 -0
- package/dist/esm/abstracts/flag/Flag.types.js +1 -0
- package/dist/esm/abstracts/flag/index.js +2 -0
- package/dist/esm/abstracts/index.js +6 -0
- package/dist/esm/abstracts/{Magnitude.js → magnitude/Magnitude.js} +5 -1
- package/dist/esm/abstracts/magnitude/Magnitude.types.js +1 -0
- package/dist/esm/abstracts/magnitude/index.js +2 -0
- package/dist/esm/abstracts/{Point.js → point/Point.js} +2 -1
- package/dist/esm/abstracts/point/Point.types.js +1 -0
- package/dist/esm/abstracts/point/index.js +2 -0
- package/dist/esm/abstracts/{Vector.js → vector/Vector.js} +3 -2
- package/dist/esm/abstracts/vector/Vector.types.js +1 -0
- package/dist/esm/abstracts/vector/index.js +2 -0
- package/dist/esm/figures/{ArcCurve.js → arc-curve/ArcCurve.js} +50 -8
- package/dist/esm/figures/arc-curve/ArcCurve.types.js +1 -0
- package/dist/esm/figures/arc-curve/index.js +2 -0
- package/dist/esm/figures/{Circle.js → circle/Circle.js} +3 -4
- package/dist/esm/figures/circle/Circle.types.js +1 -0
- package/dist/esm/figures/circle/index.js +2 -0
- package/dist/esm/figures/{CubicBezierCurve.js → cubic-bezier-curve/CubicBezierCurve.js} +11 -6
- package/dist/esm/figures/cubic-bezier-curve/CubicBezierCurve.types.js +1 -0
- package/dist/esm/figures/cubic-bezier-curve/index.js +2 -0
- package/dist/esm/figures/{Ellipse.js → ellipse/Ellipse.js} +24 -6
- package/dist/esm/figures/ellipse/Ellipse.types.js +1 -0
- package/dist/esm/figures/ellipse/index.js +2 -0
- package/dist/esm/figures/index.js +7 -0
- package/dist/esm/figures/{Line.js → line/Line.js} +57 -38
- package/dist/esm/figures/line/Line.types.js +1 -0
- package/dist/esm/figures/line/index.js +2 -0
- package/dist/esm/figures/polygon/Polygon.js +47 -0
- package/dist/esm/figures/polygon/Polygon.types.js +1 -0
- package/dist/esm/figures/polygon/index.js +2 -0
- package/dist/esm/figures/{QuadraticBezierCurve.js → quadratic-bezier-curve/QuadraticBezierCurve.js} +7 -3
- package/dist/esm/figures/quadratic-bezier-curve/QuadraticBezierCurve.types.js +1 -0
- package/dist/esm/figures/quadratic-bezier-curve/index.js +2 -0
- package/dist/esm/index.js +2 -14
- package/dist/esm/utilities/{Calculator.js → calculator/Calculator.js} +9 -1
- package/dist/esm/utilities/calculator/index.js +1 -0
- package/dist/esm/utilities/index.js +4 -6
- package/dist/types/abstracts/{Angle.d.ts → angle/Angle.d.ts} +2 -1
- package/dist/types/abstracts/angle/Angle.types.d.ts +16 -0
- package/dist/types/abstracts/angle/index.d.ts +2 -0
- package/dist/types/abstracts/{Figure.d.ts → figure/Figure.d.ts} +4 -4
- package/dist/types/abstracts/figure/Figure.types.d.ts +14 -0
- package/dist/types/abstracts/figure/index.d.ts +2 -0
- package/dist/types/abstracts/{Flag.d.ts → flag/Flag.d.ts} +2 -1
- package/dist/types/abstracts/flag/Flag.types.d.ts +8 -0
- package/dist/types/abstracts/flag/index.d.ts +2 -0
- package/dist/types/abstracts/index.d.ts +6 -0
- package/dist/types/abstracts/{Magnitude.d.ts → magnitude/Magnitude.d.ts} +3 -1
- package/dist/types/abstracts/magnitude/Magnitude.types.d.ts +8 -0
- package/dist/types/abstracts/magnitude/index.d.ts +2 -0
- package/dist/types/abstracts/{Point.d.ts → point/Point.d.ts} +2 -1
- package/dist/types/abstracts/point/Point.types.d.ts +13 -0
- package/dist/types/abstracts/point/index.d.ts +2 -0
- package/dist/types/abstracts/{Vector.d.ts → vector/Vector.d.ts} +3 -1
- package/dist/types/abstracts/vector/Vector.types.d.ts +19 -0
- package/dist/types/abstracts/vector/index.d.ts +2 -0
- package/dist/types/figures/{ArcCurve.d.ts → arc-curve/ArcCurve.d.ts} +7 -2
- package/dist/types/figures/arc-curve/ArcCurve.types.d.ts +11 -0
- package/dist/types/figures/arc-curve/index.d.ts +2 -0
- package/dist/types/figures/{Circle.d.ts → circle/Circle.d.ts} +3 -2
- package/dist/types/figures/circle/Circle.types.d.ts +9 -0
- package/dist/types/figures/circle/index.d.ts +2 -0
- package/dist/types/figures/{CubicBezierCurve.d.ts → cubic-bezier-curve/CubicBezierCurve.d.ts} +4 -2
- package/dist/types/figures/cubic-bezier-curve/CubicBezierCurve.types.d.ts +8 -0
- package/dist/types/figures/cubic-bezier-curve/index.d.ts +2 -0
- package/dist/types/figures/{Ellipse.d.ts → ellipse/Ellipse.d.ts} +5 -2
- package/dist/types/figures/ellipse/Ellipse.types.d.ts +16 -0
- package/dist/types/figures/ellipse/index.d.ts +2 -0
- package/dist/types/figures/index.d.ts +7 -0
- package/dist/types/figures/{Line.d.ts → line/Line.d.ts} +6 -4
- package/dist/types/figures/line/Line.types.d.ts +30 -0
- package/dist/types/figures/line/index.d.ts +2 -0
- package/dist/types/figures/polygon/Polygon.d.ts +17 -0
- package/dist/types/figures/polygon/Polygon.types.d.ts +8 -0
- package/dist/types/figures/polygon/index.d.ts +2 -0
- package/dist/types/figures/{QuadraticBezierCurve.d.ts → quadratic-bezier-curve/QuadraticBezierCurve.d.ts} +4 -2
- package/dist/types/figures/quadratic-bezier-curve/QuadraticBezierCurve.types.d.ts +8 -0
- package/dist/types/figures/quadratic-bezier-curve/index.d.ts +2 -0
- package/dist/types/index.d.ts +2 -14
- package/dist/types/types/index.d.ts +0 -129
- package/dist/types/utilities/{Calculator.d.ts → calculator/Calculator.d.ts} +4 -0
- package/dist/types/utilities/calculator/index.d.ts +1 -0
- package/dist/types/utilities/index.d.ts +2 -4
- package/package.json +24 -18
- package/dist/cjs/figures/ArcCurve.js +0 -132
- package/dist/cjs/figures/Ellipse.js +0 -111
- package/dist/cjs/figures/Polygon.js +0 -17
- package/dist/esm/figures/Polygon.js +0 -13
- 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
|
|
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
|
-
##
|
|
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
|
-
|
|
20
|
+
## Importing (ESM)
|
|
23
21
|
|
|
24
|
-
|
|
22
|
+
```javascript
|
|
23
|
+
import { Point, Line, Vector, Angle } from 'geometric-library';
|
|
24
|
+
```
|
|
25
25
|
|
|
26
|
-
##
|
|
26
|
+
## Importing (CommonJS)
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
```javascript
|
|
29
|
+
const { Point, Line, Vector, Angle } = require('geometric-library');
|
|
30
|
+
```
|
|
29
31
|
|
|
30
|
-
|
|
32
|
+
## TypeScript Types
|
|
31
33
|
|
|
32
|
-
|
|
34
|
+
If you're using TypeScript, you can import types and interfaces for all exported functionalities:
|
|
33
35
|
|
|
34
|
-
|
|
36
|
+
```typescript
|
|
37
|
+
import { IPoint, TPointValues, ILine, TLineValues } from 'geometric-library';
|
|
38
|
+
```
|
|
35
39
|
|
|
36
|
-
|
|
40
|
+
This is recommended as it will help you understand how everything works and provides full type safety.
|
|
37
41
|
|
|
38
|
-
|
|
42
|
+
## Quick Example
|
|
39
43
|
|
|
40
|
-
|
|
44
|
+
```typescript
|
|
45
|
+
import { Point, Vector, Line, Angle } from 'geometric-library';
|
|
41
46
|
|
|
42
|
-
|
|
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
|
-
|
|
64
|
+
### Decimal.js
|
|
45
65
|
|
|
46
|
-
This
|
|
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
|
-
|
|
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
|
-
|
|
70
|
+
## Documentation
|
|
51
71
|
|
|
52
|
-
|
|
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
|
-
##
|
|
80
|
+
## References
|
|
55
81
|
|
|
56
|
-
-
|
|
57
|
-
-
|
|
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
|
|
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 +
|
|
12
|
+
return +calculator_1.Calculator.cos(this.radians);
|
|
13
13
|
}
|
|
14
14
|
get cot() {
|
|
15
|
-
return +
|
|
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 +
|
|
24
|
+
return +calculator_1.Calculator.sin(this.radians);
|
|
25
25
|
}
|
|
26
26
|
get tan() {
|
|
27
|
-
return +
|
|
27
|
+
return +calculator_1.Calculator.tan(this.radians);
|
|
28
28
|
}
|
|
29
29
|
static toDegrees(radians) {
|
|
30
|
-
return +
|
|
30
|
+
return +calculator_1.Calculator.mul(radians, 180).div(Math.PI);
|
|
31
31
|
}
|
|
32
32
|
static toRadians(degrees) {
|
|
33
|
-
return +
|
|
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 = +
|
|
41
|
+
this._radians = +calculator_1.Calculator.add(radians, calculator_1.Calculator.PI2);
|
|
42
42
|
}
|
|
43
43
|
else if (radians > 0) {
|
|
44
|
-
this._radians = +
|
|
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 = +
|
|
53
|
+
this._radians = +calculator_1.Calculator.mul(this.radians, factor);
|
|
54
54
|
return this;
|
|
55
55
|
}
|
|
56
56
|
valueOf() {
|
|
@@ -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
|
|
5
|
-
const
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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 = +
|
|
61
|
-
const xMin = +
|
|
62
|
-
const yMax = +
|
|
63
|
-
const yMin = +
|
|
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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
|
109
|
+
const rotatedVector = new _abstracts_1.Vector([referencePoint, positionalPoint]);
|
|
110
110
|
vector.replace(rotatedVector);
|
|
111
111
|
});
|
|
112
112
|
angles.forEach((angle) => {
|
|
113
|
-
angle.replace(+
|
|
113
|
+
angle.replace(+calculator_1.Calculator.add(+angle, +phi), 'radians').normalize();
|
|
114
114
|
});
|
|
115
115
|
return this;
|
|
116
116
|
}
|
|
117
|
-
scale(factor, about = new
|
|
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
|
|
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,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);
|
|
@@ -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
|
|
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 = +
|
|
22
|
+
this._value = +calculator_1.Calculator.mul(+this, factor);
|
|
19
23
|
return this;
|
|
20
24
|
}
|
|
21
25
|
valueOf() {
|
|
@@ -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
|
|
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 = +
|
|
28
|
-
this._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 =
|
|
38
|
-
const dy =
|
|
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 = +
|
|
46
|
-
this._y = +
|
|
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,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
|
|
5
|
-
const
|
|
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 = +
|
|
14
|
-
this._dy = +
|
|
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 +
|
|
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 =
|
|
39
|
-
const cosAngle =
|
|
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
|
|
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 +
|
|
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 ? +
|
|
53
|
-
this._dy = y ? +
|
|
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 = +
|
|
64
|
-
this._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 = +
|
|
70
|
-
this._dy = +
|
|
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,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);
|