@lakuna/umath 1.3.4 → 1.3.6

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 (162) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +7 -9
  3. package/dist/algorithms/combinations.d.ts +7 -0
  4. package/dist/algorithms/combinations.d.ts.map +1 -1
  5. package/dist/algorithms/combinations.js +8 -1
  6. package/dist/algorithms/combinations.js.map +1 -1
  7. package/dist/algorithms/degreesToRadians.d.ts +7 -0
  8. package/dist/algorithms/degreesToRadians.d.ts.map +1 -1
  9. package/dist/algorithms/degreesToRadians.js +7 -0
  10. package/dist/algorithms/degreesToRadians.js.map +1 -1
  11. package/dist/algorithms/factorial.d.ts +6 -0
  12. package/dist/algorithms/factorial.d.ts.map +1 -1
  13. package/dist/algorithms/factorial.js +15 -5
  14. package/dist/algorithms/factorial.js.map +1 -1
  15. package/dist/algorithms/fibonacci.d.ts +6 -1
  16. package/dist/algorithms/fibonacci.d.ts.map +1 -1
  17. package/dist/algorithms/fibonacci.js +6 -1
  18. package/dist/algorithms/fibonacci.js.map +1 -1
  19. package/dist/algorithms/greatestCommonDivisor.d.ts +14 -0
  20. package/dist/algorithms/greatestCommonDivisor.d.ts.map +1 -1
  21. package/dist/algorithms/greatestCommonDivisor.js +7 -9
  22. package/dist/algorithms/greatestCommonDivisor.js.map +1 -1
  23. package/dist/algorithms/hypergeometricPmf.d.ts +9 -0
  24. package/dist/algorithms/hypergeometricPmf.d.ts.map +1 -1
  25. package/dist/algorithms/hypergeometricPmf.js +10 -1
  26. package/dist/algorithms/hypergeometricPmf.js.map +1 -1
  27. package/dist/algorithms/isPrime.d.ts +6 -0
  28. package/dist/algorithms/isPrime.d.ts.map +1 -1
  29. package/dist/algorithms/isPrime.js +8 -1
  30. package/dist/algorithms/isPrime.js.map +1 -1
  31. package/dist/algorithms/permutations.d.ts +7 -0
  32. package/dist/algorithms/permutations.d.ts.map +1 -1
  33. package/dist/algorithms/permutations.js +8 -1
  34. package/dist/algorithms/permutations.js.map +1 -1
  35. package/dist/algorithms/primeFactorization.d.ts +7 -1
  36. package/dist/algorithms/primeFactorization.d.ts.map +1 -1
  37. package/dist/algorithms/primeFactorization.js +10 -3
  38. package/dist/algorithms/primeFactorization.js.map +1 -1
  39. package/dist/algorithms/radiansToDegrees.d.ts +7 -0
  40. package/dist/algorithms/radiansToDegrees.d.ts.map +1 -1
  41. package/dist/algorithms/radiansToDegrees.js +7 -0
  42. package/dist/algorithms/radiansToDegrees.js.map +1 -1
  43. package/dist/algorithms/summation.d.ts +8 -0
  44. package/dist/algorithms/summation.d.ts.map +1 -1
  45. package/dist/algorithms/summation.js +9 -0
  46. package/dist/algorithms/summation.js.map +1 -1
  47. package/dist/index.d.ts +32 -33
  48. package/dist/index.d.ts.map +1 -1
  49. package/dist/index.js +27 -27
  50. package/dist/index.js.map +1 -1
  51. package/dist/linalg/DualQuaternion.d.ts +460 -83
  52. package/dist/linalg/DualQuaternion.d.ts.map +1 -1
  53. package/dist/linalg/DualQuaternion.js +514 -133
  54. package/dist/linalg/DualQuaternion.js.map +1 -1
  55. package/dist/linalg/Matrix.d.ts +80 -12
  56. package/dist/linalg/Matrix.d.ts.map +1 -1
  57. package/dist/linalg/Matrix2.d.ts +337 -52
  58. package/dist/linalg/Matrix2.d.ts.map +1 -1
  59. package/dist/linalg/Matrix2.js +345 -61
  60. package/dist/linalg/Matrix2.js.map +1 -1
  61. package/dist/linalg/Matrix3.d.ts +470 -72
  62. package/dist/linalg/Matrix3.d.ts.map +1 -1
  63. package/dist/linalg/Matrix3.js +488 -94
  64. package/dist/linalg/Matrix3.js.map +1 -1
  65. package/dist/linalg/Matrix4.d.ts +842 -137
  66. package/dist/linalg/Matrix4.d.ts.map +1 -1
  67. package/dist/linalg/Matrix4.js +896 -175
  68. package/dist/linalg/Matrix4.js.map +1 -1
  69. package/dist/linalg/Quaternion.d.ts +395 -70
  70. package/dist/linalg/Quaternion.d.ts.map +1 -1
  71. package/dist/linalg/Quaternion.js +416 -70
  72. package/dist/linalg/Quaternion.js.map +1 -1
  73. package/dist/linalg/SlowMatrix.d.ts +79 -9
  74. package/dist/linalg/SlowMatrix.d.ts.map +1 -1
  75. package/dist/linalg/SlowMatrix.js +147 -27
  76. package/dist/linalg/SlowMatrix.js.map +1 -1
  77. package/dist/linalg/SlowSquareMatrix.d.ts +58 -3
  78. package/dist/linalg/SlowSquareMatrix.d.ts.map +1 -1
  79. package/dist/linalg/SlowSquareMatrix.js +111 -21
  80. package/dist/linalg/SlowSquareMatrix.js.map +1 -1
  81. package/dist/linalg/SquareMatrix.d.ts +26 -3
  82. package/dist/linalg/SquareMatrix.d.ts.map +1 -1
  83. package/dist/linalg/Vector.d.ts +148 -24
  84. package/dist/linalg/Vector.d.ts.map +1 -1
  85. package/dist/linalg/Vector2.d.ts +484 -84
  86. package/dist/linalg/Vector2.d.ts.map +1 -1
  87. package/dist/linalg/Vector2.js +487 -71
  88. package/dist/linalg/Vector2.js.map +1 -1
  89. package/dist/linalg/Vector3.d.ts +582 -98
  90. package/dist/linalg/Vector3.d.ts.map +1 -1
  91. package/dist/linalg/Vector3.js +625 -134
  92. package/dist/linalg/Vector3.js.map +1 -1
  93. package/dist/linalg/Vector4.d.ts +450 -75
  94. package/dist/linalg/Vector4.d.ts.map +1 -1
  95. package/dist/linalg/Vector4.js +447 -62
  96. package/dist/linalg/Vector4.js.map +1 -1
  97. package/dist/types/AxisAngle.d.ts +4 -1
  98. package/dist/types/AxisAngle.d.ts.map +1 -1
  99. package/dist/types/FieldOfView.d.ts +5 -0
  100. package/dist/types/FieldOfView.d.ts.map +1 -1
  101. package/dist/utility/BigNumber.d.ts +41 -8
  102. package/dist/utility/BigNumber.d.ts.map +1 -1
  103. package/dist/utility/BigNumber.js +47 -5
  104. package/dist/utility/BigNumber.js.map +1 -1
  105. package/dist/utility/MagnitudeError.d.ts +5 -0
  106. package/dist/utility/MagnitudeError.d.ts.map +1 -1
  107. package/dist/utility/MagnitudeError.js +6 -1
  108. package/dist/utility/MagnitudeError.js.map +1 -1
  109. package/dist/utility/MatrixSizeError.d.ts +5 -0
  110. package/dist/utility/MatrixSizeError.d.ts.map +1 -1
  111. package/dist/utility/MatrixSizeError.js +5 -0
  112. package/dist/utility/MatrixSizeError.js.map +1 -1
  113. package/dist/utility/PartialMatrixError.d.ts +5 -0
  114. package/dist/utility/PartialMatrixError.d.ts.map +1 -1
  115. package/dist/utility/PartialMatrixError.js +5 -0
  116. package/dist/utility/PartialMatrixError.js.map +1 -1
  117. package/dist/utility/SingularMatrixError.d.ts +8 -0
  118. package/dist/utility/SingularMatrixError.d.ts.map +1 -1
  119. package/dist/utility/SingularMatrixError.js +8 -0
  120. package/dist/utility/SingularMatrixError.js.map +1 -1
  121. package/dist/utility/epsilon.d.ts +1 -0
  122. package/dist/utility/epsilon.d.ts.map +1 -1
  123. package/dist/utility/epsilon.js +1 -0
  124. package/dist/utility/epsilon.js.map +1 -1
  125. package/package.json +20 -51
  126. package/src/algorithms/combinations.ts +4 -4
  127. package/src/algorithms/degreesToRadians.ts +3 -3
  128. package/src/algorithms/factorial.ts +13 -8
  129. package/src/algorithms/fibonacci.ts +3 -3
  130. package/src/algorithms/greatestCommonDivisor.ts +15 -19
  131. package/src/algorithms/hypergeometricPmf.ts +5 -6
  132. package/src/algorithms/isPrime.ts +4 -4
  133. package/src/algorithms/permutations.ts +4 -4
  134. package/src/algorithms/primeFactorization.ts +9 -9
  135. package/src/algorithms/radiansToDegrees.ts +3 -3
  136. package/src/algorithms/summation.ts +5 -5
  137. package/src/index.ts +35 -33
  138. package/src/linalg/DualQuaternion.ts +558 -804
  139. package/src/linalg/Matrix.ts +35 -36
  140. package/src/linalg/Matrix2.ts +277 -413
  141. package/src/linalg/Matrix3.ts +532 -737
  142. package/src/linalg/Matrix4.ts +1078 -1604
  143. package/src/linalg/Quaternion.ts +415 -690
  144. package/src/linalg/SlowMatrix.ts +118 -69
  145. package/src/linalg/SlowSquareMatrix.ts +85 -56
  146. package/src/linalg/SquareMatrix.ts +7 -7
  147. package/src/linalg/Vector.ts +71 -70
  148. package/src/linalg/Vector2.ts +380 -576
  149. package/src/linalg/Vector3.ts +544 -840
  150. package/src/linalg/Vector4.ts +383 -549
  151. package/src/types/AxisAngle.ts +1 -1
  152. package/src/utility/BigNumber.ts +33 -42
  153. package/src/utility/MagnitudeError.ts +4 -4
  154. package/src/utility/MatrixSizeError.ts +2 -3
  155. package/src/utility/PartialMatrixError.ts +2 -3
  156. package/src/utility/SingularMatrixError.ts +2 -2
  157. package/src/utility/epsilon.ts +1 -4
  158. package/dist/types/IntegerRepresentation.d.ts +0 -2
  159. package/dist/types/IntegerRepresentation.d.ts.map +0 -1
  160. package/dist/types/IntegerRepresentation.js +0 -2
  161. package/dist/types/IntegerRepresentation.js.map +0 -1
  162. package/src/types/IntegerRepresentation.ts +0 -2
@@ -1,4 +1,4 @@
1
- import type { Vector3Like } from "#Vector3";
1
+ import type { Vector3Like } from "../linalg/Vector3.js";
2
2
 
3
3
  /** An axis and an angle to rotate around it. */
4
4
  export default interface AxisAngle {
@@ -1,33 +1,22 @@
1
- import greatestCommonDivisor from "#greatestCommonDivisor";
2
- import type { IntegerRepresentation } from "#IntegerRepresentation";
1
+ import greatestCommonDivisor from "../algorithms/greatestCommonDivisor.js";
3
2
 
4
3
  /** A number with no maximum precise size. */
5
4
  export default class BigNumber {
6
5
  /**
7
- * Creates a number.
8
- * @param source The number.
9
- */
10
- public constructor(source?: IntegerRepresentation);
11
-
12
- /**
13
- * Creates a number from a fraction.
14
- * @param dividend The dividend of the fraction.
15
- * @param divisor The divisor of the fraction.
6
+ * Create a number.
7
+ * @param dividend - The dividend of the number.
8
+ * @param divisor - The divisor of the number.
16
9
  */
17
10
  public constructor(
18
- dividend?: IntegerRepresentation,
19
- divisor?: IntegerRepresentation
20
- );
21
-
22
- public constructor(
23
- dividend: IntegerRepresentation = 0,
24
- divisor: IntegerRepresentation = 1
11
+ dividend: bigint | boolean | number | string = 0,
12
+ divisor: bigint | boolean | number | string = 1
25
13
  ) {
26
- this.dividend = BigInt(dividend);
27
- this.divisor = BigInt(divisor);
28
- if (!this.divisor) {
14
+ if (divisor === 0) {
29
15
  throw new Error("Cannot divide by zero.");
30
16
  }
17
+
18
+ this.dividend = BigInt(dividend);
19
+ this.divisor = BigInt(divisor);
31
20
  this.simplify();
32
21
  }
33
22
 
@@ -37,16 +26,19 @@ export default class BigNumber {
37
26
  /** The divisor of this fraction. */
38
27
  public divisor: bigint;
39
28
 
40
- /** Simplifies this fraction. */
41
- private simplify(): void {
42
- // Switches signs such that only the dividend can be negative.
29
+ /**
30
+ * Simplify this fraction.
31
+ * @internal
32
+ */
33
+ private simplify() {
34
+ // Switch signs such that only the dividend can be negative.
43
35
  if (this.divisor < 0) {
44
36
  this.dividend = -this.dividend;
45
37
  this.divisor = -this.divisor;
46
38
  }
47
39
 
48
40
  // Divide both by their greatest common divisor.
49
- const gcd: bigint = greatestCommonDivisor(this.dividend, this.divisor);
41
+ const gcd = greatestCommonDivisor(this.dividend, this.divisor);
50
42
  if (gcd > 1) {
51
43
  this.dividend /= gcd;
52
44
  this.divisor /= gcd;
@@ -54,11 +46,11 @@ export default class BigNumber {
54
46
  }
55
47
 
56
48
  /**
57
- * Adds a number to this number.
58
- * @param n The other number.
49
+ * Add a number to this number.
50
+ * @param n - The other number.
59
51
  * @returns This number.
60
52
  */
61
- public add(n: IntegerRepresentation | BigNumber): this {
53
+ public add(n: bigint | boolean | number | string | BigNumber): this {
62
54
  if (n instanceof BigNumber) {
63
55
  this.dividend = this.dividend * n.divisor + n.dividend * this.divisor;
64
56
  this.divisor *= n.divisor;
@@ -71,11 +63,11 @@ export default class BigNumber {
71
63
  }
72
64
 
73
65
  /**
74
- * Subtracts a number from this number.
75
- * @param n The other number.
66
+ * Subtract a number from this number.
67
+ * @param n - The other number.
76
68
  * @returns This number.
77
69
  */
78
- public subtract(n: IntegerRepresentation | BigNumber): this {
70
+ public subtract(n: bigint | boolean | number | string | BigNumber): this {
79
71
  if (n instanceof BigNumber) {
80
72
  this.dividend = this.dividend * n.divisor - n.dividend * this.divisor;
81
73
  this.divisor *= n.divisor;
@@ -88,11 +80,11 @@ export default class BigNumber {
88
80
  }
89
81
 
90
82
  /**
91
- * Multiplies this number by a number.
92
- * @param n The other number.
83
+ * Multiply this number by a number.
84
+ * @param n - The other number.
93
85
  * @returns This number.
94
86
  */
95
- public multiply(n: IntegerRepresentation | BigNumber): this {
87
+ public multiply(n: bigint | boolean | number | string | BigNumber): this {
96
88
  if (n instanceof BigNumber) {
97
89
  this.dividend *= n.dividend;
98
90
  this.divisor *= n.divisor;
@@ -105,11 +97,11 @@ export default class BigNumber {
105
97
  }
106
98
 
107
99
  /**
108
- * Divides this number by a number.
109
- * @param n The other number.
100
+ * Divide this number by a number.
101
+ * @param n - The other number.
110
102
  * @returns This number.
111
103
  */
112
- public divide(n: IntegerRepresentation | BigNumber): this {
104
+ public divide(n: bigint | boolean | number | string | BigNumber): this {
113
105
  if (n instanceof BigNumber) {
114
106
  this.dividend *= n.divisor;
115
107
  this.divisor *= n.dividend;
@@ -122,8 +114,7 @@ export default class BigNumber {
122
114
  }
123
115
 
124
116
  /**
125
- * Converts this number to a regular `number`. Might result in loss of
126
- * precision.
117
+ * Convert this number to a regular `number`. Might result in loss of precision.
127
118
  * @returns This number as a `number`.
128
119
  */
129
120
  public toNumber(): number {
@@ -134,10 +125,10 @@ export default class BigNumber {
134
125
  }
135
126
 
136
127
  /**
137
- * Converts this number to a string.
128
+ * Convert this number to a string.
138
129
  * @returns A string representation of this number.
139
130
  */
140
- public toString(): string {
141
- return `${this.dividend}/${this.divisor}`;
131
+ public toString() {
132
+ return `${this.dividend.toLocaleString()}/${this.divisor.toLocaleString()}`;
142
133
  }
143
134
  }
@@ -1,10 +1,10 @@
1
- /** An error resulting from using a vector that is too small. */
1
+ /** An error resulting from using a vector that is too small or too large. */
2
2
  export default class MagnitudeError extends Error {
3
3
  /**
4
- * Creates an error resulting from using a vector that is too small.
5
- * @param message The message of the error.
4
+ * Create an error resulting from using a vector that is too small or too large.
5
+ * @param message - The message of the error.
6
6
  */
7
- public constructor(message = "The vector is too small.") {
7
+ public constructor(message = "The vector is too small or too large.") {
8
8
  super(message);
9
9
  this.name = "MagnitudeError";
10
10
  }
@@ -1,9 +1,8 @@
1
1
  /** An error resulting from trying to use a matrix that is the wrong size. */
2
2
  export default class PartialMatrixError extends Error {
3
3
  /**
4
- * Creates an error resulting from trying to use a matrix that is the wrong
5
- * size.
6
- * @param message The message of the error.
4
+ * Create an error resulting from trying to use a matrix that is the wrong size.
5
+ * @param message - The message of the error.
7
6
  */
8
7
  public constructor(message = "Invalid matrix dimensions.") {
9
8
  super(message);
@@ -1,9 +1,8 @@
1
1
  /** An error resulting from creating a matrix that isn't a perfect rectangle. */
2
2
  export default class PartialMatrixError extends Error {
3
3
  /**
4
- * Creates an error resulting from creating a matrix that isn't a perfect
5
- * rectangle.
6
- * @param message The message of the error.
4
+ * Create an error resulting from creating a matrix that isn't a perfect rectangle.
5
+ * @param message - The message of the error.
7
6
  */
8
7
  public constructor(message = "The matrix is not rectangular.") {
9
8
  super(message);
@@ -4,8 +4,8 @@
4
4
  */
5
5
  export default class SingularMatrixError extends Error {
6
6
  /**
7
- * Creates an error resulting from trying to invert a singular matrix.
8
- * @param message The message of the error.
7
+ * Create an error resulting from trying to invert a singular matrix.
8
+ * @param message - The message of the error.
9
9
  */
10
10
  public constructor(message = "The matrix cannot be inverted.") {
11
11
  super(message);
@@ -1,5 +1,2 @@
1
- /**
2
- * The largest difference between two numbers for them to be considered
3
- * "roughly" equivalent.
4
- */
1
+ /** The largest difference between two numbers for them to be considered "roughly" equivalent. */
5
2
  export default 0.000001;
@@ -1,2 +0,0 @@
1
- export type IntegerRepresentation = string | number | bigint | boolean;
2
- //# sourceMappingURL=IntegerRepresentation.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"IntegerRepresentation.d.ts","sourceRoot":"","sources":["../../src/types/IntegerRepresentation.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,qBAAqB,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=IntegerRepresentation.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"IntegerRepresentation.js","sourceRoot":"","sources":["../../src/types/IntegerRepresentation.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- /** A value that represents an integer. */
2
- export type IntegerRepresentation = string | number | bigint | boolean;