@fbltd/math 1.0.9 → 1.0.11
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/bin/__tests__/angle.test.js +66 -68
- package/dist/bin/__tests__/matrix.test.js +22 -24
- package/dist/bin/__tests__/utils.test.js +25 -27
- package/dist/bin/index.js +1 -17
- package/dist/bin/src/angle.js +8 -12
- package/dist/bin/src/colors/color.js +1 -5
- package/dist/bin/src/colors/conic.gradient.js +3 -7
- package/dist/bin/src/colors/index.js +2 -18
- package/dist/bin/src/figures/circle.js +3 -7
- package/dist/bin/src/figures/index.js +3 -19
- package/dist/bin/src/figures/point.js +1 -5
- package/dist/bin/src/figures/straight-line.js +3 -7
- package/dist/bin/src/index.js +6 -22
- package/dist/bin/src/matrix.js +13 -18
- package/dist/bin/src/operator.js +1 -5
- package/dist/bin/src/utils.js +3 -8
- package/package.json +3 -3
|
@@ -1,110 +1,108 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const src_1 = require("../src");
|
|
1
|
+
import { Angle, AngleUnits, approximately } from "../src";
|
|
4
2
|
describe('math.angle.toDeg', () => {
|
|
5
3
|
test('from Turn', () => {
|
|
6
|
-
expect(
|
|
7
|
-
expect(
|
|
8
|
-
expect(
|
|
9
|
-
expect(
|
|
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);
|
|
10
8
|
});
|
|
11
9
|
test('from Rad', () => {
|
|
12
|
-
expect(
|
|
13
|
-
expect(
|
|
14
|
-
expect(
|
|
15
|
-
expect(
|
|
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);
|
|
16
14
|
});
|
|
17
15
|
test('from Deg', () => {
|
|
18
|
-
expect(
|
|
16
|
+
expect(Angle.toDeg(180, AngleUnits.Deg)).toBe(180);
|
|
19
17
|
});
|
|
20
18
|
});
|
|
21
19
|
describe('math.angle.toRad', () => {
|
|
22
20
|
test('from Rad', () => {
|
|
23
|
-
expect(
|
|
21
|
+
expect(Angle.toRad(1, AngleUnits.Rad)).toBe(1);
|
|
24
22
|
});
|
|
25
23
|
test('from Deg', () => {
|
|
26
|
-
expect(
|
|
27
|
-
expect(
|
|
28
|
-
expect(
|
|
29
|
-
expect(
|
|
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);
|
|
30
28
|
});
|
|
31
29
|
test('from Turn', () => {
|
|
32
|
-
expect(
|
|
33
|
-
expect(
|
|
34
|
-
expect(
|
|
35
|
-
expect(
|
|
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);
|
|
36
34
|
});
|
|
37
35
|
});
|
|
38
36
|
describe('math.angle.toTurn', () => {
|
|
39
37
|
test('from Turn', () => {
|
|
40
|
-
expect(
|
|
38
|
+
expect(Angle.toTurn(0.1, AngleUnits.Turn)).toBe(0.1);
|
|
41
39
|
});
|
|
42
40
|
test('from Deg', () => {
|
|
43
|
-
expect(
|
|
44
|
-
expect(
|
|
45
|
-
expect(
|
|
46
|
-
expect(
|
|
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);
|
|
47
45
|
});
|
|
48
46
|
test('from Rad', () => {
|
|
49
|
-
expect(
|
|
50
|
-
expect(
|
|
51
|
-
expect(
|
|
52
|
-
expect(
|
|
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);
|
|
53
51
|
});
|
|
54
52
|
});
|
|
55
53
|
describe('math.angle.toPositive', () => {
|
|
56
54
|
test('deg', () => {
|
|
57
|
-
expect(
|
|
58
|
-
expect(
|
|
59
|
-
expect(
|
|
60
|
-
expect(
|
|
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);
|
|
61
59
|
});
|
|
62
60
|
test('rad', () => {
|
|
63
|
-
expect(
|
|
64
|
-
expect(
|
|
65
|
-
expect(
|
|
66
|
-
expect(
|
|
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);
|
|
67
65
|
});
|
|
68
66
|
test('turn', () => {
|
|
69
|
-
expect(
|
|
70
|
-
expect(
|
|
71
|
-
expect(
|
|
72
|
-
expect(
|
|
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);
|
|
73
71
|
});
|
|
74
72
|
});
|
|
75
73
|
describe('math.angle.normalize', () => {
|
|
76
74
|
test('deg', () => {
|
|
77
|
-
expect(
|
|
78
|
-
expect(
|
|
79
|
-
expect(
|
|
80
|
-
expect(
|
|
81
|
-
expect(
|
|
82
|
-
expect(
|
|
83
|
-
expect(
|
|
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);
|
|
84
82
|
});
|
|
85
83
|
test('rad', () => {
|
|
86
|
-
expect(
|
|
87
|
-
expect(
|
|
88
|
-
expect(
|
|
89
|
-
expect(
|
|
90
|
-
expect(
|
|
91
|
-
expect(
|
|
92
|
-
expect(
|
|
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);
|
|
93
91
|
});
|
|
94
92
|
test('turn', () => {
|
|
95
93
|
});
|
|
96
94
|
});
|
|
97
95
|
describe('math.angle.toCSS', () => {
|
|
98
|
-
expect(
|
|
99
|
-
expect(
|
|
100
|
-
expect(
|
|
101
|
-
expect(
|
|
102
|
-
expect(
|
|
103
|
-
expect(
|
|
104
|
-
expect(
|
|
105
|
-
expect(
|
|
106
|
-
expect(
|
|
107
|
-
expect(
|
|
108
|
-
expect(
|
|
109
|
-
expect(
|
|
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('');
|
|
110
108
|
});
|
|
@@ -1,42 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const src_1 = require("../src");
|
|
1
|
+
import { approximately, identityMatrix, Matrix2d } from "../src";
|
|
4
2
|
describe('Matrix', () => {
|
|
5
3
|
let matrix;
|
|
6
4
|
test('should be the same', () => {
|
|
7
|
-
matrix =
|
|
8
|
-
matrix =
|
|
9
|
-
expect(matrix).toEqual(
|
|
10
|
-
expect(matrix).not.toBe(
|
|
5
|
+
matrix = identityMatrix;
|
|
6
|
+
matrix = Matrix2d.multiply(matrix, identityMatrix);
|
|
7
|
+
expect(matrix).toEqual(identityMatrix);
|
|
8
|
+
expect(matrix).not.toBe(identityMatrix);
|
|
11
9
|
});
|
|
12
10
|
test('transform', () => {
|
|
13
|
-
matrix =
|
|
14
|
-
matrix =
|
|
11
|
+
matrix = identityMatrix;
|
|
12
|
+
matrix = Matrix2d.translate(matrix, 10);
|
|
15
13
|
expect(matrix).toEqual([1, 0, 0, 1, 10, 0]);
|
|
16
|
-
matrix =
|
|
14
|
+
matrix = Matrix2d.translate(matrix, 10);
|
|
17
15
|
expect(matrix).not.toEqual([1, 0, 0, 1, 10, 0]);
|
|
18
16
|
expect(matrix[4]).toBe(20);
|
|
19
|
-
matrix =
|
|
17
|
+
matrix = Matrix2d.translate(matrix, 0, 1);
|
|
20
18
|
expect(matrix[4]).toBe(20);
|
|
21
19
|
expect(matrix[5]).toBe(1);
|
|
22
|
-
matrix =
|
|
20
|
+
matrix = Matrix2d.scale(matrix, 2);
|
|
23
21
|
expect(matrix[0]).toBe(2);
|
|
24
22
|
expect(matrix[1]).toBe(0);
|
|
25
23
|
expect(matrix[2]).toBe(0);
|
|
26
24
|
expect(matrix[3]).toBe(2);
|
|
27
25
|
expect(matrix[4]).toBe(20);
|
|
28
26
|
expect(matrix[5]).toBe(1);
|
|
29
|
-
matrix =
|
|
30
|
-
expect(
|
|
31
|
-
expect(
|
|
32
|
-
expect(
|
|
33
|
-
expect(
|
|
34
|
-
expect(
|
|
35
|
-
expect(
|
|
36
|
-
matrix =
|
|
37
|
-
expect(
|
|
38
|
-
expect(
|
|
39
|
-
matrix =
|
|
40
|
-
expect(
|
|
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);
|
|
41
39
|
});
|
|
42
40
|
});
|
|
@@ -1,33 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const src_1 = require("../src");
|
|
1
|
+
import { approximately, isCorrectNumber, toPositive } from "../src";
|
|
4
2
|
test('approximately', () => {
|
|
5
|
-
expect(
|
|
6
|
-
expect(
|
|
7
|
-
expect(
|
|
8
|
-
expect(
|
|
9
|
-
expect(
|
|
10
|
-
expect(
|
|
11
|
-
expect(
|
|
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);
|
|
12
10
|
});
|
|
13
11
|
test('toPositive', () => {
|
|
14
|
-
expect(
|
|
15
|
-
expect(
|
|
16
|
-
expect(
|
|
17
|
-
expect(
|
|
18
|
-
expect(
|
|
19
|
-
expect(
|
|
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);
|
|
20
18
|
});
|
|
21
19
|
test('isCorrectNumber', () => {
|
|
22
|
-
expect(
|
|
23
|
-
expect(
|
|
24
|
-
expect(
|
|
25
|
-
expect(
|
|
26
|
-
expect(
|
|
27
|
-
expect(
|
|
28
|
-
expect(
|
|
29
|
-
expect(
|
|
30
|
-
expect(
|
|
31
|
-
expect(
|
|
32
|
-
expect(
|
|
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);
|
|
33
31
|
});
|
package/dist/bin/index.js
CHANGED
|
@@ -1,17 +1 @@
|
|
|
1
|
-
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./src"), exports);
|
|
1
|
+
export * from './src';
|
package/dist/bin/src/angle.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.Angle = exports.AngleUnits = void 0;
|
|
4
|
-
const utils_1 = require("./utils");
|
|
5
|
-
var AngleUnits;
|
|
1
|
+
import { isCorrectNumber, toPositive } from "./utils";
|
|
2
|
+
export var AngleUnits;
|
|
6
3
|
(function (AngleUnits) {
|
|
7
4
|
AngleUnits[AngleUnits["Deg"] = 0] = "Deg";
|
|
8
5
|
AngleUnits[AngleUnits["Rad"] = 1] = "Rad";
|
|
9
6
|
AngleUnits[AngleUnits["Turn"] = 2] = "Turn";
|
|
10
|
-
})(AngleUnits || (
|
|
11
|
-
class Angle {
|
|
7
|
+
})(AngleUnits || (AngleUnits = {}));
|
|
8
|
+
export class Angle {
|
|
12
9
|
static toRad(angle, unit = AngleUnits.Deg) {
|
|
13
10
|
switch (unit) {
|
|
14
11
|
case AngleUnits.Rad:
|
|
@@ -42,11 +39,11 @@ class Angle {
|
|
|
42
39
|
static toPositive(angle, unit) {
|
|
43
40
|
switch (unit) {
|
|
44
41
|
case AngleUnits.Deg:
|
|
45
|
-
return
|
|
42
|
+
return toPositive(angle, 360);
|
|
46
43
|
case AngleUnits.Turn:
|
|
47
|
-
return
|
|
44
|
+
return toPositive(angle, 1);
|
|
48
45
|
case AngleUnits.Rad:
|
|
49
|
-
return
|
|
46
|
+
return toPositive(angle, Math.PI * 2);
|
|
50
47
|
}
|
|
51
48
|
}
|
|
52
49
|
static normalize(angle, unit) {
|
|
@@ -60,7 +57,7 @@ class Angle {
|
|
|
60
57
|
}
|
|
61
58
|
}
|
|
62
59
|
static toCSS(angle, unit) {
|
|
63
|
-
if (!
|
|
60
|
+
if (!isCorrectNumber(angle))
|
|
64
61
|
return '';
|
|
65
62
|
return `rotate(${angle}${Angle.angleUnitCorrespondence[unit]})`;
|
|
66
63
|
}
|
|
@@ -70,4 +67,3 @@ class Angle {
|
|
|
70
67
|
[AngleUnits.Deg]: 'deg',
|
|
71
68
|
};
|
|
72
69
|
}
|
|
73
|
-
exports.Angle = Angle;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Color = void 0;
|
|
4
|
-
class Color {
|
|
1
|
+
export class Color {
|
|
5
2
|
red;
|
|
6
3
|
green;
|
|
7
4
|
blue;
|
|
@@ -17,4 +14,3 @@ class Color {
|
|
|
17
14
|
return `rgb(${this.red}, ${this.green}, ${this.blue})`;
|
|
18
15
|
}
|
|
19
16
|
}
|
|
20
|
-
exports.Color = Color;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.ConicGradient = void 0;
|
|
4
|
-
const color_1 = require("./color");
|
|
5
|
-
class ConicGradient {
|
|
1
|
+
import { Color } from "./color";
|
|
2
|
+
export class ConicGradient {
|
|
6
3
|
colors;
|
|
7
4
|
constructor(...colors) {
|
|
8
5
|
this.colors = [...colors].sort((a, b) => a.angle - b.angle);
|
|
@@ -27,7 +24,7 @@ class ConicGradient {
|
|
|
27
24
|
if (!prev || !next)
|
|
28
25
|
return undefined;
|
|
29
26
|
const coef = (angle - prev.angle) / (next.angle - prev.angle);
|
|
30
|
-
return new
|
|
27
|
+
return new Color(Math.floor((next.color.red - prev.color.red) * coef + prev.color.red), Math.floor((next.color.green - prev.color.green) * coef + prev.color.green), Math.floor((next.color.blue - prev.color.blue) * coef + prev.color.blue));
|
|
31
28
|
}
|
|
32
29
|
getAngleByColor(color) {
|
|
33
30
|
let prev;
|
|
@@ -78,4 +75,3 @@ class ConicGradient {
|
|
|
78
75
|
return s;
|
|
79
76
|
}
|
|
80
77
|
}
|
|
81
|
-
exports.ConicGradient = ConicGradient;
|
|
@@ -1,18 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./color"), exports);
|
|
18
|
-
__exportStar(require("./conic.gradient"), exports);
|
|
1
|
+
export * from './color';
|
|
2
|
+
export * from './conic.gradient';
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.Circle = void 0;
|
|
4
|
-
const matrix_1 = require("../matrix");
|
|
5
|
-
class Circle {
|
|
1
|
+
import { Matrix2d } from "../matrix";
|
|
2
|
+
export class Circle {
|
|
6
3
|
center;
|
|
7
4
|
r;
|
|
8
5
|
constructor(center, r) {
|
|
@@ -10,7 +7,6 @@ class Circle {
|
|
|
10
7
|
this.r = r;
|
|
11
8
|
}
|
|
12
9
|
transform(matrix) {
|
|
13
|
-
this.center =
|
|
10
|
+
this.center = Matrix2d.apply(matrix, this.center);
|
|
14
11
|
}
|
|
15
12
|
}
|
|
16
|
-
exports.Circle = Circle;
|
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./point"), exports);
|
|
18
|
-
__exportStar(require("./circle"), exports);
|
|
19
|
-
__exportStar(require("./straight-line"), exports);
|
|
1
|
+
export * from './point';
|
|
2
|
+
export * from './circle';
|
|
3
|
+
export * from './straight-line';
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Point2 = void 0;
|
|
4
|
-
class Point2 {
|
|
1
|
+
export class Point2 {
|
|
5
2
|
static sum(p1, p2) {
|
|
6
3
|
return [
|
|
7
4
|
p1[0] + p2[0],
|
|
@@ -15,4 +12,3 @@ class Point2 {
|
|
|
15
12
|
];
|
|
16
13
|
}
|
|
17
14
|
}
|
|
18
|
-
exports.Point2 = Point2;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.StraightLine = void 0;
|
|
4
|
-
const matrix_1 = require("../matrix");
|
|
5
|
-
class StraightLine {
|
|
1
|
+
import { Matrix2d } from "../matrix";
|
|
2
|
+
export class StraightLine {
|
|
6
3
|
p1;
|
|
7
4
|
p2;
|
|
8
5
|
constructor(p1, p2) {
|
|
@@ -13,7 +10,6 @@ class StraightLine {
|
|
|
13
10
|
if (transformThis) {
|
|
14
11
|
return this;
|
|
15
12
|
}
|
|
16
|
-
return new StraightLine(
|
|
13
|
+
return new StraightLine(Matrix2d.apply(matrix, this.p1), Matrix2d.apply(matrix, this.p2));
|
|
17
14
|
}
|
|
18
15
|
}
|
|
19
|
-
exports.StraightLine = StraightLine;
|
package/dist/bin/src/index.js
CHANGED
|
@@ -1,22 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./angle"), exports);
|
|
18
|
-
__exportStar(require("./matrix"), exports);
|
|
19
|
-
__exportStar(require("./operator"), exports);
|
|
20
|
-
__exportStar(require("./utils"), exports);
|
|
21
|
-
__exportStar(require("./colors"), exports);
|
|
22
|
-
__exportStar(require("./figures"), exports);
|
|
1
|
+
export * from './angle';
|
|
2
|
+
export * from './matrix';
|
|
3
|
+
export * from './operator';
|
|
4
|
+
export * from './utils';
|
|
5
|
+
export * from './colors';
|
|
6
|
+
export * from './figures';
|
package/dist/bin/src/matrix.js
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
exports.getIdentityMatrix = getIdentityMatrix;
|
|
5
|
-
const angle_1 = require("./angle");
|
|
6
|
-
exports.identityMatrix = [1, 0, 0, 1, 0, 0];
|
|
7
|
-
function getIdentityMatrix() {
|
|
1
|
+
import { Angle, AngleUnits } from "./angle";
|
|
2
|
+
export const identityMatrix = [1, 0, 0, 1, 0, 0];
|
|
3
|
+
export function getIdentityMatrix() {
|
|
8
4
|
return [1, 0, 0, 1, 0, 0];
|
|
9
5
|
}
|
|
10
|
-
class Matrix2d {
|
|
6
|
+
export class Matrix2d {
|
|
11
7
|
static multiply(matrix, ...matrices) {
|
|
12
8
|
for (let m of matrices) {
|
|
13
9
|
matrix = [
|
|
@@ -33,13 +29,13 @@ class Matrix2d {
|
|
|
33
29
|
static scale(m, x, y = x) {
|
|
34
30
|
return Matrix2d.multiply(m, Matrix2d.scaleIdentity(x, y));
|
|
35
31
|
}
|
|
36
|
-
static rotateIdentity(angle, units =
|
|
37
|
-
angle =
|
|
32
|
+
static rotateIdentity(angle, units = AngleUnits.Deg) {
|
|
33
|
+
angle = Angle.toRad(angle, units);
|
|
38
34
|
const cos = Math.cos(angle);
|
|
39
35
|
const sin = Math.sin(angle);
|
|
40
36
|
return [cos, sin, -sin, cos, 0, 0];
|
|
41
37
|
}
|
|
42
|
-
static rotate(m, angle, units =
|
|
38
|
+
static rotate(m, angle, units = AngleUnits.Deg) {
|
|
43
39
|
return Matrix2d.multiply(m, Matrix2d.rotateIdentity(angle, units));
|
|
44
40
|
}
|
|
45
41
|
static translateIdentity(x, y = 0) {
|
|
@@ -54,21 +50,20 @@ class Matrix2d {
|
|
|
54
50
|
static translateY(m, y) {
|
|
55
51
|
return Matrix2d.multiply(m, this.translateIdentity(0, y));
|
|
56
52
|
}
|
|
57
|
-
static skewIdentity(x, y, units =
|
|
58
|
-
x =
|
|
59
|
-
y =
|
|
53
|
+
static skewIdentity(x, y, units = AngleUnits.Deg) {
|
|
54
|
+
x = Angle.toRad(x, units);
|
|
55
|
+
y = Angle.toRad(y, units);
|
|
60
56
|
x = Math.tan(x);
|
|
61
57
|
y = Math.tan(y);
|
|
62
58
|
return [1, y, x, 1, 0, 0];
|
|
63
59
|
}
|
|
64
|
-
static skewX(m, x, units =
|
|
60
|
+
static skewX(m, x, units = AngleUnits.Deg) {
|
|
65
61
|
return Matrix2d.multiply(m, Matrix2d.skewIdentity(x, 0, units));
|
|
66
62
|
}
|
|
67
|
-
static skewY(m, y, units =
|
|
63
|
+
static skewY(m, y, units = AngleUnits.Deg) {
|
|
68
64
|
return Matrix2d.multiply(m, Matrix2d.skewIdentity(0, y, units));
|
|
69
65
|
}
|
|
70
|
-
static skew(m, x, y = 0, units =
|
|
66
|
+
static skew(m, x, y = 0, units = AngleUnits.Deg) {
|
|
71
67
|
return Matrix2d.multiply(m, Matrix2d.skewIdentity(x, y, units));
|
|
72
68
|
}
|
|
73
69
|
}
|
|
74
|
-
exports.Matrix2d = Matrix2d;
|
package/dist/bin/src/operator.js
CHANGED
package/dist/bin/src/utils.js
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.approximately = approximately;
|
|
4
|
-
exports.toPositive = toPositive;
|
|
5
|
-
exports.isCorrectNumber = isCorrectNumber;
|
|
6
|
-
function approximately(theValue, is, withPrecision = 1e-8) {
|
|
1
|
+
export function approximately(theValue, is, withPrecision = 1e-8) {
|
|
7
2
|
return Math.abs(theValue - is) <= withPrecision;
|
|
8
3
|
}
|
|
9
|
-
function toPositive(value, range) {
|
|
4
|
+
export function toPositive(value, range) {
|
|
10
5
|
if (value >= 0)
|
|
11
6
|
return Math.abs(value);
|
|
12
7
|
return Math.abs((range + value % range) % range);
|
|
13
8
|
}
|
|
14
|
-
function isCorrectNumber(value) {
|
|
9
|
+
export function isCorrectNumber(value) {
|
|
15
10
|
let v = +value;
|
|
16
11
|
if (!isNaN(value) && isFinite(value)) {
|
|
17
12
|
v = parseFloat(value);
|
package/package.json
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fbltd/math",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.11",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/bin/index.js",
|
|
6
6
|
"types": "dist/types/index.d.ts",
|
|
7
|
-
"type": "module",
|
|
8
7
|
"exports": {
|
|
9
8
|
".": {
|
|
10
9
|
"require": "./dist/bin/index.js",
|
|
@@ -37,6 +36,7 @@
|
|
|
37
36
|
"access": "public"
|
|
38
37
|
},
|
|
39
38
|
"devDependencies": {
|
|
40
|
-
"@fbltd/bundler": "^2.0.46"
|
|
39
|
+
"@fbltd/bundler": "^2.0.46",
|
|
40
|
+
"typedoc": "^0.26.6"
|
|
41
41
|
}
|
|
42
42
|
}
|