@lakuna/umath 0.0.2 → 0.0.4
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/README.md +41 -1
- package/dist/algorithms/combinations.d.ts +2 -0
- package/dist/algorithms/combinations.d.ts.map +1 -0
- package/dist/algorithms/combinations.js +5 -0
- package/dist/algorithms/combinations.js.map +1 -0
- package/dist/algorithms/degreesToRadians.d.ts +2 -0
- package/dist/algorithms/degreesToRadians.d.ts.map +1 -0
- package/dist/algorithms/degreesToRadians.js +4 -0
- package/dist/algorithms/degreesToRadians.js.map +1 -0
- package/dist/algorithms/factorial.d.ts +2 -0
- package/dist/algorithms/factorial.d.ts.map +1 -0
- package/dist/algorithms/factorial.js +4 -0
- package/dist/algorithms/factorial.js.map +1 -0
- package/dist/algorithms/fibonacci.d.ts +2 -0
- package/dist/algorithms/fibonacci.d.ts.map +1 -0
- package/dist/algorithms/fibonacci.js +9 -0
- package/dist/algorithms/fibonacci.js.map +1 -0
- package/dist/algorithms/greatestCommonDivisor.d.ts +3 -0
- package/dist/algorithms/greatestCommonDivisor.d.ts.map +1 -0
- package/dist/algorithms/greatestCommonDivisor.js +13 -0
- package/dist/algorithms/greatestCommonDivisor.js.map +1 -0
- package/dist/algorithms/isPrime.d.ts +2 -0
- package/dist/algorithms/isPrime.d.ts.map +1 -0
- package/dist/algorithms/isPrime.js +12 -0
- package/dist/algorithms/isPrime.js.map +1 -0
- package/dist/algorithms/permutations.d.ts +2 -0
- package/dist/algorithms/permutations.d.ts.map +1 -0
- package/dist/algorithms/permutations.js +5 -0
- package/dist/algorithms/permutations.js.map +1 -0
- package/dist/algorithms/primeFactorization.d.ts +2 -0
- package/dist/algorithms/primeFactorization.d.ts.map +1 -0
- package/dist/algorithms/primeFactorization.js +15 -0
- package/dist/algorithms/primeFactorization.js.map +1 -0
- package/dist/algorithms/radiansToDegrees.d.ts +2 -0
- package/dist/algorithms/radiansToDegrees.d.ts.map +1 -0
- package/dist/algorithms/radiansToDegrees.js +4 -0
- package/dist/algorithms/radiansToDegrees.js.map +1 -0
- package/dist/algorithms/summation.d.ts +2 -0
- package/dist/algorithms/summation.d.ts.map +1 -0
- package/dist/algorithms/summation.js +7 -0
- package/dist/algorithms/summation.js.map +1 -0
- package/dist/index.d.ts +28 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -1
- package/dist/index.js.map +1 -1
- package/dist/linear/DualQuaternion.d.ts +89 -0
- package/dist/linear/DualQuaternion.d.ts.map +1 -0
- package/dist/linear/DualQuaternion.js +530 -0
- package/dist/linear/DualQuaternion.js.map +1 -0
- package/dist/linear/Matrix.d.ts +18 -0
- package/dist/linear/Matrix.d.ts.map +1 -0
- package/dist/linear/Matrix.js +2 -0
- package/dist/linear/Matrix.js.map +1 -0
- package/dist/linear/Matrix2.d.ts +66 -0
- package/dist/linear/Matrix2.d.ts.map +1 -0
- package/dist/linear/Matrix2.js +240 -0
- package/dist/linear/Matrix2.js.map +1 -0
- package/dist/linear/Matrix3.d.ts +91 -0
- package/dist/linear/Matrix3.d.ts.map +1 -0
- package/dist/linear/Matrix3.js +533 -0
- package/dist/linear/Matrix3.js.map +1 -0
- package/dist/linear/Matrix4.d.ts +140 -0
- package/dist/linear/Matrix4.d.ts.map +1 -0
- package/dist/linear/Matrix4.js +1363 -0
- package/dist/linear/Matrix4.js.map +1 -0
- package/dist/linear/Quaternion.d.ts +80 -0
- package/dist/linear/Quaternion.d.ts.map +1 -0
- package/dist/linear/Quaternion.js +371 -0
- package/dist/linear/Quaternion.js.map +1 -0
- package/dist/linear/SquareMatrix.d.ts +7 -0
- package/dist/linear/SquareMatrix.d.ts.map +1 -0
- package/dist/linear/SquareMatrix.js +2 -0
- package/dist/linear/SquareMatrix.js.map +1 -0
- package/dist/linear/Vector.d.ts +30 -0
- package/dist/linear/Vector.d.ts.map +1 -0
- package/dist/linear/Vector.js +2 -0
- package/dist/linear/Vector.js.map +1 -0
- package/dist/linear/Vector2.d.ts +96 -0
- package/dist/linear/Vector2.d.ts.map +1 -0
- package/dist/linear/Vector2.js +293 -0
- package/dist/linear/Vector2.js.map +1 -0
- package/dist/linear/Vector3.d.ts +111 -0
- package/dist/linear/Vector3.d.ts.map +1 -0
- package/dist/linear/Vector3.js +466 -0
- package/dist/linear/Vector3.js.map +1 -0
- package/dist/linear/Vector4.d.ts +86 -0
- package/dist/linear/Vector4.d.ts.map +1 -0
- package/dist/linear/Vector4.js +348 -0
- package/dist/linear/Vector4.js.map +1 -0
- package/dist/types/AxisAngle.d.ts +6 -0
- package/dist/types/AxisAngle.d.ts.map +1 -0
- package/dist/types/AxisAngle.js +2 -0
- package/dist/types/AxisAngle.js.map +1 -0
- package/dist/types/FieldOfView.d.ts +7 -0
- package/dist/types/FieldOfView.d.ts.map +1 -0
- package/dist/types/FieldOfView.js +2 -0
- package/dist/types/FieldOfView.js.map +1 -0
- package/dist/types/IntegerRepresentation.d.ts +2 -0
- package/dist/types/IntegerRepresentation.d.ts.map +1 -0
- package/dist/types/IntegerRepresentation.js +2 -0
- package/dist/types/IntegerRepresentation.js.map +1 -0
- package/dist/utility/BigNumber.d.ts +15 -0
- package/dist/utility/BigNumber.d.ts.map +1 -0
- package/dist/utility/BigNumber.js +75 -0
- package/dist/utility/BigNumber.js.map +1 -0
- package/dist/utility/MagnitudeError.d.ts +4 -0
- package/dist/utility/MagnitudeError.d.ts.map +1 -0
- package/dist/utility/MagnitudeError.js +6 -0
- package/dist/utility/MagnitudeError.js.map +1 -0
- package/dist/utility/SingularMatrixError.d.ts +4 -0
- package/dist/utility/SingularMatrixError.d.ts.map +1 -0
- package/dist/utility/SingularMatrixError.js +6 -0
- package/dist/utility/SingularMatrixError.js.map +1 -0
- package/dist/utility/epsilon.d.ts +3 -0
- package/dist/utility/epsilon.d.ts.map +1 -0
- package/dist/utility/epsilon.js +2 -0
- package/dist/utility/epsilon.js.map +1 -0
- package/package.json +17 -9
- package/src/algorithms/combinations.ts +12 -0
- package/src/algorithms/degreesToRadians.ts +10 -0
- package/src/algorithms/factorial.ts +9 -0
- package/src/algorithms/fibonacci.ts +14 -0
- package/src/algorithms/greatestCommonDivisor.ts +30 -0
- package/src/algorithms/isPrime.ts +20 -0
- package/src/algorithms/permutations.ts +12 -0
- package/src/algorithms/primeFactorization.ts +21 -0
- package/src/algorithms/radiansToDegrees.ts +10 -0
- package/src/algorithms/summation.ts +23 -0
- package/src/index.ts +28 -1
- package/src/linear/DualQuaternion.ts +1213 -0
- package/src/linear/Matrix.ts +106 -0
- package/src/linear/Matrix2.ts +709 -0
- package/src/linear/Matrix3.ts +1194 -0
- package/src/linear/Matrix4.ts +2569 -0
- package/src/linear/Quaternion.ts +967 -0
- package/src/linear/SquareMatrix.ts +27 -0
- package/src/linear/Vector.ts +178 -0
- package/src/linear/Vector2.ts +979 -0
- package/src/linear/Vector3.ts +1320 -0
- package/src/linear/Vector4.ts +975 -0
- package/src/types/AxisAngle.ts +10 -0
- package/src/types/FieldOfView.ts +14 -0
- package/src/types/IntegerRepresentation.ts +2 -0
- package/src/utility/BigNumber.ts +130 -0
- package/src/utility/MagnitudeError.ts +10 -0
- package/src/utility/SingularMatrixError.ts +13 -0
- package/src/utility/epsilon.ts +2 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a given number of degrees to an equivalent number of radians.
|
|
3
|
+
* @param degrees The number of degrees.
|
|
4
|
+
* @returns An equivalent number of radians.
|
|
5
|
+
* @see [Degree](https://en.wikipedia.org/wiki/Degree_(angle))
|
|
6
|
+
* @see [Radian](https://en.wikipedia.org/wiki/Radian)
|
|
7
|
+
*/
|
|
8
|
+
export default function degreesToRadians(degrees: number): number {
|
|
9
|
+
return degrees * Math.PI / 180;
|
|
10
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the factorial of the given number.
|
|
3
|
+
* @param n The number.
|
|
4
|
+
* @returns The factorial of the number.
|
|
5
|
+
* @see [Factorial](https://en.wikipedia.org/wiki/Factorial)
|
|
6
|
+
*/
|
|
7
|
+
export default function factorial(n: number): number {
|
|
8
|
+
return n == 0 ? 1 : n * factorial(n - 1);
|
|
9
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A generator function that returns numbers in the Fibonacci sequence.
|
|
3
|
+
* @returns The next value in the Fibonacci sequence.
|
|
4
|
+
* @see [Fibonacci sequence](https://en.wikipedia.org/wiki/Fibonacci_sequence)
|
|
5
|
+
*/
|
|
6
|
+
export default function* fibonacci(): Generator<number> {
|
|
7
|
+
let a = 0;
|
|
8
|
+
let b = 1;
|
|
9
|
+
|
|
10
|
+
while (true) {
|
|
11
|
+
yield a;
|
|
12
|
+
[a, b] = [b, a + b];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Determines the greatest common divisor of two integers.
|
|
3
|
+
* @param a The first integer.
|
|
4
|
+
* @param b The second integer.
|
|
5
|
+
* @returns The greatest common divisor of the integers.
|
|
6
|
+
* @see [Greatest common divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor)
|
|
7
|
+
*/
|
|
8
|
+
export default function greatestCommonDivisor(a: bigint, b: bigint): bigint;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Determines the greatest common divisor of two integers.
|
|
12
|
+
* @param a The first integer.
|
|
13
|
+
* @param b The second integer.
|
|
14
|
+
* @returns The greatest common divisor of the integers.
|
|
15
|
+
* @see [Greatest common divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor)
|
|
16
|
+
*/
|
|
17
|
+
export default function greatestCommonDivisor(a: number, b: number): number;
|
|
18
|
+
|
|
19
|
+
export default function greatestCommonDivisor(a: bigint | number, b: bigint | number): bigint | number {
|
|
20
|
+
// Ensure that all of the integers are positive.
|
|
21
|
+
if (a < 0) { a = -a; }
|
|
22
|
+
if (b < 0) { b = -b; }
|
|
23
|
+
|
|
24
|
+
// Apply the Euclidean algorithm.
|
|
25
|
+
while (b) {
|
|
26
|
+
[a, b] = [b, (a as number) % (b as number)];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return a;
|
|
30
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns whether the given number is prime.
|
|
3
|
+
* @param n The given number.
|
|
4
|
+
* @returns Whether the given number is prime.
|
|
5
|
+
* @see [Prime number](https://en.wikipedia.org/wiki/Prime_number)
|
|
6
|
+
*/
|
|
7
|
+
export default function isPrime(n: number): boolean {
|
|
8
|
+
// Negatives, zero, and one can't be prime.
|
|
9
|
+
if (n < 2) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
for (let i = 2; i * i <= n; i++) {
|
|
14
|
+
if (n % i == 0) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { factorial } from "@lakuna/umath";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Calculates the number of permutations.
|
|
5
|
+
* @param n The total number of units.
|
|
6
|
+
* @param r The number of units taken at a time.
|
|
7
|
+
* @returns The number of permutations.
|
|
8
|
+
* @see [Permutation](https://en.wikipedia.org/wiki/Permutation)
|
|
9
|
+
*/
|
|
10
|
+
export default function permutations(n: number, r: number): number {
|
|
11
|
+
return factorial(n) / factorial(n - r);
|
|
12
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Factors the given number into a list of prime numbers.
|
|
3
|
+
* @param n The number to factor.
|
|
4
|
+
* @returns A list of prime number factors of the given number.
|
|
5
|
+
* @see [Integer factorization](https://en.wikipedia.org/wiki/Integer_factorization)
|
|
6
|
+
*/
|
|
7
|
+
export default function primeFactorization(n: number): Array<number> {
|
|
8
|
+
const out: Array<number> = [];
|
|
9
|
+
|
|
10
|
+
let divisor = 2;
|
|
11
|
+
while (n >= 2) {
|
|
12
|
+
if (n % divisor == 0) {
|
|
13
|
+
out.push(divisor);
|
|
14
|
+
n /= divisor;
|
|
15
|
+
} else {
|
|
16
|
+
divisor++;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return out;
|
|
21
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a given number of radians to an equivalent number of degrees.
|
|
3
|
+
* @param radians The number of radians.
|
|
4
|
+
* @returns An equivalent number of degrees.
|
|
5
|
+
* @see [Degree](https://en.wikipedia.org/wiki/Degree_(angle))
|
|
6
|
+
* @see [Radian](https://en.wikipedia.org/wiki/Radian)
|
|
7
|
+
*/
|
|
8
|
+
export default function radiansToDegrees(radians: number): number {
|
|
9
|
+
return radians * 180 / Math.PI;
|
|
10
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recursively sums up the results of the given function.
|
|
3
|
+
* @param i The index of summation.
|
|
4
|
+
* @param max The upper bound of the index of summation.
|
|
5
|
+
* @param term The function used to generate each term.
|
|
6
|
+
* @returns The sum.
|
|
7
|
+
* @see [Summation](https://en.wikipedia.org/wiki/Summation)
|
|
8
|
+
*/
|
|
9
|
+
function summationInternal(i: number, max: number, term: (i: number) => number): number {
|
|
10
|
+
return term(i) + (i < max ? summationInternal(i + 1, max, term) : 0);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Performs a summation.
|
|
15
|
+
* @param min The lower bound (inclusive) of the index of summation.
|
|
16
|
+
* @param max The upper bound (inclusive) of the index of summation.
|
|
17
|
+
* @param term The function used to generate each term.
|
|
18
|
+
* @returns The sum.
|
|
19
|
+
* @see [Summation](https://en.wikipedia.org/wiki/Summation)
|
|
20
|
+
*/
|
|
21
|
+
export default function summation(min: number, max: number, term: (i: number) => number): number {
|
|
22
|
+
return summationInternal(min, max, term);
|
|
23
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1 +1,28 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { default as combinations } from "./algorithms/combinations.js";
|
|
2
|
+
export { default as degreesToRadians } from "./algorithms/degreesToRadians.js";
|
|
3
|
+
export { default as factorial } from "./algorithms/factorial.js";
|
|
4
|
+
export { default as fibonacci } from "./algorithms/fibonacci.js";
|
|
5
|
+
export { default as greatestCommonDivisor } from "./algorithms/greatestCommonDivisor.js";
|
|
6
|
+
export { default as isPrime } from "./algorithms/isPrime.js";
|
|
7
|
+
export { default as permutations } from "./algorithms/permutations.js";
|
|
8
|
+
export { default as primeFactorization } from "./algorithms/primeFactorization.js";
|
|
9
|
+
export { default as radiansToDegrees } from "./algorithms/radiansToDegrees.js";
|
|
10
|
+
export { default as summation } from "./algorithms/summation.js";
|
|
11
|
+
export { type DualQuaternionLike, default as DualQuaternion } from "@lakuna/umath/DualQuaternion";
|
|
12
|
+
export type { MatrixLike, default as Matrix } from "./linear/Matrix.js";
|
|
13
|
+
export { type Matrix2Like, default as Matrix2 } from "@lakuna/umath/Matrix2";
|
|
14
|
+
export { type Matrix3Like, default as Matrix3 } from "@lakuna/umath/Matrix3";
|
|
15
|
+
export { type Matrix4Like, default as Matrix4 } from "@lakuna/umath/Matrix4";
|
|
16
|
+
export { type QuaternionLike, default as Quaternion } from "@lakuna/umath/Quaternion";
|
|
17
|
+
export type { default as SquareMatrix } from "./linear/SquareMatrix.js";
|
|
18
|
+
export type { VectorLike, default as Vector } from "./linear/Vector.js";
|
|
19
|
+
export { type Vector2Like, default as Vector2 } from "@lakuna/umath/Vector2";
|
|
20
|
+
export { type Vector3Like, default as Vector3 } from "@lakuna/umath/Vector3";
|
|
21
|
+
export { type Vector4Like, default as Vector4 } from "@lakuna/umath/Vector4";
|
|
22
|
+
export type { default as AxisAngle } from "./types/AxisAngle.js";
|
|
23
|
+
export type { default as FieldOfView } from "./types/FieldOfView.js";
|
|
24
|
+
export type { IntegerRepresentation } from "./types/IntegerRepresentation.js";
|
|
25
|
+
export { default as BigNumber } from "./utility/BigNumber.js";
|
|
26
|
+
export { default as epsilon } from "./utility/epsilon.js";
|
|
27
|
+
export { default as MagnitudeError } from "./utility/MagnitudeError.js";
|
|
28
|
+
export { default as SingularMatrixError } from "./utility/SingularMatrixError.js";
|