pimath 0.0.18 → 0.0.22

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.
package/dev/index.html CHANGED
@@ -18,41 +18,50 @@
18
18
 
19
19
  <script>
20
20
 
21
- let C1 = new Pi.Geometry.Point(-5, 4),
22
- r1 = 36,
23
- C2 = new Pi.Geometry.Point(7, -2),
24
- T = new Pi.Geometry.Point(2, 3)
21
+ let P = new Pi.Random.polynom({
22
+ degree: 4,
23
+ fraction: false
24
+ })
25
25
 
26
- let G1 = new Pi.Geometry.Circle(C1, r1, true),
27
- G2 = new Pi.Geometry.Circle(C2, T)
26
+ console.log(P.display)
28
27
 
29
- console.log('G1', G1.tex)
30
- console.log('G2', G2.tex)
31
-
32
- let t = new Pi.Geometry.Line(
33
- new Pi.Geometry.Vector(C2, T),
34
- T
35
- )
36
-
37
- console.log(t.tex.canonical)
38
- console.log(G1.relativePosition(t))
39
-
40
- let d = new Pi.Geometry.Line(G1.center, G2.center)
41
- console.log(d.tex.canonical)
42
-
43
- let M = new Pi.Geometry.Point(
44
- G1.center.x.clone().add(G2.center.x).divide(2),
45
- G1.center.y.clone().add(G2.center.y).divide(2),
46
- )
47
-
48
- console.log(M.display)
49
-
50
- let k = new Pi.Geometry.Line().parseByPointAndLine(
51
- M, d,
52
- Pi.Geometry.Line.PERPENDICULAR
53
- )
54
-
55
- console.log(k.tex.canonical)
28
+ // let C1 = new Pi.Geometry.Point(-5, 4),
29
+ // r1 = 36,
30
+ // C2 = new Pi.Geometry.Point(7, -2),
31
+ // T = new Pi.Geometry.Point(2, 3)
32
+ //
33
+ // let G1 = new Pi.Geometry.Circle(C1, r1, true),
34
+ // G2 = new Pi.Geometry.Circle(C2, T)
35
+ //
36
+ // console.log('G1', G1.tex)
37
+ // console.log('G2', G2.tex)
38
+ //
39
+ // let t = new Pi.Geometry.Line(
40
+ // new Pi.Geometry.Vector(C2, T),
41
+ // T
42
+ // )
43
+ //
44
+ // console.log(t.tex.canonical)
45
+ // console.log(G1.relativePosition(t))
46
+ //
47
+ // let d = new Pi.Geometry.Line(G1.center, G2.center)
48
+ // console.log(d.tex.canonical)
49
+ //
50
+ // let M = new Pi.Geometry.Point(
51
+ // G1.center.x.clone().add(G2.center.x).divide(2),
52
+ // G1.center.y.clone().add(G2.center.y).divide(2),
53
+ // )
54
+ //
55
+ // console.log(M.display)
56
+ //
57
+ // let k = new Pi.Geometry.Line().parseByPointAndLine(
58
+ // M, d,
59
+ // Pi.Geometry.Line.PERPENDICULAR
60
+ // )
61
+ //
62
+ // console.log(k.tex.canonical)
63
+ //
64
+ // console.log(G1.lineIntersection(d))
56
65
  </script>
57
66
  </body>
58
67
  </html>
package/dev/pi.js CHANGED
@@ -84,6 +84,9 @@ class Equation {
84
84
  get tex() {
85
85
  return `${this._left.tex}${this.signAsTex}${this._right.tex}`;
86
86
  }
87
+ get display() {
88
+ return `${this._left.display}${this.signAsTex}${this._right.display}`;
89
+ }
87
90
  get raw() {
88
91
  return `${this._left.raw}${this.signAsTex}${this._right.raw}`;
89
92
  }
@@ -1981,9 +1984,9 @@ class Polynom {
1981
1984
  resultPolynom.add(m.clone());
1982
1985
  }
1983
1986
  else {
1984
- pow = +m.literal[letter];
1987
+ pow = m.literal[letter].clone();
1985
1988
  delete m.literal[letter];
1986
- resultPolynom.add(P.clone().pow(pow).multiply(m));
1989
+ resultPolynom.add(P.clone().pow(Math.abs(pow.numerator)).multiply(m));
1987
1990
  }
1988
1991
  }
1989
1992
  this._monoms = resultPolynom.reduce().reorder().monoms;
@@ -2941,27 +2944,6 @@ class Circle {
2941
2944
  get center() {
2942
2945
  return this._center;
2943
2946
  }
2944
- parse(...values) {
2945
- if (values.length === 1 && typeof values[0] === 'string') {
2946
- this.checkCircle(new algebra_1.Equation(values[0]));
2947
- }
2948
- else if (values.length >= 2) {
2949
- this._center = new point_1.Point(values[0]);
2950
- if (values[1] instanceof point_1.Point) {
2951
- this._squareRadius = new vector_1.Vector(this._center, values[1]).normSquare;
2952
- }
2953
- else {
2954
- if (values[2] === true) {
2955
- this._squareRadius = new coefficients_1.Fraction(values[1]);
2956
- }
2957
- else {
2958
- this._radius = new coefficients_1.Fraction(values[1]);
2959
- this._squareRadius = this._radius.clone().pow(2);
2960
- }
2961
- }
2962
- this._cartesian = (new algebra_1.Equation(new algebra_1.Polynom(`(x-(${this._center.x.display}))^2+(y-(${this._center.y.display}))^2`), new algebra_1.Polynom(`${this._squareRadius.display}`))).moveLeft();
2963
- }
2964
- }
2965
2947
  get radius() {
2966
2948
  if (this._squareRadius.isSquare()) {
2967
2949
  return {
@@ -2996,6 +2978,33 @@ class Circle {
2996
2978
  get developed() {
2997
2979
  return this._cartesian.tex;
2998
2980
  }
2981
+ get display() {
2982
+ return this._cartesian.display;
2983
+ }
2984
+ get cartesian() {
2985
+ return this._cartesian;
2986
+ }
2987
+ parse(...values) {
2988
+ if (values.length === 1 && typeof values[0] === 'string') {
2989
+ this.checkCircle(new algebra_1.Equation(values[0]));
2990
+ }
2991
+ else if (values.length >= 2) {
2992
+ this._center = new point_1.Point(values[0]);
2993
+ if (values[1] instanceof point_1.Point) {
2994
+ this._squareRadius = new vector_1.Vector(this._center, values[1]).normSquare;
2995
+ }
2996
+ else {
2997
+ if (values[2] === true) {
2998
+ this._squareRadius = new coefficients_1.Fraction(values[1]);
2999
+ }
3000
+ else {
3001
+ this._radius = new coefficients_1.Fraction(values[1]);
3002
+ this._squareRadius = this._radius.clone().pow(2);
3003
+ }
3004
+ }
3005
+ this._cartesian = (new algebra_1.Equation(new algebra_1.Polynom(`(x-(${this._center.x.display}))^2+(y-(${this._center.y.display}))^2`), new algebra_1.Polynom(`${this._squareRadius.display}`))).moveLeft();
3006
+ }
3007
+ }
2999
3008
  checkCircle = (P) => {
3000
3009
  if (P.degree('x').value === 2 && P.degree('y').value === 2) {
3001
3010
  let x2 = P.left.monomByDegree(2, 'x'), y2 = P.left.monomByDegree(2, 'y'), x1, y1, c;
@@ -3024,6 +3033,15 @@ class Circle {
3024
3033
  return 2;
3025
3034
  }
3026
3035
  };
3036
+ lineIntersection = (L) => {
3037
+ let P1, P2;
3038
+ const equ = this._cartesian.clone(), yLine = L.equation.clone().isolate('y');
3039
+ if (yLine instanceof algebra_1.Equation) {
3040
+ equ.replaceBy('y', yLine.right);
3041
+ equ.solve();
3042
+ }
3043
+ return [];
3044
+ };
3027
3045
  }
3028
3046
  exports.Circle = Circle;
3029
3047
 
@@ -3341,6 +3359,20 @@ class Line {
3341
3359
  }
3342
3360
  return false;
3343
3361
  }
3362
+ getValueAtX = (value) => {
3363
+ const equ = this.equation.clone().isolate('y');
3364
+ if (equ instanceof algebra_1.Equation) {
3365
+ return equ.right.evaluate({ x: value });
3366
+ }
3367
+ return;
3368
+ };
3369
+ getValueAtY = (value) => {
3370
+ const equ = this.equation.clone().isolate('x');
3371
+ if (equ instanceof algebra_1.Equation) {
3372
+ return equ.right.evaluate({ y: value });
3373
+ }
3374
+ return;
3375
+ };
3344
3376
  canonicalAsFloatCoefficient(decimals) {
3345
3377
  if (decimals === undefined) {
3346
3378
  decimals = 2;
@@ -4009,17 +4041,29 @@ var Random;
4009
4041
  return (new rndFraction_1.rndFraction(config)).generate();
4010
4042
  }
4011
4043
  Random.fraction = fraction;
4012
- function number(from, to) { return rndHelpers_1.rndHelpers.randomInt(from, to); }
4044
+ function number(from, to) {
4045
+ return rndHelpers_1.rndHelpers.randomInt(from, to);
4046
+ }
4013
4047
  Random.number = number;
4014
- function numberSym(max, allowZero) { return rndHelpers_1.rndHelpers.randomIntSym(max, allowZero); }
4048
+ function numberSym(max, allowZero) {
4049
+ return rndHelpers_1.rndHelpers.randomIntSym(max, allowZero);
4050
+ }
4015
4051
  Random.numberSym = numberSym;
4016
- function bool(percent) { return rndHelpers_1.rndHelpers.randomBool(percent); }
4052
+ function bool(percent) {
4053
+ return rndHelpers_1.rndHelpers.randomBool(percent);
4054
+ }
4017
4055
  Random.bool = bool;
4018
- function array(arr, number) { return rndHelpers_1.rndHelpers.randomArray(arr, number); }
4056
+ function array(arr, number) {
4057
+ return rndHelpers_1.rndHelpers.randomArray(arr, number);
4058
+ }
4019
4059
  Random.array = array;
4020
- function item(arr) { return rndHelpers_1.rndHelpers.randomItem(arr); }
4060
+ function item(arr) {
4061
+ return rndHelpers_1.rndHelpers.randomItem(arr);
4062
+ }
4021
4063
  Random.item = item;
4022
- function shuffle(arr) { rndHelpers_1.rndHelpers.shuffleArray(arr); }
4064
+ function shuffle(arr) {
4065
+ rndHelpers_1.rndHelpers.shuffleArray(arr);
4066
+ }
4023
4067
  Random.shuffle = shuffle;
4024
4068
  })(Random = exports.Random || (exports.Random = {}));
4025
4069
 
@@ -4075,7 +4119,8 @@ class rndFraction extends randomCore_1.randomCore {
4075
4119
  this._defaultConfig = {
4076
4120
  negative: true,
4077
4121
  reduced: true,
4078
- zero: true
4122
+ zero: true,
4123
+ natural: false
4079
4124
  };
4080
4125
  this._config = this.mergeConfig(userConfig, this._defaultConfig);
4081
4126
  }
@@ -4087,7 +4132,12 @@ class rndFraction extends randomCore_1.randomCore {
4087
4132
  else {
4088
4133
  Q.numerator = index_1.Random.number(this._config.zero ? 0 : 1, 10);
4089
4134
  }
4090
- Q.denominator = index_1.Random.number(1, 10);
4135
+ if (this._config.natural) {
4136
+ Q.denominator = 1;
4137
+ }
4138
+ else {
4139
+ Q.denominator = index_1.Random.number(1, 10);
4140
+ }
4091
4141
  return this._config.reduced ? Q.reduce() : Q;
4092
4142
  };
4093
4143
  }
@@ -4181,7 +4231,8 @@ class rndMonom extends randomCore_1.randomCore {
4181
4231
  let M = new monom_1.Monom();
4182
4232
  M.coefficient = index_1.Random.fraction({
4183
4233
  zero: this._config.zero,
4184
- reduced: true
4234
+ reduced: true,
4235
+ natural: !this._config.fraction
4185
4236
  });
4186
4237
  if (this._config.letters.length > 1) {
4187
4238
  for (let L of this._config.letters.split('')) {