@fbltd/math 1.0.13 → 1.0.14
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/package.json +7 -5
- package/dist/bin/__tests__/angle.test.js +0 -108
- package/dist/bin/__tests__/matrix.test.js +0 -40
- package/dist/bin/__tests__/utils.test.js +0 -31
- package/dist/types/__tests__/angle.test.d.ts +0 -2
- package/dist/types/__tests__/angle.test.d.ts.map +0 -1
- package/dist/types/__tests__/matrix.test.d.ts +0 -2
- package/dist/types/__tests__/matrix.test.d.ts.map +0 -1
- package/dist/types/__tests__/utils.test.d.ts +0 -2
- package/dist/types/__tests__/utils.test.d.ts.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fbltd/math",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.14",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/bin/index.js",
|
|
6
6
|
"types": "dist/types/index.d.ts",
|
|
@@ -20,9 +20,8 @@
|
|
|
20
20
|
"start": "node_modules/.bin/tsc --watch --noEmit",
|
|
21
21
|
"clean": "rm -r dist || echo ''",
|
|
22
22
|
"build": "node_modules/.bin/tsc",
|
|
23
|
-
"deploy": "npm run clean && npm run build && npm version patch && git push && npm publish && npm run clean",
|
|
24
|
-
"
|
|
25
|
-
"test": "node_modules/.bin/fbltd_test"
|
|
23
|
+
"deploy": "npm run clean && npm run build && npm run test && npm version patch && git push && npm publish && npm run clean",
|
|
24
|
+
"test": "npx tsc __tests__/*.test.ts --outDir __tests__/dist && npx jest && rm -r __tests__/dist"
|
|
26
25
|
},
|
|
27
26
|
"repository": {
|
|
28
27
|
"type": "git",
|
|
@@ -38,6 +37,9 @@
|
|
|
38
37
|
"access": "public"
|
|
39
38
|
},
|
|
40
39
|
"devDependencies": {
|
|
41
|
-
"@
|
|
40
|
+
"@types/jest": "^29.5.13",
|
|
41
|
+
"@types/node": "^22.7.4",
|
|
42
|
+
"jest": "^29.7.0",
|
|
43
|
+
"typescript": "^5.6.2"
|
|
42
44
|
}
|
|
43
45
|
}
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import { Angle, AngleUnits, approximately } from "../src/index.js";
|
|
2
|
-
describe('math.angle.toDeg', () => {
|
|
3
|
-
test('from Turn', () => {
|
|
4
|
-
expect(Angle.toDeg(1, AngleUnits.Turn)).toBe(360);
|
|
5
|
-
expect(Angle.toDeg(0, AngleUnits.Turn)).toBe(0);
|
|
6
|
-
expect(Angle.toDeg(0.5, AngleUnits.Turn)).toBe(180);
|
|
7
|
-
expect(Angle.toDeg(-0.5, AngleUnits.Turn)).toBe(-180);
|
|
8
|
-
});
|
|
9
|
-
test('from Rad', () => {
|
|
10
|
-
expect(Angle.toDeg(Math.PI * 2, AngleUnits.Rad)).toBe(360);
|
|
11
|
-
expect(Angle.toDeg(0, AngleUnits.Rad)).toBe(0);
|
|
12
|
-
expect(Angle.toDeg(Math.PI, AngleUnits.Rad)).toBe(180);
|
|
13
|
-
expect(Angle.toDeg(-Math.PI, AngleUnits.Rad)).toBe(-180);
|
|
14
|
-
});
|
|
15
|
-
test('from Deg', () => {
|
|
16
|
-
expect(Angle.toDeg(180, AngleUnits.Deg)).toBe(180);
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
describe('math.angle.toRad', () => {
|
|
20
|
-
test('from Rad', () => {
|
|
21
|
-
expect(Angle.toRad(1, AngleUnits.Rad)).toBe(1);
|
|
22
|
-
});
|
|
23
|
-
test('from Deg', () => {
|
|
24
|
-
expect(Angle.toRad(360, AngleUnits.Deg)).toBe(Math.PI * 2);
|
|
25
|
-
expect(Angle.toRad(0, AngleUnits.Deg)).toBe(0);
|
|
26
|
-
expect(Angle.toRad(180, AngleUnits.Deg)).toBe(Math.PI);
|
|
27
|
-
expect(Angle.toRad(-180, AngleUnits.Deg)).toBe(-Math.PI);
|
|
28
|
-
});
|
|
29
|
-
test('from Turn', () => {
|
|
30
|
-
expect(Angle.toRad(1, AngleUnits.Turn)).toBe(Math.PI * 2);
|
|
31
|
-
expect(Angle.toRad(0, AngleUnits.Turn)).toBe(0);
|
|
32
|
-
expect(Angle.toRad(0.5, AngleUnits.Turn)).toBe(Math.PI);
|
|
33
|
-
expect(Angle.toRad(-0.5, AngleUnits.Turn)).toBe(-Math.PI);
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
describe('math.angle.toTurn', () => {
|
|
37
|
-
test('from Turn', () => {
|
|
38
|
-
expect(Angle.toTurn(0.1, AngleUnits.Turn)).toBe(0.1);
|
|
39
|
-
});
|
|
40
|
-
test('from Deg', () => {
|
|
41
|
-
expect(Angle.toTurn(360, AngleUnits.Deg)).toBe(1);
|
|
42
|
-
expect(Angle.toTurn(0, AngleUnits.Deg)).toBe(0);
|
|
43
|
-
expect(Angle.toTurn(180, AngleUnits.Deg)).toBe(0.5);
|
|
44
|
-
expect(Angle.toTurn(-180, AngleUnits.Deg)).toBe(-0.5);
|
|
45
|
-
});
|
|
46
|
-
test('from Rad', () => {
|
|
47
|
-
expect(Angle.toTurn(Math.PI * 2, AngleUnits.Rad)).toBe(1);
|
|
48
|
-
expect(Angle.toTurn(0, AngleUnits.Rad)).toBe(0);
|
|
49
|
-
expect(Angle.toTurn(Math.PI, AngleUnits.Rad)).toBe(0.5);
|
|
50
|
-
expect(Angle.toTurn(-Math.PI, AngleUnits.Rad)).toBe(-0.5);
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
describe('math.angle.toPositive', () => {
|
|
54
|
-
test('deg', () => {
|
|
55
|
-
expect(Angle.toPositive(0, AngleUnits.Deg)).toBe(0);
|
|
56
|
-
expect(Angle.toPositive(-0, AngleUnits.Deg)).toBe(0);
|
|
57
|
-
expect(Angle.toPositive(-721, AngleUnits.Deg)).toBe(359);
|
|
58
|
-
expect(Angle.toPositive(361, AngleUnits.Deg)).toBe(361);
|
|
59
|
-
});
|
|
60
|
-
test('rad', () => {
|
|
61
|
-
expect(Angle.toPositive(0, AngleUnits.Rad)).toBe(0);
|
|
62
|
-
expect(Angle.toPositive(-0, AngleUnits.Rad)).toBe(0);
|
|
63
|
-
expect(Angle.toPositive(-Math.PI, AngleUnits.Rad)).toBe(Math.PI);
|
|
64
|
-
expect(Angle.toPositive(-(Math.PI * 3), AngleUnits.Rad)).toBe(Math.PI);
|
|
65
|
-
});
|
|
66
|
-
test('turn', () => {
|
|
67
|
-
expect(Angle.toPositive(0, AngleUnits.Turn)).toBe(0);
|
|
68
|
-
expect(Angle.toPositive(-0, AngleUnits.Turn)).toBe(0);
|
|
69
|
-
expect(approximately(Angle.toPositive(-1.1, AngleUnits.Turn), 0.9)).toBe(true);
|
|
70
|
-
expect(Angle.toPositive(1.1, AngleUnits.Turn)).toBe(1.1);
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
describe('math.angle.normalize', () => {
|
|
74
|
-
test('deg', () => {
|
|
75
|
-
expect(Angle.normalize(0, AngleUnits.Deg)).toBe(0);
|
|
76
|
-
expect(Angle.normalize(-0, AngleUnits.Deg)).toBe(0);
|
|
77
|
-
expect(Angle.normalize(-721, AngleUnits.Deg)).toBe(359);
|
|
78
|
-
expect(Angle.normalize(721, AngleUnits.Deg)).toBe(1);
|
|
79
|
-
expect(Angle.normalize(361, AngleUnits.Deg)).toBe(1);
|
|
80
|
-
expect(Angle.normalize(360, AngleUnits.Deg)).toBe(0);
|
|
81
|
-
expect(Angle.normalize(-360, AngleUnits.Deg)).toBe(0);
|
|
82
|
-
});
|
|
83
|
-
test('rad', () => {
|
|
84
|
-
expect(Angle.normalize(0, AngleUnits.Rad)).toBe(0);
|
|
85
|
-
expect(Angle.normalize(-0, AngleUnits.Rad)).toBe(0);
|
|
86
|
-
expect(Angle.normalize(-(Math.PI * 3), AngleUnits.Rad)).toBe(Math.PI);
|
|
87
|
-
expect(Angle.normalize(Math.PI * 3, AngleUnits.Rad)).toBe(Math.PI);
|
|
88
|
-
expect(approximately(Angle.normalize(Math.PI * 2 + 0.01, AngleUnits.Rad), 0.01)).toBe(true);
|
|
89
|
-
expect(Angle.normalize(Math.PI * 2, AngleUnits.Rad)).toBe(0);
|
|
90
|
-
expect(Angle.normalize(-Math.PI * 2, AngleUnits.Rad)).toBe(0);
|
|
91
|
-
});
|
|
92
|
-
test('turn', () => {
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
describe('math.angle.toCSS', () => {
|
|
96
|
-
expect(Angle.toCSS(1, AngleUnits.Deg)).toEqual('rotate(1deg)');
|
|
97
|
-
expect(Angle.toCSS(1, AngleUnits.Rad)).toEqual('rotate(1rad)');
|
|
98
|
-
expect(Angle.toCSS(1, AngleUnits.Turn)).toEqual('rotate(1turn)');
|
|
99
|
-
expect(Angle.toCSS(-1, AngleUnits.Deg)).toEqual('rotate(-1deg)');
|
|
100
|
-
expect(Angle.toCSS(-1, AngleUnits.Rad)).toEqual('rotate(-1rad)');
|
|
101
|
-
expect(Angle.toCSS(-1, AngleUnits.Turn)).toEqual('rotate(-1turn)');
|
|
102
|
-
expect(Angle.toCSS(NaN, AngleUnits.Deg)).toEqual('');
|
|
103
|
-
expect(Angle.toCSS(Infinity, AngleUnits.Rad)).toEqual('');
|
|
104
|
-
expect(Angle.toCSS(-Infinity, AngleUnits.Turn)).toEqual('');
|
|
105
|
-
expect(Angle.toCSS('1e -08', AngleUnits.Deg)).toEqual('');
|
|
106
|
-
expect(Angle.toCSS(undefined, AngleUnits.Deg)).toEqual('');
|
|
107
|
-
expect(Angle.toCSS(null, AngleUnits.Deg)).toEqual('');
|
|
108
|
-
});
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { approximately, identityMatrix, Matrix2d } from "../index.js";
|
|
2
|
-
describe('Matrix', () => {
|
|
3
|
-
let matrix;
|
|
4
|
-
test('should be the same', () => {
|
|
5
|
-
matrix = identityMatrix;
|
|
6
|
-
matrix = Matrix2d.multiply(matrix, identityMatrix);
|
|
7
|
-
expect(matrix).toEqual(identityMatrix);
|
|
8
|
-
expect(matrix).not.toBe(identityMatrix);
|
|
9
|
-
});
|
|
10
|
-
test('transform', () => {
|
|
11
|
-
matrix = identityMatrix;
|
|
12
|
-
matrix = Matrix2d.translate(matrix, 10);
|
|
13
|
-
expect(matrix).toEqual([1, 0, 0, 1, 10, 0]);
|
|
14
|
-
matrix = Matrix2d.translate(matrix, 10);
|
|
15
|
-
expect(matrix).not.toEqual([1, 0, 0, 1, 10, 0]);
|
|
16
|
-
expect(matrix[4]).toBe(20);
|
|
17
|
-
matrix = Matrix2d.translate(matrix, 0, 1);
|
|
18
|
-
expect(matrix[4]).toBe(20);
|
|
19
|
-
expect(matrix[5]).toBe(1);
|
|
20
|
-
matrix = Matrix2d.scale(matrix, 2);
|
|
21
|
-
expect(matrix[0]).toBe(2);
|
|
22
|
-
expect(matrix[1]).toBe(0);
|
|
23
|
-
expect(matrix[2]).toBe(0);
|
|
24
|
-
expect(matrix[3]).toBe(2);
|
|
25
|
-
expect(matrix[4]).toBe(20);
|
|
26
|
-
expect(matrix[5]).toBe(1);
|
|
27
|
-
matrix = Matrix2d.rotate(matrix, 90);
|
|
28
|
-
expect(approximately(matrix[0], 0)).toBe(true);
|
|
29
|
-
expect(approximately(matrix[1], 2)).toBe(true);
|
|
30
|
-
expect(approximately(matrix[2], -2)).toBe(true);
|
|
31
|
-
expect(approximately(matrix[3], 0)).toBe(true);
|
|
32
|
-
expect(approximately(matrix[4], 20)).toBe(true);
|
|
33
|
-
expect(approximately(matrix[5], 1)).toBe(true);
|
|
34
|
-
matrix = Matrix2d.rotateIdentity(45);
|
|
35
|
-
expect(approximately(matrix[0], matrix[1])).toBe(true);
|
|
36
|
-
expect(approximately(matrix[2], -matrix[3])).toBe(true);
|
|
37
|
-
matrix = Matrix2d.skewIdentity(-45, 0);
|
|
38
|
-
expect(approximately(matrix[3], 1)).toBe(true);
|
|
39
|
-
});
|
|
40
|
-
});
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { approximately, isCorrectNumber, toPositive } from "../src/index.js";
|
|
2
|
-
test('approximately', () => {
|
|
3
|
-
expect(approximately(0, 0)).toBe(true);
|
|
4
|
-
expect(approximately(1 + 1e-8, 1)).toBe(true);
|
|
5
|
-
expect(approximately(-1 - 1e-8, -1)).toBe(true);
|
|
6
|
-
expect(approximately(1 + 1e-8 + 1e-9, 1)).toBe(false);
|
|
7
|
-
expect(approximately(-1 - 1e-8 - 1e-9, -1)).toBe(false);
|
|
8
|
-
expect(approximately(0, 0.1)).toBe(false);
|
|
9
|
-
expect(approximately(0, 0.1, 0.1)).toBe(true);
|
|
10
|
-
});
|
|
11
|
-
test('toPositive', () => {
|
|
12
|
-
expect(toPositive(-1, 360)).toEqual(359);
|
|
13
|
-
expect(toPositive(1, 360)).toEqual(1);
|
|
14
|
-
expect(toPositive(0, 1)).toEqual(0);
|
|
15
|
-
expect(toPositive(-720, 360)).toEqual(0);
|
|
16
|
-
expect(toPositive(-721, 360)).toEqual(359);
|
|
17
|
-
expect(toPositive(-0, 0)).toEqual(0);
|
|
18
|
-
});
|
|
19
|
-
test('isCorrectNumber', () => {
|
|
20
|
-
expect(isCorrectNumber(0)).toBe(true);
|
|
21
|
-
expect(isCorrectNumber('0')).toBe(true);
|
|
22
|
-
expect(isCorrectNumber('0e-08')).toBe(true);
|
|
23
|
-
expect(isCorrectNumber('0e -08')).toBe(false);
|
|
24
|
-
expect(isCorrectNumber({ 1: 2 })).toBe(false);
|
|
25
|
-
expect(isCorrectNumber(null)).toBe(false);
|
|
26
|
-
expect(isCorrectNumber(undefined)).toBe(false);
|
|
27
|
-
expect(isCorrectNumber(Infinity)).toBe(false);
|
|
28
|
-
expect(isCorrectNumber(-Infinity)).toBe(false);
|
|
29
|
-
expect(isCorrectNumber(NaN)).toBe(false);
|
|
30
|
-
expect(isCorrectNumber('')).toBe(false);
|
|
31
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"angle.test.d.ts","sourceRoot":"","sources":["../../../__tests__/angle.test.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"matrix.test.d.ts","sourceRoot":"","sources":["../../../__tests__/matrix.test.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.test.d.ts","sourceRoot":"","sources":["../../../__tests__/utils.test.ts"],"names":[],"mappings":""}
|