pimath 0.0.120 → 0.0.122

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 (175) hide show
  1. package/.idea/PI.iml +7 -1
  2. package/.idea/shelf/Uncommitted_changes_before_Update_at_24_07_2023_15_31_[Default_Changelist]/shelved.patch +90 -0
  3. package/.idea/shelf/Uncommitted_changes_before_Update_at_24_07_2023_15_31_[Default_Changelist]1/shelved.patch +107 -0
  4. package/.idea/shelf/Uncommitted_changes_before_Update_at_24_07_2023_15_31__Default_Changelist_.xml +4 -0
  5. package/.idea/shelf/Uncommitted_changes_before_Update_at_24_07_2023_15_31__Default_Changelist_1.xml +4 -0
  6. package/LICENSE.md +1 -1
  7. package/dev/pimath.js +7929 -0
  8. package/dev/pimath.js.map +1 -0
  9. package/dist/{pi.js → pimath.js} +7613 -7840
  10. package/dist/pimath.js.map +1 -0
  11. package/dist/pimath.min.js +2 -0
  12. package/dist/pimath.min.js.map +1 -0
  13. package/docs/assets/main.js +58 -58
  14. package/docs/assets/search.js +1 -1
  15. package/docs/assets/style.css +1367 -1280
  16. package/docs/classes/Logicalset.Logicalset.html +221 -212
  17. package/docs/classes/Polynom.Rational.html +391 -388
  18. package/docs/classes/Vector-1.Vector.html +494 -448
  19. package/docs/classes/Vector.Point.html +341 -342
  20. package/docs/classes/algebra_equation.Equation.html +796 -753
  21. package/docs/classes/algebra_linearSystem.LinearSystem.html +408 -397
  22. package/docs/classes/algebra_monom.Monom.html +967 -910
  23. package/docs/classes/algebra_polynom.Polynom.html +1281 -1260
  24. package/docs/classes/coefficients_fraction.Fraction.html +939 -931
  25. package/docs/classes/geometry_circle.Circle.html +476 -476
  26. package/docs/classes/geometry_line.Line.html +779 -719
  27. package/docs/classes/geometry_triangle.Triangle.html +429 -420
  28. package/docs/classes/numeric.Numeric.html +269 -263
  29. package/docs/classes/shutingyard.Shutingyard.html +259 -248
  30. package/docs/enums/algebra_equation.PARTICULAR_SOLUTION.html +89 -88
  31. package/docs/enums/geometry_line.LinePropriety.html +102 -102
  32. package/docs/enums/shutingyard.ShutingyardMode.html +106 -102
  33. package/docs/enums/shutingyard.ShutingyardType.html +120 -116
  34. package/docs/index.html +63 -65
  35. package/docs/interfaces/algebra_equation.ISolution.html +111 -109
  36. package/docs/interfaces/algebra_polynom.IEuclidian.html +93 -92
  37. package/docs/interfaces/geometry_triangle.remarquableLines.html +150 -150
  38. package/docs/modules/Logicalset.html +69 -74
  39. package/docs/modules/Polynom.html +69 -74
  40. package/docs/modules/Vector-1.html +69 -74
  41. package/docs/modules/Vector.html +69 -74
  42. package/docs/modules/algebra_equation.html +75 -81
  43. package/docs/modules/algebra_linearSystem.html +65 -71
  44. package/docs/modules/algebra_monom.html +70 -76
  45. package/docs/modules/algebra_polynom.html +75 -81
  46. package/docs/modules/coefficients_fraction.html +70 -76
  47. package/docs/modules/geometry_circle.html +65 -71
  48. package/docs/modules/geometry_line.html +70 -76
  49. package/docs/modules/geometry_triangle.html +70 -76
  50. package/docs/modules/numeric.html +65 -71
  51. package/docs/modules/shutingyard.html +84 -90
  52. package/docs/types/algebra_monom.literalType.html +66 -70
  53. package/docs/types/algebra_polynom.PolynomParsingType.html +62 -66
  54. package/docs/types/coefficients_fraction.FractionParsingType.html +61 -65
  55. package/docs/types/shutingyard.Token.html +72 -76
  56. package/docs/types/shutingyard.tokenType.html +77 -81
  57. package/docs/variables/shutingyard.tokenConstant.html +70 -74
  58. package/esm/index.d.ts +38 -41
  59. package/esm/index.js +43 -46
  60. package/esm/index.js.map +1 -1
  61. package/esm/maths/algebra/equation.d.ts +119 -117
  62. package/esm/maths/algebra/equation.js +796 -785
  63. package/esm/maths/algebra/equation.js.map +1 -1
  64. package/esm/maths/algebra/linearSystem.d.ts +39 -38
  65. package/esm/maths/algebra/linearSystem.js +278 -262
  66. package/esm/maths/algebra/linearSystem.js.map +1 -1
  67. package/esm/maths/algebra/logicalset.d.ts +28 -28
  68. package/esm/maths/algebra/logicalset.js +157 -157
  69. package/esm/maths/algebra/monom.d.ts +206 -206
  70. package/esm/maths/algebra/monom.js +908 -908
  71. package/esm/maths/algebra/monom.js.map +1 -1
  72. package/esm/maths/algebra/polynom.d.ts +157 -157
  73. package/esm/maths/algebra/polynom.js +1277 -1277
  74. package/esm/maths/algebra/rational.d.ts +45 -45
  75. package/esm/maths/algebra/rational.js +183 -183
  76. package/esm/maths/algebra/study/rationalStudy.d.ts +28 -28
  77. package/esm/maths/algebra/study/rationalStudy.js +243 -243
  78. package/esm/maths/algebra/study.d.ts +143 -142
  79. package/esm/maths/algebra/study.js +378 -377
  80. package/esm/maths/algebra/study.js.map +1 -1
  81. package/esm/maths/coefficients/fraction.d.ts +90 -90
  82. package/esm/maths/coefficients/fraction.js +516 -516
  83. package/esm/maths/coefficients/fraction.js.map +1 -1
  84. package/esm/maths/coefficients/nthRoot.d.ts +23 -23
  85. package/esm/maths/coefficients/nthRoot.js +136 -136
  86. package/esm/maths/geometry/circle.d.ts +45 -45
  87. package/esm/maths/geometry/circle.js +323 -323
  88. package/esm/maths/geometry/line.d.ts +99 -99
  89. package/esm/maths/geometry/line.js +481 -481
  90. package/esm/maths/geometry/line.js.map +1 -1
  91. package/esm/maths/geometry/point.d.ts +34 -34
  92. package/esm/maths/geometry/point.js +166 -166
  93. package/esm/maths/geometry/point.js.map +1 -1
  94. package/esm/maths/geometry/triangle.d.ts +85 -85
  95. package/esm/maths/geometry/triangle.js +268 -268
  96. package/esm/maths/geometry/vector.d.ts +41 -41
  97. package/esm/maths/geometry/vector.js +197 -197
  98. package/esm/maths/geometry/vector.js.map +1 -1
  99. package/esm/maths/numeric.d.ts +28 -28
  100. package/esm/maths/numeric.js +180 -180
  101. package/esm/maths/numexp.d.ts +19 -0
  102. package/esm/maths/numexp.js +186 -0
  103. package/esm/maths/numexp.js.map +1 -0
  104. package/esm/maths/randomization/random.d.ts +23 -23
  105. package/esm/maths/randomization/random.js +78 -78
  106. package/esm/maths/randomization/random.js.map +1 -1
  107. package/esm/maths/randomization/randomCore.d.ts +7 -7
  108. package/esm/maths/randomization/randomCore.js +21 -21
  109. package/esm/maths/randomization/rndFraction.d.ts +12 -12
  110. package/esm/maths/randomization/rndFraction.js +43 -43
  111. package/esm/maths/randomization/rndGeometryLine.d.ts +12 -12
  112. package/esm/maths/randomization/rndGeometryLine.js +45 -45
  113. package/esm/maths/randomization/rndGeometryPoint.d.ts +12 -12
  114. package/esm/maths/randomization/rndGeometryPoint.js +60 -60
  115. package/esm/maths/randomization/rndHelpers.d.ts +23 -23
  116. package/esm/maths/randomization/rndHelpers.js +76 -76
  117. package/esm/maths/randomization/rndMonom.d.ts +12 -12
  118. package/esm/maths/randomization/rndMonom.js +52 -52
  119. package/esm/maths/randomization/rndPolynom.d.ts +13 -13
  120. package/esm/maths/randomization/rndPolynom.js +74 -74
  121. package/esm/maths/randomization/rndTypes.d.ts +34 -34
  122. package/esm/maths/randomization/rndTypes.js +2 -2
  123. package/esm/maths/shutingyard.d.ts +59 -59
  124. package/esm/maths/shutingyard.js +442 -442
  125. package/esm/maths/shutingyard.js.map +1 -1
  126. package/package.json +11 -11
  127. package/public/index.html +50 -81
  128. package/public/playground.html +7 -8
  129. package/src/index.ts +1 -4
  130. package/src/maths/algebra/equation.ts +16 -0
  131. package/src/maths/algebra/linearSystem.ts +20 -0
  132. package/src/maths/algebra/study.ts +12 -10
  133. package/src/maths/{expressions/numexp.ts → numexp.ts} +2 -2
  134. package/tests/algebra/equation.test.ts +19 -5
  135. package/tests/algebra/linear.test.ts +3 -11
  136. package/tests/algebra/polynom.test.ts +7 -8
  137. package/tests/algebra/rationnal.test.ts +1 -1
  138. package/tests/algebra/study.test.ts +2 -9
  139. package/tests/coefficients/fraction.test.ts +8 -8
  140. package/tests/custom.test.ts +33 -37
  141. package/tests/numeric.test.ts +1 -2
  142. package/tests/numexp.test.ts +13 -5
  143. package/tests/shutingyard.test.ts +3 -3
  144. package/webpack-production-min.config.js +1 -1
  145. package/webpack-production.config.js +1 -1
  146. package/webpack.config.js +1 -1
  147. package/dist/pi.js.map +0 -1
  148. package/dist/pi.min.js +0 -2
  149. package/dist/pi.min.js.map +0 -1
  150. package/docs/classes/expressions_numexp.NumExp.html +0 -236
  151. package/docs/classes/expressions_polynomexp.PolynomExpFactor.html +0 -317
  152. package/docs/classes/expressions_polynomexp.PolynomExpProduct.html +0 -285
  153. package/docs/modules/expressions_numexp.html +0 -71
  154. package/docs/modules/expressions_polynomexp.html +0 -73
  155. package/docs/modules.html +0 -76
  156. package/graph.svg +0 -1033
  157. package/src/maths/expressions/ExpressionTree.ts +0 -172
  158. package/src/maths/expressions/expression.ts +0 -286
  159. package/src/maths/expressions/expressionFactor.ts +0 -190
  160. package/src/maths/expressions/expressionMember.ts +0 -233
  161. package/src/maths/expressions/expressionOperators.ts +0 -49
  162. package/src/maths/expressions/expressionParser.ts +0 -295
  163. package/src/maths/expressions/factors/ExpFactor.ts +0 -39
  164. package/src/maths/expressions/factors/ExpFactorConstant.ts +0 -60
  165. package/src/maths/expressions/factors/ExpFactorExponential.ts +0 -26
  166. package/src/maths/expressions/factors/ExpFactorNumber.ts +0 -72
  167. package/src/maths/expressions/factors/ExpFactorPower.ts +0 -42
  168. package/src/maths/expressions/factors/ExpFactorTrigo.ts +0 -53
  169. package/src/maths/expressions/factors/ExpFactorVariable.ts +0 -45
  170. package/src/maths/expressions/internals.ts +0 -14
  171. package/src/maths/expressions/polynomexp.bkp.ts +0 -221
  172. package/src/maths/expressions/polynomexp.ts +0 -310
  173. package/tests/expressions/expressions.test.ts +0 -145
  174. package/tests/expressions/expressiontree.test.ts +0 -11
  175. package/tests/polynomexp.test.ts +0 -12
@@ -1,485 +1,485 @@
1
- "use strict";
2
- /**
3
- * This class works for 2d line in a plane.
4
- */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Line = exports.LinePropriety = void 0;
7
- const vector_1 = require("./vector");
8
- const point_1 = require("./point");
9
- const numeric_1 = require("../numeric");
10
- const fraction_1 = require("../coefficients/fraction");
11
- const equation_1 = require("../algebra/equation");
12
- const polynom_1 = require("../algebra/polynom");
13
- const random_1 = require("../randomization/random");
14
- const monom_1 = require("../algebra/monom");
15
- var LinePropriety;
16
- (function (LinePropriety) {
17
- LinePropriety[LinePropriety["None"] = 0] = "None";
18
- LinePropriety["Parallel"] = "parallel";
19
- LinePropriety["Perpendicular"] = "perpendicular";
20
- LinePropriety["Tangent"] = "tangent";
21
- })(LinePropriety = exports.LinePropriety || (exports.LinePropriety = {}));
22
- class Line {
23
- constructor(...values) {
24
- this.randomPoint = (k) => {
25
- // Return a random point on the line.
26
- return this._d
27
- .clone()
28
- .multiplyByScalar(random_1.Random.numberSym((k === undefined || k <= 1) ? 3 : k, false))
29
- .add(this._OA.asVector)
30
- .asPoint;
31
- };
32
- this.randomNearPoint = (k) => {
33
- let pt = this.randomPoint(k);
34
- let maxIterationTest = 10;
35
- while (this.isOnLine(pt) && maxIterationTest > 0) {
36
- pt.x.add(random_1.Random.numberSym(1, false));
37
- pt.y.add(random_1.Random.numberSym(1, false));
38
- maxIterationTest--;
39
- }
40
- return pt;
41
- };
42
- // ------------------------------------------
43
- // Creation / parsing functions
44
- // ------------------------------------------
45
- /**
46
- * Parse data to a line
47
- * @param {any} values
48
- * @returns {Line}
49
- */
50
- this.parse = (...values) => {
51
- this._exists = false;
52
- // Nothing is given...
53
- if (values.length === 0) {
54
- return this;
55
- }
56
- // One value only: already a line (clone it), an Equation, a string (as Equation)
57
- if (values.length === 1) {
58
- if (values[0] instanceof Line) {
59
- // Already a Line
60
- return values[0].clone();
61
- }
62
- else if (values[0] instanceof equation_1.Equation) {
63
- // It's an Equation
64
- return this.parseEquation(values[0]);
65
- }
66
- else if (typeof values[0] === "string") {
67
- // It's a string - create an Equation from it.
68
- try {
69
- let E = new equation_1.Equation(values[0]);
70
- return this.parse(E);
71
- }
72
- catch (e) {
73
- return this;
74
- }
75
- }
76
- }
77
- if (values.length === 2) {
78
- if (values[0] instanceof point_1.Point && values[1] instanceof vector_1.Vector) {
79
- return this.parseByPointAndVector(values[0], values[1]);
80
- }
81
- else if (values[0] instanceof point_1.Point && values[1] instanceof point_1.Point) {
82
- return this.parseByPointAndVector(values[0], new vector_1.Vector(values[0], values[1]));
83
- }
84
- else if (values[0] instanceof vector_1.Vector && values[1] instanceof point_1.Point) {
85
- return this.parseByPointAndNormal(values[1], values[0]);
86
- }
87
- }
88
- if (values.length === 3) {
89
- if ((values[0] instanceof fraction_1.Fraction || typeof values[0] === 'number')
90
- &&
91
- (values[1] instanceof fraction_1.Fraction || typeof values[1] === 'number')
92
- &&
93
- (values[2] instanceof fraction_1.Fraction || typeof values[2] === 'number')) {
94
- return this.parseByCoefficient(values[0], values[1], values[2]);
95
- }
96
- else if (values[0] instanceof point_1.Point && values[1] instanceof vector_1.Vector) {
97
- if (values[2] === LinePropriety.Perpendicular) {
98
- return this.parseByPointAndNormal(values[0], values[1]);
99
- }
100
- else if (values[2] === LinePropriety.Parallel) {
101
- return this.parseByPointAndVector(values[0], values[1]);
102
- }
103
- }
104
- else if (values[0] instanceof point_1.Point && values[1] instanceof Line) {
105
- if (values[2] === LinePropriety.Parallel || values[2] === null) {
106
- return this.parseByPointAndLine(values[0], values[1], LinePropriety.Parallel);
107
- }
108
- else {
109
- return this.parseByPointAndLine(values[0], values[1], LinePropriety.Perpendicular);
110
- }
111
- }
112
- }
113
- // TODO: Add the ability to create line from a normal vector
114
- console.log('Someting wrong happend while creating the line');
115
- return this;
116
- };
117
- this.parseEquation = (equ) => {
118
- // Reorder the eequation
119
- equ.reorder(true);
120
- // It must contain either x, y or both.
121
- let letters = new Set(equ.letters());
122
- // No 'x', no 'y' in the equations
123
- if (!(letters.has('x') || letters.has('y'))) {
124
- return this;
125
- }
126
- // Another letter in the equation ?
127
- for (let elem of ['x', 'y']) {
128
- if (letters.has(elem)) {
129
- letters.delete(elem);
130
- }
131
- }
132
- if (letters.size > 0) {
133
- return this;
134
- }
135
- // Everything should be ok now...
136
- return this.parseByCoefficient(equ.left.monomByLetter('x').coefficient, equ.left.monomByLetter('y').coefficient, equ.left.monomByDegree(0).coefficient);
137
- };
138
- this.parseByCoefficient = (a, b, c) => {
139
- this._a = new fraction_1.Fraction(a);
140
- this._b = new fraction_1.Fraction(b);
141
- this._c = new fraction_1.Fraction(c);
142
- this._d = new vector_1.Vector(this._b.clone(), this._a.clone().opposed());
143
- this._OA = new point_1.Point(new fraction_1.Fraction().zero(), this._c.clone());
144
- this._n = this._d.clone().normal();
145
- this._exists = true;
146
- return this;
147
- };
148
- this.parseByPointAndVector = (P, d) => {
149
- // OX = OP + k*d
150
- // x = px + kdx * dy
151
- // y = py + kdy * dx
152
- // ------------------
153
- // dy * x = px * dy + kdxdy
154
- // dx * y = py * dx + kdxdy
155
- // ------------------
156
- // dy * x - dx * y = px * dy - py * dx
157
- // dy * x - dx * y - (px * dy - py * dx) = 0
158
- this.parseByCoefficient(d.y, d.x.clone().opposed(), P.x.clone().multiply(d.y).subtract(P.y.clone().multiply(d.x)).opposed());
159
- // Choose the current values as point and direction vector instead of the automatic version.
160
- this._OA = P.clone();
161
- this._d = d.clone();
162
- this._n = this._d.clone().normal();
163
- this._exists = true;
164
- return this;
165
- };
166
- this.parseByPointAndNormal = (P, n) => {
167
- return this.parseByCoefficient(n.x, n.y, P.x.clone().multiply(n.x)
168
- .add(P.y.clone().multiply(n.y)).opposed());
169
- };
170
- this.parseByPointAndLine = (P, L, orientation) => {
171
- if (orientation === undefined) {
172
- orientation = LinePropriety.Parallel;
173
- }
174
- if (orientation === LinePropriety.Parallel) {
175
- return this.parseByPointAndNormal(P, L.normal);
176
- }
177
- else if (orientation === LinePropriety.Perpendicular) {
178
- return this.parseByPointAndNormal(P, L.director);
179
- }
180
- this._exists = false;
181
- return this;
182
- };
183
- this.clone = () => {
184
- this._a = this._a.clone();
185
- this._b = this._b.clone();
186
- this._c = this._c.clone();
187
- this._d = this._d.clone();
188
- this._OA = this._OA.clone();
189
- this._n = this._n.clone();
190
- this._exists = this.exists;
191
- return this;
192
- };
193
- // ------------------------------------------
194
- // Mathematical operations
195
- // ------------------------------------------
196
- this.isOnLine = (pt) => {
197
- return this._a.clone()
198
- .multiply(pt.x)
199
- .add(this._b.clone()
200
- .multiply(pt.y))
201
- .add(this._c)
202
- .isZero();
203
- };
204
- this.isParallelTo = (line) => {
205
- // Do they have the isSame direction ?
206
- return this.slope.isEqual(line.slope) && this.height.isNotEqual(line.height);
207
- };
208
- this.isSameAs = (line) => {
209
- return this.slope.isEqual(line.slope) && this.height.isEqual(line.height);
210
- };
211
- this.isPerpendicularTo = (line) => {
212
- return this.d.isNormalTo(line.d);
213
- };
214
- this.isVertical = () => {
215
- return this.slope.isInfinity();
216
- };
217
- this.simplify = () => {
218
- let lcm = numeric_1.Numeric.lcm(this._a.denominator, this._b.denominator, this._c.denominator), gcd = numeric_1.Numeric.gcd(this._a.numerator, this._b.numerator, this._c.numerator);
219
- this.parseByCoefficient(this._a.clone().multiply(lcm).divide(gcd), this._b.clone().multiply(lcm).divide(gcd), this._c.clone().multiply(lcm).divide(gcd));
220
- return this;
221
- };
222
- this.simplifyDirection = () => {
223
- this._d.simplifyDirection();
224
- return this;
225
- };
226
- this.intersection = (line) => {
227
- let Pt = new point_1.Point(), isParallel = false, isSame = false, hasIntersection = true;
228
- // this => ax+by+c = 0
229
- // line => dx+ey+f = 0
230
- //
231
- // aex + bey + ce = 0
232
- // dbx + bey + bf = 0
233
- // (ae-db)x + ce-bf = 0
234
- //
235
- // adx + bdy + cd = 0
236
- // adx + aey + af = 0
237
- // (bd-ae)y + (cd-af)
238
- //
239
- // x = (bf-ce)/(ae-db)
240
- // y = (af-cd)/(bd-ae)
241
- // Theres is no 'y'
242
- if (this._b.isZero() || line.b.isZero()) {
243
- // TODO : handle no y in the line canonical form
244
- }
245
- if (this.isParallelTo(line)) {
246
- Pt.x = null;
247
- Pt.y = null;
248
- isParallel = true;
249
- }
250
- else if (this.isSameAs(line)) {
251
- Pt.x = null;
252
- Pt.y = null;
253
- isSame = true;
254
- }
255
- else {
256
- Pt.x = this._b.clone().multiply(line.c).subtract(this._c.clone().multiply(line.b))
257
- .divide(this._a.clone().multiply(line.b).subtract(this._b.clone().multiply(line.a)));
258
- Pt.y = this._a.clone().multiply(line.c).subtract(this._c.clone().multiply(line.a))
259
- .divide(this._b.clone().multiply(line.a).subtract(this._a.clone().multiply(line.b)));
260
- }
261
- return {
262
- point: Pt,
263
- hasIntersection: !(isParallel || isSame),
264
- isParallel,
265
- isSame
266
- };
267
- };
268
- this.getValueAtX = (value) => {
269
- const equ = this.equation.clone().isolate('y'), F = new fraction_1.Fraction(value);
270
- if (equ instanceof equation_1.Equation) {
271
- return equ.right.evaluate({ x: F });
272
- }
273
- return;
274
- };
275
- this.getValueAtY = (value) => {
276
- const equ = this.equation.clone().isolate('x'), F = new fraction_1.Fraction(value);
277
- if (equ instanceof equation_1.Equation) {
278
- return equ.right.evaluate({ y: F });
279
- }
280
- return;
281
- };
282
- this._exists = false;
283
- this._reduceBeforeDisplay = true;
284
- if (values.length > 0) {
285
- this.parse(...values);
286
- }
287
- return this;
288
- }
289
- get a() {
290
- return this._a;
291
- }
292
- set a(value) {
293
- this._a = value;
294
- }
295
- get b() {
296
- return this._b;
297
- }
298
- set b(value) {
299
- this._b = value;
300
- }
301
- get c() {
302
- return this._c;
303
- }
304
- // ------------------------------------------
305
- // Getter and setter
306
- set c(value) {
307
- this._c = value;
308
- }
309
- get OA() {
310
- return this._OA;
311
- }
312
- set OA(value) {
313
- this._OA = value;
314
- }
315
- get d() {
316
- return this._d;
317
- }
318
- set d(value) {
319
- this._d = value;
320
- }
321
- get n() {
322
- return this._n;
323
- }
324
- get exists() {
325
- return this._exists;
326
- }
327
- // ------------------------------------------
328
- get equation() {
329
- let equ = new equation_1.Equation(new polynom_1.Polynom().parse('xy', this._a, this._b, this._c), new polynom_1.Polynom('0'));
330
- if (this._reduceBeforeDisplay) {
331
- return equ.simplify();
332
- }
333
- else {
334
- return equ;
335
- }
336
- }
337
- get system() {
338
- let e1 = new equation_1.Equation(new polynom_1.Polynom('x'), new polynom_1.Polynom(this._OA.x)
339
- .add(new monom_1.Monom('k').multiplyByNumber(this._d.x))), e2 = new equation_1.Equation(new polynom_1.Polynom('y'), new polynom_1.Polynom(this._OA.y)
340
- .add(new monom_1.Monom('k').multiplyByNumber(this._d.y)));
341
- return { x: e1, y: e2 };
342
- }
343
- get tex() {
344
- // canonical => ax + by + c = 0
345
- // mxh => y = -a/b x - c/b
346
- // parametric => (xy) = OA + k*d
347
- // equation => ax + by = -c
348
- let canonical = this.equation.clone().reorder(true);
349
- // Make sur the first item is positive.
350
- if (this._a.isNegative()) {
351
- canonical.multiply(-1);
352
- }
353
- let d = this._d.clone();
354
- if (this._reduceBeforeDisplay) {
355
- d.simplifyDirection();
356
- }
357
- return {
358
- canonical: canonical.tex,
359
- equation: canonical.clone().reorder().tex,
360
- mxh: this.slope.isInfinity() ? 'x=' + this.OA.x.tex : 'y=' + new polynom_1.Polynom().parse('x', this.slope, this.height).tex,
361
- parametric: `${point_1.Point.pmatrix('x', 'y')} = ${point_1.Point.pmatrix(this._OA.x, this._OA.y)} + k\\cdot ${point_1.Point.pmatrix(d.x, d.y)}`,
1
+ "use strict";
2
+ /**
3
+ * This class works for 2d line in a plane.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Line = exports.LinePropriety = void 0;
7
+ const vector_1 = require("./vector");
8
+ const point_1 = require("./point");
9
+ const numeric_1 = require("../numeric");
10
+ const fraction_1 = require("../coefficients/fraction");
11
+ const equation_1 = require("../algebra/equation");
12
+ const polynom_1 = require("../algebra/polynom");
13
+ const random_1 = require("../randomization/random");
14
+ const monom_1 = require("../algebra/monom");
15
+ var LinePropriety;
16
+ (function (LinePropriety) {
17
+ LinePropriety[LinePropriety["None"] = 0] = "None";
18
+ LinePropriety["Parallel"] = "parallel";
19
+ LinePropriety["Perpendicular"] = "perpendicular";
20
+ LinePropriety["Tangent"] = "tangent";
21
+ })(LinePropriety || (exports.LinePropriety = LinePropriety = {}));
22
+ class Line {
23
+ constructor(...values) {
24
+ this.randomPoint = (k) => {
25
+ // Return a random point on the line.
26
+ return this._d
27
+ .clone()
28
+ .multiplyByScalar(random_1.Random.numberSym((k === undefined || k <= 1) ? 3 : k, false))
29
+ .add(this._OA.asVector)
30
+ .asPoint;
31
+ };
32
+ this.randomNearPoint = (k) => {
33
+ let pt = this.randomPoint(k);
34
+ let maxIterationTest = 10;
35
+ while (this.isOnLine(pt) && maxIterationTest > 0) {
36
+ pt.x.add(random_1.Random.numberSym(1, false));
37
+ pt.y.add(random_1.Random.numberSym(1, false));
38
+ maxIterationTest--;
39
+ }
40
+ return pt;
41
+ };
42
+ // ------------------------------------------
43
+ // Creation / parsing functions
44
+ // ------------------------------------------
45
+ /**
46
+ * Parse data to a line
47
+ * @param {any} values
48
+ * @returns {Line}
49
+ */
50
+ this.parse = (...values) => {
51
+ this._exists = false;
52
+ // Nothing is given...
53
+ if (values.length === 0) {
54
+ return this;
55
+ }
56
+ // One value only: already a line (clone it), an Equation, a string (as Equation)
57
+ if (values.length === 1) {
58
+ if (values[0] instanceof Line) {
59
+ // Already a Line
60
+ return values[0].clone();
61
+ }
62
+ else if (values[0] instanceof equation_1.Equation) {
63
+ // It's an Equation
64
+ return this.parseEquation(values[0]);
65
+ }
66
+ else if (typeof values[0] === "string") {
67
+ // It's a string - create an Equation from it.
68
+ try {
69
+ let E = new equation_1.Equation(values[0]);
70
+ return this.parse(E);
71
+ }
72
+ catch (e) {
73
+ return this;
74
+ }
75
+ }
76
+ }
77
+ if (values.length === 2) {
78
+ if (values[0] instanceof point_1.Point && values[1] instanceof vector_1.Vector) {
79
+ return this.parseByPointAndVector(values[0], values[1]);
80
+ }
81
+ else if (values[0] instanceof point_1.Point && values[1] instanceof point_1.Point) {
82
+ return this.parseByPointAndVector(values[0], new vector_1.Vector(values[0], values[1]));
83
+ }
84
+ else if (values[0] instanceof vector_1.Vector && values[1] instanceof point_1.Point) {
85
+ return this.parseByPointAndNormal(values[1], values[0]);
86
+ }
87
+ }
88
+ if (values.length === 3) {
89
+ if ((values[0] instanceof fraction_1.Fraction || typeof values[0] === 'number')
90
+ &&
91
+ (values[1] instanceof fraction_1.Fraction || typeof values[1] === 'number')
92
+ &&
93
+ (values[2] instanceof fraction_1.Fraction || typeof values[2] === 'number')) {
94
+ return this.parseByCoefficient(values[0], values[1], values[2]);
95
+ }
96
+ else if (values[0] instanceof point_1.Point && values[1] instanceof vector_1.Vector) {
97
+ if (values[2] === LinePropriety.Perpendicular) {
98
+ return this.parseByPointAndNormal(values[0], values[1]);
99
+ }
100
+ else if (values[2] === LinePropriety.Parallel) {
101
+ return this.parseByPointAndVector(values[0], values[1]);
102
+ }
103
+ }
104
+ else if (values[0] instanceof point_1.Point && values[1] instanceof Line) {
105
+ if (values[2] === LinePropriety.Parallel || values[2] === null) {
106
+ return this.parseByPointAndLine(values[0], values[1], LinePropriety.Parallel);
107
+ }
108
+ else {
109
+ return this.parseByPointAndLine(values[0], values[1], LinePropriety.Perpendicular);
110
+ }
111
+ }
112
+ }
113
+ // TODO: Add the ability to create line from a normal vector
114
+ console.log('Someting wrong happend while creating the line');
115
+ return this;
116
+ };
117
+ this.parseEquation = (equ) => {
118
+ // Reorder the eequation
119
+ equ.reorder(true);
120
+ // It must contain either x, y or both.
121
+ let letters = new Set(equ.letters());
122
+ // No 'x', no 'y' in the equations
123
+ if (!(letters.has('x') || letters.has('y'))) {
124
+ return this;
125
+ }
126
+ // Another letter in the equation ?
127
+ for (let elem of ['x', 'y']) {
128
+ if (letters.has(elem)) {
129
+ letters.delete(elem);
130
+ }
131
+ }
132
+ if (letters.size > 0) {
133
+ return this;
134
+ }
135
+ // Everything should be ok now...
136
+ return this.parseByCoefficient(equ.left.monomByLetter('x').coefficient, equ.left.monomByLetter('y').coefficient, equ.left.monomByDegree(0).coefficient);
137
+ };
138
+ this.parseByCoefficient = (a, b, c) => {
139
+ this._a = new fraction_1.Fraction(a);
140
+ this._b = new fraction_1.Fraction(b);
141
+ this._c = new fraction_1.Fraction(c);
142
+ this._d = new vector_1.Vector(this._b.clone(), this._a.clone().opposed());
143
+ this._OA = new point_1.Point(new fraction_1.Fraction().zero(), this._c.clone());
144
+ this._n = this._d.clone().normal();
145
+ this._exists = true;
146
+ return this;
147
+ };
148
+ this.parseByPointAndVector = (P, d) => {
149
+ // OX = OP + k*d
150
+ // x = px + kdx * dy
151
+ // y = py + kdy * dx
152
+ // ------------------
153
+ // dy * x = px * dy + kdxdy
154
+ // dx * y = py * dx + kdxdy
155
+ // ------------------
156
+ // dy * x - dx * y = px * dy - py * dx
157
+ // dy * x - dx * y - (px * dy - py * dx) = 0
158
+ this.parseByCoefficient(d.y, d.x.clone().opposed(), P.x.clone().multiply(d.y).subtract(P.y.clone().multiply(d.x)).opposed());
159
+ // Choose the current values as point and direction vector instead of the automatic version.
160
+ this._OA = P.clone();
161
+ this._d = d.clone();
162
+ this._n = this._d.clone().normal();
163
+ this._exists = true;
164
+ return this;
165
+ };
166
+ this.parseByPointAndNormal = (P, n) => {
167
+ return this.parseByCoefficient(n.x, n.y, P.x.clone().multiply(n.x)
168
+ .add(P.y.clone().multiply(n.y)).opposed());
169
+ };
170
+ this.parseByPointAndLine = (P, L, orientation) => {
171
+ if (orientation === undefined) {
172
+ orientation = LinePropriety.Parallel;
173
+ }
174
+ if (orientation === LinePropriety.Parallel) {
175
+ return this.parseByPointAndNormal(P, L.normal);
176
+ }
177
+ else if (orientation === LinePropriety.Perpendicular) {
178
+ return this.parseByPointAndNormal(P, L.director);
179
+ }
180
+ this._exists = false;
181
+ return this;
182
+ };
183
+ this.clone = () => {
184
+ this._a = this._a.clone();
185
+ this._b = this._b.clone();
186
+ this._c = this._c.clone();
187
+ this._d = this._d.clone();
188
+ this._OA = this._OA.clone();
189
+ this._n = this._n.clone();
190
+ this._exists = this.exists;
191
+ return this;
192
+ };
193
+ // ------------------------------------------
194
+ // Mathematical operations
195
+ // ------------------------------------------
196
+ this.isOnLine = (pt) => {
197
+ return this._a.clone()
198
+ .multiply(pt.x)
199
+ .add(this._b.clone()
200
+ .multiply(pt.y))
201
+ .add(this._c)
202
+ .isZero();
203
+ };
204
+ this.isParallelTo = (line) => {
205
+ // Do they have the isSame direction ?
206
+ return this.slope.isEqual(line.slope) && this.height.isNotEqual(line.height);
207
+ };
208
+ this.isSameAs = (line) => {
209
+ return this.slope.isEqual(line.slope) && this.height.isEqual(line.height);
210
+ };
211
+ this.isPerpendicularTo = (line) => {
212
+ return this.d.isNormalTo(line.d);
213
+ };
214
+ this.isVertical = () => {
215
+ return this.slope.isInfinity();
216
+ };
217
+ this.simplify = () => {
218
+ let lcm = numeric_1.Numeric.lcm(this._a.denominator, this._b.denominator, this._c.denominator), gcd = numeric_1.Numeric.gcd(this._a.numerator, this._b.numerator, this._c.numerator);
219
+ this.parseByCoefficient(this._a.clone().multiply(lcm).divide(gcd), this._b.clone().multiply(lcm).divide(gcd), this._c.clone().multiply(lcm).divide(gcd));
220
+ return this;
221
+ };
222
+ this.simplifyDirection = () => {
223
+ this._d.simplifyDirection();
224
+ return this;
225
+ };
226
+ this.intersection = (line) => {
227
+ let Pt = new point_1.Point(), isParallel = false, isSame = false, hasIntersection = true;
228
+ // this => ax+by+c = 0
229
+ // line => dx+ey+f = 0
230
+ //
231
+ // aex + bey + ce = 0
232
+ // dbx + bey + bf = 0
233
+ // (ae-db)x + ce-bf = 0
234
+ //
235
+ // adx + bdy + cd = 0
236
+ // adx + aey + af = 0
237
+ // (bd-ae)y + (cd-af)
238
+ //
239
+ // x = (bf-ce)/(ae-db)
240
+ // y = (af-cd)/(bd-ae)
241
+ // Theres is no 'y'
242
+ if (this._b.isZero() || line.b.isZero()) {
243
+ // TODO : handle no y in the line canonical form
244
+ }
245
+ if (this.isParallelTo(line)) {
246
+ Pt.x = null;
247
+ Pt.y = null;
248
+ isParallel = true;
249
+ }
250
+ else if (this.isSameAs(line)) {
251
+ Pt.x = null;
252
+ Pt.y = null;
253
+ isSame = true;
254
+ }
255
+ else {
256
+ Pt.x = this._b.clone().multiply(line.c).subtract(this._c.clone().multiply(line.b))
257
+ .divide(this._a.clone().multiply(line.b).subtract(this._b.clone().multiply(line.a)));
258
+ Pt.y = this._a.clone().multiply(line.c).subtract(this._c.clone().multiply(line.a))
259
+ .divide(this._b.clone().multiply(line.a).subtract(this._a.clone().multiply(line.b)));
260
+ }
261
+ return {
262
+ point: Pt,
263
+ hasIntersection: !(isParallel || isSame),
264
+ isParallel,
265
+ isSame
266
+ };
267
+ };
268
+ this.getValueAtX = (value) => {
269
+ const equ = this.equation.clone().isolate('y'), F = new fraction_1.Fraction(value);
270
+ if (equ instanceof equation_1.Equation) {
271
+ return equ.right.evaluate({ x: F });
272
+ }
273
+ return;
274
+ };
275
+ this.getValueAtY = (value) => {
276
+ const equ = this.equation.clone().isolate('x'), F = new fraction_1.Fraction(value);
277
+ if (equ instanceof equation_1.Equation) {
278
+ return equ.right.evaluate({ y: F });
279
+ }
280
+ return;
281
+ };
282
+ this._exists = false;
283
+ this._reduceBeforeDisplay = true;
284
+ if (values.length > 0) {
285
+ this.parse(...values);
286
+ }
287
+ return this;
288
+ }
289
+ get a() {
290
+ return this._a;
291
+ }
292
+ set a(value) {
293
+ this._a = value;
294
+ }
295
+ get b() {
296
+ return this._b;
297
+ }
298
+ set b(value) {
299
+ this._b = value;
300
+ }
301
+ get c() {
302
+ return this._c;
303
+ }
304
+ // ------------------------------------------
305
+ // Getter and setter
306
+ set c(value) {
307
+ this._c = value;
308
+ }
309
+ get OA() {
310
+ return this._OA;
311
+ }
312
+ set OA(value) {
313
+ this._OA = value;
314
+ }
315
+ get d() {
316
+ return this._d;
317
+ }
318
+ set d(value) {
319
+ this._d = value;
320
+ }
321
+ get n() {
322
+ return this._n;
323
+ }
324
+ get exists() {
325
+ return this._exists;
326
+ }
327
+ // ------------------------------------------
328
+ get equation() {
329
+ let equ = new equation_1.Equation(new polynom_1.Polynom().parse('xy', this._a, this._b, this._c), new polynom_1.Polynom('0'));
330
+ if (this._reduceBeforeDisplay) {
331
+ return equ.simplify();
332
+ }
333
+ else {
334
+ return equ;
335
+ }
336
+ }
337
+ get system() {
338
+ let e1 = new equation_1.Equation(new polynom_1.Polynom('x'), new polynom_1.Polynom(this._OA.x)
339
+ .add(new monom_1.Monom('k').multiplyByNumber(this._d.x))), e2 = new equation_1.Equation(new polynom_1.Polynom('y'), new polynom_1.Polynom(this._OA.y)
340
+ .add(new monom_1.Monom('k').multiplyByNumber(this._d.y)));
341
+ return { x: e1, y: e2 };
342
+ }
343
+ get tex() {
344
+ // canonical => ax + by + c = 0
345
+ // mxh => y = -a/b x - c/b
346
+ // parametric => (xy) = OA + k*d
347
+ // equation => ax + by = -c
348
+ let canonical = this.equation.clone().reorder(true);
349
+ // Make sur the first item is positive.
350
+ if (this._a.isNegative()) {
351
+ canonical.multiply(-1);
352
+ }
353
+ let d = this._d.clone();
354
+ if (this._reduceBeforeDisplay) {
355
+ d.simplifyDirection();
356
+ }
357
+ return {
358
+ canonical: canonical.tex,
359
+ equation: canonical.clone().reorder().tex,
360
+ mxh: this.slope.isInfinity() ? 'x=' + this.OA.x.tex : 'y=' + new polynom_1.Polynom().parse('x', this.slope, this.height).tex,
361
+ parametric: `${point_1.Point.pmatrix('x', 'y')} = ${point_1.Point.pmatrix(this._OA.x, this._OA.y)} + k\\cdot ${point_1.Point.pmatrix(d.x, d.y)}`,
362
362
  system: `\\left\\{\\begin{aligned}
363
- x &= ${(new polynom_1.Polynom(this._OA.x)
364
- .add(new monom_1.Monom(this._d.x).multiply(new monom_1.Monom('k'))))
365
- .reorder('k', true)
363
+ x &= ${(new polynom_1.Polynom(this._OA.x)
364
+ .add(new monom_1.Monom(this._d.x).multiply(new monom_1.Monom('k'))))
365
+ .reorder('k', true)
366
366
  .tex}\\\\\
367
- y &= ${(new polynom_1.Polynom(this._OA.y)
368
- .add(new monom_1.Monom(this._d.y).multiply(new monom_1.Monom('k'))))
369
- .reorder('k', true)
367
+ y &= ${(new polynom_1.Polynom(this._OA.y)
368
+ .add(new monom_1.Monom(this._d.y).multiply(new monom_1.Monom('k'))))
369
+ .reorder('k', true)
370
370
  .tex}
371
- \\end{aligned}\\right.`
372
- };
373
- }
374
- get reduceBeforeDisplay() {
375
- return this._reduceBeforeDisplay;
376
- }
377
- set reduceBeforeDisplay(value) {
378
- this._reduceBeforeDisplay = value;
379
- }
380
- get display() {
381
- // canonical => ax + by + c = 0
382
- // mxh => y = -a/b x - c/b
383
- // parametric => (xy) = OA + k*d // not relevant in display mode.
384
- let canonical = this.equation;
385
- // Make sur the first item is positive.
386
- if (this._a.isNegative()) {
387
- canonical.multiply(-1);
388
- }
389
- return {
390
- canonical: canonical.display,
391
- mxh: this.slope.isInfinity() ? 'x=' + this.OA.x.display : 'y=' + new polynom_1.Polynom().parse('x', this.slope, this.height).display,
392
- parametric: ""
393
- };
394
- }
395
- get normal() {
396
- return new vector_1.Vector(this._a, this._b);
397
- }
398
- get director() {
399
- return this._d.clone();
400
- }
401
- get slope() {
402
- return this._a.clone().opposed().divide(this._b);
403
- }
404
- get height() {
405
- return this._c.clone().opposed().divide(this._b);
406
- }
407
- distanceTo(pt) {
408
- let numerator = pt.x.clone().multiply(this._a)
409
- .add(pt.y.clone().multiply(this._b))
410
- .add(this._c).abs(), d2 = this.normal.normSquare;
411
- // The denominator is null - shouldn't be possible
412
- if (d2.isZero()) {
413
- return {
414
- value: NaN,
415
- tex: 'Not a line',
416
- fraction: new fraction_1.Fraction().infinite()
417
- };
418
- }
419
- // The denominator is a perfect square - simplify the tex result
420
- let value = numerator.value / Math.sqrt(d2.value), F = numerator.clone().divide(d2.clone().sqrt());
421
- // The denominator is a perfect square.
422
- if (d2.isSquare()) {
423
- return {
424
- value,
425
- tex: F.tex,
426
- fraction: F
427
- };
428
- }
429
- // Complete answer...
430
- return {
431
- value,
432
- tex: `\\frac{${numerator.tex}}{\\sqrt{${d2.tex}}}`,
433
- fraction: F
434
- };
435
- }
436
- hitSegment(A, B) {
437
- let iPt = this.intersection(new Line(A, B));
438
- // There is an intersection point
439
- if (iPt.hasIntersection) {
440
- return iPt.point.x.value >= Math.min(A.x.value, B.x.value)
441
- && iPt.point.x.value <= Math.max(A.x.value, B.x.value)
442
- && iPt.point.y.value >= Math.min(A.y.value, B.y.value)
443
- && iPt.point.y.value <= Math.max(A.y.value, B.y.value);
444
- }
445
- return false;
446
- }
447
- // ------------------------------------------
448
- // Special functions
449
- // ------------------------------------------
450
- canonicalAsFloatCoefficient(decimals) {
451
- if (decimals === undefined) {
452
- decimals = 2;
453
- }
454
- let ca = this._a.value, cb = this._b.value, cc = this._c.value, canonical = '';
455
- if (!this._a.isZero()) {
456
- if (this._a.isOne()) {
457
- canonical = 'x';
458
- }
459
- else if (this._a.clone().opposed().isOne()) {
460
- canonical = '-x';
461
- }
462
- else {
463
- canonical = this._a.value.toFixed(decimals) + 'x';
464
- }
465
- }
466
- if (!this._b.isZero()) {
467
- if (this._b.isPositive()) {
468
- canonical += '+';
469
- }
470
- canonical += this._b.value.toFixed(decimals) + 'y';
471
- }
472
- if (!this._c.isZero()) {
473
- if (this._c.isPositive()) {
474
- canonical += '+';
475
- }
476
- canonical += this._c.value.toFixed(decimals);
477
- }
478
- return canonical + '=0';
479
- }
480
- }
481
- exports.Line = Line;
482
- // A line is defined as the canonical form
483
- Line.PERPENDICULAR = LinePropriety.Perpendicular;
484
- Line.PARALLEL = LinePropriety.Parallel;
371
+ \\end{aligned}\\right.`
372
+ };
373
+ }
374
+ get reduceBeforeDisplay() {
375
+ return this._reduceBeforeDisplay;
376
+ }
377
+ set reduceBeforeDisplay(value) {
378
+ this._reduceBeforeDisplay = value;
379
+ }
380
+ get display() {
381
+ // canonical => ax + by + c = 0
382
+ // mxh => y = -a/b x - c/b
383
+ // parametric => (xy) = OA + k*d // not relevant in display mode.
384
+ let canonical = this.equation;
385
+ // Make sur the first item is positive.
386
+ if (this._a.isNegative()) {
387
+ canonical.multiply(-1);
388
+ }
389
+ return {
390
+ canonical: canonical.display,
391
+ mxh: this.slope.isInfinity() ? 'x=' + this.OA.x.display : 'y=' + new polynom_1.Polynom().parse('x', this.slope, this.height).display,
392
+ parametric: ""
393
+ };
394
+ }
395
+ get normal() {
396
+ return new vector_1.Vector(this._a, this._b);
397
+ }
398
+ get director() {
399
+ return this._d.clone();
400
+ }
401
+ get slope() {
402
+ return this._a.clone().opposed().divide(this._b);
403
+ }
404
+ get height() {
405
+ return this._c.clone().opposed().divide(this._b);
406
+ }
407
+ distanceTo(pt) {
408
+ let numerator = pt.x.clone().multiply(this._a)
409
+ .add(pt.y.clone().multiply(this._b))
410
+ .add(this._c).abs(), d2 = this.normal.normSquare;
411
+ // The denominator is null - shouldn't be possible
412
+ if (d2.isZero()) {
413
+ return {
414
+ value: NaN,
415
+ tex: 'Not a line',
416
+ fraction: new fraction_1.Fraction().infinite()
417
+ };
418
+ }
419
+ // The denominator is a perfect square - simplify the tex result
420
+ let value = numerator.value / Math.sqrt(d2.value), F = numerator.clone().divide(d2.clone().sqrt());
421
+ // The denominator is a perfect square.
422
+ if (d2.isSquare()) {
423
+ return {
424
+ value,
425
+ tex: F.tex,
426
+ fraction: F
427
+ };
428
+ }
429
+ // Complete answer...
430
+ return {
431
+ value,
432
+ tex: `\\frac{${numerator.tex}}{\\sqrt{${d2.tex}}}`,
433
+ fraction: F
434
+ };
435
+ }
436
+ hitSegment(A, B) {
437
+ let iPt = this.intersection(new Line(A, B));
438
+ // There is an intersection point
439
+ if (iPt.hasIntersection) {
440
+ return iPt.point.x.value >= Math.min(A.x.value, B.x.value)
441
+ && iPt.point.x.value <= Math.max(A.x.value, B.x.value)
442
+ && iPt.point.y.value >= Math.min(A.y.value, B.y.value)
443
+ && iPt.point.y.value <= Math.max(A.y.value, B.y.value);
444
+ }
445
+ return false;
446
+ }
447
+ // ------------------------------------------
448
+ // Special functions
449
+ // ------------------------------------------
450
+ canonicalAsFloatCoefficient(decimals) {
451
+ if (decimals === undefined) {
452
+ decimals = 2;
453
+ }
454
+ let ca = this._a.value, cb = this._b.value, cc = this._c.value, canonical = '';
455
+ if (!this._a.isZero()) {
456
+ if (this._a.isOne()) {
457
+ canonical = 'x';
458
+ }
459
+ else if (this._a.clone().opposed().isOne()) {
460
+ canonical = '-x';
461
+ }
462
+ else {
463
+ canonical = this._a.value.toFixed(decimals) + 'x';
464
+ }
465
+ }
466
+ if (!this._b.isZero()) {
467
+ if (this._b.isPositive()) {
468
+ canonical += '+';
469
+ }
470
+ canonical += this._b.value.toFixed(decimals) + 'y';
471
+ }
472
+ if (!this._c.isZero()) {
473
+ if (this._c.isPositive()) {
474
+ canonical += '+';
475
+ }
476
+ canonical += this._c.value.toFixed(decimals);
477
+ }
478
+ return canonical + '=0';
479
+ }
480
+ }
481
+ exports.Line = Line;
482
+ // A line is defined as the canonical form
483
+ Line.PERPENDICULAR = LinePropriety.Perpendicular;
484
+ Line.PARALLEL = LinePropriety.Parallel;
485
485
  //# sourceMappingURL=line.js.map