pimath 0.2.13 → 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.
Files changed (59) hide show
  1. package/dist/pimath.js +856 -1882
  2. package/dist/pimath.js.map +1 -1
  3. package/package.json +2 -2
  4. package/src/algebra/equation.ts +562 -558
  5. package/src/algebra/equationSolver.ts +489 -489
  6. package/src/algebra/factor.ts +396 -392
  7. package/src/algebra/linearSystem.ts +446 -442
  8. package/src/algebra/matrix.ts +515 -511
  9. package/src/algebra/monom.ts +932 -928
  10. package/src/algebra/polyFactor.ts +724 -720
  11. package/src/algebra/polynom.ts +1233 -1229
  12. package/src/coefficients/fraction.ts +907 -748
  13. package/src/coefficients/root.ts +500 -359
  14. package/src/geometry/TupleN.ts +129 -129
  15. package/src/geometry/circle.ts +455 -455
  16. package/src/geometry/line.ts +658 -654
  17. package/src/geometry/point.ts +105 -105
  18. package/src/geometry/sphere3.ts +2 -2
  19. package/src/geometry/triangle.ts +488 -488
  20. package/src/geometry/vector.ts +230 -226
  21. package/src/numeric.ts +136 -51
  22. package/src/pimath.interface.ts +2 -0
  23. package/types/algebra/equation.d.ts +1 -0
  24. package/types/algebra/equation.d.ts.map +1 -1
  25. package/types/algebra/equationSolver.d.ts.map +1 -1
  26. package/types/algebra/factor.d.ts +1 -0
  27. package/types/algebra/factor.d.ts.map +1 -1
  28. package/types/algebra/linearSystem.d.ts +1 -0
  29. package/types/algebra/linearSystem.d.ts.map +1 -1
  30. package/types/algebra/matrix.d.ts +6 -5
  31. package/types/algebra/matrix.d.ts.map +1 -1
  32. package/types/algebra/monom.d.ts +1 -0
  33. package/types/algebra/monom.d.ts.map +1 -1
  34. package/types/algebra/polyFactor.d.ts +1 -0
  35. package/types/algebra/polyFactor.d.ts.map +1 -1
  36. package/types/algebra/polynom.d.ts +1 -0
  37. package/types/algebra/polynom.d.ts.map +1 -1
  38. package/types/coefficients/fraction.d.ts +62 -53
  39. package/types/coefficients/fraction.d.ts.map +1 -1
  40. package/types/coefficients/root.d.ts +3 -0
  41. package/types/coefficients/root.d.ts.map +1 -1
  42. package/types/geometry/TupleN.d.ts +1 -1
  43. package/types/geometry/TupleN.d.ts.map +1 -1
  44. package/types/geometry/circle.d.ts.map +1 -1
  45. package/types/geometry/line.d.ts +1 -0
  46. package/types/geometry/line.d.ts.map +1 -1
  47. package/types/geometry/point.d.ts.map +1 -1
  48. package/types/geometry/sphere3.d.ts +2 -2
  49. package/types/geometry/sphere3.d.ts.map +1 -1
  50. package/types/geometry/triangle.d.ts.map +1 -1
  51. package/types/geometry/vector.d.ts +1 -0
  52. package/types/geometry/vector.d.ts.map +1 -1
  53. package/types/index.d.ts +3 -3
  54. package/types/numeric.d.ts +4 -4
  55. package/types/numeric.d.ts.map +1 -1
  56. package/types/pimath.interface.d.ts +1 -0
  57. package/types/pimath.interface.d.ts.map +1 -1
  58. package/types/primes.data.d.ts +2 -0
  59. package/types/primes.data.d.ts.map +1 -0
@@ -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
- public parse(...values: (Point|Vector)[] | InputValue<Fraction>[]): this {
26
- if (values.length === 1) {
27
- if (values[0] instanceof TupleN) {
28
- this.array = values[0].copy()
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
- public clone(): Point {
57
- return new Point(...this.copy())
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
- public isEqual(pt: Point): boolean {
86
- return this.x.value===pt.x.value && this.y.value===pt.y.value
87
- }
88
-
89
- public 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
- }
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
+ }
@@ -113,12 +113,12 @@ export class Sphere3 {
113
113
  return this
114
114
  }
115
115
 
116
- get centerRadius(): this {
116
+ get asCenterRadius(): this {
117
117
  this.#format = SPHERE3_FORMAT.CENTER_RADIUS
118
118
  return this
119
119
  }
120
120
 
121
- get developped(): this {
121
+ get asDeveloped(): this {
122
122
  this.#format = SPHERE3_FORMAT.DEVELOPPED
123
123
  return this
124
124
  }