pimath 0.0.33 → 0.0.36

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 (165) hide show
  1. package/dist/pi.js +6468 -1
  2. package/dist/pi.js.map +1 -1
  3. package/dist/pi.min.js +2 -0
  4. package/dist/pi.min.js.map +1 -0
  5. package/docs/assets/search.js +1 -1
  6. package/docs/classes/algebra.Equation.html +9 -9
  7. package/docs/classes/algebra.LinearSystem.html +1 -1
  8. package/docs/classes/algebra.Logicalset.html +2 -2
  9. package/docs/classes/algebra.Monom.html +37 -37
  10. package/docs/classes/algebra.Polynom.html +10 -10
  11. package/docs/classes/algebra.PolynomExpFactor.html +1 -1
  12. package/docs/classes/algebra.PolynomExpProduct.html +1 -1
  13. package/docs/classes/algebra.Rational.html +2 -2
  14. package/docs/classes/coefficients.Fraction.html +4 -4
  15. package/docs/classes/coefficients.Nthroot.html +1 -1
  16. package/docs/classes/geometry.Circle.html +2 -2
  17. package/docs/classes/geometry.Line.html +2 -2
  18. package/docs/classes/geometry.Point.html +1 -1
  19. package/docs/classes/geometry.Triangle.html +5 -5
  20. package/docs/classes/geometry.Vector.html +1 -1
  21. package/docs/classes/numeric.Numeric.html +5 -5
  22. package/docs/classes/shutingyard.Shutingyard.html +4 -4
  23. package/docs/enums/geometry.LinePropriety.html +1 -0
  24. package/docs/enums/shutingyard.ShutingyardMode.html +1 -1
  25. package/docs/enums/shutingyard.ShutingyardType.html +1 -1
  26. package/docs/interfaces/geometry.remarquableLines.html +1 -1
  27. package/docs/modules/algebra.html +1 -1
  28. package/docs/modules/coefficients.html +1 -1
  29. package/docs/modules/geometry.html +1 -1
  30. package/docs/modules/random.Random.html +1 -1
  31. package/docs/modules/random.html +1 -1
  32. package/docs/modules/shutingyard.html +1 -1
  33. package/esm/main.d.ts +41 -1
  34. package/esm/main.js +34 -20
  35. package/esm/main.js.map +1 -1
  36. package/esm/maths/algebra/equation.d.ts +63 -18
  37. package/esm/maths/algebra/equation.js +599 -503
  38. package/esm/maths/algebra/equation.js.map +1 -1
  39. package/esm/maths/algebra/linearSystem.d.ts +1 -1
  40. package/esm/maths/algebra/linearSystem.js +157 -104
  41. package/esm/maths/algebra/linearSystem.js.map +1 -1
  42. package/esm/maths/algebra/logicalset.d.ts +11 -0
  43. package/esm/maths/algebra/logicalset.js +18 -6
  44. package/esm/maths/algebra/logicalset.js.map +1 -1
  45. package/esm/maths/algebra/monom.d.ts +142 -1
  46. package/esm/maths/algebra/monom.js +633 -405
  47. package/esm/maths/algebra/monom.js.map +1 -1
  48. package/esm/maths/algebra/polynom.d.ts +52 -3
  49. package/esm/maths/algebra/polynom.js +1003 -720
  50. package/esm/maths/algebra/polynom.js.map +1 -1
  51. package/esm/maths/algebra/rational.d.ts +13 -1
  52. package/esm/maths/algebra/rational.js +98 -83
  53. package/esm/maths/algebra/rational.js.map +1 -1
  54. package/esm/maths/coefficients/fraction.d.ts +18 -0
  55. package/esm/maths/coefficients/fraction.js +390 -332
  56. package/esm/maths/coefficients/fraction.js.map +1 -1
  57. package/esm/maths/coefficients/nthroot.d.ts +3 -0
  58. package/esm/maths/coefficients/nthroot.js +48 -33
  59. package/esm/maths/coefficients/nthroot.js.map +1 -1
  60. package/esm/maths/expressions/numexp.js +13 -5
  61. package/esm/maths/expressions/numexp.js.map +1 -1
  62. package/esm/maths/expressions/polynomexp.bkp.d.ts +2 -2
  63. package/esm/maths/expressions/polynomexp.bkp.js +95 -95
  64. package/esm/maths/expressions/polynomexp.bkp.js.map +1 -1
  65. package/esm/maths/expressions/polynomexp.d.ts +2 -2
  66. package/esm/maths/expressions/polynomexp.js +27 -14
  67. package/esm/maths/expressions/polynomexp.js.map +1 -1
  68. package/esm/maths/geometry/circle.d.ts +20 -8
  69. package/esm/maths/geometry/circle.js +148 -50
  70. package/esm/maths/geometry/circle.js.map +1 -1
  71. package/esm/maths/geometry/line.d.ts +11 -4
  72. package/esm/maths/geometry/line.js +251 -193
  73. package/esm/maths/geometry/line.js.map +1 -1
  74. package/esm/maths/geometry/point.d.ts +13 -1
  75. package/esm/maths/geometry/point.js +124 -76
  76. package/esm/maths/geometry/point.js.map +1 -1
  77. package/esm/maths/geometry/triangle.d.ts +23 -1
  78. package/esm/maths/geometry/triangle.js +197 -158
  79. package/esm/maths/geometry/triangle.js.map +1 -1
  80. package/esm/maths/geometry/vector.d.ts +5 -1
  81. package/esm/maths/geometry/vector.js +139 -115
  82. package/esm/maths/geometry/vector.js.map +1 -1
  83. package/esm/maths/numeric.d.ts +17 -0
  84. package/esm/maths/numeric.js +40 -0
  85. package/esm/maths/numeric.js.map +1 -1
  86. package/esm/maths/{random/index.d.ts → randomization/random.d.ts} +3 -2
  87. package/esm/maths/{random/index.js → randomization/random.js} +6 -2
  88. package/esm/maths/randomization/random.js.map +1 -0
  89. package/esm/maths/{random → randomization}/randomCore.d.ts +0 -0
  90. package/esm/maths/randomization/randomCore.js +22 -0
  91. package/esm/maths/randomization/randomCore.js.map +1 -0
  92. package/esm/maths/{random → randomization}/rndFraction.d.ts +4 -1
  93. package/esm/maths/randomization/rndFraction.js +40 -0
  94. package/esm/maths/randomization/rndFraction.js.map +1 -0
  95. package/esm/maths/randomization/rndHelpers.d.ts +25 -0
  96. package/esm/maths/{random → randomization}/rndHelpers.js +20 -0
  97. package/esm/maths/randomization/rndHelpers.js.map +1 -0
  98. package/esm/maths/{random → randomization}/rndMonom.d.ts +4 -1
  99. package/esm/maths/randomization/rndMonom.js +53 -0
  100. package/esm/maths/randomization/rndMonom.js.map +1 -0
  101. package/esm/maths/{random → randomization}/rndPolynom.d.ts +4 -1
  102. package/esm/maths/randomization/rndPolynom.js +75 -0
  103. package/esm/maths/randomization/rndPolynom.js.map +1 -0
  104. package/esm/maths/{random → randomization}/rndTypes.d.ts +0 -0
  105. package/esm/maths/{random → randomization}/rndTypes.js +0 -0
  106. package/esm/maths/randomization/rndTypes.js.map +1 -0
  107. package/esm/maths/shutingyard.d.ts +21 -0
  108. package/esm/maths/shutingyard.js +86 -9
  109. package/esm/maths/shutingyard.js.map +1 -1
  110. package/package.json +2 -2
  111. package/public/index.html +47 -0
  112. package/src/main.ts +17 -15
  113. package/src/maths/algebra/equation.ts +144 -129
  114. package/src/maths/algebra/linearSystem.ts +2 -2
  115. package/src/maths/algebra/monom.ts +1 -1
  116. package/src/maths/algebra/polynom.ts +136 -136
  117. package/src/maths/algebra/rational.ts +1 -1
  118. package/src/maths/expressions/numexp.ts +1 -1
  119. package/src/maths/expressions/polynomexp.bkp.ts +2 -2
  120. package/src/maths/expressions/polynomexp.ts +2 -2
  121. package/src/maths/geometry/circle.ts +172 -77
  122. package/src/maths/geometry/line.ts +4 -3
  123. package/src/maths/geometry/point.ts +26 -3
  124. package/src/maths/geometry/triangle.ts +1 -1
  125. package/src/maths/geometry/vector.ts +1 -1
  126. package/src/maths/numeric.ts +15 -0
  127. package/src/maths/{random/index.ts → randomization/random.ts} +3 -2
  128. package/src/maths/{random → randomization}/randomCore.ts +0 -0
  129. package/src/maths/{random → randomization}/rndFraction.ts +2 -2
  130. package/src/maths/{random → randomization}/rndHelpers.ts +0 -0
  131. package/src/maths/{random → randomization}/rndMonom.ts +2 -2
  132. package/src/maths/{random → randomization}/rndPolynom.ts +3 -3
  133. package/src/maths/{random → randomization}/rndTypes.ts +0 -0
  134. package/tests/algebra/monom.test.ts +1 -1
  135. package/tests/algebra/polynom.test.ts +8 -9
  136. package/tests/geometry/circle.test.ts +33 -0
  137. package/tsconfig.json +2 -2
  138. package/webpack-production-min.config.js +26 -0
  139. package/webpack-production.config.js +1 -1
  140. package/dev/pi.js +0 -5392
  141. package/dev/pi.js.map +0 -1
  142. package/esm/maths/algebra/index.d.ts +0 -7
  143. package/esm/maths/algebra/index.js +0 -20
  144. package/esm/maths/algebra/index.js.map +0 -1
  145. package/esm/maths/coefficients/index.d.ts +0 -2
  146. package/esm/maths/coefficients/index.js +0 -15
  147. package/esm/maths/coefficients/index.js.map +0 -1
  148. package/esm/maths/geometry/index.d.ts +0 -5
  149. package/esm/maths/geometry/index.js +0 -18
  150. package/esm/maths/geometry/index.js.map +0 -1
  151. package/esm/maths/random/index.js.map +0 -1
  152. package/esm/maths/random/randomCore.js +0 -22
  153. package/esm/maths/random/randomCore.js.map +0 -1
  154. package/esm/maths/random/rndFraction.js +0 -37
  155. package/esm/maths/random/rndFraction.js.map +0 -1
  156. package/esm/maths/random/rndHelpers.d.ts +0 -8
  157. package/esm/maths/random/rndHelpers.js.map +0 -1
  158. package/esm/maths/random/rndMonom.js +0 -46
  159. package/esm/maths/random/rndMonom.js.map +0 -1
  160. package/esm/maths/random/rndPolynom.js +0 -63
  161. package/esm/maths/random/rndPolynom.js.map +0 -1
  162. package/esm/maths/random/rndTypes.js.map +0 -1
  163. package/src/maths/algebra/index.ts +0 -7
  164. package/src/maths/coefficients/index.ts +0 -2
  165. package/src/maths/geometry/index.ts +0 -5
@@ -2,13 +2,14 @@
2
2
  * This class works for 2d line in a plane.
3
3
  */
4
4
 
5
- import {Fraction} from "../coefficients";
6
5
  import {Vector} from "./vector";
7
6
  import {Point} from "./point";
8
- import {Equation, Polynom} from "../algebra";
9
7
  import {Numeric} from "../numeric";
8
+ import {Fraction} from "../coefficients/fraction";
9
+ import {Equation} from "../algebra/equation";
10
+ import {Polynom} from "../algebra/polynom";
10
11
 
11
- enum LinePropriety {
12
+ export enum LinePropriety {
12
13
  None,
13
14
  Parallel='parallel',
14
15
  Perpendicular = 'perpendicular',
@@ -2,7 +2,9 @@
2
2
  * Vector module contains everything necessary to handle 2d or 3d vectors.
3
3
  * @module Vector
4
4
  */
5
- import {Fraction} from "../coefficients"
5
+ import {Line} from "./line";
6
+ import {Vector} from "./vector";
7
+ import {Fraction} from "../coefficients/fraction";
6
8
 
7
9
  /**
8
10
  * Helper class - a way to identify an object {x: number, y: number}
@@ -68,8 +70,6 @@ export class Point {
68
70
  // ------------------------------------------
69
71
  // Creation / parsing functions
70
72
  // ------------------------------------------
71
-
72
-
73
73
  parse = (...values: unknown[]): Point => {
74
74
  // Initialize the value.
75
75
  this.zero();
@@ -171,4 +171,27 @@ export class Point {
171
171
  }
172
172
  };
173
173
 
174
+ distanceTo = (item:Point|Line): { value: number, fraction: Fraction, tex: string } => {
175
+ let value = 0, fraction = new Fraction(), tex = ''
176
+
177
+ if(item instanceof Line){
178
+ return item.distanceTo(this)
179
+ }else if(item instanceof Point){
180
+ let V = new Vector(this, item)
181
+
182
+ value = V.norm
183
+ fraction = V.normSquare.sqrt()
184
+ tex = V.normSquare.isSquare()?fraction.tex:`\\sqrt{\\dfrac{ ${V.normSquare.numerator} }{ ${V.normSquare.denominator} }}`
185
+ }
186
+ return { value, fraction, tex }
187
+ }
188
+
189
+ get key(): string {
190
+ return `${this.x.display};${this.y.display}`
191
+ }
192
+ isInListOfPoints = (list: Point[]): boolean => {
193
+ const keyList = list.map(x=>x.key)
194
+
195
+ return keyList.includes(this.key)
196
+ }
174
197
  }
@@ -48,7 +48,7 @@ export class Triangle {
48
48
  private _remarquables: remarquableLines;
49
49
 
50
50
 
51
- constructor(...values: any) {
51
+ constructor(...values: unknown[]) {
52
52
 
53
53
  if (values.length > 0) {
54
54
  this.parse(...values);
@@ -10,7 +10,7 @@ export class Vector {
10
10
  private _x: Fraction; // 1st component
11
11
  private _y: Fraction; // 2nd component
12
12
 
13
- constructor(...values: any) {
13
+ constructor(...values: unknown[]) {
14
14
  this._x = new Fraction().zero();
15
15
  this._y = new Fraction().zero();
16
16
 
@@ -89,4 +89,19 @@ export class Numeric{
89
89
  return Math.abs(a * b / Numeric.gcd(a, b));
90
90
  });
91
91
  }
92
+
93
+ static pythagoricianTripletsWithTarget(target: number, targetIsSquare?:boolean): number[][] {
94
+ // méthode inverse, à partir du triplet.
95
+ const triplets = [],
96
+ targetValue = targetIsSquare===true?+target:target**2
97
+ for(let u = 0; u <= target; u++){
98
+ for(let v = 0; v <=target; v++){
99
+ if(u**2+v**2===targetValue){
100
+ triplets.push([u, v, target])
101
+ }
102
+ }
103
+ }
104
+
105
+ return triplets
106
+ }
92
107
  }
@@ -2,9 +2,10 @@ import {rndPolynom} from "./rndPolynom";
2
2
  import {rndMonom} from "./rndMonom";
3
3
  import {rndHelpers} from "./rndHelpers";
4
4
  import {randomCoefficientConfig, randomMonomConfig, randomPolynomConfig} from "./rndTypes";
5
- import {Monom, Polynom} from "../algebra";
6
- import {Fraction} from "../coefficients";
7
5
  import {rndFraction} from "./rndFraction";
6
+ import {Polynom} from "../algebra/polynom";
7
+ import {Monom} from "../algebra/monom";
8
+ import {Fraction} from "../coefficients/fraction";
8
9
 
9
10
  export * from "./rndTypes"
10
11
 
@@ -1,7 +1,7 @@
1
1
  import {randomCore} from "./randomCore";
2
2
  import {randomCoefficientConfig, randomMonomConfig, randomPolynomConfig} from "./rndTypes";
3
- import {Fraction} from "../coefficients";
4
- import {Random} from "./index";
3
+ import {Random} from "./random";
4
+ import {Fraction} from "../coefficients/fraction";
5
5
 
6
6
  /**
7
7
  * Create a random monom based on a based configuration
@@ -1,7 +1,7 @@
1
1
  import {randomCore} from "./randomCore";
2
2
  import {randomMonomConfig} from "./rndTypes";
3
- import {Random} from "./index";
4
- import {Monom} from "../algebra";
3
+ import {Random} from "./random";
4
+ import {Monom} from "../algebra/monom";
5
5
 
6
6
  /**
7
7
  * Create a random monom based on a based configuration
@@ -1,9 +1,9 @@
1
1
  import {randomCore} from "./randomCore";
2
2
  import {randomPolynomConfig} from "./rndTypes";
3
3
  import {rndMonom} from "./rndMonom";
4
- import {Random} from "./index";
5
- import {Polynom} from "../algebra";
6
- import {Monom} from "../algebra";
4
+ import {Random} from "./random";
5
+ import {Polynom} from "../algebra/polynom";
6
+ import {Monom} from "../algebra/monom";
7
7
 
8
8
  /**
9
9
  * Random polynoms
File without changes
@@ -1,6 +1,6 @@
1
1
  import {expect} from 'chai';
2
2
  import {Monom} from "../../src/maths/algebra";
3
- import {Random} from "../../src/maths/random";
3
+ import {Random} from "../../src/maths/randomization/random";
4
4
  import {describe} from "mocha";
5
5
  import {Fraction} from "../../src/maths/coefficients";
6
6
  import {Shutingyard} from "../../src/maths/shutingyard";
@@ -1,9 +1,8 @@
1
1
  import {expect} from 'chai';
2
- import {Fraction} from "../../src/maths/coefficients";
3
- import {Monom, Polynom} from "../../src/maths/algebra";
4
- import {Random} from "../../src/maths/random";
2
+ import {Random} from "../../src/maths/randomization/random";
5
3
  import {describe} from "mocha";
6
- import {Shutingyard} from "../../src/maths/shutingyard";
4
+ import {Polynom} from "../../src/maths/algebra/polynom";
5
+ import {Fraction} from "../../src/maths/coefficients/fraction";
7
6
 
8
7
  describe('Polynom tests', () => {
9
8
  it('Parse polynom', () => {
@@ -12,7 +11,7 @@ describe('Polynom tests', () => {
12
11
  expect(options.tex).to.be.equal('2x^{4}+10x^{3}+6x^{2}-18x');
13
12
  });
14
13
 
15
- it('Parse polynom with coefficient as fraction', ()=>{
14
+ it('Parse polynom with coefficient as fraction', () => {
16
15
  const P = new Polynom('-3/5x-2')
17
16
 
18
17
  console.log(P.tex)
@@ -68,16 +67,16 @@ describe('Polynom tests', () => {
68
67
  expect(euclidian.reminder.tex).to.be.equal('12')
69
68
  });
70
69
 
71
- it('should factorize the polynom', ()=> {
70
+ it('should factorize the polynom', () => {
72
71
  let P = new Polynom('x^2-5x+6')
73
72
 
74
73
  P.factorize()
75
- expect(P.factors.map(x=>x.tex)).to.have.all.members(['x-2', 'x-3'])
74
+ expect(P.factors.map(x => x.tex)).to.have.all.members(['x-2', 'x-3'])
76
75
  })
77
76
  })
78
77
 
79
- describe('Polynom parsing with rational power', ()=>{
80
- it('should parse with rational powers', ()=> {
78
+ describe('Polynom parsing with rational power', () => {
79
+ it('should parse with rational powers', () => {
81
80
  const P = new Polynom('3x^(2/3)-5x+5/3');
82
81
 
83
82
  expect(P.tex).to.be.equal('3x^{\\tfrac{ 2 }{ 3 }}-5x+\\dfrac{ 5 }{ 3 }')
@@ -25,4 +25,37 @@ describe('Circle', function () {
25
25
  expect(IPS[1].x.value).to.be.equal(6)
26
26
  expect(IPS[1].y.value).to.be.equal(10)
27
27
  });
28
+
29
+ it('should calculate tangents', function(){
30
+
31
+ // Through one point on the circle
32
+ const C = new Circle(
33
+ new Point(-2, 3),
34
+ 25,
35
+ true
36
+ ), P = new Point(-5, 7);
37
+
38
+ expect(C.tangents(P).map(x=>x.tex.canonical)).to.have.all.members(['3x-4y+43=0'])
39
+
40
+ // With a slope
41
+ const D = new Circle('x^2+y^2+10x=2y-6'),
42
+ slope = new Fraction(-2, 1)
43
+
44
+ expect(D.tangents(slope).map(x=>x.tex.canonical)).to.have.all.members(['2x+y-1=0', '2x+y+19=0'])
45
+
46
+ const E = new Circle('(x-2)^2+(y-1)^2=5'),
47
+ P2 = new Point(6, -2)
48
+
49
+ expect(E.tangents(P2).map(x=>x.tex.canonical)).to.have.all.members(['2x+y-10=0','2x+11y+10=0'])
50
+
51
+ let P3 = new Point(2, 2)
52
+ expect(E.tangents(P3)).to.be.empty
53
+ })
54
+
55
+ it('should get a list of point on the circle', function () {
56
+ const C = new Circle('(x-3)^2+(y+4)^2=16'),
57
+ pts = C.getPointsOnCircle()
58
+
59
+ expect(pts.map(x=>x.x.display + ',' + x.y.display)).to.have.all.members([ '3,0', '3,-8', '7,-4', '-1,-4' ])
60
+ });
28
61
  });
package/tsconfig.json CHANGED
@@ -17,12 +17,12 @@
17
17
  "outDir": "./esm/",
18
18
  "noImplicitAny": true,
19
19
  "module": "commonjs",
20
- "target": "esnext",
20
+ "target": "es2021",
21
21
  "allowJs": true,
22
22
  "sourceMap": true,
23
23
  "moduleResolution": "node",
24
24
  "declaration": true,
25
- "removeComments": true
25
+ "removeComments": false
26
26
  },
27
27
  "include": [
28
28
  "./src/**/*"
@@ -0,0 +1,26 @@
1
+ const path = require('path');
2
+
3
+ module.exports = {
4
+ mode: 'production',
5
+ entry: './src/main.ts',
6
+ devtool: 'source-map',
7
+ module: {
8
+ rules: [
9
+ {
10
+ test: /\.tsx?$/,
11
+ use: 'ts-loader',
12
+ exclude: /node_module/,
13
+ },
14
+ ],
15
+ },
16
+ resolve: {
17
+ extensions: ['.tsx','.ts', '.js'],
18
+ },
19
+ output: {
20
+ filename: 'pi.min.js',
21
+ path: path.resolve(__dirname, 'dist'),
22
+ },
23
+ optimization: {
24
+ minimize: true
25
+ }
26
+ };
@@ -21,6 +21,6 @@ module.exports = {
21
21
  path: path.resolve(__dirname, 'dist'),
22
22
  },
23
23
  optimization: {
24
- minimize: true
24
+ minimize: false
25
25
  }
26
26
  };