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/point.ts
CHANGED
|
@@ -1,105 +1,105 @@
|
|
|
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, InvalidArgumentError, ParseError} from "../errors"
|
|
10
|
-
import {Root} from "../coefficients/root"
|
|
11
|
-
import {TupleN} from "./TupleN"
|
|
12
|
-
import type {Vector} from "./vector"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
export class Point extends TupleN {
|
|
16
|
-
constructor(...values: (Point|Vector)[] | InputValue<Fraction>[]) {
|
|
17
|
-
super()
|
|
18
|
-
|
|
19
|
-
// Initialize the vector
|
|
20
|
-
if (values.length > 0) {
|
|
21
|
-
this.parse(...values)
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (values.length === 1) {
|
|
27
|
-
if (values[0] instanceof TupleN) {
|
|
28
|
-
this.array = values[0].
|
|
29
|
-
return this
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (typeof values[0] === 'string') {
|
|
33
|
-
this.fromString(values[0])
|
|
34
|
-
return this
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if (values.length > 1) {
|
|
40
|
-
if (values.some(x => x instanceof Point)) {
|
|
41
|
-
throw new InvalidArgumentError('Creating a point with multiple argument requires an input fraction')
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const nbs: Fraction[] = values.map(x => new Fraction(x as InputValue<Fraction>))
|
|
45
|
-
|
|
46
|
-
if (nbs.some(x => x.isNaN())) {
|
|
47
|
-
throw new ParseError('The given values are not a valid point string (a,b): ')
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
this.array = nbs
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return this
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return new Point(...this.
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
get tex(): string {
|
|
61
|
-
return `\\left(${this.array.map(x => x.tex).join(';')}\\right)`
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
get display(): string {
|
|
65
|
-
return `(${this.array.map(x => x.display).join(';')})`
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
distanceTo(B: Point): Root {
|
|
69
|
-
if (this.dimension !== B.dimension) {
|
|
70
|
-
throw new DimensionError('The two points must have the same dimensions.')
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const AB = this.array
|
|
74
|
-
.map((x, index) => B.array[index].clone().subtract(x))
|
|
75
|
-
|
|
76
|
-
const distance2 = AB
|
|
77
|
-
.reduce(
|
|
78
|
-
(acc, x) =>
|
|
79
|
-
acc.add(x.clone().pow(2)), new Fraction(0)
|
|
80
|
-
)
|
|
81
|
-
|
|
82
|
-
return new Root().from(2, distance2).reduce()
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
return this.x.value===pt.x.value && this.y.value===pt.y.value
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return this.isEqual(new Point(x, y))
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
middleOf(V1: Point, V2: Point): this {
|
|
94
|
-
if (V1.dimension !== V2.dimension) {
|
|
95
|
-
throw new DimensionError('Vectors must be the same dimension')
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
this.array = []
|
|
99
|
-
V1.array.forEach((x, index) => {
|
|
100
|
-
this.array.push(x.clone().add(V2.array[index]).divide(2))
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
return this
|
|
104
|
-
}
|
|
105
|
-
}
|
|
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, InvalidArgumentError, ParseError} from "../errors"
|
|
10
|
+
import {Root} from "../coefficients/root"
|
|
11
|
+
import {TupleN} from "./TupleN"
|
|
12
|
+
import type {Vector} from "./vector"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
export class Point extends TupleN {
|
|
16
|
+
constructor(...values: (Point|Vector)[] | InputValue<Fraction>[]) {
|
|
17
|
+
super()
|
|
18
|
+
|
|
19
|
+
// Initialize the vector
|
|
20
|
+
if (values.length > 0) {
|
|
21
|
+
this.parse(...values)
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
parse(...values: (Point|Vector)[] | InputValue<Fraction>[]): this {
|
|
26
|
+
if (values.length === 1) {
|
|
27
|
+
if (values[0] instanceof TupleN) {
|
|
28
|
+
this.array = values[0].cloneCoordinates()
|
|
29
|
+
return this
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (typeof values[0] === 'string') {
|
|
33
|
+
this.fromString(values[0])
|
|
34
|
+
return this
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
if (values.length > 1) {
|
|
40
|
+
if (values.some(x => x instanceof Point)) {
|
|
41
|
+
throw new InvalidArgumentError('Creating a point with multiple argument requires an input fraction')
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const nbs: Fraction[] = values.map(x => new Fraction(x as InputValue<Fraction>))
|
|
45
|
+
|
|
46
|
+
if (nbs.some(x => x.isNaN())) {
|
|
47
|
+
throw new ParseError('The given values are not a valid point string (a,b): ')
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
this.array = nbs
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return this
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
clone(): Point {
|
|
57
|
+
return new Point(...this.cloneCoordinates())
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
get tex(): string {
|
|
61
|
+
return `\\left(${this.array.map(x => x.tex).join(';')}\\right)`
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
get display(): string {
|
|
65
|
+
return `(${this.array.map(x => x.display).join(';')})`
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
distanceTo(B: Point): Root {
|
|
69
|
+
if (this.dimension !== B.dimension) {
|
|
70
|
+
throw new DimensionError('The two points must have the same dimensions.')
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const AB = this.array
|
|
74
|
+
.map((x, index) => B.array[index].clone().subtract(x))
|
|
75
|
+
|
|
76
|
+
const distance2 = AB
|
|
77
|
+
.reduce(
|
|
78
|
+
(acc, x) =>
|
|
79
|
+
acc.add(x.clone().pow(2)), new Fraction(0)
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
return new Root().from(2, distance2).reduce()
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
isEqual(pt: Point): boolean {
|
|
86
|
+
return this.x.value===pt.x.value && this.y.value===pt.y.value
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
isEqualXY(x: InputValue<Fraction>, y: InputValue<Fraction>): boolean {
|
|
90
|
+
return this.isEqual(new Point(x, y))
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
middleOf(V1: Point, V2: Point): this {
|
|
94
|
+
if (V1.dimension !== V2.dimension) {
|
|
95
|
+
throw new DimensionError('Vectors must be the same dimension')
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
this.array = []
|
|
99
|
+
V1.array.forEach((x, index) => {
|
|
100
|
+
this.array.push(x.clone().add(V2.array[index]).divide(2))
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
return this
|
|
104
|
+
}
|
|
105
|
+
}
|
package/src/geometry/sphere3.ts
CHANGED
|
@@ -113,12 +113,12 @@ export class Sphere3 {
|
|
|
113
113
|
return this
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
-
get
|
|
116
|
+
get asCenterRadius(): this {
|
|
117
117
|
this.#format = SPHERE3_FORMAT.CENTER_RADIUS
|
|
118
118
|
return this
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
get
|
|
121
|
+
get asDeveloped(): this {
|
|
122
122
|
this.#format = SPHERE3_FORMAT.DEVELOPPED
|
|
123
123
|
return this
|
|
124
124
|
}
|