pimath 0.0.127 → 0.0.129

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (212) hide show
  1. package/dist/main.d.ts +39 -0
  2. package/{esm → dist}/maths/algebra/equation.d.ts +11 -10
  3. package/{esm → dist}/maths/algebra/linearSystem.d.ts +5 -4
  4. package/{esm → dist}/maths/algebra/monom.d.ts +5 -4
  5. package/{esm → dist}/maths/algebra/polynom.d.ts +11 -13
  6. package/{esm → dist}/maths/algebra/rational.d.ts +7 -9
  7. package/dist/maths/algebra/study/rationalStudy.d.ts +14 -0
  8. package/{esm → dist}/maths/algebra/study.d.ts +4 -7
  9. package/{esm → dist}/maths/geometry/circle.d.ts +9 -8
  10. package/{esm → dist}/maths/geometry/line.d.ts +17 -14
  11. package/{esm → dist}/maths/geometry/point.d.ts +11 -9
  12. package/{esm → dist}/maths/geometry/triangle.d.ts +4 -3
  13. package/{esm → dist}/maths/geometry/vector.d.ts +7 -10
  14. package/{esm → dist}/maths/randomization/random.d.ts +10 -7
  15. package/{esm → dist}/maths/randomization/rndFraction.d.ts +4 -3
  16. package/dist/maths/randomization/rndGeometryCircle.d.ts +13 -0
  17. package/{esm → dist}/maths/randomization/rndGeometryLine.d.ts +4 -3
  18. package/{esm → dist}/maths/randomization/rndGeometryPoint.d.ts +4 -3
  19. package/{esm → dist}/maths/randomization/rndMonom.d.ts +5 -4
  20. package/{esm → dist}/maths/randomization/rndPolynom.d.ts +5 -4
  21. package/{esm → dist}/maths/randomization/rndTypes.d.ts +7 -1
  22. package/dist/pimath.js +4239 -7819
  23. package/package.json +13 -7
  24. package/.eslintrc.js +0 -24
  25. package/.idea/$CACHE_FILE$ +0 -6
  26. package/.idea/PI.iml +0 -14
  27. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  28. package/.idea/inspectionProfiles/Project_Default.xml +0 -6
  29. package/.idea/misc.xml +0 -6
  30. package/.idea/modules.xml +0 -8
  31. package/.idea/php.xml +0 -19
  32. package/.idea/shelf/Uncommitted_changes_before_Checkout_at_07_11_2023_08_30_[Default_Changelist]/shelved.patch +0 -192
  33. package/.idea/shelf/Uncommitted_changes_before_Checkout_at_07_11_2023_08_30_[Default_Changelist]1/shelved.patch +0 -0
  34. package/.idea/shelf/Uncommitted_changes_before_Checkout_at_07_11_2023_08_30__Default_Changelist_.xml +0 -4
  35. package/.idea/shelf/Uncommitted_changes_before_Checkout_at_09_11_2023_10_43_[Default_Changelist]/shelved.patch +0 -2404
  36. package/.idea/shelf/Uncommitted_changes_before_Checkout_at_09_11_2023_10_43__Default_Changelist_.xml +0 -4
  37. package/.idea/shelf/Uncommitted_changes_before_Checkout_at_09_11_2023_11_01_[Default_Changelist]/shelved.patch +0 -1362
  38. package/.idea/shelf/Uncommitted_changes_before_Checkout_at_09_11_2023_11_01__Default_Changelist_.xml +0 -4
  39. package/.idea/shelf/Uncommitted_changes_before_Update_at_24_07_2023_15_31_[Default_Changelist]/shelved.patch +0 -90
  40. package/.idea/shelf/Uncommitted_changes_before_Update_at_24_07_2023_15_31__Default_Changelist_.xml +0 -4
  41. package/.idea/vcs.xml +0 -6
  42. package/dev/pimath.js +0 -7945
  43. package/dev/pimath.js.map +0 -1
  44. package/dist/pimath.js.map +0 -1
  45. package/dist/pimath.min.js +0 -2
  46. package/dist/pimath.min.js.map +0 -1
  47. package/docs/.nojekyll +0 -1
  48. package/docs/assets/highlight.css +0 -78
  49. package/docs/assets/main.js +0 -59
  50. package/docs/assets/navigation.js +0 -1
  51. package/docs/assets/search.js +0 -1
  52. package/docs/assets/style.css +0 -1383
  53. package/docs/classes/Logicalset.Logicalset.html +0 -217
  54. package/docs/classes/Polynom.Rational.html +0 -397
  55. package/docs/classes/Vector-1.Vector.html +0 -490
  56. package/docs/classes/Vector.Point.html +0 -337
  57. package/docs/classes/algebra_equation.Equation.html +0 -790
  58. package/docs/classes/algebra_linearSystem.LinearSystem.html +0 -404
  59. package/docs/classes/algebra_monom.Monom.html +0 -962
  60. package/docs/classes/algebra_polynom.Polynom.html +0 -1275
  61. package/docs/classes/coefficients_fraction.Fraction.html +0 -934
  62. package/docs/classes/geometry_circle.Circle.html +0 -472
  63. package/docs/classes/geometry_line.Line.html +0 -774
  64. package/docs/classes/geometry_triangle.Triangle.html +0 -429
  65. package/docs/classes/numeric.Numeric.html +0 -265
  66. package/docs/classes/shutingyard.Shutingyard.html +0 -250
  67. package/docs/enums/algebra_equation.PARTICULAR_SOLUTION.html +0 -83
  68. package/docs/enums/geometry_line.LinePropriety.html +0 -97
  69. package/docs/enums/shutingyard.ShutingyardMode.html +0 -97
  70. package/docs/enums/shutingyard.ShutingyardType.html +0 -111
  71. package/docs/index.html +0 -63
  72. package/docs/interfaces/algebra_equation.ISolution.html +0 -105
  73. package/docs/interfaces/algebra_polynom.IEuclidian.html +0 -87
  74. package/docs/interfaces/geometry_triangle.remarquableLines.html +0 -163
  75. package/docs/modules/Logicalset.html +0 -65
  76. package/docs/modules/Polynom.html +0 -65
  77. package/docs/modules/Vector-1.html +0 -65
  78. package/docs/modules/Vector.html +0 -65
  79. package/docs/modules/algebra_equation.html +0 -69
  80. package/docs/modules/algebra_linearSystem.html +0 -61
  81. package/docs/modules/algebra_monom.html +0 -65
  82. package/docs/modules/algebra_polynom.html +0 -69
  83. package/docs/modules/coefficients_fraction.html +0 -65
  84. package/docs/modules/geometry_circle.html +0 -61
  85. package/docs/modules/geometry_line.html +0 -65
  86. package/docs/modules/geometry_triangle.html +0 -65
  87. package/docs/modules/numeric.html +0 -61
  88. package/docs/modules/shutingyard.html +0 -75
  89. package/docs/types/algebra_monom.literalType.html +0 -61
  90. package/docs/types/algebra_polynom.PolynomParsingType.html +0 -56
  91. package/docs/types/coefficients_fraction.FractionParsingType.html +0 -56
  92. package/docs/types/shutingyard.Token.html +0 -63
  93. package/docs/types/shutingyard.tokenType.html +0 -68
  94. package/docs/variables/shutingyard.tokenConstant.html +0 -61
  95. package/esm/index.d.ts +0 -38
  96. package/esm/index.js +0 -44
  97. package/esm/index.js.map +0 -1
  98. package/esm/maths/algebra/equation.js +0 -797
  99. package/esm/maths/algebra/equation.js.map +0 -1
  100. package/esm/maths/algebra/linearSystem.js +0 -279
  101. package/esm/maths/algebra/linearSystem.js.map +0 -1
  102. package/esm/maths/algebra/logicalset.js +0 -158
  103. package/esm/maths/algebra/logicalset.js.map +0 -1
  104. package/esm/maths/algebra/monom.js +0 -909
  105. package/esm/maths/algebra/monom.js.map +0 -1
  106. package/esm/maths/algebra/polynom.js +0 -1305
  107. package/esm/maths/algebra/polynom.js.map +0 -1
  108. package/esm/maths/algebra/rational.js +0 -195
  109. package/esm/maths/algebra/rational.js.map +0 -1
  110. package/esm/maths/algebra/study/rationalStudy.d.ts +0 -28
  111. package/esm/maths/algebra/study/rationalStudy.js +0 -244
  112. package/esm/maths/algebra/study/rationalStudy.js.map +0 -1
  113. package/esm/maths/algebra/study.js +0 -380
  114. package/esm/maths/algebra/study.js.map +0 -1
  115. package/esm/maths/coefficients/fraction.js +0 -517
  116. package/esm/maths/coefficients/fraction.js.map +0 -1
  117. package/esm/maths/coefficients/nthRoot.js +0 -137
  118. package/esm/maths/coefficients/nthRoot.js.map +0 -1
  119. package/esm/maths/geometry/circle.js +0 -324
  120. package/esm/maths/geometry/circle.js.map +0 -1
  121. package/esm/maths/geometry/line.js +0 -485
  122. package/esm/maths/geometry/line.js.map +0 -1
  123. package/esm/maths/geometry/point.js +0 -167
  124. package/esm/maths/geometry/point.js.map +0 -1
  125. package/esm/maths/geometry/triangle.js +0 -276
  126. package/esm/maths/geometry/triangle.js.map +0 -1
  127. package/esm/maths/geometry/vector.js +0 -198
  128. package/esm/maths/geometry/vector.js.map +0 -1
  129. package/esm/maths/numeric.js +0 -136
  130. package/esm/maths/numeric.js.map +0 -1
  131. package/esm/maths/numexp.js +0 -186
  132. package/esm/maths/numexp.js.map +0 -1
  133. package/esm/maths/randomization/random.js +0 -79
  134. package/esm/maths/randomization/random.js.map +0 -1
  135. package/esm/maths/randomization/randomCore.js +0 -22
  136. package/esm/maths/randomization/randomCore.js.map +0 -1
  137. package/esm/maths/randomization/rndFraction.js +0 -44
  138. package/esm/maths/randomization/rndFraction.js.map +0 -1
  139. package/esm/maths/randomization/rndGeometryLine.js +0 -46
  140. package/esm/maths/randomization/rndGeometryLine.js.map +0 -1
  141. package/esm/maths/randomization/rndGeometryPoint.js +0 -61
  142. package/esm/maths/randomization/rndGeometryPoint.js.map +0 -1
  143. package/esm/maths/randomization/rndHelpers.js +0 -98
  144. package/esm/maths/randomization/rndHelpers.js.map +0 -1
  145. package/esm/maths/randomization/rndMonom.js +0 -53
  146. package/esm/maths/randomization/rndMonom.js.map +0 -1
  147. package/esm/maths/randomization/rndPolynom.js +0 -75
  148. package/esm/maths/randomization/rndPolynom.js.map +0 -1
  149. package/esm/maths/randomization/rndTypes.js +0 -3
  150. package/esm/maths/randomization/rndTypes.js.map +0 -1
  151. package/esm/maths/shutingyard.js +0 -443
  152. package/esm/maths/shutingyard.js.map +0 -1
  153. package/public/demo.css +0 -3
  154. package/public/index.html +0 -283
  155. package/public/matrices.html +0 -100
  156. package/public/playground.html +0 -168
  157. package/src/index.ts +0 -42
  158. package/src/maths/algebra/equation.ts +0 -897
  159. package/src/maths/algebra/linearSystem.ts +0 -370
  160. package/src/maths/algebra/logicalset.ts +0 -183
  161. package/src/maths/algebra/monom.ts +0 -1028
  162. package/src/maths/algebra/polynom.ts +0 -1537
  163. package/src/maths/algebra/rational.ts +0 -240
  164. package/src/maths/algebra/study/rationalStudy.ts +0 -287
  165. package/src/maths/algebra/study.ts +0 -506
  166. package/src/maths/coefficients/fraction.ts +0 -593
  167. package/src/maths/coefficients/nthRoot.ts +0 -148
  168. package/src/maths/geometry/circle.ts +0 -382
  169. package/src/maths/geometry/line.ts +0 -604
  170. package/src/maths/geometry/point.ts +0 -215
  171. package/src/maths/geometry/triangle.ts +0 -368
  172. package/src/maths/geometry/vector.ts +0 -242
  173. package/src/maths/numeric.ts +0 -162
  174. package/src/maths/numexp.ts +0 -184
  175. package/src/maths/randomization/random.ts +0 -80
  176. package/src/maths/randomization/randomCore.ts +0 -19
  177. package/src/maths/randomization/rndFraction.ts +0 -47
  178. package/src/maths/randomization/rndGeometryCircle.ts +0 -50
  179. package/src/maths/randomization/rndGeometryLine.ts +0 -53
  180. package/src/maths/randomization/rndGeometryPoint.ts +0 -69
  181. package/src/maths/randomization/rndHelpers.ts +0 -107
  182. package/src/maths/randomization/rndMonom.ts +0 -57
  183. package/src/maths/randomization/rndPolynom.ts +0 -90
  184. package/src/maths/randomization/rndTypes.ts +0 -43
  185. package/src/maths/shutingyard.ts +0 -496
  186. package/tests/algebra/equation.test.ts +0 -64
  187. package/tests/algebra/linear.test.ts +0 -58
  188. package/tests/algebra/monom.test.ts +0 -78
  189. package/tests/algebra/polynom.test.ts +0 -343
  190. package/tests/algebra/rationnal.test.ts +0 -64
  191. package/tests/algebra/study.test.ts +0 -48
  192. package/tests/coefficients/fraction.test.ts +0 -131
  193. package/tests/custom.test.ts +0 -33
  194. package/tests/geometry/circle.test.ts +0 -404
  195. package/tests/geometry/line.test.ts +0 -36
  196. package/tests/numeric.test.ts +0 -43
  197. package/tests/numexp.test.ts +0 -89
  198. package/tests/shutingyard.test.ts +0 -58
  199. package/tsconfig.json +0 -41
  200. package/tsconfig.testing.json +0 -28
  201. package/typedoc.katex.js +0 -11
  202. package/webpack-production-min.config.js +0 -26
  203. package/webpack-production.config.js +0 -26
  204. package/webpack.config.js +0 -26
  205. package/{esm → dist}/maths/algebra/logicalset.d.ts +6 -6
  206. package/{esm → dist}/maths/coefficients/fraction.d.ts +0 -0
  207. package/{esm → dist}/maths/coefficients/nthRoot.d.ts +0 -0
  208. package/{esm → dist}/maths/numeric.d.ts +0 -0
  209. package/{esm → dist}/maths/numexp.d.ts +3 -3
  210. /package/{esm → dist}/maths/randomization/randomCore.d.ts +0 -0
  211. /package/{esm → dist}/maths/randomization/rndHelpers.d.ts +0 -0
  212. /package/{esm → dist}/maths/shutingyard.d.ts +0 -0
@@ -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
- }