pimath 0.0.119 → 0.0.121

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. package/.eslintrc.js +23 -23
  2. package/.idea/PI.iml +7 -1
  3. package/dev/pimath.js +7929 -0
  4. package/dev/pimath.js.map +1 -0
  5. package/dist/{pi.js → pimath.js} +7612 -7829
  6. package/dist/pimath.js.map +1 -0
  7. package/dist/pimath.min.js +2 -0
  8. package/dist/pimath.min.js.map +1 -0
  9. package/docs/assets/main.js +3 -3
  10. package/docs/assets/search.js +1 -1
  11. package/docs/assets/style.css +450 -363
  12. package/docs/classes/Logicalset.Logicalset.html +119 -110
  13. package/docs/classes/Polynom.Rational.html +230 -227
  14. package/docs/classes/Vector-1.Vector.html +319 -273
  15. package/docs/classes/Vector.Point.html +189 -190
  16. package/docs/classes/algebra_equation.Equation.html +489 -446
  17. package/docs/classes/algebra_linearSystem.LinearSystem.html +228 -217
  18. package/docs/classes/algebra_monom.Monom.html +564 -507
  19. package/docs/classes/algebra_polynom.Polynom.html +774 -753
  20. package/docs/classes/coefficients_fraction.Fraction.html +573 -565
  21. package/docs/classes/geometry_circle.Circle.html +299 -299
  22. package/docs/classes/geometry_line.Line.html +511 -451
  23. package/docs/classes/geometry_triangle.Triangle.html +273 -264
  24. package/docs/classes/numeric.Numeric.html +138 -132
  25. package/docs/classes/shutingyard.Shutingyard.html +144 -133
  26. package/docs/enums/algebra_equation.PARTICULAR_SOLUTION.html +47 -46
  27. package/docs/enums/geometry_line.LinePropriety.html +58 -58
  28. package/docs/enums/shutingyard.ShutingyardMode.html +62 -58
  29. package/docs/enums/shutingyard.ShutingyardType.html +74 -70
  30. package/docs/index.html +31 -33
  31. package/docs/interfaces/algebra_equation.ISolution.html +61 -59
  32. package/docs/interfaces/algebra_polynom.IEuclidian.html +47 -46
  33. package/docs/interfaces/geometry_triangle.remarquableLines.html +74 -74
  34. package/docs/modules/Logicalset.html +33 -38
  35. package/docs/modules/Polynom.html +33 -38
  36. package/docs/modules/Vector-1.html +33 -38
  37. package/docs/modules/Vector.html +33 -38
  38. package/docs/modules/algebra_equation.html +35 -41
  39. package/docs/modules/algebra_linearSystem.html +31 -37
  40. package/docs/modules/algebra_monom.html +33 -39
  41. package/docs/modules/algebra_polynom.html +35 -41
  42. package/docs/modules/coefficients_fraction.html +33 -39
  43. package/docs/modules/geometry_circle.html +31 -37
  44. package/docs/modules/geometry_line.html +33 -39
  45. package/docs/modules/geometry_triangle.html +33 -39
  46. package/docs/modules/numeric.html +31 -37
  47. package/docs/modules/shutingyard.html +41 -47
  48. package/docs/types/algebra_monom.literalType.html +33 -37
  49. package/docs/types/algebra_polynom.PolynomParsingType.html +33 -37
  50. package/docs/types/coefficients_fraction.FractionParsingType.html +32 -36
  51. package/docs/types/shutingyard.Token.html +38 -42
  52. package/docs/types/shutingyard.tokenType.html +40 -44
  53. package/docs/variables/shutingyard.tokenConstant.html +37 -41
  54. package/esm/index.d.ts +38 -41
  55. package/esm/index.js +43 -46
  56. package/esm/index.js.map +1 -1
  57. package/esm/maths/algebra/equation.d.ts +119 -117
  58. package/esm/maths/algebra/equation.js +796 -785
  59. package/esm/maths/algebra/equation.js.map +1 -1
  60. package/esm/maths/algebra/linearSystem.d.ts +39 -38
  61. package/esm/maths/algebra/linearSystem.js +278 -262
  62. package/esm/maths/algebra/linearSystem.js.map +1 -1
  63. package/esm/maths/algebra/logicalset.d.ts +28 -28
  64. package/esm/maths/algebra/logicalset.js +157 -157
  65. package/esm/maths/algebra/monom.d.ts +206 -206
  66. package/esm/maths/algebra/monom.js +908 -908
  67. package/esm/maths/algebra/monom.js.map +1 -1
  68. package/esm/maths/algebra/polynom.d.ts +157 -157
  69. package/esm/maths/algebra/polynom.js +1277 -1277
  70. package/esm/maths/algebra/rational.d.ts +45 -45
  71. package/esm/maths/algebra/rational.js +183 -183
  72. package/esm/maths/algebra/study/rationalStudy.d.ts +28 -28
  73. package/esm/maths/algebra/study/rationalStudy.js +243 -243
  74. package/esm/maths/algebra/study.d.ts +142 -142
  75. package/esm/maths/algebra/study.js +377 -377
  76. package/esm/maths/algebra/study.js.map +1 -1
  77. package/esm/maths/coefficients/fraction.d.ts +90 -90
  78. package/esm/maths/coefficients/fraction.js +516 -516
  79. package/esm/maths/coefficients/fraction.js.map +1 -1
  80. package/esm/maths/coefficients/nthRoot.d.ts +23 -23
  81. package/esm/maths/coefficients/nthRoot.js +136 -136
  82. package/esm/maths/geometry/circle.d.ts +45 -45
  83. package/esm/maths/geometry/circle.js +323 -323
  84. package/esm/maths/geometry/line.d.ts +99 -99
  85. package/esm/maths/geometry/line.js +481 -481
  86. package/esm/maths/geometry/line.js.map +1 -1
  87. package/esm/maths/geometry/point.d.ts +34 -34
  88. package/esm/maths/geometry/point.js +166 -166
  89. package/esm/maths/geometry/point.js.map +1 -1
  90. package/esm/maths/geometry/triangle.d.ts +85 -85
  91. package/esm/maths/geometry/triangle.js +268 -268
  92. package/esm/maths/geometry/vector.d.ts +41 -41
  93. package/esm/maths/geometry/vector.js +197 -197
  94. package/esm/maths/geometry/vector.js.map +1 -1
  95. package/esm/maths/numeric.d.ts +28 -28
  96. package/esm/maths/numeric.js +180 -169
  97. package/esm/maths/numeric.js.map +1 -1
  98. package/esm/maths/numexp.d.ts +19 -0
  99. package/esm/maths/numexp.js +186 -0
  100. package/esm/maths/numexp.js.map +1 -0
  101. package/esm/maths/randomization/random.d.ts +23 -23
  102. package/esm/maths/randomization/random.js +78 -78
  103. package/esm/maths/randomization/random.js.map +1 -1
  104. package/esm/maths/randomization/randomCore.d.ts +7 -7
  105. package/esm/maths/randomization/randomCore.js +21 -21
  106. package/esm/maths/randomization/rndFraction.d.ts +12 -12
  107. package/esm/maths/randomization/rndFraction.js +43 -43
  108. package/esm/maths/randomization/rndGeometryLine.d.ts +12 -12
  109. package/esm/maths/randomization/rndGeometryLine.js +45 -45
  110. package/esm/maths/randomization/rndGeometryPoint.d.ts +12 -12
  111. package/esm/maths/randomization/rndGeometryPoint.js +60 -60
  112. package/esm/maths/randomization/rndHelpers.d.ts +23 -23
  113. package/esm/maths/randomization/rndHelpers.js +76 -76
  114. package/esm/maths/randomization/rndMonom.d.ts +12 -12
  115. package/esm/maths/randomization/rndMonom.js +52 -52
  116. package/esm/maths/randomization/rndPolynom.d.ts +13 -13
  117. package/esm/maths/randomization/rndPolynom.js +74 -74
  118. package/esm/maths/randomization/rndTypes.d.ts +34 -34
  119. package/esm/maths/randomization/rndTypes.js +2 -2
  120. package/esm/maths/shutingyard.d.ts +59 -59
  121. package/esm/maths/shutingyard.js +442 -442
  122. package/esm/maths/shutingyard.js.map +1 -1
  123. package/package.json +11 -11
  124. package/public/index.html +50 -81
  125. package/public/playground.html +7 -8
  126. package/src/index.ts +2 -5
  127. package/src/maths/algebra/equation.ts +16 -0
  128. package/src/maths/algebra/linearSystem.ts +20 -0
  129. package/src/maths/algebra/study.ts +1 -1
  130. package/src/maths/numeric.ts +49 -48
  131. package/src/maths/{expressions/numexp.ts → numexp.ts} +2 -2
  132. package/tests/algebra/equation.test.ts +19 -5
  133. package/tests/algebra/linear.test.ts +3 -11
  134. package/tests/algebra/polynom.test.ts +7 -8
  135. package/tests/algebra/rationnal.test.ts +1 -1
  136. package/tests/algebra/study.test.ts +2 -9
  137. package/tests/coefficients/fraction.test.ts +8 -8
  138. package/tests/custom.test.ts +33 -37
  139. package/tests/numeric.test.ts +1 -2
  140. package/tests/numexp.test.ts +1 -5
  141. package/tests/shutingyard.test.ts +3 -3
  142. package/webpack-production-min.config.js +1 -1
  143. package/webpack-production.config.js +1 -1
  144. package/webpack.config.js +1 -1
  145. package/dist/pi.js.map +0 -1
  146. package/dist/pi.min.js +0 -2
  147. package/dist/pi.min.js.map +0 -1
  148. package/docs/classes/expressions_numexp.NumExp.html +0 -236
  149. package/docs/classes/expressions_polynomexp.PolynomExpFactor.html +0 -317
  150. package/docs/classes/expressions_polynomexp.PolynomExpProduct.html +0 -285
  151. package/docs/modules/expressions_numexp.html +0 -71
  152. package/docs/modules/expressions_polynomexp.html +0 -73
  153. package/docs/modules.html +0 -76
  154. package/graph.svg +0 -1033
  155. package/src/maths/expressions/ExpressionTree.ts +0 -172
  156. package/src/maths/expressions/expression.ts +0 -286
  157. package/src/maths/expressions/expressionFactor.ts +0 -190
  158. package/src/maths/expressions/expressionMember.ts +0 -233
  159. package/src/maths/expressions/expressionOperators.ts +0 -49
  160. package/src/maths/expressions/expressionParser.ts +0 -295
  161. package/src/maths/expressions/factors/ExpFactor.ts +0 -39
  162. package/src/maths/expressions/factors/ExpFactorConstant.ts +0 -60
  163. package/src/maths/expressions/factors/ExpFactorExponential.ts +0 -26
  164. package/src/maths/expressions/factors/ExpFactorNumber.ts +0 -72
  165. package/src/maths/expressions/factors/ExpFactorPower.ts +0 -42
  166. package/src/maths/expressions/factors/ExpFactorTrigo.ts +0 -53
  167. package/src/maths/expressions/factors/ExpFactorVariable.ts +0 -45
  168. package/src/maths/expressions/internals.ts +0 -14
  169. package/src/maths/expressions/polynomexp.bkp.ts +0 -221
  170. package/src/maths/expressions/polynomexp.ts +0 -310
  171. package/tests/expressions/expressions.test.ts +0 -145
  172. package/tests/expressions/expressiontree.test.ts +0 -11
  173. package/tests/polynomexp.test.ts +0 -12
@@ -1,269 +1,269 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Triangle = void 0;
4
- const point_1 = require("./point");
5
- const fraction_1 = require("../coefficients/fraction");
6
- const vector_1 = require("./vector");
7
- const line_1 = require("./line");
8
- const equation_1 = require("../algebra/equation");
9
- class Triangle {
10
- constructor(...values) {
11
- // ------------------------------------------
12
- // Creation / parsing functions
13
- // ------------------------------------------
14
- /**
15
- * Parse values to a triangle. Supported formats:
16
- * Point, Point, Point
17
- * x1, y1, x2, y2, x3, y3
18
- * TODO: Something else ?
19
- * @param values
20
- */
21
- this.parse = (...values) => {
22
- if (values.length === 6) {
23
- // Check if all values are number or fractions.
24
- let v = values.map((x) => new fraction_1.Fraction(x));
25
- return this.parse(new point_1.Point(v[0], v[1]), new point_1.Point(v[2], v[3]), new point_1.Point(v[4], v[5]));
26
- }
27
- else if (values.length === 3) {
28
- // Possibilities:
29
- // - Three points (or part of points, only dict for example, or array (TODO: Add the array syntax for point)
30
- // - Three lines
31
- // - Three lines as text.
32
- if (values.filter((x) => typeof x === 'string').length === 3) {
33
- return this.parse(...values.map((x) => new line_1.Line(x)));
34
- }
35
- else if (values.filter((x) => x instanceof line_1.Line).length === 3) {
36
- // We have three lines
37
- this._lines = {
38
- 'AB': values[0],
39
- 'BC': values[1],
40
- 'AC': values[2]
41
- };
42
- // Get the intersection points -> build the triangle using these intersection points.
43
- let intersect = values[0].intersection(values[1]);
44
- if (intersect.hasIntersection) {
45
- this._B = intersect.point.clone();
46
- }
47
- else {
48
- return this;
49
- }
50
- intersect = values[1].intersection(values[2]);
51
- if (intersect.hasIntersection) {
52
- this._C = intersect.point.clone();
53
- }
54
- else {
55
- return this;
56
- }
57
- intersect = values[2].intersection(values[0]);
58
- if (intersect.hasIntersection) {
59
- this._A = intersect.point.clone();
60
- }
61
- else {
62
- return this;
63
- }
64
- }
65
- else {
66
- // At least, one of the value is not a point.
67
- if (values.filter((x) => (x instanceof point_1.Point)).length < 3) {
68
- return this.parse(new point_1.Point(values[0]), new point_1.Point(values[1]), new point_1.Point(values[2]));
69
- }
70
- // We have three points.
71
- this._A = values[0].clone();
72
- this._B = values[1].clone();
73
- this._C = values[2].clone();
74
- this._lines = {
75
- 'AB': new line_1.Line(this._A, this._B),
76
- 'BC': new line_1.Line(this._B, this._C),
77
- 'AC': new line_1.Line(this._A, this._C)
78
- };
79
- }
80
- }
81
- else if (values.length === 1) {
82
- if (values[0] instanceof Triangle) {
83
- return values[0].clone();
84
- }
85
- }
86
- this._updateTriangle();
87
- return this;
88
- };
89
- /**
90
- * Clone the Triangle class
91
- */
92
- this.clone = () => {
93
- this._A = this._A.clone();
94
- this._B = this._B.clone();
95
- this._C = this._C.clone();
96
- this._lines = {
97
- 'AB': this._lines.AB.clone(),
98
- 'BC': this._lines.BC.clone(),
99
- 'AC': this._lines.AC.clone()
100
- };
101
- this._updateTriangle();
102
- return this;
103
- };
104
- // ------------------------------------------
105
- // Triangle operations and properties
106
- // ------------------------------------------
107
- /**
108
- * Generate the Line object for the three segments of the triangle
109
- */
110
- this._updateTriangle = () => {
111
- this._middles = {
112
- 'AB': new point_1.Point().middleOf(this._A, this._B),
113
- 'AC': new point_1.Point().middleOf(this._A, this._C),
114
- 'BC': new point_1.Point().middleOf(this._B, this._C)
115
- };
116
- this._remarquables = this._calculateRemarquableLines();
117
- };
118
- /**
119
- * Get the Point class for the given name
120
- * @param ptName
121
- */
122
- this.getPointByName = (ptName) => {
123
- switch (ptName.toUpperCase()) {
124
- case 'A':
125
- return this._A;
126
- case 'B':
127
- return this._B;
128
- case 'C':
129
- return this._C;
130
- }
131
- // Something went wrong ! Return the first point
132
- return this._A;
133
- };
134
- /**
135
- * Get the vector for the segment given by name.
136
- * @param ptName1
137
- * @param ptName2
138
- */
139
- this.getSegment = (ptName1, ptName2) => {
140
- return new vector_1.Vector(this.getPointByName(ptName1), this.getPointByName(ptName2));
141
- };
142
- this._calculateRemarquableLines = () => {
143
- let remarquables = {
144
- 'medians': {
145
- 'A': new line_1.Line(this._A, this._middles.BC),
146
- 'B': new line_1.Line(this._B, this._middles.AC),
147
- 'C': new line_1.Line(this._C, this._middles.AB),
148
- 'intersection': null
149
- },
150
- 'mediators': {
151
- 'AB': new line_1.Line(this._middles.AB, new vector_1.Vector(this._A, this._B).normal()),
152
- 'AC': new line_1.Line(this._middles.AC, new vector_1.Vector(this._A, this._C).normal()),
153
- 'BC': new line_1.Line(this._middles.BC, new vector_1.Vector(this._B, this._C).normal()),
154
- 'intersection': null
155
- },
156
- 'heights': {
157
- 'A': new line_1.Line(this._A, new vector_1.Vector(this._B, this._C).normal()),
158
- 'B': new line_1.Line(this._B, new vector_1.Vector(this._A, this._C).normal()),
159
- 'C': new line_1.Line(this._C, new vector_1.Vector(this._A, this._B).normal()),
160
- 'intersection': null
161
- },
162
- 'bisectors': {
163
- 'A': this._calculateBisectors('A'),
164
- 'B': this._calculateBisectors('B'),
165
- 'C': this._calculateBisectors('C'),
166
- 'intersection': null
167
- }
168
- };
169
- // As it's a triangle, we assume the lines are intersecting and aren't parallel or superposed.
170
- remarquables.medians.intersection = remarquables.medians.A.intersection(remarquables.medians.B).point;
171
- remarquables.mediators.intersection = remarquables.mediators.AB.intersection(remarquables.mediators.BC).point;
172
- remarquables.heights.intersection = remarquables.heights.A.intersection(remarquables.heights.B).point;
173
- remarquables.bisectors.intersection = remarquables.bisectors.A.intersection(remarquables.bisectors.B).point;
174
- // Everything was calculated for the remarquable lines.
175
- return remarquables;
176
- };
177
- this._calculateBisectors = (pt) => {
178
- let tlines = this.lines, d1, d2;
179
- if (pt === 'A') {
180
- d1 = tlines.AB;
181
- d2 = tlines.AC;
182
- }
183
- else if (pt === 'B') {
184
- d1 = tlines.AB;
185
- d2 = tlines.BC;
186
- }
187
- else if (pt === 'C') {
188
- d1 = tlines.BC;
189
- d2 = tlines.AC;
190
- }
191
- let b1 = new line_1.Line(new equation_1.Equation(d1.equation.left.clone().multiply(d2.n.simplify().norm), d2.equation.left.clone().multiply(d1.n.simplify().norm)).reorder(true).simplify()), b2 = new line_1.Line(new equation_1.Equation(d1.equation.left.clone().multiply(d2.n.simplify().norm), d2.equation.left.clone().multiply(d1.n.simplify().norm).opposed()).reorder(true).simplify());
192
- // Must determine which bisectors is in the triangle
193
- if (pt === 'A') {
194
- return b1.hitSegment(this.B, this.C) ? b1 : b2;
195
- }
196
- if (pt === 'B') {
197
- return b1.hitSegment(this.A, this.C) ? b1 : b2;
198
- }
199
- if (pt === 'C') {
200
- return b1.hitSegment(this.B, this.A) ? b1 : b2;
201
- }
202
- // Default returns the first bisector
203
- return b1;
204
- };
205
- if (values.length > 0) {
206
- this.parse(...values);
207
- }
208
- return this;
209
- }
210
- // ------------------------------------------
211
- // Getter and setters
212
- // ------------------------------------------
213
- get A() {
214
- return this._A;
215
- }
216
- get B() {
217
- return this._B;
218
- }
219
- get C() {
220
- return this._C;
221
- }
222
- get AB() {
223
- return this.getSegment('A', 'B');
224
- }
225
- get BA() {
226
- return this.getSegment('B', 'A');
227
- }
228
- get BC() {
229
- return this.getSegment('B', 'C');
230
- }
231
- get CB() {
232
- return this.getSegment('C', 'B');
233
- }
234
- get AC() {
235
- return this.getSegment('A', 'C');
236
- }
237
- get CA() {
238
- return this.getSegment('C', 'A');
239
- }
240
- get isRectangle() {
241
- if (this.AB.isNormalTo(this.BC)) {
242
- return true;
243
- }
244
- if (this.AB.isNormalTo(this.AC)) {
245
- return true;
246
- }
247
- if (this.BC.isNormalTo(this.AC)) {
248
- return true;
249
- }
250
- return false;
251
- }
252
- get isEquilateral() {
253
- return this.AB.normSquare.isEqual(this.BC.normSquare) &&
254
- this.AB.normSquare.isEqual(this.AC.normSquare);
255
- }
256
- get isIsocele() {
257
- return this.AB.normSquare.isEqual(this.BC.normSquare) ||
258
- this.AB.normSquare.isEqual(this.AC.normSquare) ||
259
- this.BC.normSquare.isEqual(this.AC.normSquare);
260
- }
261
- get lines() {
262
- return this._lines;
263
- }
264
- get remarquables() {
265
- return this._remarquables;
266
- }
267
- }
268
- exports.Triangle = Triangle;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Triangle = void 0;
4
+ const point_1 = require("./point");
5
+ const fraction_1 = require("../coefficients/fraction");
6
+ const vector_1 = require("./vector");
7
+ const line_1 = require("./line");
8
+ const equation_1 = require("../algebra/equation");
9
+ class Triangle {
10
+ constructor(...values) {
11
+ // ------------------------------------------
12
+ // Creation / parsing functions
13
+ // ------------------------------------------
14
+ /**
15
+ * Parse values to a triangle. Supported formats:
16
+ * Point, Point, Point
17
+ * x1, y1, x2, y2, x3, y3
18
+ * TODO: Something else ?
19
+ * @param values
20
+ */
21
+ this.parse = (...values) => {
22
+ if (values.length === 6) {
23
+ // Check if all values are number or fractions.
24
+ let v = values.map((x) => new fraction_1.Fraction(x));
25
+ return this.parse(new point_1.Point(v[0], v[1]), new point_1.Point(v[2], v[3]), new point_1.Point(v[4], v[5]));
26
+ }
27
+ else if (values.length === 3) {
28
+ // Possibilities:
29
+ // - Three points (or part of points, only dict for example, or array (TODO: Add the array syntax for point)
30
+ // - Three lines
31
+ // - Three lines as text.
32
+ if (values.filter((x) => typeof x === 'string').length === 3) {
33
+ return this.parse(...values.map((x) => new line_1.Line(x)));
34
+ }
35
+ else if (values.filter((x) => x instanceof line_1.Line).length === 3) {
36
+ // We have three lines
37
+ this._lines = {
38
+ 'AB': values[0],
39
+ 'BC': values[1],
40
+ 'AC': values[2]
41
+ };
42
+ // Get the intersection points -> build the triangle using these intersection points.
43
+ let intersect = values[0].intersection(values[1]);
44
+ if (intersect.hasIntersection) {
45
+ this._B = intersect.point.clone();
46
+ }
47
+ else {
48
+ return this;
49
+ }
50
+ intersect = values[1].intersection(values[2]);
51
+ if (intersect.hasIntersection) {
52
+ this._C = intersect.point.clone();
53
+ }
54
+ else {
55
+ return this;
56
+ }
57
+ intersect = values[2].intersection(values[0]);
58
+ if (intersect.hasIntersection) {
59
+ this._A = intersect.point.clone();
60
+ }
61
+ else {
62
+ return this;
63
+ }
64
+ }
65
+ else {
66
+ // At least, one of the value is not a point.
67
+ if (values.filter((x) => (x instanceof point_1.Point)).length < 3) {
68
+ return this.parse(new point_1.Point(values[0]), new point_1.Point(values[1]), new point_1.Point(values[2]));
69
+ }
70
+ // We have three points.
71
+ this._A = values[0].clone();
72
+ this._B = values[1].clone();
73
+ this._C = values[2].clone();
74
+ this._lines = {
75
+ 'AB': new line_1.Line(this._A, this._B),
76
+ 'BC': new line_1.Line(this._B, this._C),
77
+ 'AC': new line_1.Line(this._A, this._C)
78
+ };
79
+ }
80
+ }
81
+ else if (values.length === 1) {
82
+ if (values[0] instanceof Triangle) {
83
+ return values[0].clone();
84
+ }
85
+ }
86
+ this._updateTriangle();
87
+ return this;
88
+ };
89
+ /**
90
+ * Clone the Triangle class
91
+ */
92
+ this.clone = () => {
93
+ this._A = this._A.clone();
94
+ this._B = this._B.clone();
95
+ this._C = this._C.clone();
96
+ this._lines = {
97
+ 'AB': this._lines.AB.clone(),
98
+ 'BC': this._lines.BC.clone(),
99
+ 'AC': this._lines.AC.clone()
100
+ };
101
+ this._updateTriangle();
102
+ return this;
103
+ };
104
+ // ------------------------------------------
105
+ // Triangle operations and properties
106
+ // ------------------------------------------
107
+ /**
108
+ * Generate the Line object for the three segments of the triangle
109
+ */
110
+ this._updateTriangle = () => {
111
+ this._middles = {
112
+ 'AB': new point_1.Point().middleOf(this._A, this._B),
113
+ 'AC': new point_1.Point().middleOf(this._A, this._C),
114
+ 'BC': new point_1.Point().middleOf(this._B, this._C)
115
+ };
116
+ this._remarquables = this._calculateRemarquableLines();
117
+ };
118
+ /**
119
+ * Get the Point class for the given name
120
+ * @param ptName
121
+ */
122
+ this.getPointByName = (ptName) => {
123
+ switch (ptName.toUpperCase()) {
124
+ case 'A':
125
+ return this._A;
126
+ case 'B':
127
+ return this._B;
128
+ case 'C':
129
+ return this._C;
130
+ }
131
+ // Something went wrong ! Return the first point
132
+ return this._A;
133
+ };
134
+ /**
135
+ * Get the vector for the segment given by name.
136
+ * @param ptName1
137
+ * @param ptName2
138
+ */
139
+ this.getSegment = (ptName1, ptName2) => {
140
+ return new vector_1.Vector(this.getPointByName(ptName1), this.getPointByName(ptName2));
141
+ };
142
+ this._calculateRemarquableLines = () => {
143
+ let remarquables = {
144
+ 'medians': {
145
+ 'A': new line_1.Line(this._A, this._middles.BC),
146
+ 'B': new line_1.Line(this._B, this._middles.AC),
147
+ 'C': new line_1.Line(this._C, this._middles.AB),
148
+ 'intersection': null
149
+ },
150
+ 'mediators': {
151
+ 'AB': new line_1.Line(this._middles.AB, new vector_1.Vector(this._A, this._B).normal()),
152
+ 'AC': new line_1.Line(this._middles.AC, new vector_1.Vector(this._A, this._C).normal()),
153
+ 'BC': new line_1.Line(this._middles.BC, new vector_1.Vector(this._B, this._C).normal()),
154
+ 'intersection': null
155
+ },
156
+ 'heights': {
157
+ 'A': new line_1.Line(this._A, new vector_1.Vector(this._B, this._C).normal()),
158
+ 'B': new line_1.Line(this._B, new vector_1.Vector(this._A, this._C).normal()),
159
+ 'C': new line_1.Line(this._C, new vector_1.Vector(this._A, this._B).normal()),
160
+ 'intersection': null
161
+ },
162
+ 'bisectors': {
163
+ 'A': this._calculateBisectors('A'),
164
+ 'B': this._calculateBisectors('B'),
165
+ 'C': this._calculateBisectors('C'),
166
+ 'intersection': null
167
+ }
168
+ };
169
+ // As it's a triangle, we assume the lines are intersecting and aren't parallel or superposed.
170
+ remarquables.medians.intersection = remarquables.medians.A.intersection(remarquables.medians.B).point;
171
+ remarquables.mediators.intersection = remarquables.mediators.AB.intersection(remarquables.mediators.BC).point;
172
+ remarquables.heights.intersection = remarquables.heights.A.intersection(remarquables.heights.B).point;
173
+ remarquables.bisectors.intersection = remarquables.bisectors.A.intersection(remarquables.bisectors.B).point;
174
+ // Everything was calculated for the remarquable lines.
175
+ return remarquables;
176
+ };
177
+ this._calculateBisectors = (pt) => {
178
+ let tlines = this.lines, d1, d2;
179
+ if (pt === 'A') {
180
+ d1 = tlines.AB;
181
+ d2 = tlines.AC;
182
+ }
183
+ else if (pt === 'B') {
184
+ d1 = tlines.AB;
185
+ d2 = tlines.BC;
186
+ }
187
+ else if (pt === 'C') {
188
+ d1 = tlines.BC;
189
+ d2 = tlines.AC;
190
+ }
191
+ let b1 = new line_1.Line(new equation_1.Equation(d1.equation.left.clone().multiply(d2.n.simplify().norm), d2.equation.left.clone().multiply(d1.n.simplify().norm)).reorder(true).simplify()), b2 = new line_1.Line(new equation_1.Equation(d1.equation.left.clone().multiply(d2.n.simplify().norm), d2.equation.left.clone().multiply(d1.n.simplify().norm).opposed()).reorder(true).simplify());
192
+ // Must determine which bisectors is in the triangle
193
+ if (pt === 'A') {
194
+ return b1.hitSegment(this.B, this.C) ? b1 : b2;
195
+ }
196
+ if (pt === 'B') {
197
+ return b1.hitSegment(this.A, this.C) ? b1 : b2;
198
+ }
199
+ if (pt === 'C') {
200
+ return b1.hitSegment(this.B, this.A) ? b1 : b2;
201
+ }
202
+ // Default returns the first bisector
203
+ return b1;
204
+ };
205
+ if (values.length > 0) {
206
+ this.parse(...values);
207
+ }
208
+ return this;
209
+ }
210
+ // ------------------------------------------
211
+ // Getter and setters
212
+ // ------------------------------------------
213
+ get A() {
214
+ return this._A;
215
+ }
216
+ get B() {
217
+ return this._B;
218
+ }
219
+ get C() {
220
+ return this._C;
221
+ }
222
+ get AB() {
223
+ return this.getSegment('A', 'B');
224
+ }
225
+ get BA() {
226
+ return this.getSegment('B', 'A');
227
+ }
228
+ get BC() {
229
+ return this.getSegment('B', 'C');
230
+ }
231
+ get CB() {
232
+ return this.getSegment('C', 'B');
233
+ }
234
+ get AC() {
235
+ return this.getSegment('A', 'C');
236
+ }
237
+ get CA() {
238
+ return this.getSegment('C', 'A');
239
+ }
240
+ get isRectangle() {
241
+ if (this.AB.isNormalTo(this.BC)) {
242
+ return true;
243
+ }
244
+ if (this.AB.isNormalTo(this.AC)) {
245
+ return true;
246
+ }
247
+ if (this.BC.isNormalTo(this.AC)) {
248
+ return true;
249
+ }
250
+ return false;
251
+ }
252
+ get isEquilateral() {
253
+ return this.AB.normSquare.isEqual(this.BC.normSquare) &&
254
+ this.AB.normSquare.isEqual(this.AC.normSquare);
255
+ }
256
+ get isIsocele() {
257
+ return this.AB.normSquare.isEqual(this.BC.normSquare) ||
258
+ this.AB.normSquare.isEqual(this.AC.normSquare) ||
259
+ this.BC.normSquare.isEqual(this.AC.normSquare);
260
+ }
261
+ get lines() {
262
+ return this._lines;
263
+ }
264
+ get remarquables() {
265
+ return this._remarquables;
266
+ }
267
+ }
268
+ exports.Triangle = Triangle;
269
269
  //# sourceMappingURL=triangle.js.map
@@ -1,41 +1,41 @@
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 { Point } from "./point";
7
- export declare class Vector {
8
- private _x;
9
- private _y;
10
- constructor(...values: unknown[]);
11
- get x(): Fraction;
12
- set x(value: Fraction | number | string);
13
- get y(): Fraction;
14
- set y(value: Fraction | number | string);
15
- get normSquare(): Fraction;
16
- get norm(): number;
17
- get tex(): string;
18
- get asPoint(): Point;
19
- parse: (...values: any) => Vector;
20
- clone: () => Vector;
21
- reset: () => Vector;
22
- zero: () => Vector;
23
- one: () => Vector;
24
- private _parseString;
25
- opposed: () => Vector;
26
- add: (V: Vector) => Vector;
27
- subtract: (V: Vector) => Vector;
28
- scalarProductWithVector: (V: Vector) => Fraction;
29
- determinantWithVector: (V: Vector) => Fraction;
30
- static scalarProduct: (v1: Vector, v2: Vector) => Fraction;
31
- static determinant: (v1: Vector, v2: Vector) => Fraction;
32
- normal: () => Vector;
33
- isColinearTo: (v: Vector) => boolean;
34
- isNormalTo: (v: Vector) => boolean;
35
- get isNull(): boolean;
36
- multiplyByScalar: (k: any) => Vector;
37
- divideByScalar: (k: any) => Vector;
38
- simplify: () => Vector;
39
- simplifyDirection: () => Vector;
40
- angleWith: (V: Vector, sharp?: Boolean, radian?: Boolean) => number;
41
- }
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 { Point } from "./point";
7
+ export declare class Vector {
8
+ private _x;
9
+ private _y;
10
+ constructor(...values: unknown[]);
11
+ get x(): Fraction;
12
+ set x(value: Fraction | number | string);
13
+ get y(): Fraction;
14
+ set y(value: Fraction | number | string);
15
+ get normSquare(): Fraction;
16
+ get norm(): number;
17
+ get tex(): string;
18
+ get asPoint(): Point;
19
+ parse: (...values: any) => Vector;
20
+ clone: () => Vector;
21
+ reset: () => Vector;
22
+ zero: () => Vector;
23
+ one: () => Vector;
24
+ private _parseString;
25
+ opposed: () => Vector;
26
+ add: (V: Vector) => Vector;
27
+ subtract: (V: Vector) => Vector;
28
+ scalarProductWithVector: (V: Vector) => Fraction;
29
+ determinantWithVector: (V: Vector) => Fraction;
30
+ static scalarProduct: (v1: Vector, v2: Vector) => Fraction;
31
+ static determinant: (v1: Vector, v2: Vector) => Fraction;
32
+ normal: () => Vector;
33
+ isColinearTo: (v: Vector) => boolean;
34
+ isNormalTo: (v: Vector) => boolean;
35
+ get isNull(): boolean;
36
+ multiplyByScalar: (k: any) => Vector;
37
+ divideByScalar: (k: any) => Vector;
38
+ simplify: () => Vector;
39
+ simplifyDirection: () => Vector;
40
+ angleWith: (V: Vector, sharp?: Boolean, radian?: Boolean) => number;
41
+ }