pimath 0.0.125 → 0.0.127
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/.idea/inspectionProfiles/Project_Default.xml +5 -5
- package/.idea/shelf/Uncommitted_changes_before_Checkout_at_07_11_2023_08_30_[Default_Changelist]/shelved.patch +192 -192
- package/.idea/shelf/Uncommitted_changes_before_Checkout_at_09_11_2023_10_43_[Default_Changelist]/shelved.patch +2404 -2404
- package/.idea/shelf/Uncommitted_changes_before_Checkout_at_09_11_2023_11_01_[Default_Changelist]/shelved.patch +1362 -1362
- package/dev/pimath.js +7945 -0
- package/dev/pimath.js.map +1 -0
- package/dist/pimath.js +192 -221
- package/dist/pimath.js.map +1 -1
- package/dist/pimath.min.js +1 -1
- package/dist/pimath.min.js.map +1 -1
- package/docs/.nojekyll +1 -0
- package/docs/assets/highlight.css +78 -0
- package/docs/assets/main.js +59 -0
- package/docs/assets/navigation.js +1 -0
- package/docs/assets/search.js +1 -0
- package/docs/assets/style.css +1383 -0
- package/docs/classes/Logicalset.Logicalset.html +217 -0
- package/docs/classes/Polynom.Rational.html +397 -0
- package/docs/classes/Vector-1.Vector.html +490 -0
- package/docs/classes/Vector.Point.html +337 -0
- package/docs/classes/algebra_equation.Equation.html +790 -0
- package/docs/classes/algebra_linearSystem.LinearSystem.html +404 -0
- package/docs/classes/algebra_monom.Monom.html +962 -0
- package/docs/classes/algebra_polynom.Polynom.html +1275 -0
- package/docs/classes/coefficients_fraction.Fraction.html +934 -0
- package/docs/classes/geometry_circle.Circle.html +472 -0
- package/docs/classes/geometry_line.Line.html +774 -0
- package/docs/classes/geometry_triangle.Triangle.html +429 -0
- package/docs/classes/numeric.Numeric.html +265 -0
- package/docs/classes/shutingyard.Shutingyard.html +250 -0
- package/docs/enums/algebra_equation.PARTICULAR_SOLUTION.html +83 -0
- package/docs/enums/geometry_line.LinePropriety.html +97 -0
- package/docs/enums/shutingyard.ShutingyardMode.html +97 -0
- package/docs/enums/shutingyard.ShutingyardType.html +111 -0
- package/docs/index.html +63 -0
- package/docs/interfaces/algebra_equation.ISolution.html +105 -0
- package/docs/interfaces/algebra_polynom.IEuclidian.html +87 -0
- package/docs/interfaces/geometry_triangle.remarquableLines.html +163 -0
- package/docs/modules/Logicalset.html +65 -0
- package/docs/modules/Polynom.html +65 -0
- package/docs/modules/Vector-1.html +65 -0
- package/docs/modules/Vector.html +65 -0
- package/docs/modules/algebra_equation.html +69 -0
- package/docs/modules/algebra_linearSystem.html +61 -0
- package/docs/modules/algebra_monom.html +65 -0
- package/docs/modules/algebra_polynom.html +69 -0
- package/docs/modules/coefficients_fraction.html +65 -0
- package/docs/modules/geometry_circle.html +61 -0
- package/docs/modules/geometry_line.html +65 -0
- package/docs/modules/geometry_triangle.html +65 -0
- package/docs/modules/numeric.html +61 -0
- package/docs/modules/shutingyard.html +75 -0
- package/docs/types/algebra_monom.literalType.html +61 -0
- package/docs/types/algebra_polynom.PolynomParsingType.html +56 -0
- package/docs/types/coefficients_fraction.FractionParsingType.html +56 -0
- package/docs/types/shutingyard.Token.html +63 -0
- package/docs/types/shutingyard.tokenType.html +68 -0
- package/docs/variables/shutingyard.tokenConstant.html +61 -0
- package/esm/index.js +1 -1
- package/esm/index.js.map +1 -1
- package/esm/maths/algebra/monom.d.ts +19 -19
- package/esm/maths/algebra/monom.js +66 -66
- package/esm/maths/algebra/monom.js.map +1 -1
- package/esm/maths/algebra/polynom.d.ts +14 -14
- package/esm/maths/algebra/polynom.js +72 -50
- package/esm/maths/algebra/polynom.js.map +1 -1
- package/esm/maths/numeric.js +3 -48
- package/esm/maths/numeric.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -1
- package/src/maths/algebra/monom.ts +138 -130
- package/src/maths/algebra/polynom.ts +97 -82
- package/src/maths/geometry/line.ts +22 -25
- package/src/maths/geometry/point.ts +43 -29
- package/src/maths/numeric.ts +61 -90
- package/src/maths/randomization/random.ts +7 -0
- package/src/maths/randomization/rndGeometryCircle.ts +50 -0
- package/src/maths/randomization/rndTypes.ts +10 -4
- package/tests/algebra/linear.test.ts +1 -1
- package/tests/algebra/polynom.test.ts +162 -1
- package/tests/algebra/study.test.ts +1 -0
- package/tests/geometry/circle.test.ts +320 -115
- package/tests/geometry/line.test.ts +8 -17
- package/tests/numeric.test.ts +19 -3
|
@@ -7,8 +7,6 @@ import {Shutingyard, ShutingyardType, Token} from '../shutingyard';
|
|
|
7
7
|
import {Numeric} from '../numeric';
|
|
8
8
|
import {Fraction} from "../coefficients/fraction";
|
|
9
9
|
import {Equation, ISolution} from "./equation";
|
|
10
|
-
import {Random} from "../randomization/random";
|
|
11
|
-
import {loadHighlighter} from "typedoc/dist/lib/utils/highlighter";
|
|
12
10
|
|
|
13
11
|
export type PolynomParsingType = string | Polynom | number | Fraction | Monom
|
|
14
12
|
|
|
@@ -24,12 +22,12 @@ export interface IEuclidian {
|
|
|
24
22
|
* ```
|
|
25
23
|
*/
|
|
26
24
|
export class Polynom {
|
|
25
|
+
private _rawString: string;
|
|
27
26
|
private _dirty_factors: boolean
|
|
28
27
|
private _dirty_zeroes: boolean
|
|
29
28
|
private _euclidianCache: { [Key: string]: IEuclidian }
|
|
30
29
|
private _factors: Polynom[];
|
|
31
30
|
private _monoms: Monom[];
|
|
32
|
-
private _rawString: string;
|
|
33
31
|
private _texString: string;
|
|
34
32
|
private _zeroes: ISolution[]
|
|
35
33
|
|
|
@@ -49,12 +47,13 @@ export class Polynom {
|
|
|
49
47
|
return this;
|
|
50
48
|
}
|
|
51
49
|
|
|
52
|
-
|
|
53
|
-
|
|
50
|
+
// ------------------------------------------
|
|
51
|
+
get dirty_factors(): boolean {
|
|
52
|
+
return this._dirty_factors;
|
|
54
53
|
}
|
|
55
54
|
|
|
56
|
-
set
|
|
57
|
-
this.
|
|
55
|
+
set dirty_factors(value: boolean) {
|
|
56
|
+
this._dirty_factors = value;
|
|
58
57
|
}
|
|
59
58
|
|
|
60
59
|
get dirty_zeroes(): boolean {
|
|
@@ -65,26 +64,12 @@ export class Polynom {
|
|
|
65
64
|
this._dirty_zeroes = value;
|
|
66
65
|
}
|
|
67
66
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return this._dirty_factors;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
set dirty_factors(value: boolean) {
|
|
74
|
-
this._dirty_factors = value;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// ------------------------------------------
|
|
78
|
-
get monoms() {
|
|
79
|
-
return this._monoms;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
set monoms(M: Monom[]) {
|
|
83
|
-
this._monoms = M;
|
|
67
|
+
get euclidianCache(): { [p: string]: IEuclidian } {
|
|
68
|
+
return this._euclidianCache;
|
|
84
69
|
}
|
|
85
70
|
|
|
86
|
-
|
|
87
|
-
|
|
71
|
+
set euclidianCache(value: { [p: string]: IEuclidian }) {
|
|
72
|
+
this._euclidianCache = value;
|
|
88
73
|
}
|
|
89
74
|
|
|
90
75
|
get factors(): Polynom[] {
|
|
@@ -96,10 +81,23 @@ export class Polynom {
|
|
|
96
81
|
this._factors = value;
|
|
97
82
|
}
|
|
98
83
|
|
|
84
|
+
// ------------------------------------------
|
|
85
|
+
get monoms() {
|
|
86
|
+
return this._monoms;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
set monoms(M: Monom[]) {
|
|
90
|
+
this._monoms = M;
|
|
91
|
+
}
|
|
92
|
+
|
|
99
93
|
get texString(): string {
|
|
100
94
|
return this._texString;
|
|
101
95
|
}
|
|
102
96
|
|
|
97
|
+
get zeroes(): ISolution[] {
|
|
98
|
+
return this.getZeroes()
|
|
99
|
+
}
|
|
100
|
+
|
|
103
101
|
get texFactors(): string {
|
|
104
102
|
this.factorize()
|
|
105
103
|
|
|
@@ -439,7 +437,7 @@ export class Polynom {
|
|
|
439
437
|
this.mark_as_dirty()
|
|
440
438
|
|
|
441
439
|
if (value instanceof Polynom) {
|
|
442
|
-
return this.multiplyByPolynom(value)
|
|
440
|
+
return this.multiplyByPolynom(value)
|
|
443
441
|
} else if (value instanceof Fraction) {
|
|
444
442
|
return this.multiplyByFraction(value);
|
|
445
443
|
} else if (value instanceof Monom) {
|
|
@@ -471,33 +469,33 @@ export class Polynom {
|
|
|
471
469
|
if (P.variables.length === 0) {
|
|
472
470
|
let q = this.clone().divide(P)
|
|
473
471
|
return {
|
|
474
|
-
quotient: this.clone().divide(P),
|
|
472
|
+
quotient: this.clone().divide(P).reduce(),
|
|
475
473
|
reminder: new Polynom().zero()
|
|
476
474
|
}
|
|
477
475
|
}
|
|
478
476
|
|
|
479
477
|
// Get at least a letter
|
|
480
|
-
|
|
481
478
|
const maxMP: Monom = P.monomByDegree(undefined, letter);
|
|
482
479
|
const degreeP: Fraction = P.degree(letter);
|
|
483
480
|
|
|
484
481
|
let newM: Monom;
|
|
485
482
|
|
|
486
483
|
// Make the euclidian division of the two polynoms.
|
|
487
|
-
let MaxIteration = this.degree(letter).
|
|
488
|
-
while (reminder.degree(letter).geq(degreeP) && MaxIteration
|
|
489
|
-
MaxIteration
|
|
484
|
+
let MaxIteration = this.degree(letter).value * 2;
|
|
485
|
+
while (reminder.degree(letter).geq(degreeP) && MaxIteration > 0) {
|
|
486
|
+
MaxIteration--
|
|
490
487
|
|
|
491
488
|
// Get the greatest monom divided by the max monom of the divider
|
|
492
489
|
newM = reminder.monomByDegree(undefined, letter).clone().divide(maxMP);
|
|
493
490
|
|
|
494
|
-
if (newM.isZero())
|
|
495
|
-
break;
|
|
496
|
-
}
|
|
491
|
+
if (newM.isZero()) continue;
|
|
497
492
|
|
|
498
493
|
// Get the new quotient and reminder.
|
|
499
494
|
quotient.add(newM);
|
|
500
|
-
reminder.subtract(P.clone().multiply(newM));
|
|
495
|
+
reminder.subtract(P.clone().multiply(newM)).reduce();
|
|
496
|
+
|
|
497
|
+
// Check if the reminder is zero.
|
|
498
|
+
if (newM.degree(letter).isZero()) break
|
|
501
499
|
}
|
|
502
500
|
|
|
503
501
|
quotient.reduce()
|
|
@@ -517,11 +515,11 @@ export class Polynom {
|
|
|
517
515
|
} else if (value instanceof Polynom) {
|
|
518
516
|
if (value.monoms.length === 1 && value.variables.length === 0) {
|
|
519
517
|
return this.divideByFraction(value.monoms[0].coefficient)
|
|
520
|
-
}else {
|
|
518
|
+
} else {
|
|
521
519
|
let {quotient, reminder} = this.euclidian(value)
|
|
522
|
-
if(reminder.isZero()){
|
|
520
|
+
if (reminder.isZero()) {
|
|
523
521
|
return quotient
|
|
524
|
-
}else{
|
|
522
|
+
} else {
|
|
525
523
|
console.log(`${this.tex} is not divideable by ${value.tex}`)
|
|
526
524
|
return new Polynom().zero()
|
|
527
525
|
}
|
|
@@ -663,19 +661,21 @@ export class Polynom {
|
|
|
663
661
|
let polyFactors = factors.map(x => new Polynom(x));
|
|
664
662
|
|
|
665
663
|
// polyFactors contain all polynoms.
|
|
666
|
-
let checkPolyFactors = polyFactors.filter(x=>x.degree().geq(1) && !x.commonMonom().isOne())
|
|
664
|
+
let checkPolyFactors = polyFactors.filter(x => x.degree().geq(1) && !x.commonMonom().isOne())
|
|
667
665
|
|
|
668
666
|
// Some polynoms are not completely factorized.
|
|
669
|
-
if(checkPolyFactors.length>0 && !soft){
|
|
670
|
-
|
|
671
|
-
|
|
667
|
+
if (checkPolyFactors.length > 0 && !soft) {
|
|
668
|
+
return false
|
|
669
|
+
}
|
|
670
|
+
if (checkPolyFactors.length > 0 && soft) {
|
|
671
|
+
polyFactors = polyFactors.filter(x => x.commonMonom().isOne())
|
|
672
672
|
|
|
673
673
|
let FactorizedConstant = new Fraction().one()
|
|
674
|
-
for(let p of checkPolyFactors){
|
|
674
|
+
for (let p of checkPolyFactors) {
|
|
675
675
|
let k = p.commonMonom(),
|
|
676
676
|
pFactor = p.clone().divide(k)
|
|
677
677
|
|
|
678
|
-
if(k.degree().isZero()){
|
|
678
|
+
if (k.degree().isZero()) {
|
|
679
679
|
FactorizedConstant.multiply(k.coefficient)
|
|
680
680
|
polyFactors.push(pFactor.clone())
|
|
681
681
|
}
|
|
@@ -786,39 +786,57 @@ export class Polynom {
|
|
|
786
786
|
// -------------------------------------
|
|
787
787
|
reduce = (): Polynom => {
|
|
788
788
|
// Reduce the polynom
|
|
789
|
-
let values =
|
|
789
|
+
let values = this._monoms.map(x => x.clone()),
|
|
790
790
|
vars = [...this.variables]
|
|
791
791
|
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
let M = values.filter(x => x.hasLetter(letter))
|
|
804
|
-
|
|
805
|
-
while (M.length > 0) {
|
|
806
|
-
// Take the first element
|
|
807
|
-
const m = M.shift(), degree = m.degree(letter)
|
|
808
|
-
|
|
809
|
-
for (let a of M.filter(x => x.degree(letter).isEqual(degree))) {
|
|
810
|
-
m.add(a)
|
|
792
|
+
// Group the monoms by similarity
|
|
793
|
+
let i = 0
|
|
794
|
+
while (i < this._monoms.length) {
|
|
795
|
+
for (let j = i + 1; j < this._monoms.length; j++) {
|
|
796
|
+
if (this._monoms[i].isSameAs(this._monoms[j])) {
|
|
797
|
+
this._monoms[i].add(this._monoms[j])
|
|
798
|
+
this._monoms.splice(j, 1)
|
|
799
|
+
if (this._monoms[i].isZero()) {
|
|
800
|
+
this._monoms[i] = new Monom().zero()
|
|
801
|
+
}
|
|
802
|
+
j--
|
|
811
803
|
}
|
|
812
|
-
|
|
813
|
-
this._monoms.push(m)
|
|
814
|
-
|
|
815
|
-
// Make the new array.
|
|
816
|
-
M = M.filter(x => x.degree(letter).isNotEqual(degree))
|
|
817
804
|
}
|
|
818
|
-
|
|
819
|
-
|
|
805
|
+
i++
|
|
820
806
|
}
|
|
821
807
|
|
|
808
|
+
//
|
|
809
|
+
//
|
|
810
|
+
//
|
|
811
|
+
// let coeffs = values.filter(x => x.variables.length === 0)
|
|
812
|
+
//
|
|
813
|
+
// if (coeffs.length > 0) {
|
|
814
|
+
// this._monoms.push(coeffs.reduce((a, b) => a.add(b)))
|
|
815
|
+
// }
|
|
816
|
+
//
|
|
817
|
+
// // Build the new monoms
|
|
818
|
+
// for (let letter of vars) {
|
|
819
|
+
// // Monom with same letters, but might be of different degrees
|
|
820
|
+
// let M = values.filter(x => x.hasLetter(letter))
|
|
821
|
+
//
|
|
822
|
+
// while (M.length > 0) {
|
|
823
|
+
// // Take the first element
|
|
824
|
+
// const m = M.shift(), degree = m.degree(letter)
|
|
825
|
+
//
|
|
826
|
+
// for (let a of M.filter(x => x.degree(letter).isEqual(degree))) {
|
|
827
|
+
// m.add(a)
|
|
828
|
+
// }
|
|
829
|
+
//
|
|
830
|
+
// this._monoms.push(m)
|
|
831
|
+
//
|
|
832
|
+
// // Make the new array.
|
|
833
|
+
// M = M.filter(x => x.degree(letter).isNotEqual(degree))
|
|
834
|
+
// }
|
|
835
|
+
// // reduce the monom
|
|
836
|
+
//
|
|
837
|
+
// }
|
|
838
|
+
|
|
839
|
+
|
|
822
840
|
// Remove all null monoms
|
|
823
841
|
this._monoms = this._monoms.filter((m) => {
|
|
824
842
|
return m.coefficient.value !== 0
|
|
@@ -832,11 +850,14 @@ export class Polynom {
|
|
|
832
850
|
if (this.length === 0) {
|
|
833
851
|
return new Polynom().zero();
|
|
834
852
|
}
|
|
853
|
+
|
|
835
854
|
return this.reorder();
|
|
836
855
|
};
|
|
837
856
|
|
|
838
857
|
reorder = (letter: string = 'x', revert?: boolean): Polynom => {
|
|
839
|
-
if(revert===undefined){
|
|
858
|
+
if (revert === undefined) {
|
|
859
|
+
revert = false
|
|
860
|
+
}
|
|
840
861
|
|
|
841
862
|
// TODO: Must handle multiple setLetter reorder system
|
|
842
863
|
let otherLetters = this.variables.filter(x => x !== letter)
|
|
@@ -845,7 +866,7 @@ export class Polynom {
|
|
|
845
866
|
db = b.degree(letter).value
|
|
846
867
|
|
|
847
868
|
// Values are different
|
|
848
|
-
if (da !== db) return revert?da-db : db - da
|
|
869
|
+
if (da !== db) return revert ? da - db : db - da
|
|
849
870
|
|
|
850
871
|
// if values are equals, check other letters - it must be revert in that case !
|
|
851
872
|
if (otherLetters.length > 0) {
|
|
@@ -854,7 +875,7 @@ export class Polynom {
|
|
|
854
875
|
db = b.degree(L).value
|
|
855
876
|
|
|
856
877
|
// Values are different
|
|
857
|
-
if (da !== db) return revert?da - db : db - da
|
|
878
|
+
if (da !== db) return revert ? da - db : db - da
|
|
858
879
|
}
|
|
859
880
|
}
|
|
860
881
|
|
|
@@ -1045,16 +1066,10 @@ export class Polynom {
|
|
|
1045
1066
|
dC = x.monoms[x.monoms.length - 1]
|
|
1046
1067
|
|
|
1047
1068
|
// Check last item (degree zero)
|
|
1048
|
-
if (!pC.isDivisible(dC))
|
|
1049
|
-
return false
|
|
1050
|
-
}
|
|
1069
|
+
if (!pC.isDivisible(dC)) return false
|
|
1051
1070
|
|
|
1052
1071
|
// Check the first item (degree max)
|
|
1053
|
-
|
|
1054
|
-
return false
|
|
1055
|
-
}
|
|
1056
|
-
|
|
1057
|
-
return true
|
|
1072
|
+
return pX.isDivisible(dX);
|
|
1058
1073
|
})
|
|
1059
1074
|
}
|
|
1060
1075
|
}
|
|
@@ -9,7 +9,6 @@ import {Fraction} from "../coefficients/fraction";
|
|
|
9
9
|
import {Equation} from "../algebra/equation";
|
|
10
10
|
import {Polynom} from "../algebra/polynom";
|
|
11
11
|
import {Random} from "../randomization/random";
|
|
12
|
-
import {LinearSystem} from "../algebra/linearSystem";
|
|
13
12
|
import {Monom} from "../algebra/monom";
|
|
14
13
|
|
|
15
14
|
export enum LinePropriety {
|
|
@@ -26,7 +25,20 @@ export class Line {
|
|
|
26
25
|
private _referencePropriety: LinePropriety
|
|
27
26
|
private _referenceLine: Line
|
|
28
27
|
private _reduceBeforeDisplay: boolean
|
|
28
|
+
// ax + by + c = 0
|
|
29
|
+
private _a: Fraction;
|
|
30
|
+
private _b: Fraction;
|
|
31
|
+
private _c: Fraction;
|
|
32
|
+
private _OA: Point;
|
|
33
|
+
private _d: Vector;
|
|
34
|
+
private _n: Vector;
|
|
35
|
+
private _exists: boolean
|
|
29
36
|
|
|
37
|
+
/**
|
|
38
|
+
* Value can be a mix of:
|
|
39
|
+
*
|
|
40
|
+
* @param values
|
|
41
|
+
*/
|
|
30
42
|
constructor(...values: unknown[]) {
|
|
31
43
|
|
|
32
44
|
this._exists = false;
|
|
@@ -39,19 +51,17 @@ export class Line {
|
|
|
39
51
|
return this;
|
|
40
52
|
}
|
|
41
53
|
|
|
42
|
-
// ax + by + c = 0
|
|
43
|
-
private _a: Fraction;
|
|
44
|
-
|
|
45
54
|
get a(): Fraction {
|
|
46
55
|
return this._a;
|
|
47
56
|
}
|
|
48
57
|
|
|
58
|
+
// ------------------------------------------
|
|
59
|
+
// Getter and setter
|
|
60
|
+
|
|
49
61
|
set a(value: Fraction) {
|
|
50
62
|
this._a = value;
|
|
51
63
|
}
|
|
52
64
|
|
|
53
|
-
private _b: Fraction;
|
|
54
|
-
|
|
55
65
|
get b(): Fraction {
|
|
56
66
|
return this._b;
|
|
57
67
|
}
|
|
@@ -60,21 +70,14 @@ export class Line {
|
|
|
60
70
|
this._b = value;
|
|
61
71
|
}
|
|
62
72
|
|
|
63
|
-
private _c: Fraction;
|
|
64
|
-
|
|
65
73
|
get c(): Fraction {
|
|
66
74
|
return this._c;
|
|
67
75
|
}
|
|
68
76
|
|
|
69
|
-
// ------------------------------------------
|
|
70
|
-
// Getter and setter
|
|
71
|
-
|
|
72
77
|
set c(value: Fraction) {
|
|
73
78
|
this._c = value;
|
|
74
79
|
}
|
|
75
80
|
|
|
76
|
-
private _OA: Point;
|
|
77
|
-
|
|
78
81
|
get OA(): Point {
|
|
79
82
|
return this._OA;
|
|
80
83
|
}
|
|
@@ -83,8 +86,6 @@ export class Line {
|
|
|
83
86
|
this._OA = value;
|
|
84
87
|
}
|
|
85
88
|
|
|
86
|
-
private _d: Vector;
|
|
87
|
-
|
|
88
89
|
get d(): Vector {
|
|
89
90
|
return this._d;
|
|
90
91
|
}
|
|
@@ -93,14 +94,10 @@ export class Line {
|
|
|
93
94
|
this._d = value;
|
|
94
95
|
}
|
|
95
96
|
|
|
96
|
-
private _n: Vector;
|
|
97
|
-
|
|
98
97
|
get n(): Vector {
|
|
99
98
|
return this._n;
|
|
100
99
|
}
|
|
101
100
|
|
|
102
|
-
private _exists: boolean
|
|
103
|
-
|
|
104
101
|
get exists(): boolean {
|
|
105
102
|
return this._exists;
|
|
106
103
|
}
|
|
@@ -108,19 +105,19 @@ export class Line {
|
|
|
108
105
|
// ------------------------------------------
|
|
109
106
|
get equation(): Equation {
|
|
110
107
|
let equ = new Equation(new Polynom().parse('xy', this._a, this._b, this._c), new Polynom('0'))
|
|
111
|
-
if(this._reduceBeforeDisplay) {
|
|
108
|
+
if (this._reduceBeforeDisplay) {
|
|
112
109
|
return equ.simplify();
|
|
113
|
-
}else{
|
|
110
|
+
} else {
|
|
114
111
|
return equ
|
|
115
112
|
}
|
|
116
113
|
}
|
|
117
114
|
|
|
118
115
|
get system(): { x: Equation, y: Equation } {
|
|
119
116
|
let e1 = new Equation(
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
117
|
+
new Polynom('x'),
|
|
118
|
+
new Polynom(this._OA.x)
|
|
119
|
+
.add(new Monom('k').multiplyByNumber(this._d.x))
|
|
120
|
+
),
|
|
124
121
|
e2 = new Equation(
|
|
125
122
|
new Polynom('y'),
|
|
126
123
|
new Polynom(this._OA.y)
|
|
@@ -73,6 +73,20 @@ export class Point {
|
|
|
73
73
|
|
|
74
74
|
// ------------------------------------------
|
|
75
75
|
// Creation / parsing functions
|
|
76
|
+
|
|
77
|
+
get key(): string {
|
|
78
|
+
return `${this.x.display};${this.y.display}`
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// ------------------------------------------
|
|
82
|
+
static pmatrix = (a: any, b: any, c?: any): string => {
|
|
83
|
+
if (c === undefined) {
|
|
84
|
+
return `\\begin{pmatrix} ${a.tex ? a.tex : a} \\\\ ${b.tex ? b.tex : b} \\end{pmatrix}`;
|
|
85
|
+
} else {
|
|
86
|
+
return `\\begin{pmatrix} ${a.tex ? a.tex : a} \\\\ ${b.tex ? b.tex : b} \\\\ ${c.tex ? c.tex : c} \\end{pmatrix}`;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
76
90
|
// ------------------------------------------
|
|
77
91
|
parse = (...values: unknown[]): Point => {
|
|
78
92
|
// Initialize the value.
|
|
@@ -103,9 +117,9 @@ export class Point {
|
|
|
103
117
|
}
|
|
104
118
|
|
|
105
119
|
// Value given as an object with {x: value, y: value}
|
|
106
|
-
if(values[0] instanceof PointXY){
|
|
107
|
-
|
|
108
|
-
|
|
120
|
+
if (values[0] instanceof PointXY) {
|
|
121
|
+
this._x = new Fraction(values[0].x).reduce()
|
|
122
|
+
this._y = new Fraction(values[0].y).reduce()
|
|
109
123
|
return this
|
|
110
124
|
} else {
|
|
111
125
|
return this.zero()
|
|
@@ -138,6 +152,8 @@ export class Point {
|
|
|
138
152
|
this.zero();
|
|
139
153
|
return this;
|
|
140
154
|
}
|
|
155
|
+
// ------------------------------------------
|
|
156
|
+
// Display functions
|
|
141
157
|
|
|
142
158
|
middleOf = (P1: Point, P2: Point): Point => {
|
|
143
159
|
this._x = P1.x.clone().add(P2.x).divide(2);
|
|
@@ -146,17 +162,6 @@ export class Point {
|
|
|
146
162
|
return this;
|
|
147
163
|
}
|
|
148
164
|
// ------------------------------------------
|
|
149
|
-
// Display functions
|
|
150
|
-
// ------------------------------------------
|
|
151
|
-
texValues = (numberOfDigits: number): string => {
|
|
152
|
-
let pts = [];
|
|
153
|
-
|
|
154
|
-
pts.push(this._x.value.toFixed(numberOfDigits === undefined ? 2 : numberOfDigits));
|
|
155
|
-
pts.push(this._y.value.toFixed(numberOfDigits === undefined ? 2 : numberOfDigits));
|
|
156
|
-
|
|
157
|
-
return `\\left(${pts.join(';')}\\right)`
|
|
158
|
-
}
|
|
159
|
-
// ------------------------------------------
|
|
160
165
|
// Mathematical operations
|
|
161
166
|
// ------------------------------------------
|
|
162
167
|
|
|
@@ -166,36 +171,45 @@ export class Point {
|
|
|
166
171
|
|
|
167
172
|
// ------------------------------------------
|
|
168
173
|
// Static functions
|
|
174
|
+
|
|
175
|
+
translate = (value: { x: number | Fraction, y: number | Fraction }): Point => {
|
|
176
|
+
this._x = this._x.add(value.x)
|
|
177
|
+
this._y = this._y.add(value.y)
|
|
178
|
+
return this
|
|
179
|
+
}
|
|
180
|
+
|
|
169
181
|
// ------------------------------------------
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
182
|
+
texValues = (numberOfDigits: number): string => {
|
|
183
|
+
let pts = [];
|
|
184
|
+
|
|
185
|
+
pts.push(this._x.value.toFixed(numberOfDigits === undefined ? 2 : numberOfDigits));
|
|
186
|
+
pts.push(this._y.value.toFixed(numberOfDigits === undefined ? 2 : numberOfDigits));
|
|
187
|
+
|
|
188
|
+
return `\\left(${pts.join(';')}\\right)`
|
|
189
|
+
}
|
|
177
190
|
|
|
178
|
-
distanceTo = (item:Point|Line): { value: number, fraction: Fraction, tex: string } => {
|
|
191
|
+
distanceTo = (item: Point | Line): { value: number, fraction: Fraction, tex: string } => {
|
|
179
192
|
let value = 0, fraction = new Fraction(), tex = ''
|
|
180
193
|
|
|
181
|
-
if(item instanceof Line){
|
|
194
|
+
if (item instanceof Line) {
|
|
182
195
|
return item.distanceTo(this)
|
|
183
|
-
}else if(item instanceof Point){
|
|
196
|
+
} else if (item instanceof Point) {
|
|
184
197
|
let V = new Vector(this, item)
|
|
185
198
|
|
|
186
199
|
value = V.norm
|
|
187
200
|
fraction = V.normSquare.sqrt()
|
|
188
201
|
tex = V.normSquare.isSquare() ? fraction.tex : `\\sqrt{\\frac{ ${V.normSquare.numerator} }{ ${V.normSquare.denominator} }}`
|
|
189
202
|
}
|
|
190
|
-
return {
|
|
203
|
+
return {value, fraction, tex}
|
|
191
204
|
}
|
|
192
205
|
|
|
193
|
-
get key(): string {
|
|
194
|
-
return `${this.x.display};${this.y.display}`
|
|
195
|
-
}
|
|
196
206
|
isInListOfPoints = (list: Point[]): boolean => {
|
|
197
|
-
const keyList = list.map(x=>x.key)
|
|
207
|
+
const keyList = list.map(x => x.key)
|
|
198
208
|
|
|
199
209
|
return keyList.includes(this.key)
|
|
200
210
|
}
|
|
211
|
+
|
|
212
|
+
isEqual = (pt: Point): boolean => {
|
|
213
|
+
return this.x.isEqual(pt.x) && this.y.isEqual(pt.y)
|
|
214
|
+
}
|
|
201
215
|
}
|