pimath 0.0.109 → 0.0.111

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/dist/pi.js CHANGED
@@ -857,6 +857,7 @@ exports.LinearSystem = void 0;
857
857
  const equation_1 = __webpack_require__(760);
858
858
  const fraction_1 = __webpack_require__(506);
859
859
  const polynom_1 = __webpack_require__(38);
860
+ const numeric_1 = __webpack_require__(956);
860
861
  // TODO: Must check and rework
861
862
  class LinearSystem {
862
863
  constructor(...equationStrings) {
@@ -885,7 +886,7 @@ class LinearSystem {
885
886
  // Add the right hand part of the equation (should be only a number, because it has been reordered)
886
887
  equStr.push(equ.right.tex);
887
888
  // Add the operations if existing
888
- if (operators[i]) {
889
+ if (operators !== undefined && operators[i] !== undefined) {
889
890
  // add extra space at the end of the equation
890
891
  equStr[equStr.length - 1] = equStr[equStr.length - 1] + ' \\phantom{\\quad}';
891
892
  for (let o of operators[i]) {
@@ -1027,9 +1028,16 @@ class LinearSystem {
1027
1028
  }
1028
1029
  return `\\left(${tex.join(';')}\\right)`;
1029
1030
  }
1031
+ get resolutionSteps() {
1032
+ return this._resolutionSteps;
1033
+ }
1030
1034
  _linearReduction(eq1, eq2, letter) {
1031
1035
  // Get the monom for the particular letter.
1032
1036
  let c1 = eq1.left.monomByDegree(1, letter).coefficient.clone(), c2 = eq2.left.monomByDegree(1, letter).coefficient.clone().opposed();
1037
+ // Reduce c1 and c2 by the gcd
1038
+ const gcdN = numeric_1.Numeric.gcd(c1.numerator, c2.numerator), gcdD = numeric_1.Numeric.gcd(c1.denominator, c2.denominator);
1039
+ c1.divide(gcdN).multiply(gcdD);
1040
+ c2.divide(gcdN).multiply(gcdD);
1033
1041
  // if one value is -1, use 1 and make the other one opposed
1034
1042
  if (c2.isNegativeOne()) {
1035
1043
  c1.opposed();
@@ -5928,9 +5936,7 @@ class Line {
5928
5936
  return this;
5929
5937
  };
5930
5938
  this.simplifyDirection = () => {
5931
- let lcm = numeric_1.Numeric.lcm(this._d.x.denominator, this._d.y.denominator), gcd = numeric_1.Numeric.gcd(this._d.x.numerator, this._d.y.numerator);
5932
- this._d.x.multiply(lcm).divide(gcd);
5933
- this._d.y.multiply(lcm).divide(gcd);
5939
+ this._d.simplifyDirection();
5934
5940
  return this;
5935
5941
  };
5936
5942
  this.intersection = (line) => {
@@ -6008,15 +6014,18 @@ class Line {
6008
6014
  // canonical => ax + by + c = 0
6009
6015
  // mxh => y = -a/b x - c/b
6010
6016
  // parametric => (xy) = OA + k*d
6011
- let canonical = this.equation;
6017
+ // equation => ax + by = -c
6018
+ let canonical = this.equation.clone().moveLeft();
6012
6019
  // Make sur the first item is positive.
6013
6020
  if (this._a.isNegative()) {
6014
6021
  canonical.multiply(-1);
6015
6022
  }
6023
+ const d = this._d.clone().simplifyDirection();
6016
6024
  return {
6017
6025
  canonical: canonical.tex,
6018
6026
  mxh: this.slope.isInfinity() ? 'x=' + this.OA.x.tex : 'y=' + new polynom_1.Polynom().parse('x', this.slope, this.height).tex,
6019
- parametric: `${point_1.Point.pmatrix('x', 'y')} = ${point_1.Point.pmatrix(this._OA.x, this._OA.y)} + k\\cdot ${point_1.Point.pmatrix(this._d.x, this._d.y)}`
6027
+ 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)}`,
6028
+ equation: canonical.clone().reorder().tex
6020
6029
  };
6021
6030
  }
6022
6031
  get display() {
@@ -6741,6 +6750,12 @@ class Vector {
6741
6750
  return this.multiplyByScalar(numeric_1.Numeric.lcm(this._x.denominator, this._y.denominator))
6742
6751
  .divideByScalar(numeric_1.Numeric.gcd(this._x.numerator, this._y.numerator));
6743
6752
  };
6753
+ this.simplifyDirection = () => {
6754
+ let lcm = numeric_1.Numeric.lcm(this.x.denominator, this.y.denominator), gcd = numeric_1.Numeric.gcd(this.x.numerator, this.y.numerator);
6755
+ this.x.multiply(lcm).divide(gcd);
6756
+ this.y.multiply(lcm).divide(gcd);
6757
+ return this;
6758
+ };
6744
6759
  this.angleWith = (V, sharp, radian) => {
6745
6760
  let scalar = this.scalarProductWithVector(V).value, toDegree = radian ? 1 : 180 / Math.PI;
6746
6761
  if (sharp) {