pimath 0.1.35 → 0.1.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.
package/dist/pimath.js
CHANGED
|
@@ -594,7 +594,7 @@ class J {
|
|
|
594
594
|
}
|
|
595
595
|
var Ce = Object.defineProperty, ue = (n) => {
|
|
596
596
|
throw TypeError(n);
|
|
597
|
-
}, ke = (n, e, t) => e in n ? Ce(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, ie = (n, e, t) => ke(n, typeof e != "symbol" ? e + "" : e, t), fe = (n, e, t) => e.has(n) || ue("Cannot " + t), O = (n, e, t) => (fe(n, e, "read from private field"), t ? t.call(n) : e.get(n)), j = (n, e, t) => e.has(n) ? ue("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(n) : e.set(n, t),
|
|
597
|
+
}, ke = (n, e, t) => e in n ? Ce(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, ie = (n, e, t) => ke(n, typeof e != "symbol" ? e + "" : e, t), fe = (n, e, t) => e.has(n) || ue("Cannot " + t), O = (n, e, t) => (fe(n, e, "read from private field"), t ? t.call(n) : e.get(n)), j = (n, e, t) => e.has(n) ? ue("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(n) : e.set(n, t), S = (n, e, t, i) => (fe(n, e, "write to private field"), e.set(n, t), t);
|
|
598
598
|
const oe = {
|
|
599
599
|
pi: Math.PI,
|
|
600
600
|
e: Math.exp(1)
|
|
@@ -655,7 +655,7 @@ const Me = {
|
|
|
655
655
|
"/": { precedence: 3, associative: "left", type: f.OPERATION },
|
|
656
656
|
"+": { precedence: 2, associative: "left", type: f.OPERATION },
|
|
657
657
|
"-": { precedence: 2, associative: "left", type: f.OPERATION }
|
|
658
|
-
},
|
|
658
|
+
}, Ie = {
|
|
659
659
|
"^": { precedence: 4, associative: "right", type: f.OPERATION },
|
|
660
660
|
"*": { precedence: 3, associative: "left", type: f.OPERATION },
|
|
661
661
|
"/": { precedence: 3, associative: "left", type: f.OPERATION },
|
|
@@ -668,7 +668,7 @@ const Me = {
|
|
|
668
668
|
sqrt: { precedence: 4, associative: "right", type: f.FUNCTION },
|
|
669
669
|
nthrt: { precedence: 4, associative: "right", type: f.FUNCTION },
|
|
670
670
|
",": { precedence: 2, associative: "left", type: f.FUNCTION_ARGUMENT }
|
|
671
|
-
},
|
|
671
|
+
}, Se = {
|
|
672
672
|
"^": { precedence: 4, associative: "right", type: f.OPERATION },
|
|
673
673
|
"*": { precedence: 3, associative: "left", type: f.OPERATION },
|
|
674
674
|
"/": { precedence: 3, associative: "left", type: f.OPERATION },
|
|
@@ -691,7 +691,7 @@ const Me = {
|
|
|
691
691
|
var L, F, C, Y, R;
|
|
692
692
|
class _ {
|
|
693
693
|
constructor(e) {
|
|
694
|
-
j(this, L), j(this, F, []), j(this, C, {}), j(this, Y, []), j(this, R),
|
|
694
|
+
j(this, L), j(this, F, []), j(this, C, {}), j(this, Y, []), j(this, R), S(this, L, typeof e > "u" ? D.POLYNOM : e), this.tokenConfigInitialization();
|
|
695
695
|
}
|
|
696
696
|
// Getter
|
|
697
697
|
get rpn() {
|
|
@@ -701,7 +701,7 @@ class _ {
|
|
|
701
701
|
return O(this, F).map((e) => e.token);
|
|
702
702
|
}
|
|
703
703
|
tokenConfigInitialization() {
|
|
704
|
-
return O(this, L) === D.SET ? (
|
|
704
|
+
return O(this, L) === D.SET ? (S(this, C, ze), S(this, R, !1)) : O(this, L) === D.NUMERIC ? (S(this, C, Se), S(this, R, !0)) : O(this, L) === D.EXPRESSION ? (S(this, C, Ie), S(this, R, !0)) : (S(this, C, Me), S(this, R, !0)), S(this, Y, Object.keys(O(this, C)).sort((e, t) => t.length - e.length)), O(this, C);
|
|
705
705
|
}
|
|
706
706
|
/**
|
|
707
707
|
* Get the next token to analyse.
|
|
@@ -813,7 +813,7 @@ class _ {
|
|
|
813
813
|
throw new Error(`Token type ${r} is not handled`);
|
|
814
814
|
}
|
|
815
815
|
}
|
|
816
|
-
return
|
|
816
|
+
return S(this, F, i.concat(s.reverse())), this;
|
|
817
817
|
}
|
|
818
818
|
}
|
|
819
819
|
L = /* @__PURE__ */ new WeakMap(), F = /* @__PURE__ */ new WeakMap(), C = /* @__PURE__ */ new WeakMap(), Y = /* @__PURE__ */ new WeakMap(), R = /* @__PURE__ */ new WeakMap();
|
|
@@ -929,7 +929,7 @@ class p {
|
|
|
929
929
|
* @param inputStr
|
|
930
930
|
*/
|
|
931
931
|
parse(e) {
|
|
932
|
-
return this.#t = new a(), this.#e = {}, typeof e == "string" ? this.#r(e) : typeof e == "number" ? this.#t = new a(e) : e instanceof a ? this.#t = e.clone() : e instanceof p && (this.#t = e.#t.clone(), this.#i(e)), this;
|
|
932
|
+
return this.#t = new a(), this.#e = {}, typeof e == "string" ? isNaN(Number(e)) ? this.#r(e) : this.#t = new a(Number(e)) : typeof e == "number" ? this.#t = new a(e) : e instanceof a ? this.#t = e.clone() : e instanceof p && (this.#t = e.#t.clone(), this.#i(e)), this;
|
|
933
933
|
}
|
|
934
934
|
/**
|
|
935
935
|
* Clone the current Monom.
|
|
@@ -941,6 +941,27 @@ class p {
|
|
|
941
941
|
e.setLetter(t, this.#e[t].clone());
|
|
942
942
|
return e;
|
|
943
943
|
};
|
|
944
|
+
/**
|
|
945
|
+
* Get the tex output of the monom
|
|
946
|
+
*/
|
|
947
|
+
get tex() {
|
|
948
|
+
let e = "";
|
|
949
|
+
const t = Object.keys(this.#e).sort();
|
|
950
|
+
for (const i of t)
|
|
951
|
+
this.#e[i].isNotZero() && (e += i, this.#e[i].isNotEqual(1) && (e += `^{ ${this.#e[i].tfrac.tex} }`));
|
|
952
|
+
return e === "" ? this.#t.value != 0 ? this.#t.frac.tex : "0" : this.#t.value === 1 ? e : this.#t.value === -1 ? `-${e}` : this.#t.value === 0 ? "0" : `${this.#t.frac.tex}${e}`;
|
|
953
|
+
}
|
|
954
|
+
// Display getter
|
|
955
|
+
/**
|
|
956
|
+
* This display getter is to be used in the polynom display getter
|
|
957
|
+
*/
|
|
958
|
+
get display() {
|
|
959
|
+
let e = "";
|
|
960
|
+
const t = Object.keys(this.#e).sort();
|
|
961
|
+
for (const i of t)
|
|
962
|
+
this.#e[i].isNotZero() && (e += i, this.#e[i].isNotEqual(1) && (e += `^(${this.#e[i].display})`));
|
|
963
|
+
return e === "" ? this.#t.value != 0 ? this.#t.display : "" : this.#t.value === 1 ? e : this.#t.value === -1 ? `-${e}` : this.#t.value === 0 ? "0" : `${this.#t.display}${e}`;
|
|
964
|
+
}
|
|
944
965
|
static gcd = (...e) => {
|
|
945
966
|
for (const r of e)
|
|
946
967
|
if (r.containsRationalPower())
|
|
@@ -1007,17 +1028,6 @@ class p {
|
|
|
1007
1028
|
} else
|
|
1008
1029
|
return new p().zero();
|
|
1009
1030
|
};
|
|
1010
|
-
// Display getter
|
|
1011
|
-
/**
|
|
1012
|
-
* This display getter is to be used in the polynom display getter
|
|
1013
|
-
*/
|
|
1014
|
-
get display() {
|
|
1015
|
-
let e = "";
|
|
1016
|
-
const t = Object.keys(this.#e).sort();
|
|
1017
|
-
for (const i of t)
|
|
1018
|
-
this.#e[i].isNotZero() && (e += i, this.#e[i].isNotEqual(1) && (e += `^(${this.#e[i].display})`));
|
|
1019
|
-
return e === "" ? this.#t.value != 0 ? this.#t.display : "" : this.#t.value === 1 ? e : this.#t.value === -1 ? `-${e}` : this.#t.value === 0 ? "0" : `${this.#t.display}${e}`;
|
|
1020
|
-
}
|
|
1021
1031
|
/**
|
|
1022
1032
|
* Divide the current monoms by multiple monoms
|
|
1023
1033
|
* @param M (Monom[])
|
|
@@ -1284,16 +1294,6 @@ class p {
|
|
|
1284
1294
|
}
|
|
1285
1295
|
return this;
|
|
1286
1296
|
};
|
|
1287
|
-
/**
|
|
1288
|
-
* Get the tex output of the monom
|
|
1289
|
-
*/
|
|
1290
|
-
get tex() {
|
|
1291
|
-
let e = "";
|
|
1292
|
-
const t = Object.keys(this.#e).sort();
|
|
1293
|
-
for (const i of t)
|
|
1294
|
-
this.#e[i].isNotZero() && (e += i, this.#e[i].isNotEqual(1) && (e += `^{ ${this.#e[i].tfrac.tex} }`));
|
|
1295
|
-
return e === "" ? this.#t.value != 0 ? this.#t.frac.tex : "0" : this.#t.value === 1 ? e : this.#t.value === -1 ? `-${e}` : this.#t.value === 0 ? "0" : `${this.#t.frac.tex}${e}`;
|
|
1296
|
-
}
|
|
1297
1297
|
// Getter helpers.
|
|
1298
1298
|
/**
|
|
1299
1299
|
* Get the variables letters
|
|
@@ -1336,21 +1336,6 @@ class p {
|
|
|
1336
1336
|
}
|
|
1337
1337
|
return t;
|
|
1338
1338
|
};
|
|
1339
|
-
_getLiteralDividers(e, t) {
|
|
1340
|
-
const i = [];
|
|
1341
|
-
for (let s = 0; s <= this.literal[t].value; s++)
|
|
1342
|
-
if (e.length === 0) {
|
|
1343
|
-
const r = {};
|
|
1344
|
-
r[t] = new a(s), i.push(r);
|
|
1345
|
-
} else
|
|
1346
|
-
for (const r of e) {
|
|
1347
|
-
const o = {};
|
|
1348
|
-
for (const h in r)
|
|
1349
|
-
o[h] = r[h];
|
|
1350
|
-
o[t] = new a(s), i.push(o);
|
|
1351
|
-
}
|
|
1352
|
-
return i;
|
|
1353
|
-
}
|
|
1354
1339
|
#r = (e) => {
|
|
1355
1340
|
const i = new _().parse(e).rpn, s = [];
|
|
1356
1341
|
if (i.length === 0)
|
|
@@ -1387,6 +1372,21 @@ class p {
|
|
|
1387
1372
|
}
|
|
1388
1373
|
}
|
|
1389
1374
|
};
|
|
1375
|
+
_getLiteralDividers(e, t) {
|
|
1376
|
+
const i = [];
|
|
1377
|
+
for (let s = 0; s <= this.literal[t].value; s++)
|
|
1378
|
+
if (e.length === 0) {
|
|
1379
|
+
const r = {};
|
|
1380
|
+
r[t] = new a(s), i.push(r);
|
|
1381
|
+
} else
|
|
1382
|
+
for (const r of e) {
|
|
1383
|
+
const o = {};
|
|
1384
|
+
for (const h in r)
|
|
1385
|
+
o[h] = r[h];
|
|
1386
|
+
o[t] = new a(s), i.push(o);
|
|
1387
|
+
}
|
|
1388
|
+
return i;
|
|
1389
|
+
}
|
|
1390
1390
|
}
|
|
1391
1391
|
function le(n, e = !0) {
|
|
1392
1392
|
return e ? `\\left( ${n} \\right)` : `(${n})`;
|
|
@@ -1916,9 +1916,9 @@ class u {
|
|
|
1916
1916
|
};
|
|
1917
1917
|
#g(e, ...t) {
|
|
1918
1918
|
if (t.length === 0) {
|
|
1919
|
-
if (e !== "" && !isNaN(Number(e))) {
|
|
1919
|
+
if (console.log(e, Number(e)), e !== "" && !isNaN(Number(e))) {
|
|
1920
1920
|
this.empty();
|
|
1921
|
-
const i = new p(e);
|
|
1921
|
+
const i = new p(Number(e));
|
|
1922
1922
|
return this.add(i), this;
|
|
1923
1923
|
}
|
|
1924
1924
|
return this.#w(e);
|
|
@@ -3440,7 +3440,7 @@ class g {
|
|
|
3440
3440
|
};
|
|
3441
3441
|
}
|
|
3442
3442
|
}
|
|
3443
|
-
var
|
|
3443
|
+
var I = /* @__PURE__ */ ((n) => (n.None = "none", n.Parallel = "parallel", n.Perpendicular = "perpendicular", n.Tangent = "tangent", n))(I || {}), se = /* @__PURE__ */ ((n) => (n.None = "none", n.Parallel = "parallel", n.Perpendicular = "perpendicular", n.Tangent = "tangent", n))(se || {});
|
|
3444
3444
|
function pe(n = 0.5) {
|
|
3445
3445
|
return Math.random() < n;
|
|
3446
3446
|
}
|
|
@@ -3506,9 +3506,9 @@ class v extends g {
|
|
|
3506
3506
|
}
|
|
3507
3507
|
}
|
|
3508
3508
|
class b {
|
|
3509
|
-
static PARALLEL =
|
|
3509
|
+
static PARALLEL = I.Parallel;
|
|
3510
3510
|
// A line is defined as the canonical form
|
|
3511
|
-
static PERPENDICULAR =
|
|
3511
|
+
static PERPENDICULAR = I.Perpendicular;
|
|
3512
3512
|
#t;
|
|
3513
3513
|
// ax + by + c = 0
|
|
3514
3514
|
#e;
|
|
@@ -3557,12 +3557,12 @@ class b {
|
|
|
3557
3557
|
}
|
|
3558
3558
|
if (e.length === 3) {
|
|
3559
3559
|
if (e[0] instanceof g && e[1] instanceof g) {
|
|
3560
|
-
if (e[2] ===
|
|
3560
|
+
if (e[2] === I.Perpendicular)
|
|
3561
3561
|
return this.fromPointAndNormal(e[0], e[1]);
|
|
3562
|
-
if (e[2] ===
|
|
3562
|
+
if (e[2] === I.Parallel)
|
|
3563
3563
|
return this.fromPointAndDirection(e[0], e[1]);
|
|
3564
3564
|
}
|
|
3565
|
-
return e[0] instanceof g && e[1] instanceof b ? e[2] ===
|
|
3565
|
+
return e[0] instanceof g && e[1] instanceof b ? e[2] === I.Parallel || e[2] === null ? this.fromPointAndLine(e[0], e[1], I.Parallel) : this.fromPointAndLine(e[0], e[1], I.Perpendicular) : this.fromCoefficient(
|
|
3566
3566
|
e[0],
|
|
3567
3567
|
e[1],
|
|
3568
3568
|
e[2]
|
|
@@ -3707,7 +3707,7 @@ class b {
|
|
|
3707
3707
|
t.x.clone().opposite(),
|
|
3708
3708
|
e.x.clone().multiply(t.y).subtract(e.y.clone().multiply(t.x)).opposite()
|
|
3709
3709
|
), this.#t = e.clone(), this.#r = t.clone(), this.#n = this.#r.clone().normal(), this);
|
|
3710
|
-
fromPointAndLine = (e, t, i) => (i === void 0 && (i =
|
|
3710
|
+
fromPointAndLine = (e, t, i) => (i === void 0 && (i = I.Parallel), i === I.Parallel ? this.fromPointAndNormal(e, t.normal) : i === I.Perpendicular ? this.fromPointAndNormal(e, t.director) : this);
|
|
3711
3711
|
fromPointAndNormal = (e, t) => this.fromCoefficient(
|
|
3712
3712
|
t.x,
|
|
3713
3713
|
t.y,
|
|
@@ -3891,7 +3891,7 @@ class W {
|
|
|
3891
3891
|
}
|
|
3892
3892
|
#s = (e) => {
|
|
3893
3893
|
const t = new g(this.center, e);
|
|
3894
|
-
return [new b(e, t,
|
|
3894
|
+
return [new b(e, t, I.Perpendicular)];
|
|
3895
3895
|
};
|
|
3896
3896
|
#r = (e) => {
|
|
3897
3897
|
const t = this.center.x.clone().subtract(e.x), i = this.center.y.clone().subtract(e.y), s = new u("x"), r = new u("x^2+1");
|