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.
- package/README.md +39 -430
- 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} +3 -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} +2 -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} +2 -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
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Polygon = void 0;
|
|
4
|
+
const _abstracts_1 = require("../../abstracts");
|
|
5
|
+
const Line_1 = require("../line/Line");
|
|
6
|
+
class Polygon extends _abstracts_1.Figure {
|
|
7
|
+
_lines;
|
|
8
|
+
constructor(values) {
|
|
9
|
+
super(values);
|
|
10
|
+
this._lines = this.computeLines();
|
|
11
|
+
}
|
|
12
|
+
get lines() {
|
|
13
|
+
return this._lines;
|
|
14
|
+
}
|
|
15
|
+
get sides() {
|
|
16
|
+
return this.points.length;
|
|
17
|
+
}
|
|
18
|
+
clone() {
|
|
19
|
+
const values = this.values.map((value) => value.clone());
|
|
20
|
+
return new Polygon(values);
|
|
21
|
+
}
|
|
22
|
+
reflect(about) {
|
|
23
|
+
super.reflect(about);
|
|
24
|
+
this._lines = this.computeLines();
|
|
25
|
+
return this;
|
|
26
|
+
}
|
|
27
|
+
rotate(phi, about) {
|
|
28
|
+
super.rotate(phi, about);
|
|
29
|
+
this._lines = this.computeLines();
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
32
|
+
scale(factor, about) {
|
|
33
|
+
super.scale(factor, about);
|
|
34
|
+
this._lines = this.computeLines();
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
37
|
+
scaleXY(factorX, factorY, about) {
|
|
38
|
+
super.scaleXY(factorX, factorY, about);
|
|
39
|
+
this._lines = this.computeLines();
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
translate(vector) {
|
|
43
|
+
super.translate(vector);
|
|
44
|
+
this._lines = this.computeLines();
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
computeLines() {
|
|
48
|
+
return this.points.map((point, i) => new Line_1.Line([point, this.points[(i + 1) % this.points.length]]));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.Polygon = Polygon;
|
|
@@ -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("./Polygon"), exports);
|
|
18
|
+
__exportStar(require("./Polygon.types"), exports);
|
package/dist/cjs/figures/{QuadraticBezierCurve.js → quadratic-bezier-curve/QuadraticBezierCurve.js}
RENAMED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.QuadraticBezierCurve = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
class QuadraticBezierCurve extends Figure_1.Figure {
|
|
4
|
+
const _abstracts_1 = require("../../abstracts");
|
|
5
|
+
const calculator_1 = require("../../utilities/calculator");
|
|
6
|
+
class QuadraticBezierCurve extends _abstracts_1.Figure {
|
|
8
7
|
_criticalPoints;
|
|
9
8
|
constructor(values) {
|
|
10
9
|
super(values);
|
|
@@ -13,7 +12,7 @@ class QuadraticBezierCurve extends Figure_1.Figure {
|
|
|
13
12
|
get boundingBox() {
|
|
14
13
|
const [P0, , P2] = this.values;
|
|
15
14
|
const points = [P0, P2, ...this._criticalPoints];
|
|
16
|
-
return
|
|
15
|
+
return _abstracts_1.Figure.computeBoundingBox(points);
|
|
17
16
|
}
|
|
18
17
|
get criticalPoints() {
|
|
19
18
|
return this._criticalPoints;
|
|
@@ -55,6 +54,11 @@ class QuadraticBezierCurve extends Figure_1.Figure {
|
|
|
55
54
|
this.recompute();
|
|
56
55
|
return this;
|
|
57
56
|
}
|
|
57
|
+
scaleXY(factorX, factorY, about) {
|
|
58
|
+
super.scaleXY(factorX, factorY, about);
|
|
59
|
+
this.recompute();
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
58
62
|
translate(vector) {
|
|
59
63
|
super.translate(vector);
|
|
60
64
|
this.recompute();
|
|
@@ -73,7 +77,7 @@ class QuadraticBezierCurve extends Figure_1.Figure {
|
|
|
73
77
|
}
|
|
74
78
|
getCoordinateAtParameter(t, axis) {
|
|
75
79
|
const { P0, P1, P2 } = this;
|
|
76
|
-
const coordinate =
|
|
80
|
+
const coordinate = calculator_1.Calculator.sub(1, t).pow(2).mul(P0[axis]).add(calculator_1.Calculator.sub(1, t).mul(2).mul(t).mul(P1[axis])).add(t.pow(2).mul(P2[axis]));
|
|
77
81
|
if (coordinate.isFinite()) {
|
|
78
82
|
return coordinate;
|
|
79
83
|
}
|
|
@@ -84,7 +88,7 @@ class QuadraticBezierCurve extends Figure_1.Figure {
|
|
|
84
88
|
let value;
|
|
85
89
|
for (let i = 0; i < axii.length; i++) {
|
|
86
90
|
const axis = axii[i];
|
|
87
|
-
const potentialValue =
|
|
91
|
+
const potentialValue = calculator_1.Calculator.sub(P0[axis], P1[axis]).div(calculator_1.Calculator.sub(P0[axis], calculator_1.Calculator.mul(P1[axis], 2)).add(P2[axis]));
|
|
88
92
|
if (+potentialValue > 0 && +potentialValue < 1) {
|
|
89
93
|
value = potentialValue;
|
|
90
94
|
break;
|
|
@@ -98,7 +102,7 @@ class QuadraticBezierCurve extends Figure_1.Figure {
|
|
|
98
102
|
if (typeof x === 'undefined' || typeof y === 'undefined') {
|
|
99
103
|
return;
|
|
100
104
|
}
|
|
101
|
-
return new
|
|
105
|
+
return new _abstracts_1.Point([+x, +y]);
|
|
102
106
|
}
|
|
103
107
|
}
|
|
104
108
|
exports.QuadraticBezierCurve = QuadraticBezierCurve;
|
|
@@ -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("./QuadraticBezierCurve"), exports);
|
|
18
|
+
__exportStar(require("./QuadraticBezierCurve.types"), exports);
|
package/dist/cjs/index.js
CHANGED
|
@@ -14,35 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.Calculator = exports.QuadraticBezierCurve = exports.Polygon = exports.Line = exports.Ellipse = exports.CubicBezierCurve = exports.Circle = exports.ArcCurve = exports.Vector = exports.Point = exports.Magnitude = exports.Flag = exports.Figure = exports.Angle = void 0;
|
|
18
17
|
/* v8 ignore */
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
var Figure_1 = require("./abstracts/Figure");
|
|
22
|
-
Object.defineProperty(exports, "Figure", { enumerable: true, get: function () { return Figure_1.Figure; } });
|
|
23
|
-
var Flag_1 = require("./abstracts/Flag");
|
|
24
|
-
Object.defineProperty(exports, "Flag", { enumerable: true, get: function () { return Flag_1.Flag; } });
|
|
25
|
-
var Magnitude_1 = require("./abstracts/Magnitude");
|
|
26
|
-
Object.defineProperty(exports, "Magnitude", { enumerable: true, get: function () { return Magnitude_1.Magnitude; } });
|
|
27
|
-
var Point_1 = require("./abstracts/Point");
|
|
28
|
-
Object.defineProperty(exports, "Point", { enumerable: true, get: function () { return Point_1.Point; } });
|
|
29
|
-
var Vector_js_1 = require("./abstracts/Vector.js");
|
|
30
|
-
Object.defineProperty(exports, "Vector", { enumerable: true, get: function () { return Vector_js_1.Vector; } });
|
|
31
|
-
var ArcCurve_1 = require("./figures/ArcCurve");
|
|
32
|
-
Object.defineProperty(exports, "ArcCurve", { enumerable: true, get: function () { return ArcCurve_1.ArcCurve; } });
|
|
33
|
-
var Circle_1 = require("./figures/Circle");
|
|
34
|
-
Object.defineProperty(exports, "Circle", { enumerable: true, get: function () { return Circle_1.Circle; } });
|
|
35
|
-
var CubicBezierCurve_1 = require("./figures/CubicBezierCurve");
|
|
36
|
-
Object.defineProperty(exports, "CubicBezierCurve", { enumerable: true, get: function () { return CubicBezierCurve_1.CubicBezierCurve; } });
|
|
37
|
-
var Ellipse_1 = require("./figures/Ellipse");
|
|
38
|
-
Object.defineProperty(exports, "Ellipse", { enumerable: true, get: function () { return Ellipse_1.Ellipse; } });
|
|
39
|
-
var Line_1 = require("./figures/Line");
|
|
40
|
-
Object.defineProperty(exports, "Line", { enumerable: true, get: function () { return Line_1.Line; } });
|
|
41
|
-
var Polygon_1 = require("./figures/Polygon");
|
|
42
|
-
Object.defineProperty(exports, "Polygon", { enumerable: true, get: function () { return Polygon_1.Polygon; } });
|
|
43
|
-
var QuadraticBezierCurve_1 = require("./figures/QuadraticBezierCurve");
|
|
44
|
-
Object.defineProperty(exports, "QuadraticBezierCurve", { enumerable: true, get: function () { return QuadraticBezierCurve_1.QuadraticBezierCurve; } });
|
|
45
|
-
var Calculator_1 = require("./utilities/Calculator");
|
|
46
|
-
Object.defineProperty(exports, "Calculator", { enumerable: true, get: function () { return Calculator_1.Calculator; } });
|
|
18
|
+
__exportStar(require("./abstracts"), exports);
|
|
19
|
+
__exportStar(require("./figures"), exports);
|
|
47
20
|
__exportStar(require("./utilities"), exports);
|
|
48
21
|
__exportStar(require("./types"), exports);
|
|
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Calculator = void 0;
|
|
4
4
|
const decimal_js_1 = require("decimal.js");
|
|
5
5
|
class Calculator {
|
|
6
|
+
static EPSILON = 1e-8;
|
|
7
|
+
static PI2 = +Calculator.mul(Math.PI, 2);
|
|
6
8
|
_instance;
|
|
7
9
|
constructor(arg) {
|
|
8
10
|
this._instance = new decimal_js_1.Decimal(arg);
|
|
@@ -29,6 +31,12 @@ class Calculator {
|
|
|
29
31
|
static div(first, second) {
|
|
30
32
|
return Calculator.computeBinaryOperation('div', [first, second]);
|
|
31
33
|
}
|
|
34
|
+
static isEqual(a, b) {
|
|
35
|
+
return Math.abs(a - b) <= Calculator.EPSILON;
|
|
36
|
+
}
|
|
37
|
+
static isNearZero(a) {
|
|
38
|
+
return Math.abs(a) <= Calculator.EPSILON;
|
|
39
|
+
}
|
|
32
40
|
static max(args) {
|
|
33
41
|
return Calculator.computeIndefiniteOperation('max', args);
|
|
34
42
|
}
|
|
@@ -83,7 +91,7 @@ class Calculator {
|
|
|
83
91
|
* than epsilon, and then to round up to that point instead of choosing an arbitrary precision.
|
|
84
92
|
*/
|
|
85
93
|
static roundDecimalWithPrecision(value) {
|
|
86
|
-
const epsilon = new decimal_js_1.Decimal(
|
|
94
|
+
const epsilon = new decimal_js_1.Decimal(Calculator.EPSILON);
|
|
87
95
|
const distanceToLowerInt = value.sub(value.floor());
|
|
88
96
|
const distanceToUpperInt = value.ceil().sub(value);
|
|
89
97
|
if (distanceToLowerInt.lte(epsilon)) {
|
|
@@ -0,0 +1,17 @@
|
|
|
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("./Calculator"), exports);
|
|
@@ -1,10 +1,22 @@
|
|
|
1
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
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PI2 = exports.
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
exports.coordinateOrigin = new
|
|
8
|
-
exports.
|
|
9
|
-
exports.yAxis = new Line_1.Line([exports.coordinateOrigin, new Point_1.Point([0, 1])]);
|
|
10
|
-
exports.PI2 = +Calculator_1.Calculator.mul(Math.PI, 2); // 360 degrees
|
|
17
|
+
exports.PI2 = exports.coordinateOrigin = void 0;
|
|
18
|
+
const calculator_1 = require("./calculator");
|
|
19
|
+
const _abstracts_1 = require("../abstracts");
|
|
20
|
+
__exportStar(require("./calculator"), exports);
|
|
21
|
+
exports.coordinateOrigin = new _abstracts_1.Point([0, 0]);
|
|
22
|
+
exports.PI2 = calculator_1.Calculator.PI2;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Calculator } from '
|
|
2
|
-
const PI2 = +Calculator.mul(Math.PI, 2);
|
|
1
|
+
import { Calculator } from '../../utilities/calculator';
|
|
3
2
|
export class Angle {
|
|
3
|
+
kind = 'angle';
|
|
4
4
|
_radians;
|
|
5
5
|
constructor(value, unit) {
|
|
6
6
|
this._radians = unit === 'radians' ? value : Angle.toRadians(value);
|
|
@@ -35,10 +35,10 @@ export class Angle {
|
|
|
35
35
|
normalize() {
|
|
36
36
|
const { radians } = this;
|
|
37
37
|
if (radians < 0) {
|
|
38
|
-
this._radians = +Calculator.add(radians, PI2);
|
|
38
|
+
this._radians = +Calculator.add(radians, Calculator.PI2);
|
|
39
39
|
}
|
|
40
40
|
else if (radians > 0) {
|
|
41
|
-
this._radians = +Calculator.mod(radians, PI2);
|
|
41
|
+
this._radians = +Calculator.mod(radians, Calculator.PI2);
|
|
42
42
|
}
|
|
43
43
|
return this;
|
|
44
44
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { Point } from './Point';
|
|
4
|
-
import { Vector } from './Vector';
|
|
1
|
+
import { Point, Vector } from '..';
|
|
2
|
+
import { Calculator } from '../../utilities/calculator';
|
|
5
3
|
export class Figure {
|
|
6
4
|
angles = [];
|
|
7
5
|
isRelative = false;
|
|
@@ -19,23 +17,22 @@ export class Figure {
|
|
|
19
17
|
get values() {
|
|
20
18
|
return this._values;
|
|
21
19
|
}
|
|
22
|
-
/**
|
|
23
|
-
* @todo Figure out a better way to type narrow than iterating again.
|
|
24
|
-
*/
|
|
25
20
|
set values(values) {
|
|
26
21
|
this._values = values;
|
|
27
22
|
const [points, vectors, magnitudes, angles] = values.reduce((result, value) => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
23
|
+
switch (value.kind) {
|
|
24
|
+
case 'point':
|
|
25
|
+
result[0].push(value);
|
|
26
|
+
break;
|
|
27
|
+
case 'vector':
|
|
28
|
+
result[1].push(value);
|
|
29
|
+
break;
|
|
30
|
+
case 'magnitude':
|
|
31
|
+
result[2].push(value);
|
|
32
|
+
break;
|
|
33
|
+
case 'angle':
|
|
34
|
+
result[3].push(value);
|
|
35
|
+
break;
|
|
39
36
|
}
|
|
40
37
|
return result;
|
|
41
38
|
}, [[], [], [], []]);
|
|
@@ -74,10 +71,13 @@ export class Figure {
|
|
|
74
71
|
point.reflect(perpendicularRoot);
|
|
75
72
|
});
|
|
76
73
|
vectors.forEach((vector) => {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
74
|
+
const referenceProjection = about.getPerpendicularProjection(points[0]);
|
|
75
|
+
const referencePoint = points[0].clone().reflect(referenceProjection);
|
|
76
|
+
const endPoint = points[0].clone().translate(vector);
|
|
77
|
+
const endProjection = about.getPerpendicularProjection(endPoint);
|
|
78
|
+
const positionalPoint = endPoint.reflect(endProjection);
|
|
79
|
+
const reflectedVector = new Vector([referencePoint, positionalPoint]);
|
|
80
|
+
vector.replace(reflectedVector);
|
|
81
81
|
});
|
|
82
82
|
return this;
|
|
83
83
|
}
|
|
@@ -130,6 +130,21 @@ export class Figure {
|
|
|
130
130
|
});
|
|
131
131
|
return this;
|
|
132
132
|
}
|
|
133
|
+
scaleXY(factorX, factorY, about = new Point([0, 0])) {
|
|
134
|
+
const { points, vectors } = this;
|
|
135
|
+
if (!points) {
|
|
136
|
+
throw new Error(Figure.getNoPointsErrorMessage('scaleXY'));
|
|
137
|
+
}
|
|
138
|
+
points.forEach((point) => {
|
|
139
|
+
const scaledX = +Calculator.add(about.x, Calculator.sub(point.x, about.x).mul(factorX));
|
|
140
|
+
const scaledY = +Calculator.add(about.y, Calculator.sub(point.y, about.y).mul(factorY));
|
|
141
|
+
point.replace(new Point([scaledX, scaledY]));
|
|
142
|
+
});
|
|
143
|
+
vectors.forEach((vector) => {
|
|
144
|
+
vector.replace(new Vector([+Calculator.mul(vector.dx, factorX), +Calculator.mul(vector.dy, factorY)]));
|
|
145
|
+
});
|
|
146
|
+
return this;
|
|
147
|
+
}
|
|
133
148
|
translate(vector) {
|
|
134
149
|
const { points } = this;
|
|
135
150
|
if (!points) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { Angle, Figure, Point } from '../../abstracts';
|
|
2
|
+
import { CubicBezierCurve } from '../cubic-bezier-curve/CubicBezierCurve';
|
|
3
|
+
import { Ellipse } from '../ellipse/Ellipse';
|
|
4
|
+
import { Calculator } from '../../utilities/calculator';
|
|
5
5
|
export class ArcCurve extends Figure {
|
|
6
6
|
ellipse;
|
|
7
7
|
largeArcFlag;
|
|
@@ -34,7 +34,7 @@ export class ArcCurve extends Figure {
|
|
|
34
34
|
const [minTheta, maxTheta] = this.computeThetaRange();
|
|
35
35
|
return ellipse.criticalPoints.filter((point) => {
|
|
36
36
|
const { P0, P1 } = this;
|
|
37
|
-
if ((point.x
|
|
37
|
+
if ((Calculator.isEqual(point.x, P0.x) && Calculator.isEqual(point.y, P0.y)) || (Calculator.isEqual(point.x, P1.x) && Calculator.isEqual(point.y, P1.y))) {
|
|
38
38
|
return false;
|
|
39
39
|
}
|
|
40
40
|
const theta = ellipse.computeThetaForPoint(point);
|
|
@@ -51,7 +51,7 @@ export class ArcCurve extends Figure {
|
|
|
51
51
|
return this.points[1];
|
|
52
52
|
}
|
|
53
53
|
clone() {
|
|
54
|
-
const values = this.values.map((value) => (typeof value === 'object' && 'clone' in value ? value.clone() : value));
|
|
54
|
+
const values = this.values.map((value) => (typeof value === 'object' && 'clone' in value ? value.clone() : /* v8 ignore next */ value));
|
|
55
55
|
return new ArcCurve(values);
|
|
56
56
|
}
|
|
57
57
|
reflect(about) {
|
|
@@ -59,6 +59,30 @@ export class ArcCurve extends Figure {
|
|
|
59
59
|
this.sweepFlag.invert();
|
|
60
60
|
return this;
|
|
61
61
|
}
|
|
62
|
+
toCubicBezierCurves() {
|
|
63
|
+
const [minTheta, maxTheta] = this.computeThetaRange();
|
|
64
|
+
const p0Theta = this.ellipse.computeThetaForPoint(this.P0);
|
|
65
|
+
const p0IsMin = Calculator.isEqual(+p0Theta.radians, +minTheta.radians);
|
|
66
|
+
const span = +Calculator.sub(maxTheta.radians, minTheta.radians);
|
|
67
|
+
const halfPi = Math.PI / 2;
|
|
68
|
+
const numSegments = Math.max(1, Math.ceil(span / halfPi));
|
|
69
|
+
const segmentAngle = span / numSegments;
|
|
70
|
+
const curves = [];
|
|
71
|
+
for (let i = 0; i < numSegments; i++) {
|
|
72
|
+
let t1Rad;
|
|
73
|
+
let t2Rad;
|
|
74
|
+
if (p0IsMin) {
|
|
75
|
+
t1Rad = +Calculator.add(minTheta.radians, Calculator.mul(segmentAngle, i));
|
|
76
|
+
t2Rad = +Calculator.add(minTheta.radians, Calculator.mul(segmentAngle, i + 1));
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
t1Rad = +Calculator.sub(maxTheta.radians, Calculator.mul(segmentAngle, i));
|
|
80
|
+
t2Rad = +Calculator.sub(maxTheta.radians, Calculator.mul(segmentAngle, i + 1));
|
|
81
|
+
}
|
|
82
|
+
curves.push(this.computeBezierSegment(new Angle(t1Rad, 'radians'), new Angle(t2Rad, 'radians')));
|
|
83
|
+
}
|
|
84
|
+
return curves;
|
|
85
|
+
}
|
|
62
86
|
adjustRadii() {
|
|
63
87
|
const { rx, ry } = this;
|
|
64
88
|
const P0_prime = this.computeP0Prime();
|
|
@@ -73,6 +97,18 @@ export class ArcCurve extends Figure {
|
|
|
73
97
|
ry.replace(+Calculator.mul(+ry, radii_check.sqrt()));
|
|
74
98
|
}
|
|
75
99
|
}
|
|
100
|
+
computeBezierSegment(theta1, theta2) {
|
|
101
|
+
const { ellipse } = this;
|
|
102
|
+
const alpha = +Calculator.sub(theta2.radians, theta1.radians);
|
|
103
|
+
const k = +Calculator.mul(4, Calculator.tan(Calculator.div(alpha, 4))).div(3);
|
|
104
|
+
const p0 = ellipse.computePointForTheta(theta1);
|
|
105
|
+
const p3 = ellipse.computePointForTheta(theta2);
|
|
106
|
+
const [t1x, t1y] = this.computeTangentForTheta(theta1);
|
|
107
|
+
const [t2x, t2y] = this.computeTangentForTheta(theta2);
|
|
108
|
+
const p1 = new Point([+Calculator.add(p0.x, Calculator.mul(k, t1x)), +Calculator.add(p0.y, Calculator.mul(k, t1y))]);
|
|
109
|
+
const p2 = new Point([+Calculator.sub(p3.x, Calculator.mul(k, t2x)), +Calculator.sub(p3.y, Calculator.mul(k, t2y))]);
|
|
110
|
+
return new CubicBezierCurve([p0, p1, p2, p3]);
|
|
111
|
+
}
|
|
76
112
|
computeCenter() {
|
|
77
113
|
const { P0, P1, phi } = this;
|
|
78
114
|
const center_prime = this.computeCenterPrime();
|
|
@@ -99,7 +135,7 @@ export class ArcCurve extends Figure {
|
|
|
99
135
|
.sub(rx_sq.mul(y1_prime_sq))
|
|
100
136
|
.sub(ry_sq.mul(x1_prime_sq))
|
|
101
137
|
.div(rx_sq.mul(y1_prime_sq).add(ry_sq.mul(x1_prime_sq)));
|
|
102
|
-
sq = +sq < 0 ? new Calculator(0) : sq;
|
|
138
|
+
sq = +sq < 0 ? /* v8 ignore next */ new Calculator(0) : sq;
|
|
103
139
|
const coef = sign.mul(sq.sqrt());
|
|
104
140
|
const cx_prime = coef.mul(Calculator.mul(+rx, y1_prime).div(+ry));
|
|
105
141
|
const cy_prime = coef.mul(Calculator.mul(+ry, x1_prime).div(+rx).neg());
|
|
@@ -115,11 +151,17 @@ export class ArcCurve extends Figure {
|
|
|
115
151
|
const y1_prime = Calculator.mul(phi.sin, mx).neg().add(Calculator.mul(phi.cos, my));
|
|
116
152
|
return new Point([+x1_prime, +y1_prime]);
|
|
117
153
|
}
|
|
154
|
+
computeTangentForTheta(theta) {
|
|
155
|
+
const { phi, rx, ry } = this.ellipse;
|
|
156
|
+
const tx = +Calculator.neg(Calculator.mul(+rx, theta.sin).mul(phi.cos)).sub(Calculator.mul(+ry, theta.cos).mul(phi.sin));
|
|
157
|
+
const ty = +Calculator.neg(Calculator.mul(+rx, theta.sin).mul(phi.sin)).add(Calculator.mul(+ry, theta.cos).mul(phi.cos));
|
|
158
|
+
return [tx, ty];
|
|
159
|
+
}
|
|
118
160
|
computeThetaRange() {
|
|
119
161
|
const { P0, P1, ellipse, sweepFlag } = this;
|
|
120
162
|
const theta1 = ellipse.computeThetaForPoint(P0);
|
|
121
163
|
const theta2 = ellipse.computeThetaForPoint(P1);
|
|
122
|
-
if (+theta2
|
|
164
|
+
if (Calculator.isNearZero(+theta2) && !sweepFlag.value) {
|
|
123
165
|
theta2.replace(360, 'degrees');
|
|
124
166
|
}
|
|
125
167
|
const thetaRange = [theta1, theta2].sort((a, b) => +Calculator.sub(a.radians, b.radians));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Ellipse } from '
|
|
3
|
-
import {
|
|
4
|
-
import { Angle } from '../abstracts/Angle';
|
|
1
|
+
import { Angle, Point } from '../../abstracts';
|
|
2
|
+
import { Ellipse } from '../ellipse/Ellipse';
|
|
3
|
+
import { Calculator } from '../../utilities/calculator';
|
|
5
4
|
export class Circle extends Ellipse {
|
|
6
5
|
_radius;
|
|
7
6
|
constructor(values) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|