pimath 0.0.127 → 0.0.129
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/dist/main.d.ts +39 -0
- package/{esm → dist}/maths/algebra/equation.d.ts +11 -10
- package/{esm → dist}/maths/algebra/linearSystem.d.ts +5 -4
- package/{esm → dist}/maths/algebra/monom.d.ts +5 -4
- package/{esm → dist}/maths/algebra/polynom.d.ts +11 -13
- package/{esm → dist}/maths/algebra/rational.d.ts +7 -9
- package/dist/maths/algebra/study/rationalStudy.d.ts +14 -0
- package/{esm → dist}/maths/algebra/study.d.ts +4 -7
- package/{esm → dist}/maths/geometry/circle.d.ts +9 -8
- package/{esm → dist}/maths/geometry/line.d.ts +17 -14
- package/{esm → dist}/maths/geometry/point.d.ts +11 -9
- package/{esm → dist}/maths/geometry/triangle.d.ts +4 -3
- package/{esm → dist}/maths/geometry/vector.d.ts +7 -10
- package/{esm → dist}/maths/randomization/random.d.ts +10 -7
- package/{esm → dist}/maths/randomization/rndFraction.d.ts +4 -3
- package/dist/maths/randomization/rndGeometryCircle.d.ts +13 -0
- package/{esm → dist}/maths/randomization/rndGeometryLine.d.ts +4 -3
- package/{esm → dist}/maths/randomization/rndGeometryPoint.d.ts +4 -3
- package/{esm → dist}/maths/randomization/rndMonom.d.ts +5 -4
- package/{esm → dist}/maths/randomization/rndPolynom.d.ts +5 -4
- package/{esm → dist}/maths/randomization/rndTypes.d.ts +7 -1
- package/dist/pimath.js +4239 -7819
- package/package.json +13 -7
- package/.eslintrc.js +0 -24
- package/.idea/$CACHE_FILE$ +0 -6
- package/.idea/PI.iml +0 -14
- package/.idea/codeStyles/codeStyleConfig.xml +0 -5
- package/.idea/inspectionProfiles/Project_Default.xml +0 -6
- package/.idea/misc.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/php.xml +0 -19
- package/.idea/shelf/Uncommitted_changes_before_Checkout_at_07_11_2023_08_30_[Default_Changelist]/shelved.patch +0 -192
- package/.idea/shelf/Uncommitted_changes_before_Checkout_at_07_11_2023_08_30_[Default_Changelist]1/shelved.patch +0 -0
- package/.idea/shelf/Uncommitted_changes_before_Checkout_at_07_11_2023_08_30__Default_Changelist_.xml +0 -4
- package/.idea/shelf/Uncommitted_changes_before_Checkout_at_09_11_2023_10_43_[Default_Changelist]/shelved.patch +0 -2404
- package/.idea/shelf/Uncommitted_changes_before_Checkout_at_09_11_2023_10_43__Default_Changelist_.xml +0 -4
- package/.idea/shelf/Uncommitted_changes_before_Checkout_at_09_11_2023_11_01_[Default_Changelist]/shelved.patch +0 -1362
- package/.idea/shelf/Uncommitted_changes_before_Checkout_at_09_11_2023_11_01__Default_Changelist_.xml +0 -4
- package/.idea/shelf/Uncommitted_changes_before_Update_at_24_07_2023_15_31_[Default_Changelist]/shelved.patch +0 -90
- package/.idea/shelf/Uncommitted_changes_before_Update_at_24_07_2023_15_31__Default_Changelist_.xml +0 -4
- package/.idea/vcs.xml +0 -6
- package/dev/pimath.js +0 -7945
- package/dev/pimath.js.map +0 -1
- package/dist/pimath.js.map +0 -1
- package/dist/pimath.min.js +0 -2
- package/dist/pimath.min.js.map +0 -1
- package/docs/.nojekyll +0 -1
- package/docs/assets/highlight.css +0 -78
- package/docs/assets/main.js +0 -59
- package/docs/assets/navigation.js +0 -1
- package/docs/assets/search.js +0 -1
- package/docs/assets/style.css +0 -1383
- package/docs/classes/Logicalset.Logicalset.html +0 -217
- package/docs/classes/Polynom.Rational.html +0 -397
- package/docs/classes/Vector-1.Vector.html +0 -490
- package/docs/classes/Vector.Point.html +0 -337
- package/docs/classes/algebra_equation.Equation.html +0 -790
- package/docs/classes/algebra_linearSystem.LinearSystem.html +0 -404
- package/docs/classes/algebra_monom.Monom.html +0 -962
- package/docs/classes/algebra_polynom.Polynom.html +0 -1275
- package/docs/classes/coefficients_fraction.Fraction.html +0 -934
- package/docs/classes/geometry_circle.Circle.html +0 -472
- package/docs/classes/geometry_line.Line.html +0 -774
- package/docs/classes/geometry_triangle.Triangle.html +0 -429
- package/docs/classes/numeric.Numeric.html +0 -265
- package/docs/classes/shutingyard.Shutingyard.html +0 -250
- package/docs/enums/algebra_equation.PARTICULAR_SOLUTION.html +0 -83
- package/docs/enums/geometry_line.LinePropriety.html +0 -97
- package/docs/enums/shutingyard.ShutingyardMode.html +0 -97
- package/docs/enums/shutingyard.ShutingyardType.html +0 -111
- package/docs/index.html +0 -63
- package/docs/interfaces/algebra_equation.ISolution.html +0 -105
- package/docs/interfaces/algebra_polynom.IEuclidian.html +0 -87
- package/docs/interfaces/geometry_triangle.remarquableLines.html +0 -163
- package/docs/modules/Logicalset.html +0 -65
- package/docs/modules/Polynom.html +0 -65
- package/docs/modules/Vector-1.html +0 -65
- package/docs/modules/Vector.html +0 -65
- package/docs/modules/algebra_equation.html +0 -69
- package/docs/modules/algebra_linearSystem.html +0 -61
- package/docs/modules/algebra_monom.html +0 -65
- package/docs/modules/algebra_polynom.html +0 -69
- package/docs/modules/coefficients_fraction.html +0 -65
- package/docs/modules/geometry_circle.html +0 -61
- package/docs/modules/geometry_line.html +0 -65
- package/docs/modules/geometry_triangle.html +0 -65
- package/docs/modules/numeric.html +0 -61
- package/docs/modules/shutingyard.html +0 -75
- package/docs/types/algebra_monom.literalType.html +0 -61
- package/docs/types/algebra_polynom.PolynomParsingType.html +0 -56
- package/docs/types/coefficients_fraction.FractionParsingType.html +0 -56
- package/docs/types/shutingyard.Token.html +0 -63
- package/docs/types/shutingyard.tokenType.html +0 -68
- package/docs/variables/shutingyard.tokenConstant.html +0 -61
- package/esm/index.d.ts +0 -38
- package/esm/index.js +0 -44
- package/esm/index.js.map +0 -1
- package/esm/maths/algebra/equation.js +0 -797
- package/esm/maths/algebra/equation.js.map +0 -1
- package/esm/maths/algebra/linearSystem.js +0 -279
- package/esm/maths/algebra/linearSystem.js.map +0 -1
- package/esm/maths/algebra/logicalset.js +0 -158
- package/esm/maths/algebra/logicalset.js.map +0 -1
- package/esm/maths/algebra/monom.js +0 -909
- package/esm/maths/algebra/monom.js.map +0 -1
- package/esm/maths/algebra/polynom.js +0 -1305
- package/esm/maths/algebra/polynom.js.map +0 -1
- package/esm/maths/algebra/rational.js +0 -195
- package/esm/maths/algebra/rational.js.map +0 -1
- package/esm/maths/algebra/study/rationalStudy.d.ts +0 -28
- package/esm/maths/algebra/study/rationalStudy.js +0 -244
- package/esm/maths/algebra/study/rationalStudy.js.map +0 -1
- package/esm/maths/algebra/study.js +0 -380
- package/esm/maths/algebra/study.js.map +0 -1
- package/esm/maths/coefficients/fraction.js +0 -517
- package/esm/maths/coefficients/fraction.js.map +0 -1
- package/esm/maths/coefficients/nthRoot.js +0 -137
- package/esm/maths/coefficients/nthRoot.js.map +0 -1
- package/esm/maths/geometry/circle.js +0 -324
- package/esm/maths/geometry/circle.js.map +0 -1
- package/esm/maths/geometry/line.js +0 -485
- package/esm/maths/geometry/line.js.map +0 -1
- package/esm/maths/geometry/point.js +0 -167
- package/esm/maths/geometry/point.js.map +0 -1
- package/esm/maths/geometry/triangle.js +0 -276
- package/esm/maths/geometry/triangle.js.map +0 -1
- package/esm/maths/geometry/vector.js +0 -198
- package/esm/maths/geometry/vector.js.map +0 -1
- package/esm/maths/numeric.js +0 -136
- package/esm/maths/numeric.js.map +0 -1
- package/esm/maths/numexp.js +0 -186
- package/esm/maths/numexp.js.map +0 -1
- package/esm/maths/randomization/random.js +0 -79
- package/esm/maths/randomization/random.js.map +0 -1
- package/esm/maths/randomization/randomCore.js +0 -22
- package/esm/maths/randomization/randomCore.js.map +0 -1
- package/esm/maths/randomization/rndFraction.js +0 -44
- package/esm/maths/randomization/rndFraction.js.map +0 -1
- package/esm/maths/randomization/rndGeometryLine.js +0 -46
- package/esm/maths/randomization/rndGeometryLine.js.map +0 -1
- package/esm/maths/randomization/rndGeometryPoint.js +0 -61
- package/esm/maths/randomization/rndGeometryPoint.js.map +0 -1
- package/esm/maths/randomization/rndHelpers.js +0 -98
- package/esm/maths/randomization/rndHelpers.js.map +0 -1
- package/esm/maths/randomization/rndMonom.js +0 -53
- package/esm/maths/randomization/rndMonom.js.map +0 -1
- package/esm/maths/randomization/rndPolynom.js +0 -75
- package/esm/maths/randomization/rndPolynom.js.map +0 -1
- package/esm/maths/randomization/rndTypes.js +0 -3
- package/esm/maths/randomization/rndTypes.js.map +0 -1
- package/esm/maths/shutingyard.js +0 -443
- package/esm/maths/shutingyard.js.map +0 -1
- package/public/demo.css +0 -3
- package/public/index.html +0 -283
- package/public/matrices.html +0 -100
- package/public/playground.html +0 -168
- package/src/index.ts +0 -42
- package/src/maths/algebra/equation.ts +0 -897
- package/src/maths/algebra/linearSystem.ts +0 -370
- package/src/maths/algebra/logicalset.ts +0 -183
- package/src/maths/algebra/monom.ts +0 -1028
- package/src/maths/algebra/polynom.ts +0 -1537
- package/src/maths/algebra/rational.ts +0 -240
- package/src/maths/algebra/study/rationalStudy.ts +0 -287
- package/src/maths/algebra/study.ts +0 -506
- package/src/maths/coefficients/fraction.ts +0 -593
- package/src/maths/coefficients/nthRoot.ts +0 -148
- package/src/maths/geometry/circle.ts +0 -382
- package/src/maths/geometry/line.ts +0 -604
- package/src/maths/geometry/point.ts +0 -215
- package/src/maths/geometry/triangle.ts +0 -368
- package/src/maths/geometry/vector.ts +0 -242
- package/src/maths/numeric.ts +0 -162
- package/src/maths/numexp.ts +0 -184
- package/src/maths/randomization/random.ts +0 -80
- package/src/maths/randomization/randomCore.ts +0 -19
- package/src/maths/randomization/rndFraction.ts +0 -47
- package/src/maths/randomization/rndGeometryCircle.ts +0 -50
- package/src/maths/randomization/rndGeometryLine.ts +0 -53
- package/src/maths/randomization/rndGeometryPoint.ts +0 -69
- package/src/maths/randomization/rndHelpers.ts +0 -107
- package/src/maths/randomization/rndMonom.ts +0 -57
- package/src/maths/randomization/rndPolynom.ts +0 -90
- package/src/maths/randomization/rndTypes.ts +0 -43
- package/src/maths/shutingyard.ts +0 -496
- package/tests/algebra/equation.test.ts +0 -64
- package/tests/algebra/linear.test.ts +0 -58
- package/tests/algebra/monom.test.ts +0 -78
- package/tests/algebra/polynom.test.ts +0 -343
- package/tests/algebra/rationnal.test.ts +0 -64
- package/tests/algebra/study.test.ts +0 -48
- package/tests/coefficients/fraction.test.ts +0 -131
- package/tests/custom.test.ts +0 -33
- package/tests/geometry/circle.test.ts +0 -404
- package/tests/geometry/line.test.ts +0 -36
- package/tests/numeric.test.ts +0 -43
- package/tests/numexp.test.ts +0 -89
- package/tests/shutingyard.test.ts +0 -58
- package/tsconfig.json +0 -41
- package/tsconfig.testing.json +0 -28
- package/typedoc.katex.js +0 -11
- package/webpack-production-min.config.js +0 -26
- package/webpack-production.config.js +0 -26
- package/webpack.config.js +0 -26
- package/{esm → dist}/maths/algebra/logicalset.d.ts +6 -6
- package/{esm → dist}/maths/coefficients/fraction.d.ts +0 -0
- package/{esm → dist}/maths/coefficients/nthRoot.d.ts +0 -0
- package/{esm → dist}/maths/numeric.d.ts +0 -0
- package/{esm → dist}/maths/numexp.d.ts +3 -3
- /package/{esm → dist}/maths/randomization/randomCore.d.ts +0 -0
- /package/{esm → dist}/maths/randomization/rndHelpers.d.ts +0 -0
- /package/{esm → dist}/maths/shutingyard.d.ts +0 -0
|
@@ -1,242 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Vector module contains everything necessary to handle 2d or 3d vectors.
|
|
3
|
-
* @module Vector
|
|
4
|
-
*/
|
|
5
|
-
import {Fraction} from "../coefficients/fraction";
|
|
6
|
-
import {Numeric} from "../numeric";
|
|
7
|
-
import {Point} from "./point";
|
|
8
|
-
|
|
9
|
-
export class Vector {
|
|
10
|
-
private _x: Fraction; // 1st component
|
|
11
|
-
private _y: Fraction; // 2nd component
|
|
12
|
-
|
|
13
|
-
constructor(...values: unknown[]) {
|
|
14
|
-
this._x = new Fraction().zero();
|
|
15
|
-
this._y = new Fraction().zero();
|
|
16
|
-
|
|
17
|
-
if (values !== undefined) {
|
|
18
|
-
this.parse(...values);
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
// ------------------------------------------
|
|
23
|
-
// Getter and setter
|
|
24
|
-
// ------------------------------------------
|
|
25
|
-
get x(): Fraction {
|
|
26
|
-
return this._x;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
set x(value: Fraction|number|string) {
|
|
30
|
-
this._x = new Fraction(value);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
get y(): Fraction {
|
|
34
|
-
return this._y;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
set y(value: Fraction|number|string) {
|
|
38
|
-
this._y = new Fraction(value);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
get normSquare(): Fraction {
|
|
42
|
-
return this._x.clone().pow(2).add(this._y.clone().pow(2));
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
get norm(): number {
|
|
46
|
-
return Math.sqrt(this.normSquare.value);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
get tex(): string {
|
|
50
|
-
return `\\begin{pmatrix}${this._x.tex} \\\\\ ${this._y.tex} \\end{pmatrix}`
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
get asPoint(): Point {
|
|
54
|
-
return new Point(this.x, this.y)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// ------------------------------------------
|
|
58
|
-
// Creation / parsing functions
|
|
59
|
-
// ------------------------------------------
|
|
60
|
-
|
|
61
|
-
parse = (...values: any): Vector => {
|
|
62
|
-
// TODO: Must be more strict about what is given and limit to two dimensional vectors.p
|
|
63
|
-
// Maybe more than one value was given...
|
|
64
|
-
// Initialize the vector
|
|
65
|
-
this.zero();
|
|
66
|
-
|
|
67
|
-
if (values.length === 0) {
|
|
68
|
-
return this;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (values.length === 1) {
|
|
72
|
-
if (values[0] instanceof Vector) {
|
|
73
|
-
return values[0].clone()
|
|
74
|
-
} else {
|
|
75
|
-
return this._parseString(values[0])
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (values.length >= 2) {
|
|
80
|
-
// Two points are given - skip the third value.
|
|
81
|
-
if (values[0] instanceof Point && values[1] instanceof Point) {
|
|
82
|
-
this._x = values[1].x.clone().subtract(values[0].x)
|
|
83
|
-
this._y = values[1].y.clone().subtract(values[0].y)
|
|
84
|
-
return this;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// Fractions or a number are give
|
|
88
|
-
if (values[0] instanceof Fraction || !isNaN(values[0])) {
|
|
89
|
-
this._x = new Fraction(values[0])
|
|
90
|
-
}
|
|
91
|
-
if (values[1] instanceof Fraction || !isNaN(values[1])) {
|
|
92
|
-
this._y = new Fraction(values[1])
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
if(
|
|
96
|
-
(typeof values[0] === 'object' && !isNaN(values[0].x) && !isNaN(values[0].x)) &&
|
|
97
|
-
(typeof values[1] === 'object' && !isNaN(values[1].x) && !isNaN(values[1].x))
|
|
98
|
-
){
|
|
99
|
-
this._x = new Fraction(+values[1].x-values[0].x)
|
|
100
|
-
this._y = new Fraction(+values[1].y-values[0].y)
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return this;
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
clone = (): Vector => {
|
|
108
|
-
let V = new Vector();
|
|
109
|
-
|
|
110
|
-
if (this._x !== null) {
|
|
111
|
-
V.x = this._x.clone();
|
|
112
|
-
}
|
|
113
|
-
if (this._y !== null) {
|
|
114
|
-
V.y = this._y.clone();
|
|
115
|
-
}
|
|
116
|
-
return V;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
reset = (): Vector => {
|
|
120
|
-
this._x = null;
|
|
121
|
-
this._y = null;
|
|
122
|
-
return this;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
zero = (): Vector => {
|
|
126
|
-
this.reset();
|
|
127
|
-
this._x = new Fraction(null);
|
|
128
|
-
this._y = new Fraction(null);
|
|
129
|
-
return this;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
one = (): Vector => {
|
|
133
|
-
this._x = new Fraction();
|
|
134
|
-
this._y = new Fraction();
|
|
135
|
-
return this;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
private _parseString = (value: string): Vector => {
|
|
139
|
-
// Split comma, semi colon or single space.
|
|
140
|
-
let components = value.split(/[,;\s]/g);
|
|
141
|
-
|
|
142
|
-
// Validate the fraction values.
|
|
143
|
-
this.x = new Fraction(components[0] || null);
|
|
144
|
-
this.y = new Fraction(components[1] || null);
|
|
145
|
-
return this;
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
// ------------------------------------------
|
|
149
|
-
// Mathematical operations
|
|
150
|
-
// ------------------------------------------
|
|
151
|
-
opposed = (): Vector => {
|
|
152
|
-
this._x.opposed();
|
|
153
|
-
this._y.opposed();
|
|
154
|
-
return this;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
add = (V: Vector): Vector => {
|
|
158
|
-
this._x.add(V.x);
|
|
159
|
-
this._y.add(V.y);
|
|
160
|
-
|
|
161
|
-
return this;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
subtract = (V: Vector): Vector => {
|
|
165
|
-
return this.add(V.clone().opposed());
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
scalarProductWithVector = (V: Vector): Fraction => {
|
|
169
|
-
return Vector.scalarProduct(this, V)
|
|
170
|
-
// return this._x.clone().multiply(V.x).add(this._y.clone().multiply(V.y));
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
determinantWithVector = (V: Vector): Fraction => {
|
|
174
|
-
return Vector.determinant(this, V)
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
static scalarProduct = (v1: Vector, v2: Vector): Fraction => {
|
|
178
|
-
return v1.x.clone().multiply(v2.x).add(v1.y.clone().multiply(v2.y));
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
static determinant = (v1: Vector, v2: Vector): Fraction => {
|
|
182
|
-
return v1.x.clone().multiply(v2.y).subtract(v1.y.clone().multiply(v2.x))
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
normal = (): Vector => {
|
|
186
|
-
let x = this.x.clone().opposed(), y = this.y.clone();
|
|
187
|
-
this._x = y;
|
|
188
|
-
this._y = x;
|
|
189
|
-
return this;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
isColinearTo = (v: Vector): boolean => {
|
|
193
|
-
return this.determinantWithVector(v).isZero()
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
isNormalTo = (v: Vector): boolean => {
|
|
197
|
-
return this.scalarProductWithVector(v).isZero()
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
get isNull(): boolean {
|
|
201
|
-
return this.x.isZero() && this.y.isZero()
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
multiplyByScalar = (k: any): Vector => {
|
|
205
|
-
let scalar = new Fraction(k);
|
|
206
|
-
this._x.multiply(scalar);
|
|
207
|
-
this._y.multiply(scalar);
|
|
208
|
-
return this;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
divideByScalar = (k: any): Vector => {
|
|
212
|
-
return this.multiplyByScalar(new Fraction(k).invert());
|
|
213
|
-
}
|
|
214
|
-
// ------------------------------------------
|
|
215
|
-
// Vector functions
|
|
216
|
-
// ------------------------------------------
|
|
217
|
-
|
|
218
|
-
simplify = (): Vector => {
|
|
219
|
-
// Multiply by the lcm of denominators.
|
|
220
|
-
return this.multiplyByScalar(Numeric.lcm(this._x.denominator, this._y.denominator))
|
|
221
|
-
.divideByScalar(Numeric.gcd(this._x.numerator, this._y.numerator));
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
simplifyDirection = (): Vector => {
|
|
225
|
-
let lcm = Numeric.lcm(this.x.denominator, this.y.denominator),
|
|
226
|
-
gcd = Numeric.gcd(this.x.numerator, this.y.numerator);
|
|
227
|
-
|
|
228
|
-
this.x.multiply(lcm).divide(gcd);
|
|
229
|
-
this.y.multiply(lcm).divide(gcd);
|
|
230
|
-
return this
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
angleWith = (V: Vector, sharp?: Boolean, radian?: Boolean): number => {
|
|
234
|
-
let scalar = this.scalarProductWithVector(V).value,
|
|
235
|
-
toDegree = radian ? 1 : 180 / Math.PI;
|
|
236
|
-
if (sharp) {
|
|
237
|
-
scalar = Math.abs(scalar);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
return toDegree * Math.acos(scalar / (this.norm * V.norm));
|
|
241
|
-
}
|
|
242
|
-
}
|
package/src/maths/numeric.ts
DELETED
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
export class Numeric {
|
|
2
|
-
static round(value: number, decimals: number = 2): number {
|
|
3
|
-
return Number(Math.round(Number(value + 'e' + decimals)) + 'e-' + decimals);
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Get the list of the nth first prime numbers.
|
|
8
|
-
* @param nb : number of primes to choose from
|
|
9
|
-
*/
|
|
10
|
-
static primes(nb?: number): number[] {
|
|
11
|
-
let primesValues: number[] = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069, 1087, 1091, 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151, 1153, 1163, 1171, 1181, 1187, 1193, 1201, 1213, 1217, 1223, 1229, 1231, 1237, 1249, 1259, 1277, 1279, 1283, 1289, 1291, 1297, 1301, 1303, 1307, 1319, 1321, 1327, 1361, 1367, 1373, 1381, 1399, 1409, 1423, 1427, 1429, 1433, 1439, 1447, 1451, 1453, 1459, 1471, 1481, 1483, 1487, 1489, 1493, 1499, 1511, 1523, 1531, 1543, 1549, 1553, 1559, 1567, 1571, 1579, 1583, 1597, 1601, 1607, 1609, 1613, 1619, 1621, 1627, 1637, 1657, 1663, 1667, 1669, 1693, 1697, 1699, 1709, 1721, 1723, 1733, 1741, 1747, 1753, 1759, 1777, 1783, 1787, 1789, 1801, 1811, 1823, 1831, 1847, 1861, 1867, 1871, 1873, 1877, 1879, 1889, 1901, 1907, 1913, 1931, 1933, 1949, 1951, 1973, 1979, 1987, 1993, 1997, 1999, 2003, 2011, 2017, 2027, 2029, 2039, 2053, 2063, 2069, 2081, 2083, 2087, 2089, 2099, 2111, 2113, 2129, 2131, 2137, 2141, 2143, 2153, 2161, 2179, 2203, 2207, 2213, 2221, 2237, 2239, 2243, 2251, 2267, 2269, 2273, 2281, 2287, 2293, 2297, 2309, 2311, 2333, 2339, 2341, 2347, 2351, 2357, 2371, 2377, 2381, 2383, 2389, 2393, 2399, 2411, 2417, 2423, 2437, 2441, 2447, 2459, 2467, 2473, 2477, 2503, 2521, 2531, 2539, 2543, 2549, 2551, 2557, 2579, 2591, 2593, 2609, 2617, 2621, 2633, 2647, 2657, 2659, 2663, 2671, 2677, 2683, 2687, 2689, 2693, 2699, 2707, 2711, 2713, 2719, 2729, 2731, 2741, 2749, 2753, 2767, 2777, 2789, 2791, 2797, 2801, 2803, 2819, 2833, 2837, 2843, 2851, 2857, 2861, 2879, 2887, 2897, 2903, 2909, 2917, 2927, 2939, 2953, 2957, 2963, 2969, 2971, 2999, 3001, 3011, 3019, 3023, 3037, 3041, 3049, 3061, 3067, 3079, 3083, 3089, 3109, 3119, 3121, 3137, 3163, 3167, 3169, 3181, 3187, 3191, 3203, 3209, 3217, 3221, 3229, 3251, 3253, 3257, 3259, 3271, 3299, 3301, 3307, 3313, 3319, 3323, 3329, 3331, 3343, 3347, 3359, 3361, 3371, 3373, 3389, 3391, 3407, 3413, 3433, 3449, 3457, 3461, 3463, 3467, 3469, 3491, 3499, 3511, 3517, 3527, 3529, 3533, 3539, 3541, 3547, 3557, 3559, 3571, 3581, 3583, 3593, 3607, 3613, 3617, 3623, 3631, 3637, 3643, 3659, 3671, 3673, 3677, 3691, 3697, 3701, 3709, 3719, 3727, 3733, 3739, 3761, 3767, 3769, 3779, 3793, 3797, 3803, 3821, 3823, 3833, 3847, 3851, 3853, 3863, 3877, 3881, 3889, 3907, 3911, 3917, 3919, 3923, 3929, 3931, 3943, 3947, 3967, 3989, 4001, 4003, 4007, 4013, 4019, 4021, 4027, 4049, 4051, 4057, 4073, 4079, 4091, 4093, 4099, 4111, 4127, 4129, 4133, 4139, 4153, 4157, 4159, 4177, 4201, 4211, 4217, 4219, 4229, 4231, 4241, 4243, 4253, 4259, 4261, 4271, 4273, 4283, 4289, 4297, 4327, 4337, 4339, 4349, 4357, 4363, 4373, 4391, 4397, 4409, 4421, 4423, 4441, 4447, 4451, 4457, 4463, 4481, 4483, 4493, 4507, 4513, 4517, 4519, 4523, 4547, 4549, 4561, 4567, 4583, 4591, 4597, 4603, 4621, 4637, 4639, 4643, 4649, 4651, 4657, 4663, 4673, 4679, 4691, 4703, 4721, 4723, 4729, 4733, 4751, 4759, 4783, 4787, 4789, 4793, 4799, 4801, 4813, 4817, 4831, 4861, 4871, 4877, 4889, 4903, 4909, 4919, 4931, 4933, 4937, 4943, 4951, 4957, 4967, 4969, 4973, 4987, 4993, 4999, 5003, 5009, 5011, 5021, 5023, 5039, 5051, 5059, 5077, 5081, 5087, 5099, 5101, 5107, 5113, 5119, 5147, 5153, 5167, 5171, 5179, 5189, 5197, 5209, 5227, 5231, 5233, 5237, 5261, 5273, 5279, 5281, 5297, 5303, 5309, 5323, 5333, 5347, 5351, 5381, 5387, 5393, 5399, 5407, 5413, 5417, 5419, 5431, 5437, 5441, 5443, 5449, 5471, 5477, 5479, 5483, 5501, 5503, 5507, 5519, 5521, 5527, 5531, 5557, 5563, 5569, 5573, 5581, 5591, 5623, 5639, 5641, 5647, 5651, 5653, 5657, 5659, 5669, 5683, 5689, 5693, 5701, 5711, 5717, 5737, 5741, 5743, 5749, 5779, 5783, 5791, 5801, 5807, 5813, 5821, 5827, 5839, 5843, 5849, 5851, 5857, 5861, 5867, 5869, 5879, 5881, 5897, 5903, 5923, 5927, 5939, 5953, 5981, 5987, 6007, 6011, 6029, 6037, 6043, 6047, 6053, 6067, 6073, 6079, 6089, 6091, 6101, 6113, 6121, 6131, 6133, 6143, 6151, 6163, 6173, 6197, 6199, 6203, 6211, 6217, 6221, 6229, 6247, 6257, 6263, 6269, 6271, 6277, 6287, 6299, 6301, 6311, 6317, 6323, 6329, 6337, 6343, 6353, 6359, 6361, 6367, 6373, 6379, 6389, 6397, 6421, 6427, 6449, 6451, 6469, 6473, 6481, 6491, 6521, 6529, 6547, 6551, 6553, 6563, 6569, 6571, 6577, 6581, 6599, 6607, 6619, 6637, 6653, 6659, 6661, 6673, 6679, 6689, 6691, 6701, 6703, 6709, 6719, 6733, 6737, 6761, 6763, 6779, 6781, 6791, 6793, 6803, 6823, 6827, 6829, 6833, 6841, 6857, 6863, 6869, 6871, 6883, 6899, 6907, 6911, 6917, 6947, 6949, 6959, 6961, 6967, 6971, 6977, 6983, 6991, 6997, 7001, 7013, 7019, 7027, 7039, 7043, 7057, 7069, 7079, 7103, 7109, 7121, 7127, 7129, 7151, 7159, 7177, 7187, 7193, 7207, 7211, 7213, 7219, 7229, 7237, 7243, 7247, 7253, 7283, 7297, 7307, 7309, 7321, 7331, 7333, 7349, 7351, 7369, 7393, 7411, 7417, 7433, 7451, 7457, 7459, 7477, 7481, 7487, 7489, 7499, 7507, 7517, 7523, 7529, 7537, 7541, 7547, 7549, 7559, 7561, 7573, 7577, 7583, 7589, 7591, 7603, 7607, 7621, 7639, 7643, 7649, 7669, 7673, 7681, 7687, 7691, 7699, 7703, 7717, 7723, 7727, 7741, 7753, 7757, 7759, 7789, 7793, 7817, 7823, 7829, 7841, 7853, 7867, 7873, 7877, 7879, 7883, 7901, 7907, 7919, 7927, 7933, 7937, 7949, 7951, 7963, 7993, 8009, 8011, 8017, 8039, 8053, 8059, 8069, 8081, 8087, 8089, 8093, 8101, 8111, 8117, 8123, 8147, 8161, 8167, 8171, 8179, 8191, 8209, 8219, 8221, 8231, 8233, 8237, 8243, 8263, 8269, 8273, 8287, 8291, 8293, 8297, 8311, 8317, 8329, 8353, 8363, 8369, 8377, 8387, 8389, 8419, 8423, 8429, 8431, 8443, 8447, 8461, 8467, 8501, 8513, 8521, 8527, 8537, 8539, 8543, 8563, 8573, 8581, 8597, 8599, 8609, 8623, 8627, 8629, 8641, 8647, 8663, 8669, 8677, 8681, 8689, 8693, 8699, 8707, 8713, 8719, 8731, 8737, 8741, 8747, 8753, 8761, 8779, 8783, 8803, 8807, 8819, 8821, 8831, 8837, 8839, 8849, 8861, 8863, 8867, 8887, 8893, 8923, 8929, 8933, 8941, 8951, 8963, 8969, 8971, 8999, 9001, 9007, 9011, 9013, 9029, 9041, 9043, 9049, 9059, 9067, 9091, 9103, 9109, 9127, 9133, 9137, 9151, 9157, 9161, 9173, 9181, 9187, 9199, 9203, 9209, 9221, 9227, 9239, 9241, 9257, 9277, 9281, 9283, 9293, 9311, 9319, 9323, 9337, 9341, 9343, 9349, 9371, 9377, 9391, 9397, 9403, 9413, 9419, 9421, 9431, 9433, 9437, 9439, 9461, 9463, 9467, 9473, 9479, 9491, 9497, 9511, 9521, 9533, 9539, 9547, 9551, 9587, 9601, 9613, 9619, 9623, 9629, 9631, 9643, 9649, 9661, 9677, 9679, 9689, 9697, 9719, 9721, 9733, 9739, 9743, 9749, 9767, 9769, 9781, 9787, 9791, 9803, 9811, 9817, 9829, 9833, 9839, 9851, 9857, 9859, 9871, 9883, 9887, 9901, 9907, 9923, 9929, 9931, 9941, 9949, 9967, 9973];
|
|
12
|
-
if (nb === undefined) {
|
|
13
|
-
return primesValues;
|
|
14
|
-
} else {
|
|
15
|
-
return primesValues.slice(0, Math.min(primesValues.length, nb));
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Get the list of all dividers of a number.
|
|
21
|
-
* @param value
|
|
22
|
-
*/
|
|
23
|
-
static dividers(value: number): number[] {
|
|
24
|
-
let D: number[];
|
|
25
|
-
const maxV = Math.sqrt(Math.abs(value));
|
|
26
|
-
|
|
27
|
-
// Initialize the list of dividers.
|
|
28
|
-
D = [];
|
|
29
|
-
|
|
30
|
-
for (let i = 1; i <= maxV; i++) {
|
|
31
|
-
if (value % i === 0) {
|
|
32
|
-
D.push(i);
|
|
33
|
-
D.push(value / i);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// Order numbers.
|
|
38
|
-
D.sort(function (a, b) {
|
|
39
|
-
return a - b;
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
// Make sure the array of value is unique.
|
|
43
|
-
return [...new Set(D)];
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Great Common Divisor
|
|
48
|
-
* @param values : number values
|
|
49
|
-
*/
|
|
50
|
-
static gcd(...values: number[]): number {
|
|
51
|
-
// Define the gcd for two number
|
|
52
|
-
let gcd2 = function (a: number, b: number): number {
|
|
53
|
-
if (b === 0) {
|
|
54
|
-
return a;
|
|
55
|
-
}
|
|
56
|
-
return gcd2(b, a % b);
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
let g: number = 1,
|
|
60
|
-
i: number = 2;
|
|
61
|
-
|
|
62
|
-
// Nothing is given
|
|
63
|
-
if (values.length === 0) {
|
|
64
|
-
return 1;
|
|
65
|
-
}
|
|
66
|
-
// Only one number is given
|
|
67
|
-
if (values.length === 1) {
|
|
68
|
-
// The first number is zero
|
|
69
|
-
if (values[0] === 0) {
|
|
70
|
-
return 1;
|
|
71
|
-
}
|
|
72
|
-
// Return the number
|
|
73
|
-
return values[0];
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// We have at least 2 numbers.
|
|
77
|
-
g = gcd2(values[0], values[1]);
|
|
78
|
-
|
|
79
|
-
// The gcd of the two first value is one ? It's already finished.
|
|
80
|
-
if (g === 1) {
|
|
81
|
-
return 1;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// The current gcd isn't one. Continue with all next values.
|
|
85
|
-
for (i = 2; i < values.length; i++) {
|
|
86
|
-
g = gcd2(g, values[i]);
|
|
87
|
-
// Escape if gcd is already one.
|
|
88
|
-
if (g === 1) {
|
|
89
|
-
break;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return Math.abs(g);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
static divideNumbersByGCD(...values: number[]): number[] {
|
|
97
|
-
let gcd = Numeric.gcd(...values)
|
|
98
|
-
|
|
99
|
-
return values.map(x => x / gcd)
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Least Common Multiple
|
|
104
|
-
* @param values: list of numbers
|
|
105
|
-
*/
|
|
106
|
-
static lcm(...values: number[]): number {
|
|
107
|
-
return values.reduce(function (a, b) {
|
|
108
|
-
return Math.abs(a * b / Numeric.gcd(a, b));
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
static pythagoricianTripletsWithTarget(target: number, targetIsSquare?: boolean): number[][] {
|
|
113
|
-
// méthode inverse, à partir du triplet.
|
|
114
|
-
const triplets = [],
|
|
115
|
-
targetValue = targetIsSquare === true ? +target : target ** 2
|
|
116
|
-
for (let u = 0; u <= target; u++) {
|
|
117
|
-
for (let v = 0; v <= target; v++) {
|
|
118
|
-
if (u ** 2 + v ** 2 === targetValue) {
|
|
119
|
-
triplets.push([u, v, target])
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
return triplets
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
static numberCorrection(value: number, epsilonDigit: number = 1, epsilonNumberOfDigits: number = 10, number_of_digits: number = 8) {
|
|
128
|
-
return +value.toFixed(number_of_digits)
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
static periodic(value: number): number {
|
|
132
|
-
if (Number.isSafeInteger(value)) {
|
|
133
|
-
return 0
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// Assume it's with decimal.
|
|
137
|
-
let decimal = (value.toString()).split('.')[0]
|
|
138
|
-
|
|
139
|
-
// The decimal part is limited
|
|
140
|
-
if (decimal.length < 10) {
|
|
141
|
-
return 0
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
// Find the periodic if it exists.
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
static decompose(value: number): number[][] {
|
|
148
|
-
let dividers = Numeric.dividers(value),
|
|
149
|
-
limit = Math.sqrt(value),
|
|
150
|
-
arr = [],
|
|
151
|
-
u, v
|
|
152
|
-
|
|
153
|
-
while (dividers.length > 0) {
|
|
154
|
-
u = dividers.shift()
|
|
155
|
-
v = dividers.length > 0 ? dividers.pop() : +u
|
|
156
|
-
|
|
157
|
-
arr.push([u, v])
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
return arr
|
|
161
|
-
}
|
|
162
|
-
}
|
package/src/maths/numexp.ts
DELETED
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import {Shutingyard, ShutingyardMode, ShutingyardType, tokenConstant} from "./shutingyard";
|
|
2
|
-
import {Fraction} from "./coefficients/fraction";
|
|
3
|
-
|
|
4
|
-
export class NumExp {
|
|
5
|
-
private _rpn: { token: string, tokenType: string }[]
|
|
6
|
-
private _expression: string
|
|
7
|
-
private _isValid: boolean
|
|
8
|
-
|
|
9
|
-
constructor(value: string, uniformize?:boolean) {
|
|
10
|
-
this._expression = value
|
|
11
|
-
try {
|
|
12
|
-
this._rpn = new Shutingyard(ShutingyardMode.NUMERIC).parse(value, uniformize || uniformize===undefined).rpn
|
|
13
|
-
}catch(e){
|
|
14
|
-
this._rpn = null
|
|
15
|
-
this._isValid = false
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
get rpn(): { token: string; tokenType: string }[] {
|
|
20
|
-
return this._rpn;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
get isValid(): boolean {
|
|
24
|
-
if(this._isValid===undefined){
|
|
25
|
-
try {
|
|
26
|
-
const v = this.evaluate({x: 0})
|
|
27
|
-
}catch{
|
|
28
|
-
this._isValid = false
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return this._isValid
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
set isValid(value: boolean){
|
|
35
|
-
this._isValid = value
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
get expression(): string {
|
|
39
|
-
return this._expression;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
private _extractDecimalPart(value: number): string {
|
|
43
|
-
let decimal = value.toString()
|
|
44
|
-
|
|
45
|
-
if (!decimal.includes('.')) {
|
|
46
|
-
return ''
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
decimal = decimal.split('.')[1]
|
|
50
|
-
|
|
51
|
-
return decimal.substring(0, decimal.length - 2)
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
private _numberCorrection(value: number): number {
|
|
55
|
-
// Must modify the number if it's like:
|
|
56
|
-
// a: 3.0000000000000003
|
|
57
|
-
// b: 3.9999999999999994
|
|
58
|
-
// remove the last character
|
|
59
|
-
// check if around n last characters are either 0 or 9
|
|
60
|
-
// if it is, 'round' the number.
|
|
61
|
-
|
|
62
|
-
const epsilon = 0.00000000000001,
|
|
63
|
-
number_of_digits = 6
|
|
64
|
-
|
|
65
|
-
const decimal = this._extractDecimalPart(value)
|
|
66
|
-
if(decimal===''){return value}
|
|
67
|
-
|
|
68
|
-
const n9 = decimal.match(/9+$/g)
|
|
69
|
-
const n0 = decimal.match(/0+$/g)
|
|
70
|
-
|
|
71
|
-
if (n9 && n9[0].length >= number_of_digits) {
|
|
72
|
-
// New tested values.
|
|
73
|
-
const mod = this._extractDecimalPart(value + epsilon),
|
|
74
|
-
mod0 = mod.match(/0+$/g)
|
|
75
|
-
|
|
76
|
-
if(mod0 && mod0[0].length>= number_of_digits){
|
|
77
|
-
// The value can be changed. Remove all zeros!
|
|
78
|
-
return +((value+epsilon).toString().split(mod0[0])[0])
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (n0 && n0[0].length >= number_of_digits) {
|
|
83
|
-
// New tested values.
|
|
84
|
-
const mod = this._extractDecimalPart(value - epsilon),
|
|
85
|
-
mod9 = mod.match(/9+$/g)
|
|
86
|
-
|
|
87
|
-
if(mod9 && mod9[0].length>= number_of_digits){
|
|
88
|
-
// The value can be changed. Remove all nines!
|
|
89
|
-
return +(value.toString().split(n0[0])[0])
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return value
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
private _addToStack(stack:number[], value: number): void {
|
|
97
|
-
stack.push(this._numberCorrection(value))
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
evaluate(values?: { [Key: string]: number }): number {
|
|
101
|
-
const stack: number[] = []
|
|
102
|
-
|
|
103
|
-
if(this._rpn===null){
|
|
104
|
-
this._isValid = false
|
|
105
|
-
return 0
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
this.isValid = true
|
|
109
|
-
|
|
110
|
-
for (const element of this._rpn) {
|
|
111
|
-
if (element.tokenType === ShutingyardType.COEFFICIENT) {
|
|
112
|
-
// May be a numeric value or a Fraction.
|
|
113
|
-
if (!isNaN(+element.token)) {
|
|
114
|
-
this._addToStack(stack, +element.token)
|
|
115
|
-
} else {
|
|
116
|
-
this._addToStack(stack, new Fraction(element.token).value)
|
|
117
|
-
}
|
|
118
|
-
} else if (element.tokenType === ShutingyardType.VARIABLE) {
|
|
119
|
-
if (values[element.token] !== undefined) {
|
|
120
|
-
this._addToStack(stack, +values[element.token])
|
|
121
|
-
}
|
|
122
|
-
} else if (element.tokenType === ShutingyardType.CONSTANT) {
|
|
123
|
-
this._addToStack(stack, tokenConstant[element.token])
|
|
124
|
-
} else if (element.tokenType === ShutingyardType.OPERATION) {
|
|
125
|
-
if (element.token === '*') {
|
|
126
|
-
const b = stack.pop(),
|
|
127
|
-
a = stack.pop()
|
|
128
|
-
if(a === undefined || b === undefined){this.isValid = false}
|
|
129
|
-
this._addToStack(stack, a * b)
|
|
130
|
-
} else if (element.token === '/') {
|
|
131
|
-
const b = stack.pop(),
|
|
132
|
-
a = stack.pop()
|
|
133
|
-
if(a === undefined || b === undefined){this.isValid = false}
|
|
134
|
-
this._addToStack(stack, a / b)
|
|
135
|
-
} else if (element.token === '+') {
|
|
136
|
-
const b = stack.pop(),
|
|
137
|
-
a = stack.pop()
|
|
138
|
-
if(a === undefined || b === undefined){this.isValid = false}
|
|
139
|
-
this._addToStack(stack, (+a) + (+b))
|
|
140
|
-
} else if (element.token === '-') {
|
|
141
|
-
const b = stack.pop(),
|
|
142
|
-
a = stack.pop() || 0
|
|
143
|
-
if(b === undefined){this.isValid = false}
|
|
144
|
-
this._addToStack(stack, a - b)
|
|
145
|
-
} else if (element.token === '^') {
|
|
146
|
-
const b = stack.pop(),
|
|
147
|
-
a = stack.pop()
|
|
148
|
-
if(a === undefined || b === undefined){this.isValid = false}
|
|
149
|
-
this._addToStack(stack, Math.pow(a, b))
|
|
150
|
-
}
|
|
151
|
-
} else if (element.tokenType === ShutingyardType.FUNCTION) {
|
|
152
|
-
const a = stack.pop()
|
|
153
|
-
if(a === undefined){this.isValid = false}
|
|
154
|
-
if (element.token === 'sin') {
|
|
155
|
-
this._addToStack(stack, Math.sin(a))
|
|
156
|
-
} else if (element.token === 'cos') {
|
|
157
|
-
this._addToStack(stack, Math.cos(a))
|
|
158
|
-
} else if (element.token === 'tan') {
|
|
159
|
-
this._addToStack(stack, Math.tan(a))
|
|
160
|
-
} else if(element.token === 'sqrt') {
|
|
161
|
-
this._addToStack(stack, Math.sqrt(a))
|
|
162
|
-
}else if(element.token ==='nthrt') {
|
|
163
|
-
// TODO: support nthrt in num. exp.
|
|
164
|
-
let b = stack.pop()
|
|
165
|
-
if(a%2===0 && b<0){
|
|
166
|
-
this._addToStack(stack, NaN)
|
|
167
|
-
}else {
|
|
168
|
-
this._addToStack(stack, (b < 0 ? -1 : 1) * Math.pow(Math.abs(b), 1 / a))
|
|
169
|
-
}
|
|
170
|
-
} else if(element.token === 'ln'){
|
|
171
|
-
this._addToStack(stack, Math.log(a))
|
|
172
|
-
} else if(element.token === 'log') {
|
|
173
|
-
this._addToStack(stack, Math.log10(a))
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
if (stack.length === 1) {
|
|
179
|
-
return stack[0]
|
|
180
|
-
} else {
|
|
181
|
-
throw `There was a problem parsing: ${this._expression}`
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import {rndPolynom} from "./rndPolynom";
|
|
2
|
-
import {rndMonom} from "./rndMonom";
|
|
3
|
-
import {rndHelpers} from "./rndHelpers";
|
|
4
|
-
import {
|
|
5
|
-
randomCoefficientConfig,
|
|
6
|
-
randomGeometryCircleConfig,
|
|
7
|
-
randomGeometryLineConfig,
|
|
8
|
-
randomGeometryPointConfig,
|
|
9
|
-
randomMonomConfig,
|
|
10
|
-
randomPolynomConfig
|
|
11
|
-
} from "./rndTypes";
|
|
12
|
-
import {rndFraction} from "./rndFraction";
|
|
13
|
-
import {Polynom} from "../algebra/polynom";
|
|
14
|
-
import {Monom} from "../algebra/monom";
|
|
15
|
-
import {Fraction} from "../coefficients/fraction";
|
|
16
|
-
import {Line} from "../geometry/line";
|
|
17
|
-
import {rndGeometryLine} from "./rndGeometryLine";
|
|
18
|
-
import {Point} from "../geometry/point";
|
|
19
|
-
import {rndGeometryPoint} from "./rndGeometryPoint";
|
|
20
|
-
import {Circle} from "../geometry/circle";
|
|
21
|
-
import {rndGeometryCircle} from "./rndGeometryCircle";
|
|
22
|
-
|
|
23
|
-
export * from "./rndTypes"
|
|
24
|
-
|
|
25
|
-
export namespace Random {
|
|
26
|
-
export function polynom(config?: randomPolynomConfig): Polynom {
|
|
27
|
-
return (new rndPolynom(config)).generate()
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function monom(config?: randomMonomConfig): Monom {
|
|
31
|
-
return (new rndMonom(config)).generate()
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function fraction(config?: randomCoefficientConfig): Fraction {
|
|
35
|
-
return (new rndFraction(config)).generate()
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function number(from: number, to: number, exclude?: number[]): number {
|
|
39
|
-
return rndHelpers.randomInt(from, to, exclude)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export function numberSym(max: number, allowZero?: boolean): number {
|
|
43
|
-
return rndHelpers.randomIntSym(max, allowZero)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function prime(max: number): number {
|
|
47
|
-
return rndHelpers.randomPrime(max)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function bool(percent?: number): boolean {
|
|
51
|
-
return rndHelpers.randomBool(percent)
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export function array(arr: any[], number?: number): any[] {
|
|
55
|
-
return rndHelpers.randomArray(arr, number)
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export function item(arr: any[]): any {
|
|
59
|
-
return rndHelpers.randomItem(arr)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export function shuffle(arr: any[]): any[] {
|
|
63
|
-
return rndHelpers.shuffleArray(arr)
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export namespace Geometry {
|
|
67
|
-
export function line(config?: randomGeometryLineConfig): Line {
|
|
68
|
-
return (new rndGeometryLine(config).generate())
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export function point(config?: randomGeometryPointConfig): Point {
|
|
72
|
-
return (new rndGeometryPoint(config).generate())
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export function circle(config?: randomGeometryCircleConfig): Circle {
|
|
76
|
-
return (new rndGeometryCircle(config).generate())
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export class randomCore {
|
|
2
|
-
protected _config: Object
|
|
3
|
-
protected _defaultConfig: Object
|
|
4
|
-
mergeConfig = (config: Object, defaultConfig: Object): Object => {
|
|
5
|
-
if (config !== undefined) {
|
|
6
|
-
return {...defaultConfig, ...config}
|
|
7
|
-
}
|
|
8
|
-
return defaultConfig
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
generate = (): unknown => {
|
|
12
|
-
return undefined
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
config = (config: Object): randomCore => {
|
|
16
|
-
this._config = this.mergeConfig(config, this._defaultConfig)
|
|
17
|
-
return this
|
|
18
|
-
}
|
|
19
|
-
}
|