pimath 0.2.6 → 0.2.7

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/pimath.js CHANGED
@@ -352,10 +352,14 @@ class h {
352
352
  function st(n, t = !0) {
353
353
  return t ? `\\left( ${n} \\right)` : `(${n})`;
354
354
  }
355
- function Q(n) {
356
- return n.startsWith("(") && (n = n.substring(1)), n.endsWith(")") && (n = n.substring(0, n.length - 1)), n;
355
+ function j(n) {
356
+ if (!n.startsWith("(") || !n.endsWith(")")) return n;
357
+ let t = 0;
358
+ for (let e = 0; e < n.length - 1; e++)
359
+ if (n[e] === "(" ? t++ : n[e] === ")" && t--, t === 0) return n;
360
+ return n.slice(1, -1);
357
361
  }
358
- function j(n, t, e, i, s) {
362
+ function F(n, t, e, i, s) {
359
363
  return n.map((r, o) => r === t ? e : r);
360
364
  }
361
365
  function H(n, t) {
@@ -529,12 +533,14 @@ class T {
529
533
  return s.length === 0 ? null : s.join(" ");
530
534
  }
531
535
  #o(t) {
532
- const [e, i] = t.split("root"), [s, r] = i.split(")");
533
- return this.index = +Q(s), this.radical = new h(Q(r)), this.factor = e === "" ? new h().one() : new h(e), this;
536
+ const e = /^(.*?)root\((\d+)\)\(?([^)]+)/.exec(t);
537
+ if (!e) throw new Error(`Invalid root format: "${t}"`);
538
+ const [, i, s, r] = e;
539
+ return this.index = +s, this.radical = new h(r), this.factor = i === "" ? new h().one() : new h(i.trim()), this;
534
540
  }
535
541
  #a(t) {
536
542
  const [e, i] = t.split("sqrt");
537
- return this.index = 2, this.radical = new h(Q(i)), this.factor = e === "" ? new h().one() : new h(e), this;
543
+ return this.index = 2, this.radical = new h(j(i)), this.factor = e === "" ? new h().one() : new h(e), this;
538
544
  }
539
545
  }
540
546
  class C {
@@ -785,12 +791,12 @@ class R {
785
791
  return k.isEqual(I) ? [this.#r(k)] : [
786
792
  this.#r(I),
787
793
  this.#r(k)
788
- ].sort((Y, M) => Y.value - M.value);
794
+ ].sort((Q, M) => Q.value - M.value);
789
795
  }
790
796
  if (q.isPositive()) {
791
- const $ = [], k = f.value, I = m.value, Y = o.value;
797
+ const $ = [], k = f.value, I = m.value, Q = o.value;
792
798
  for (let M = 0; M < 3; M++)
793
- $.push(2 * Math.sqrt(-k / 3) * Math.cos(Math.acos(3 * I / (2 * k) * Math.sqrt(-3 / k)) / 3 + 2 * Math.PI * M / 3) - Y / 3);
799
+ $.push(2 * Math.sqrt(-k / 3) * Math.cos(Math.acos(3 * I / (2 * k) * Math.sqrt(-3 / k)) / 3 + 2 * Math.PI * M / 3) - Q / 3);
794
800
  return $.map((M) => this.#s(M)).sort((M, ut) => M.value - ut.value);
795
801
  }
796
802
  return [];
@@ -925,7 +931,7 @@ const At = {
925
931
  "!": { precedence: 4, associative: "right", type: u.OPERATION },
926
932
  "-": { precedence: 2, associative: "left", type: u.OPERATION }
927
933
  };
928
- class G {
934
+ class W {
929
935
  #t;
930
936
  #e = [];
931
937
  #i = {};
@@ -1064,7 +1070,7 @@ class qt {
1064
1070
  constructor(t, e) {
1065
1071
  this._expression = t;
1066
1072
  try {
1067
- this._rpn = new G(S.NUMERIC).parse(t, e).rpn;
1073
+ this._rpn = new W(S.NUMERIC).parse(t, e).rpn;
1068
1074
  } catch (i) {
1069
1075
  throw this._rpn = null, this._isValid = !1, console.warn(i), new Error(`There was a problem parsing: ${t}`);
1070
1076
  }
@@ -1602,7 +1608,7 @@ class p {
1602
1608
  }
1603
1609
  };
1604
1610
  #a = (t) => {
1605
- const i = new G().parse(t).rpn, s = [];
1611
+ const i = new W().parse(t).rpn, s = [];
1606
1612
  if (i.length === 0)
1607
1613
  return this.zero(), this;
1608
1614
  if (i.length === 1) {
@@ -1761,7 +1767,7 @@ class l {
1761
1767
  * TODO: Handle other letter than 'x'.
1762
1768
  */
1763
1769
  factorize(t) {
1764
- this.#e = [];
1770
+ if (this.#e = [], this.monoms.length === 1) return [this.clone()];
1765
1771
  let e = this.clone().reorder();
1766
1772
  const i = e.commonMonom();
1767
1773
  e.monomByDegree().coefficient.isStrictlyNegative() && i.opposite(), i.isOne() || (this.#e.push(new l(i)), e = e.euclidean(this.#e[0]).quotient);
@@ -2029,7 +2035,7 @@ class l {
2029
2035
  let e = new Array(2 * t.length + 1).fill("").map((i, s) => s % 2 === 0 ? "" : "z");
2030
2036
  if (e.length === 1) {
2031
2037
  const [i] = this.getCoefficients().map((s) => s.value);
2032
- e = j(e, "", i > 0 ? "+" : "-");
2038
+ e = F(e, "", i > 0 ? "+" : "-");
2033
2039
  } else if (this.degree().isOne()) {
2034
2040
  const [i] = this.getCoefficients().map((s) => s.value);
2035
2041
  e[0] = i > 0 ? "-" : "+", e[1] = "z", e[2] = i > 0 ? "+" : "-";
@@ -2207,7 +2213,7 @@ class l {
2207
2213
  * @param inputStr
2208
2214
  */
2209
2215
  #w(t) {
2210
- const i = new G().parse(t).rpn;
2216
+ const i = new W().parse(t).rpn;
2211
2217
  this.zero();
2212
2218
  const s = [];
2213
2219
  for (const r of i)
@@ -2569,7 +2575,7 @@ class y {
2569
2575
  }
2570
2576
  tableOfSigns() {
2571
2577
  const t = this.power.clone().reduce(), e = this.polynom.tableOfSigns();
2572
- return t.isStrictlyNegative() && (e.signs = j(e.signs, "z", "d")), t.denominator % 2 === 0 ? e.signs = j(e.signs, "-", "h") : t.numerator % 2 === 0 && (e.signs = j(e.signs, "-", "+")), { roots: e.roots, signs: e.signs };
2578
+ return t.isStrictlyNegative() && (e.signs = F(e.signs, "z", "d")), t.denominator % 2 === 0 ? e.signs = F(e.signs, "-", "h") : t.numerator % 2 === 0 && (e.signs = F(e.signs, "-", "+")), { roots: e.roots, signs: e.signs };
2573
2579
  }
2574
2580
  get variables() {
2575
2581
  return this.polynom.variables;
@@ -2824,7 +2830,7 @@ class $t {
2824
2830
  constructor(t) {
2825
2831
  return this.#t = [], t !== void 0 && this.parse(t), this;
2826
2832
  }
2827
- parse = (t) => (this.#t = new G(S.SET).parse(t).rpn, this);
2833
+ parse = (t) => (this.#t = new W(S.SET).parse(t).rpn, this);
2828
2834
  get tex() {
2829
2835
  const t = [];
2830
2836
  for (const e of this.#t)
@@ -3114,9 +3120,9 @@ class N {
3114
3120
  const [e, ...i] = H(t, "/");
3115
3121
  if (e === "") throw new Error("Parsing a PolyFactor from a string requires a numerator");
3116
3122
  if (i.length > 1) throw new Error('Parsing a PolyFactor from a string only allows max one signe "/"');
3117
- return i.length === 0 ? this.#e = y.factorsFromString(e, !0) : this.#e = [
3118
- ...y.factorsFromString(e, !0),
3119
- ...y.factorsFromString(i[0], !1)
3123
+ return i.length === 0 ? this.#e = y.factorsFromString(j(e), !0) : this.#e = [
3124
+ ...y.factorsFromString(j(e), !0),
3125
+ ...y.factorsFromString(j(i[0]), !1)
3120
3126
  ], this;
3121
3127
  }
3122
3128
  /**
@@ -3775,16 +3781,16 @@ function A(n, t) {
3775
3781
  }
3776
3782
  function St(n, t) {
3777
3783
  const e = b.pythagoreanTripletsWithTarget(n).filter((i) => t === !0 || !i.includes(0));
3778
- return e.length === 0 ? null : W(e);
3784
+ return e.length === 0 ? null : X(e);
3779
3785
  }
3780
3786
  function It(n) {
3781
3787
  let t = b.primes();
3782
- return n !== void 0 && (t = t.filter((e) => e < n)), W(t);
3788
+ return n !== void 0 && (t = t.filter((e) => e < n)), X(t);
3783
3789
  }
3784
3790
  function Pt(n, t) {
3785
3791
  return t === void 0 && (t = 1), n.length <= 0 ? Object.values(n) : ht(n).slice(0, t);
3786
3792
  }
3787
- function W(n) {
3793
+ function X(n) {
3788
3794
  return n.length === 0 ? null : n[O(0, n.length - 1)];
3789
3795
  }
3790
3796
  function ht(n) {
@@ -4491,7 +4497,7 @@ class U {
4491
4497
  return [new E(e, i, a), new E(e, i, c)];
4492
4498
  };
4493
4499
  }
4494
- class X {
4500
+ class Y {
4495
4501
  static PARALLEL = K.Parallel;
4496
4502
  // A line is defined as the canonical form
4497
4503
  static PERPENDICULAR = K.Perpendicular;
@@ -4548,7 +4554,7 @@ class X {
4548
4554
  // Mathematical operations
4549
4555
  hitSegment(t, e) {
4550
4556
  const i = this.intersection(
4551
- new X(t, e)
4557
+ new Y(t, e)
4552
4558
  );
4553
4559
  return i.hasIntersection ? i.point.x.value >= Math.min(t.x.value, e.x.value) && i.point.x.value <= Math.max(t.x.value, e.x.value) && i.point.y.value >= Math.min(t.y.value, e.y.value) && i.point.y.value <= Math.max(t.y.value, e.y.value) && i.point.z.value >= Math.min(t.z.value, e.z.value) && i.point.z.value <= Math.max(t.z.value, e.z.value) : !1;
4554
4560
  }
@@ -4798,7 +4804,7 @@ class zt {
4798
4804
  z: t.z
4799
4805
  }) ?? !1;
4800
4806
  }
4801
- function F(n) {
4807
+ function G(n) {
4802
4808
  const t = Object.assign(
4803
4809
  {
4804
4810
  negative: !0,
@@ -4828,7 +4834,7 @@ function ct(n) {
4828
4834
  },
4829
4835
  n
4830
4836
  ), e = new p();
4831
- if (e.coefficient = F({
4837
+ if (e.coefficient = G({
4832
4838
  zero: t.zero,
4833
4839
  reduced: !0,
4834
4840
  natural: !t.fraction
@@ -4836,7 +4842,7 @@ function ct(n) {
4836
4842
  for (const i of t.letters.split(""))
4837
4843
  e.setLetter(i, 0);
4838
4844
  for (let i = 0; i < t.degree; i++) {
4839
- const s = W(t.letters.split(""));
4845
+ const s = X(t.letters.split(""));
4840
4846
  e.setLetter(s, e.degree(s).clone().add(1));
4841
4847
  }
4842
4848
  } else
@@ -4936,7 +4942,7 @@ function J(n) {
4936
4942
  quadrant: null
4937
4943
  },
4938
4944
  n
4939
- ), e = t.axis === "x", i = t.axis === "y", s = t.fraction ? F({ max: t.max, zero: e }) : new h(A(t.max, e)), r = t.fraction ? F({ max: t.max, zero: i }) : new h(A(t.max, i));
4945
+ ), e = t.axis === "x", i = t.axis === "y", s = t.fraction ? G({ max: t.max, zero: e }) : new h(A(t.max, e)), r = t.fraction ? G({ max: t.max, zero: i }) : new h(A(t.max, i));
4940
4946
  return Number(t.quadrant) === 1 && (s.abs(), r.abs()), Number(t.quadrant) === 2 && (s.isPositive() && s.opposite(), r.isNegative() && r.opposite()), Number(t.quadrant) === 3 && (s.isPositive() && s.opposite(), r.isPositive() && r.opposite()), Number(t.quadrant) === 4 && (s.isNegative() && s.opposite(), r.isPositive() && r.opposite()), new w(s, r);
4941
4947
  }
4942
4948
  function Dt(n) {
@@ -4983,20 +4989,20 @@ function Lt(n) {
4983
4989
  },
4984
4990
  n
4985
4991
  ), e = new w(t.A.x, t.A.y, t.A.z), i = new g(t.direction.x, t.direction.y, t.direction.z);
4986
- return new X(e, i);
4992
+ return new Y(e, i);
4987
4993
  }
4988
4994
  const Ut = {
4989
4995
  equation: (n) => Zt(n),
4990
4996
  polynom: (n) => it(n),
4991
4997
  monom: (n) => ct(n),
4992
- fraction: (n) => F(n),
4998
+ fraction: (n) => G(n),
4993
4999
  number: (n, t, e) => O(n, t, e),
4994
5000
  numberSym: (n, t) => A(n, t),
4995
5001
  prime: (n) => It(n),
4996
5002
  triplet: (n, t) => St(n, t),
4997
5003
  bool: (n) => ot(n),
4998
5004
  array: (n, t) => Pt(n, t),
4999
- item: (n) => W(n),
5005
+ item: (n) => X(n),
5000
5006
  shuffle: (n) => ht(n),
5001
5007
  line: (n) => Vt(n),
5002
5008
  line3: (n) => Lt(n),
@@ -5022,7 +5028,7 @@ const Ut = {
5022
5028
  Line: E,
5023
5029
  Triangle: L,
5024
5030
  Circle: U,
5025
- Line3: X,
5031
+ Line3: Y,
5026
5032
  Plane3: et,
5027
5033
  Sphere3: zt
5028
5034
  },
@@ -5037,7 +5043,7 @@ export {
5037
5043
  y as Factor,
5038
5044
  h as Fraction,
5039
5045
  E as Line,
5040
- X as Line3,
5046
+ Y as Line3,
5041
5047
  P as LinearSystem,
5042
5048
  $t as LogicalSet,
5043
5049
  B as Matrix,