pimath 0.0.128 → 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.
Files changed (160) hide show
  1. package/dist/main.d.ts +39 -0
  2. package/dist/maths/algebra/equation.d.ts +120 -0
  3. package/dist/maths/algebra/linearSystem.d.ts +40 -0
  4. package/dist/maths/algebra/logicalset.d.ts +28 -0
  5. package/dist/maths/algebra/monom.d.ts +207 -0
  6. package/dist/maths/algebra/polynom.d.ts +155 -0
  7. package/dist/maths/algebra/rational.d.ts +44 -0
  8. package/dist/maths/algebra/study/rationalStudy.d.ts +14 -0
  9. package/dist/maths/algebra/study.d.ts +140 -0
  10. package/dist/maths/coefficients/fraction.d.ts +90 -0
  11. package/dist/maths/coefficients/nthRoot.d.ts +23 -0
  12. package/dist/maths/geometry/circle.d.ts +46 -0
  13. package/dist/maths/geometry/line.d.ts +102 -0
  14. package/dist/maths/geometry/point.d.ts +36 -0
  15. package/dist/maths/geometry/triangle.d.ts +92 -0
  16. package/dist/maths/geometry/vector.d.ts +38 -0
  17. package/dist/maths/numeric.d.ts +28 -0
  18. package/dist/maths/numexp.d.ts +19 -0
  19. package/dist/maths/randomization/random.d.ts +26 -0
  20. package/dist/maths/randomization/randomCore.d.ts +7 -0
  21. package/dist/maths/randomization/rndFraction.d.ts +13 -0
  22. package/dist/maths/randomization/rndGeometryCircle.d.ts +13 -0
  23. package/dist/maths/randomization/rndGeometryLine.d.ts +13 -0
  24. package/dist/maths/randomization/rndGeometryPoint.d.ts +13 -0
  25. package/dist/maths/randomization/rndHelpers.d.ts +23 -0
  26. package/dist/maths/randomization/rndMonom.d.ts +13 -0
  27. package/dist/maths/randomization/rndPolynom.d.ts +14 -0
  28. package/dist/maths/randomization/rndTypes.d.ts +40 -0
  29. package/dist/maths/shutingyard.d.ts +59 -0
  30. package/dist/pimath.js +85 -85
  31. package/package.json +10 -12
  32. package/.eslintrc.js +0 -24
  33. package/.idea/$CACHE_FILE$ +0 -6
  34. package/.idea/PI.iml +0 -14
  35. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  36. package/.idea/inspectionProfiles/Project_Default.xml +0 -6
  37. package/.idea/jsLibraryMappings.xml +0 -6
  38. package/.idea/misc.xml +0 -6
  39. package/.idea/modules.xml +0 -8
  40. package/.idea/php.xml +0 -19
  41. package/.idea/shelf/Uncommitted_changes_before_Checkout_at_07_11_2023_08_30_[Default_Changelist]/shelved.patch +0 -192
  42. package/.idea/shelf/Uncommitted_changes_before_Checkout_at_07_11_2023_08_30_[Default_Changelist]1/shelved.patch +0 -0
  43. package/.idea/shelf/Uncommitted_changes_before_Checkout_at_07_11_2023_08_30__Default_Changelist_.xml +0 -4
  44. package/.idea/shelf/Uncommitted_changes_before_Checkout_at_09_11_2023_10_43_[Default_Changelist]/shelved.patch +0 -2404
  45. package/.idea/shelf/Uncommitted_changes_before_Checkout_at_09_11_2023_10_43__Default_Changelist_.xml +0 -4
  46. package/.idea/shelf/Uncommitted_changes_before_Checkout_at_09_11_2023_11_01_[Default_Changelist]/shelved.patch +0 -1362
  47. package/.idea/shelf/Uncommitted_changes_before_Checkout_at_09_11_2023_11_01__Default_Changelist_.xml +0 -4
  48. package/.idea/shelf/Uncommitted_changes_before_Update_at_24_07_2023_15_31_[Default_Changelist]/shelved.patch +0 -90
  49. package/.idea/shelf/Uncommitted_changes_before_Update_at_24_07_2023_15_31__Default_Changelist_.xml +0 -4
  50. package/.idea/vcs.xml +0 -6
  51. package/dist/demo/exercises.html +0 -283
  52. package/dist/demo/matrices.html +0 -39
  53. package/dist/demo/playground.html +0 -20
  54. package/dist/demo.css +0 -3
  55. package/dist/pimath.umd.cjs +0 -15
  56. package/docs/.nojekyll +0 -1
  57. package/docs/assets/highlight.css +0 -78
  58. package/docs/assets/main.js +0 -59
  59. package/docs/assets/navigation.js +0 -1
  60. package/docs/assets/search.js +0 -1
  61. package/docs/assets/style.css +0 -1383
  62. package/docs/classes/Logicalset.Logicalset.html +0 -217
  63. package/docs/classes/Polynom.Rational.html +0 -397
  64. package/docs/classes/Vector-1.Vector.html +0 -490
  65. package/docs/classes/Vector.Point.html +0 -337
  66. package/docs/classes/algebra_equation.Equation.html +0 -790
  67. package/docs/classes/algebra_linearSystem.LinearSystem.html +0 -404
  68. package/docs/classes/algebra_monom.Monom.html +0 -962
  69. package/docs/classes/algebra_polynom.Polynom.html +0 -1275
  70. package/docs/classes/coefficients_fraction.Fraction.html +0 -934
  71. package/docs/classes/geometry_circle.Circle.html +0 -472
  72. package/docs/classes/geometry_line.Line.html +0 -774
  73. package/docs/classes/geometry_triangle.Triangle.html +0 -429
  74. package/docs/classes/numeric.Numeric.html +0 -265
  75. package/docs/classes/shutingyard.Shutingyard.html +0 -250
  76. package/docs/enums/algebra_equation.PARTICULAR_SOLUTION.html +0 -83
  77. package/docs/enums/geometry_line.LinePropriety.html +0 -97
  78. package/docs/enums/shutingyard.ShutingyardMode.html +0 -97
  79. package/docs/enums/shutingyard.ShutingyardType.html +0 -111
  80. package/docs/index.html +0 -63
  81. package/docs/interfaces/algebra_equation.ISolution.html +0 -105
  82. package/docs/interfaces/algebra_polynom.IEuclidian.html +0 -87
  83. package/docs/interfaces/geometry_triangle.remarquableLines.html +0 -163
  84. package/docs/modules/Logicalset.html +0 -65
  85. package/docs/modules/Polynom.html +0 -65
  86. package/docs/modules/Vector-1.html +0 -65
  87. package/docs/modules/Vector.html +0 -65
  88. package/docs/modules/algebra_equation.html +0 -69
  89. package/docs/modules/algebra_linearSystem.html +0 -61
  90. package/docs/modules/algebra_monom.html +0 -65
  91. package/docs/modules/algebra_polynom.html +0 -69
  92. package/docs/modules/coefficients_fraction.html +0 -65
  93. package/docs/modules/geometry_circle.html +0 -61
  94. package/docs/modules/geometry_line.html +0 -65
  95. package/docs/modules/geometry_triangle.html +0 -65
  96. package/docs/modules/numeric.html +0 -61
  97. package/docs/modules/shutingyard.html +0 -75
  98. package/docs/types/algebra_monom.literalType.html +0 -61
  99. package/docs/types/algebra_polynom.PolynomParsingType.html +0 -56
  100. package/docs/types/coefficients_fraction.FractionParsingType.html +0 -56
  101. package/docs/types/shutingyard.Token.html +0 -63
  102. package/docs/types/shutingyard.tokenType.html +0 -68
  103. package/docs/variables/shutingyard.tokenConstant.html +0 -61
  104. package/index.html +0 -15
  105. package/public/demo/exercises.html +0 -283
  106. package/public/demo/matrices.html +0 -39
  107. package/public/demo/playground.html +0 -20
  108. package/public/demo.css +0 -3
  109. package/src/demo/exercises.ts +0 -0
  110. package/src/demo/matrices.ts +0 -61
  111. package/src/demo/playground.ts +0 -153
  112. package/src/main.ts +0 -42
  113. package/src/maths/algebra/equation.ts +0 -897
  114. package/src/maths/algebra/linearSystem.ts +0 -370
  115. package/src/maths/algebra/logicalset.ts +0 -183
  116. package/src/maths/algebra/monom.ts +0 -1028
  117. package/src/maths/algebra/polynom.ts +0 -1537
  118. package/src/maths/algebra/rational.ts +0 -244
  119. package/src/maths/algebra/study/rationalStudy.ts +0 -287
  120. package/src/maths/algebra/study.ts +0 -506
  121. package/src/maths/coefficients/fraction.ts +0 -593
  122. package/src/maths/coefficients/nthRoot.ts +0 -148
  123. package/src/maths/geometry/circle.ts +0 -382
  124. package/src/maths/geometry/line.ts +0 -604
  125. package/src/maths/geometry/point.ts +0 -215
  126. package/src/maths/geometry/triangle.ts +0 -368
  127. package/src/maths/geometry/vector.ts +0 -242
  128. package/src/maths/numeric.ts +0 -162
  129. package/src/maths/numexp.ts +0 -184
  130. package/src/maths/randomization/random.ts +0 -80
  131. package/src/maths/randomization/randomCore.ts +0 -19
  132. package/src/maths/randomization/rndFraction.ts +0 -47
  133. package/src/maths/randomization/rndGeometryCircle.ts +0 -50
  134. package/src/maths/randomization/rndGeometryLine.ts +0 -53
  135. package/src/maths/randomization/rndGeometryPoint.ts +0 -69
  136. package/src/maths/randomization/rndHelpers.ts +0 -107
  137. package/src/maths/randomization/rndMonom.ts +0 -57
  138. package/src/maths/randomization/rndPolynom.ts +0 -90
  139. package/src/maths/randomization/rndTypes.ts +0 -43
  140. package/src/maths/shutingyard.ts +0 -496
  141. package/tests/algebra/equation.test.ts +0 -64
  142. package/tests/algebra/linear.test.ts +0 -58
  143. package/tests/algebra/monom.test.ts +0 -78
  144. package/tests/algebra/polynom.test.ts +0 -343
  145. package/tests/algebra/rationnal.test.ts +0 -64
  146. package/tests/algebra/study.test.ts +0 -48
  147. package/tests/coefficients/fraction.test.ts +0 -131
  148. package/tests/custom.test.ts +0 -33
  149. package/tests/geometry/circle.test.ts +0 -404
  150. package/tests/geometry/line.test.ts +0 -36
  151. package/tests/numeric.test.ts +0 -43
  152. package/tests/numexp.test.ts +0 -89
  153. package/tests/shutingyard.test.ts +0 -58
  154. package/tsconfig.json +0 -52
  155. package/tsconfig.testing.json +0 -28
  156. package/typedoc.katex.js +0 -11
  157. package/vite.config.js +0 -23
  158. package/webpack-production-min.config.js +0 -26
  159. package/webpack-production.config.js +0 -26
  160. package/webpack.config.js +0 -26
@@ -1,148 +0,0 @@
1
- /**
2
- * NthRoot is something like "a+b\sqrt{3}
3
- */
4
- export class NthRoot {
5
- private _radical: number;
6
- private _nth: number;
7
- private _coefficient: number;
8
- private _isValid:boolean;
9
-
10
- constructor(...values: number[]) {
11
- this._radical = 1;
12
- this._coefficient = 1;
13
- this._nth = 2;
14
- this._isValid = true;
15
-
16
- if(values !== undefined){
17
- this.parse(values[0], values[1], values[2])
18
- }
19
- }
20
-
21
- // ------------------------------------------
22
- // Getter and setter
23
- // ------------------------------------------
24
- get radical(): number {
25
- return this._radical;
26
- }
27
-
28
- set radical(value: number) {
29
- this._radical = value;
30
- }
31
-
32
- get nth(): number {
33
- return this._nth;
34
- }
35
-
36
- set nth(value: number) {
37
- if (Number.isSafeInteger(value) && value >= 2) {
38
- this._nth = value;
39
- } else {
40
- // Error setting the nth root.
41
- console.log('Error setting the nth root');
42
- this._nth = 2;
43
- }
44
- }
45
-
46
- get coefficient(): number {
47
- return this._coefficient;
48
- }
49
-
50
- set coefficient(value: number) {
51
- this._coefficient = value;
52
- }
53
-
54
- get tex(): string {
55
- let C: string;
56
-
57
- if (this._coefficient === 1) {
58
- C = '';
59
- } else if (this._coefficient === -1) {
60
- C = '-';
61
- } else {
62
- C = this._coefficient.toString();
63
- }
64
-
65
- if (this._radical === 1) {
66
- return `${this._coefficient}`;
67
- } else {
68
- if (this._nth === 2) {
69
- return `${C}\\sqrt{${this._radical}}`
70
- } else {
71
- return `${C}\\sqrt[${this._nth}]{${this._radical}}`
72
- }
73
- }
74
- }
75
-
76
- get display(): string {
77
- let C: string;
78
-
79
- if (this._coefficient === 1) {
80
- C = '';
81
- } else if (this._coefficient === -1) {
82
- C = '-';
83
- } else {
84
- C = this._coefficient.toString();
85
- }
86
-
87
- if (this._radical === 1) {
88
- return `${this._coefficient}`;
89
- } else {
90
- if (this._nth === 2) {
91
- return `${C}sqrt{${this._radical}}`
92
- } else {
93
- return `${C}root(${this._nth}){${this._radical}}`
94
- }
95
- }
96
- }
97
-
98
- get value(): number {
99
- return this._coefficient * Math.pow(this._radical, 1 / this._nth);
100
- }
101
-
102
- // ------------------------------------------
103
- // Creation / parsing functions
104
- // ------------------------------------------
105
- parse = (radical: number, nthroot?: number, coefficient?: number): NthRoot => {
106
- this._coefficient = (coefficient === undefined) ? 1 : coefficient;
107
- this._nth = (nthroot === undefined) ? 2 : nthroot;
108
- this._radical = (radical === undefined) ? 1 : radical;
109
-
110
- if(this._nth%2===0 && this._radical<0){
111
- this._isValid = false;
112
- }
113
- return this;
114
- };
115
-
116
- // ------------------------------------------
117
- // Mathematical operations
118
- // ------------------------------------------
119
- reduce = (): NthRoot => {
120
- // Max value to test.
121
- let V = Math.floor(Math.pow(this._radical, 1 / this._nth));
122
- while (V > 1) {
123
- if (this._radical % Math.pow(V, this._nth) === 0) {
124
- // It's dividable by V^n
125
- this._coefficient *= V;
126
- this._radical = this._radical / Math.pow(V, this._nth);
127
-
128
- // Redifine the new testing value (this is optimization)
129
- V = Math.floor(Math.pow(this._radical, 1 / this._nth));
130
- continue;
131
- }
132
- V--;
133
- }
134
- return this;
135
- };
136
-
137
- multiply = (N: NthRoot): NthRoot => {
138
- this._radical *= N.radical;
139
- return this.reduce();
140
- };
141
-
142
- // ------------------------------------------
143
- // Help functions
144
- // ------------------------------------------
145
- hasRadical = ():boolean => {
146
- return !(this._radical===1 || this._radical===0 || this._isValid===false)
147
- };
148
- }
@@ -1,382 +0,0 @@
1
- import {Point} from "./point";
2
- import {Line, LinePropriety} from "./line";
3
- import {Vector} from "./vector";
4
- import {Triangle} from "./triangle";
5
- import {Numeric} from "../numeric";
6
- import {Fraction} from "../coefficients/fraction";
7
- import {Equation} from "../algebra/equation";
8
- import {Polynom} from "../algebra/polynom";
9
- import {Monom} from "../algebra/monom";
10
-
11
- export class Circle {
12
- constructor(...values: unknown[]) {
13
- this._exists = false
14
-
15
- if (values !== undefined) {
16
- this.parse(...values)
17
- }
18
- }
19
-
20
- private _center: Point;
21
-
22
- get center(): Point {
23
- return this._center;
24
- }
25
-
26
- private _squareRadius: Fraction;
27
-
28
- get squareRadius(): Fraction {
29
- return this._squareRadius
30
- }
31
-
32
- private _cartesian: Equation;
33
-
34
- get cartesian(): Equation {
35
- return this._cartesian
36
- }
37
-
38
- private _exists: boolean;
39
-
40
- get exists(): boolean {
41
- return this._exists;
42
- }
43
-
44
- get radius(): { tex: string, display: string, value: number } {
45
- if (this._squareRadius.isSquare()) {
46
- return {
47
- tex: this._squareRadius.clone().sqrt().tex,
48
- display: this._squareRadius.clone().sqrt().display,
49
- value: this._squareRadius.clone().sqrt().value
50
- }
51
- } else {
52
- return {
53
- tex: `\\sqrt{${this._squareRadius.tex}}`,
54
- display: `sqrt(${this._squareRadius.display})`,
55
- value: this._squareRadius.clone().sqrt().value
56
- }
57
- }
58
- return this._squareRadius
59
- }
60
-
61
- get tex(): string {
62
- if (this._exists) {
63
- let cx, cy
64
- if (this._center.x.isZero()) {
65
- cx = 'x^2'
66
- } else {
67
- cx = `\\left(x${this._center.x.isNegative() ? '+' : '-'}${this._center.x.clone().abs().tex}\\right)^2`
68
- }
69
- if (this._center.y.isZero()) {
70
- cy = 'y^2'
71
- } else {
72
- cy = `\\left(y${this._center.y.isNegative() ? '+' : '-'}${this._center.y.clone().abs().tex}\\right)^2`
73
- }
74
- return `${cx}+${cy}=${this._squareRadius.tex}`
75
- } else {
76
- return `\\text{le cercle n'existe pas.}`
77
- }
78
- }
79
-
80
- get developed(): string {
81
- return this._cartesian.tex
82
- }
83
-
84
- get display(): string {
85
- if (this._exists) {
86
- let cx, cy
87
- if (this._center.x.isZero()) {
88
- cx = 'x^2'
89
- } else {
90
- cx = `(x${this._center.x.isNegative() ? '+' : '-'}${this._center.x.clone().abs().tex})^2`
91
- }
92
- if (this._center.y.isZero()) {
93
- cy = 'y^2'
94
- } else {
95
- cy = `(y${this._center.y.isNegative() ? '+' : '-'}${this._center.y.clone().abs().tex})^2`
96
- }
97
- return `${cx}+${cy}=${this._squareRadius.display}`
98
- } else {
99
- return `\\text{le cercle n'existe pas.}`
100
- }
101
- }
102
-
103
- /**
104
- * Get the relative position between circle and line. It corresponds to the number of intersection.
105
- * @param {Line} L
106
- * @returns {number}
107
- */
108
- relativePosition = (L: Line): number => {
109
- let distance = L.distanceTo(this.center), radius = Math.sqrt(this._squareRadius.value)
110
-
111
- if (distance.value - radius > 0.0000000001) {
112
- return 0 // external
113
- } else if (Math.abs(distance.value - radius) < 0.0000000001) {
114
- return 1 // tangent
115
- } else {
116
- return 2 // external
117
- }
118
- }
119
-
120
- lineIntersection = (L: Line): Point[] => {
121
- let intersectionPoints: Point[] = [], solX: Fraction
122
-
123
- if (this._cartesian === null) {
124
- return []
125
- }
126
- const equX = this._cartesian.clone(), lineX = L.equation.clone().isolate('x'),
127
- lineY = L.equation.clone().isolate('y')
128
-
129
- if (lineX instanceof Equation && lineY instanceof Equation) {
130
- equX.replaceBy('y', lineY.right).simplify()
131
- equX.solve()
132
-
133
- for (let x of equX.solutions) {
134
- if (x.exact === false && isNaN(x.value)) {
135
- continue
136
- }
137
-
138
- solX = new Fraction(x.exact === false ? x.value : x.exact)
139
- intersectionPoints.push(new Point(solX.clone(), lineY.right.evaluate(solX)))
140
- }
141
- }
142
-
143
- return intersectionPoints
144
- }
145
-
146
- tangents = (P: Point | Fraction): Line[] => {
147
- if (P instanceof Fraction) {
148
- return this._tangentsWithSlope(P)
149
- } else if (this.isPointOnCircle(P)) {
150
- return this._tangentsThroughOnePointOnTheCircle(P)
151
- } else if (this.center.distanceTo(P).value > this.radius.value) {
152
- //TODO: Must check it's outside the circle
153
- return this._tangentsThroughOnePointOutsideTheCircle(P)
154
- } else {
155
- console.log('No tangents as the point is inside !')
156
- }
157
- return []
158
- }
159
-
160
- isPointOnCircle = (P: Point): Boolean => {
161
- return this._cartesian.test({x: P.x, y: P.y})
162
- }
163
-
164
- getPointsOnCircle = (numberIsInteger?: boolean): Point[] => {
165
- if (numberIsInteger === undefined) {
166
- numberIsInteger = false
167
- }
168
-
169
- // It means searching for pythagorician triples that make a perfect square.
170
- // (x-4)^2 + (y+3)^2 = 15
171
-
172
- let triplets = Numeric.pythagoricianTripletsWithTarget(this._squareRadius.value, true)
173
-
174
- let points: Point[] = [], pt
175
- triplets.forEach(triplet => {
176
- // Allow positive / negative values
177
- // x-a = t => x = a + t
178
- // x-a = -t => x = a - t
179
-
180
- for (let k of [[1, 1], [-1, 1], [-1, -1], [1, -1]]) {
181
- pt = new Point(
182
- this.center.x.clone().add(k[0] * triplet[0]),
183
- this.center.y.clone().add(k[1] * triplet[1])
184
- )
185
- // Check if the point is not already in points.
186
- if (!pt.isInListOfPoints(points)) {
187
- points.push(pt)
188
- }
189
- }
190
- })
191
- return points
192
- }
193
-
194
- clone(): Circle {
195
- this._center = this._center.clone()
196
- this._squareRadius = this._squareRadius.clone()
197
- this._calculateCartesian()
198
- return this
199
- }
200
-
201
- private _tangentsThroughOnePointOnTheCircle = (P: Point): Line[] => {
202
- let CT = new Vector(this._center, P)
203
- return [new Line(P, CT, LinePropriety.Perpendicular)]
204
- }
205
-
206
- private _tangentsThroughOnePointOutsideTheCircle = (P: Point): Line[] => {
207
- // y = mx + h
208
- // px, py => h = -m px + py => mx - y -m.px + py = 0 =>
209
- // Centre: cx, cy, radius: r
210
- // (m.cx - cy -m.px + py)^2 = r^2 * (m^2 + 1)
211
- // (m(cx-py) - (cy - py))^2 = r^2 * (m^2 + 1)
212
-
213
- let cx_px = this.center.x.clone().subtract(P.x), cy_py = this.center.y.clone().subtract(P.y),
214
- polyLeft = new Polynom('x'), polyRight = new Polynom('x^2+1')
215
-
216
- polyLeft.multiply(cx_px).subtract(cy_py).pow(2)
217
- polyRight.multiply(this.squareRadius)
218
-
219
- let equ = new Equation(polyLeft, polyRight)
220
- equ.moveLeft().simplify().solve()
221
-
222
- return equ.solutions.map(sol => {
223
- // h = -m px + py
224
- let h, equ = new Equation('y', 'x')
225
-
226
- if (sol.exact instanceof Fraction) {
227
- h = P.x.clone().opposed().multiply(sol.exact).add(P.y)
228
- equ.right.multiply(sol.exact).add(h)
229
- } else {
230
- h = P.x.clone().opposed().multiply(sol.value).add(P.y)
231
- equ.right.multiply(sol.value).add(h)
232
- }
233
-
234
- return new Line(equ)
235
- })
236
-
237
- }
238
-
239
- private _tangentsWithSlope = (slope: Fraction): Line[] => {
240
- // d(C;t)=r => ac1+bc2 + x = +- sqrt(a^2 + b^2)*r
241
- // x = -ac1-bc2 +- sqrt(a^2 + b^2)*r
242
- // y = a/bx + h => ax-by + H = 0
243
-
244
- const a = slope.numerator, b = -slope.denominator, c1 = this._center.x.clone(), c2 = this._center.y.clone(),
245
- r = this._squareRadius
246
-
247
- let sq = this._squareRadius.clone().multiply(slope.numerator ** 2 + slope.denominator ** 2),
248
- x1 = c1.clone().multiply(a).opposed().subtract(c2.clone().multiply(b)).add(sq.clone().sqrt()),
249
- x2 = c1.clone().multiply(a).opposed().subtract(c2.clone().multiply(b)).subtract(sq.clone().sqrt())
250
-
251
- return [new Line(a, b, x1), new Line(a, b, x2)]
252
- }
253
-
254
- private _reset(): Circle {
255
- this._center = null
256
- this._squareRadius = null
257
- this._cartesian = null
258
- this._exists = false
259
-
260
- return this
261
- }
262
-
263
- private parse(...values: unknown[]): Circle {
264
- // Data can be given in these formats:
265
- // one value, a string -> make it an Equation
266
- // one value, an Equation
267
- // one value, a circle -> clone it
268
- // two values: two points (center and pointThrough)
269
- // two values: point and Fraction (center and radius)
270
- // three values: Point, Fraction, Boolean (center, square radius, true)
271
-
272
- this._reset()
273
-
274
- if (typeof values[0] === 'string') {
275
- this._parseEquation(new Equation(values[0]))
276
- } else if (values[0] instanceof Equation) {
277
- this._parseEquation(values[0])
278
- } else if (values[0] instanceof Circle) {
279
- this._parseCopyCircle(values[0])
280
- } else if (values[0] instanceof Point && values.length > 1) {
281
- if (values[1] instanceof Point) {
282
- if (values[2] instanceof Point) {
283
- this._parseThroughtThreePoints(values[0], values[1], values[2])
284
- } else {
285
- this._parseCenterAndPointThrough(values[0], values[1])
286
- }
287
- } else if (values[1] instanceof Fraction || typeof values[1] === 'number') {
288
- this._parseCenterAndRadius(values[0], values[1], (typeof values[2] === "boolean") ? values[2] : false)
289
- }
290
- }
291
-
292
- // Calculate once the different values.
293
- if (this._exists) {
294
- this._calculateCartesian()
295
-
296
- // If the square radius is zero or positive, the circle exists.
297
- if (this._squareRadius !== undefined && this._squareRadius.isNegative()) {
298
- this._exists = false
299
- }
300
- }
301
-
302
- return this
303
- }
304
-
305
- private _calculateCartesian() {
306
- this._cartesian = (new Equation(new Polynom(`(x-(${this._center.x.display}))^2+(y-(${this._center.y.display}))^2`), new Polynom(`${this._squareRadius.display}`))).moveLeft()
307
- }
308
-
309
- private _parseCopyCircle(circle: Circle): Circle {
310
- this._center = circle.center.clone()
311
- this._squareRadius = circle.squareRadius.clone()
312
- this._calculateCartesian()
313
- this._exists = circle.exists
314
- return this
315
- }
316
-
317
- private _parseCenterAndRadius(center: Point, radius: Fraction | number, square?: boolean): Circle {
318
- this._center = center.clone()
319
-
320
- if (square) {
321
- this._squareRadius = (new Fraction(radius))
322
- } else {
323
- this._squareRadius = new Fraction(radius).pow(2)
324
- }
325
-
326
- this._exists = true
327
- return this
328
- }
329
-
330
- private _parseCenterAndPointThrough(center: Point, pointThrough: Point): Circle {
331
- this._center = center.clone()
332
- this._squareRadius = new Vector(this._center, pointThrough).normSquare
333
- this._exists = true
334
- return this
335
- }
336
-
337
- private _parseEquation(equ: Equation): Circle {
338
- this._exists = false
339
-
340
- // Move everything to the left.
341
- equ.moveLeft()
342
-
343
- if (equ.degree('x').value === 2 && equ.degree('y').value === 2) {
344
- // Both must be of degree 2.
345
- let x2 = equ.left.monomByDegree(2, 'x'), y2 = equ.left.monomByDegree(2, 'y'), x1: Monom, y1: Monom, c: Monom
346
-
347
- // Both square monoms must have the same coefficient.
348
- if (x2.coefficient.isEqual(y2.coefficient)) {
349
- equ.divide(x2.coefficient)
350
-
351
- x1 = equ.left.monomByDegree(1, 'x')
352
- y1 = equ.left.monomByDegree(1, 'y')
353
-
354
- c = equ.left.monomByDegree(0)
355
-
356
- this._center = new Point(x1.coefficient.clone().divide(2).opposed(), y1.coefficient.clone().divide(2).opposed())
357
-
358
- this._squareRadius = c.coefficient.clone().opposed()
359
- .add(this._center.x.clone().pow(2))
360
- .add(this._center.y.clone().pow(2))
361
-
362
- this._calculateCartesian()
363
- this._exists = true
364
- } else {
365
- // The circle is not a valid circle
366
- this._center = null
367
- this._squareRadius = null
368
- this._exists = false
369
- }
370
- }
371
- return this
372
- }
373
-
374
- private _parseThroughtThreePoints(A: Point, B: Point, C: Point): Circle {
375
- let T = new Triangle(A, B, C), mAB = T.remarquables.mediators.AB.clone(),
376
- mAC = T.remarquables.mediators.AC.clone()
377
- this.parse(mAB.intersection(mAC).point, A)
378
-
379
- return this
380
- }
381
-
382
- }