pimath 0.2.14 → 0.2.15
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 +850 -1879
- package/dist/pimath.js.map +1 -1
- package/package.json +1 -1
- package/src/algebra/equation.ts +562 -558
- package/src/algebra/equationSolver.ts +489 -489
- package/src/algebra/factor.ts +396 -392
- package/src/algebra/linearSystem.ts +446 -442
- package/src/algebra/matrix.ts +515 -511
- package/src/algebra/monom.ts +932 -928
- package/src/algebra/polyFactor.ts +724 -720
- package/src/algebra/polynom.ts +1233 -1229
- package/src/coefficients/fraction.ts +907 -748
- package/src/coefficients/root.ts +500 -359
- package/src/geometry/TupleN.ts +129 -129
- package/src/geometry/circle.ts +455 -455
- package/src/geometry/line.ts +658 -654
- package/src/geometry/point.ts +105 -105
- package/src/geometry/sphere3.ts +2 -2
- package/src/geometry/triangle.ts +488 -488
- package/src/geometry/vector.ts +230 -226
- package/src/numeric.ts +136 -51
- package/src/pimath.interface.ts +2 -0
- package/types/algebra/equation.d.ts +1 -0
- package/types/algebra/equation.d.ts.map +1 -1
- package/types/algebra/equationSolver.d.ts.map +1 -1
- package/types/algebra/factor.d.ts +1 -0
- package/types/algebra/factor.d.ts.map +1 -1
- package/types/algebra/linearSystem.d.ts +1 -0
- package/types/algebra/linearSystem.d.ts.map +1 -1
- package/types/algebra/matrix.d.ts +6 -5
- package/types/algebra/matrix.d.ts.map +1 -1
- package/types/algebra/monom.d.ts +1 -0
- package/types/algebra/monom.d.ts.map +1 -1
- package/types/algebra/polyFactor.d.ts +1 -0
- package/types/algebra/polyFactor.d.ts.map +1 -1
- package/types/algebra/polynom.d.ts +1 -0
- package/types/algebra/polynom.d.ts.map +1 -1
- package/types/coefficients/fraction.d.ts +62 -53
- package/types/coefficients/fraction.d.ts.map +1 -1
- package/types/coefficients/root.d.ts +3 -0
- package/types/coefficients/root.d.ts.map +1 -1
- package/types/geometry/TupleN.d.ts +1 -1
- package/types/geometry/TupleN.d.ts.map +1 -1
- package/types/geometry/circle.d.ts.map +1 -1
- package/types/geometry/line.d.ts +1 -0
- package/types/geometry/line.d.ts.map +1 -1
- package/types/geometry/point.d.ts.map +1 -1
- package/types/geometry/sphere3.d.ts +2 -2
- package/types/geometry/sphere3.d.ts.map +1 -1
- package/types/geometry/triangle.d.ts.map +1 -1
- package/types/geometry/vector.d.ts +1 -0
- package/types/geometry/vector.d.ts.map +1 -1
- package/types/index.d.ts +3 -3
- package/types/numeric.d.ts +4 -4
- package/types/numeric.d.ts.map +1 -1
- package/types/pimath.interface.d.ts +1 -0
- package/types/pimath.interface.d.ts.map +1 -1
- package/types/primes.data.d.ts +2 -0
- package/types/primes.data.d.ts.map +1 -0
package/src/geometry/TupleN.ts
CHANGED
|
@@ -1,129 +1,129 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* POint module contains everything necessary to handle 2d Points
|
|
3
|
-
* It's a "wrapper" of the Vector class.
|
|
4
|
-
* @module Point
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import {Fraction} from "../coefficients"
|
|
8
|
-
import type {InputValue} from "../pimath.interface"
|
|
9
|
-
import {DimensionError} from "../errors"
|
|
10
|
-
|
|
11
|
-
export abstract class TupleN {
|
|
12
|
-
#array: Fraction[] = []
|
|
13
|
-
#onChange?: () => void
|
|
14
|
-
|
|
15
|
-
constructor(...values: InputValue<Fraction>[]) {
|
|
16
|
-
this.#array = values.map(x => new Fraction(x))
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return this.#array.map(x => x.clone())
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
abstract get tex(): string
|
|
26
|
-
|
|
27
|
-
abstract get display(): string
|
|
28
|
-
|
|
29
|
-
get array(): Fraction[] {
|
|
30
|
-
return this.#array
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
set array(value: Fraction[]) {
|
|
34
|
-
this.#array = value
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
get dimension(): number {
|
|
38
|
-
return this.array.length
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
// Remove the first letter if it's a parenthesis.
|
|
43
|
-
if (value.startsWith('(')) {
|
|
44
|
-
value = value.substring(1)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// Remove the last letter if it's a parenthesis.
|
|
48
|
-
if (value.endsWith(')')) {
|
|
49
|
-
value = value.substring(0, value.length - 1)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Split comma, semi colon or single space.
|
|
53
|
-
const components = value.split(/[,;\s]/g)
|
|
54
|
-
.filter((v) => v.trim() !== '')
|
|
55
|
-
|
|
56
|
-
// there must be at least two Pages.
|
|
57
|
-
if (components.length < 2) {
|
|
58
|
-
return this
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// Validate the fraction values.
|
|
62
|
-
this.#array = components.map(x => new Fraction(x))
|
|
63
|
-
return this
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
get onChange(): undefined | (() => void) {
|
|
67
|
-
return this.#onChange
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
set onChange(value: undefined | (() => void)) {
|
|
71
|
-
this.#onChange = value
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
setDimension(value = 2): this {
|
|
75
|
-
if (value < 2) {
|
|
76
|
-
throw new DimensionError('Dimension must be at least 2')
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (value < this.dimension) {
|
|
80
|
-
this.#array = this.#array.slice(0, value)
|
|
81
|
-
} else if (value > this.dimension) {
|
|
82
|
-
for (let i = this.dimension; i < value; i++) {
|
|
83
|
-
this.#array.push(new Fraction(0))
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return this
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
get x(): Fraction {
|
|
91
|
-
return this.#array[0]
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
set x(value: Fraction | number | string) {
|
|
95
|
-
this.#array[0] = new Fraction(value)
|
|
96
|
-
this.#onChange?.()
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
get y(): Fraction {
|
|
100
|
-
return this.#array[1]
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
set y(value: Fraction | number | string) {
|
|
104
|
-
this.#array[1] = new Fraction(value)
|
|
105
|
-
this.#onChange?.()
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
get z(): Fraction {
|
|
109
|
-
if (this.dimension < 3) {
|
|
110
|
-
throw new DimensionError('Vector is not 3D')
|
|
111
|
-
}
|
|
112
|
-
return this.#array[2]
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
set z(value: Fraction | number | string) {
|
|
116
|
-
if (this.dimension < 3) {
|
|
117
|
-
throw new DimensionError('Vector is not 3D')
|
|
118
|
-
}
|
|
119
|
-
this.#array[2] = new Fraction(value)
|
|
120
|
-
this.#onChange?.()
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
zero = (): this => {
|
|
124
|
-
this.#array.forEach(x => x.zero())
|
|
125
|
-
this.#onChange?.()
|
|
126
|
-
return this
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* POint module contains everything necessary to handle 2d Points
|
|
3
|
+
* It's a "wrapper" of the Vector class.
|
|
4
|
+
* @module Point
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import {Fraction} from "../coefficients"
|
|
8
|
+
import type {InputValue} from "../pimath.interface"
|
|
9
|
+
import {DimensionError} from "../errors"
|
|
10
|
+
|
|
11
|
+
export abstract class TupleN {
|
|
12
|
+
#array: Fraction[] = []
|
|
13
|
+
#onChange?: () => void
|
|
14
|
+
|
|
15
|
+
constructor(...values: InputValue<Fraction>[]) {
|
|
16
|
+
this.#array = values.map(x => new Fraction(x))
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
abstract clone(): void
|
|
20
|
+
|
|
21
|
+
cloneCoordinates(): Fraction[] {
|
|
22
|
+
return this.#array.map(x => x.clone())
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
abstract get tex(): string
|
|
26
|
+
|
|
27
|
+
abstract get display(): string
|
|
28
|
+
|
|
29
|
+
get array(): Fraction[] {
|
|
30
|
+
return this.#array
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
set array(value: Fraction[]) {
|
|
34
|
+
this.#array = value
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
get dimension(): number {
|
|
38
|
+
return this.array.length
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
fromString(value: string): this {
|
|
42
|
+
// Remove the first letter if it's a parenthesis.
|
|
43
|
+
if (value.startsWith('(')) {
|
|
44
|
+
value = value.substring(1)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Remove the last letter if it's a parenthesis.
|
|
48
|
+
if (value.endsWith(')')) {
|
|
49
|
+
value = value.substring(0, value.length - 1)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Split comma, semi colon or single space.
|
|
53
|
+
const components = value.split(/[,;\s]/g)
|
|
54
|
+
.filter((v) => v.trim() !== '')
|
|
55
|
+
|
|
56
|
+
// there must be at least two Pages.
|
|
57
|
+
if (components.length < 2) {
|
|
58
|
+
return this
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Validate the fraction values.
|
|
62
|
+
this.#array = components.map(x => new Fraction(x))
|
|
63
|
+
return this
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
get onChange(): undefined | (() => void) {
|
|
67
|
+
return this.#onChange
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
set onChange(value: undefined | (() => void)) {
|
|
71
|
+
this.#onChange = value
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
setDimension(value = 2): this {
|
|
75
|
+
if (value < 2) {
|
|
76
|
+
throw new DimensionError('Dimension must be at least 2')
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (value < this.dimension) {
|
|
80
|
+
this.#array = this.#array.slice(0, value)
|
|
81
|
+
} else if (value > this.dimension) {
|
|
82
|
+
for (let i = this.dimension; i < value; i++) {
|
|
83
|
+
this.#array.push(new Fraction(0))
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return this
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
get x(): Fraction {
|
|
91
|
+
return this.#array[0]
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
set x(value: Fraction | number | string) {
|
|
95
|
+
this.#array[0] = new Fraction(value)
|
|
96
|
+
this.#onChange?.()
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
get y(): Fraction {
|
|
100
|
+
return this.#array[1]
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
set y(value: Fraction | number | string) {
|
|
104
|
+
this.#array[1] = new Fraction(value)
|
|
105
|
+
this.#onChange?.()
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
get z(): Fraction {
|
|
109
|
+
if (this.dimension < 3) {
|
|
110
|
+
throw new DimensionError('Vector is not 3D')
|
|
111
|
+
}
|
|
112
|
+
return this.#array[2]
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
set z(value: Fraction | number | string) {
|
|
116
|
+
if (this.dimension < 3) {
|
|
117
|
+
throw new DimensionError('Vector is not 3D')
|
|
118
|
+
}
|
|
119
|
+
this.#array[2] = new Fraction(value)
|
|
120
|
+
this.#onChange?.()
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
zero = (): this => {
|
|
124
|
+
this.#array.forEach(x => x.zero())
|
|
125
|
+
this.#onChange?.()
|
|
126
|
+
return this
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
}
|