@fbltd/math 1.0.6 → 1.0.8
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 +110 -0
- package/dist/bin/__tests__/utils.test.js +33 -0
- package/dist/bin/src/angle.js +20 -27
- package/dist/bin/src/colors/color.js +9 -7
- package/dist/bin/src/colors/conic.gradient.js +40 -56
- package/dist/bin/src/figures/circle.js +8 -7
- package/dist/bin/src/figures/point.js +6 -9
- package/dist/bin/src/figures/straight-line.js +8 -8
- package/dist/bin/src/matrix.js +7 -15
- package/dist/bin/src/operator.js +7 -9
- package/dist/bin/src/utils.js +2 -3
- package/dist/types/__tests__/angle.test.d.ts +2 -0
- package/dist/types/__tests__/angle.test.d.ts.map +1 -0
- package/dist/types/__tests__/utils.test.d.ts +2 -0
- package/dist/types/__tests__/utils.test.d.ts.map +1 -0
- package/package.json +40 -37
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const src_1 = require("../src");
|
|
4
|
+
describe('math.angle.toDeg', () => {
|
|
5
|
+
test('from Turn', () => {
|
|
6
|
+
expect(src_1.Angle.toDeg(1, src_1.AngleUnits.Turn)).toBe(360);
|
|
7
|
+
expect(src_1.Angle.toDeg(0, src_1.AngleUnits.Turn)).toBe(0);
|
|
8
|
+
expect(src_1.Angle.toDeg(0.5, src_1.AngleUnits.Turn)).toBe(180);
|
|
9
|
+
expect(src_1.Angle.toDeg(-0.5, src_1.AngleUnits.Turn)).toBe(-180);
|
|
10
|
+
});
|
|
11
|
+
test('from Rad', () => {
|
|
12
|
+
expect(src_1.Angle.toDeg(Math.PI * 2, src_1.AngleUnits.Rad)).toBe(360);
|
|
13
|
+
expect(src_1.Angle.toDeg(0, src_1.AngleUnits.Rad)).toBe(0);
|
|
14
|
+
expect(src_1.Angle.toDeg(Math.PI, src_1.AngleUnits.Rad)).toBe(180);
|
|
15
|
+
expect(src_1.Angle.toDeg(-Math.PI, src_1.AngleUnits.Rad)).toBe(-180);
|
|
16
|
+
});
|
|
17
|
+
test('from Deg', () => {
|
|
18
|
+
expect(src_1.Angle.toDeg(180, src_1.AngleUnits.Deg)).toBe(180);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
describe('math.angle.toRad', () => {
|
|
22
|
+
test('from Rad', () => {
|
|
23
|
+
expect(src_1.Angle.toRad(1, src_1.AngleUnits.Rad)).toBe(1);
|
|
24
|
+
});
|
|
25
|
+
test('from Deg', () => {
|
|
26
|
+
expect(src_1.Angle.toRad(360, src_1.AngleUnits.Deg)).toBe(Math.PI * 2);
|
|
27
|
+
expect(src_1.Angle.toRad(0, src_1.AngleUnits.Deg)).toBe(0);
|
|
28
|
+
expect(src_1.Angle.toRad(180, src_1.AngleUnits.Deg)).toBe(Math.PI);
|
|
29
|
+
expect(src_1.Angle.toRad(-180, src_1.AngleUnits.Deg)).toBe(-Math.PI);
|
|
30
|
+
});
|
|
31
|
+
test('from Turn', () => {
|
|
32
|
+
expect(src_1.Angle.toRad(1, src_1.AngleUnits.Turn)).toBe(Math.PI * 2);
|
|
33
|
+
expect(src_1.Angle.toRad(0, src_1.AngleUnits.Turn)).toBe(0);
|
|
34
|
+
expect(src_1.Angle.toRad(0.5, src_1.AngleUnits.Turn)).toBe(Math.PI);
|
|
35
|
+
expect(src_1.Angle.toRad(-0.5, src_1.AngleUnits.Turn)).toBe(-Math.PI);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
describe('math.angle.toTurn', () => {
|
|
39
|
+
test('from Turn', () => {
|
|
40
|
+
expect(src_1.Angle.toTurn(0.1, src_1.AngleUnits.Turn)).toBe(0.1);
|
|
41
|
+
});
|
|
42
|
+
test('from Deg', () => {
|
|
43
|
+
expect(src_1.Angle.toTurn(360, src_1.AngleUnits.Deg)).toBe(1);
|
|
44
|
+
expect(src_1.Angle.toTurn(0, src_1.AngleUnits.Deg)).toBe(0);
|
|
45
|
+
expect(src_1.Angle.toTurn(180, src_1.AngleUnits.Deg)).toBe(0.5);
|
|
46
|
+
expect(src_1.Angle.toTurn(-180, src_1.AngleUnits.Deg)).toBe(-0.5);
|
|
47
|
+
});
|
|
48
|
+
test('from Rad', () => {
|
|
49
|
+
expect(src_1.Angle.toTurn(Math.PI * 2, src_1.AngleUnits.Rad)).toBe(1);
|
|
50
|
+
expect(src_1.Angle.toTurn(0, src_1.AngleUnits.Rad)).toBe(0);
|
|
51
|
+
expect(src_1.Angle.toTurn(Math.PI, src_1.AngleUnits.Rad)).toBe(0.5);
|
|
52
|
+
expect(src_1.Angle.toTurn(-Math.PI, src_1.AngleUnits.Rad)).toBe(-0.5);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
describe('math.angle.toPositive', () => {
|
|
56
|
+
test('deg', () => {
|
|
57
|
+
expect(src_1.Angle.toPositive(0, src_1.AngleUnits.Deg)).toBe(0);
|
|
58
|
+
expect(src_1.Angle.toPositive(-0, src_1.AngleUnits.Deg)).toBe(0);
|
|
59
|
+
expect(src_1.Angle.toPositive(-721, src_1.AngleUnits.Deg)).toBe(359);
|
|
60
|
+
expect(src_1.Angle.toPositive(361, src_1.AngleUnits.Deg)).toBe(361);
|
|
61
|
+
});
|
|
62
|
+
test('rad', () => {
|
|
63
|
+
expect(src_1.Angle.toPositive(0, src_1.AngleUnits.Rad)).toBe(0);
|
|
64
|
+
expect(src_1.Angle.toPositive(-0, src_1.AngleUnits.Rad)).toBe(0);
|
|
65
|
+
expect(src_1.Angle.toPositive(-Math.PI, src_1.AngleUnits.Rad)).toBe(Math.PI);
|
|
66
|
+
expect(src_1.Angle.toPositive(-(Math.PI * 3), src_1.AngleUnits.Rad)).toBe(Math.PI);
|
|
67
|
+
});
|
|
68
|
+
test('turn', () => {
|
|
69
|
+
expect(src_1.Angle.toPositive(0, src_1.AngleUnits.Turn)).toBe(0);
|
|
70
|
+
expect(src_1.Angle.toPositive(-0, src_1.AngleUnits.Turn)).toBe(0);
|
|
71
|
+
expect((0, src_1.approximately)(src_1.Angle.toPositive(-1.1, src_1.AngleUnits.Turn), 0.9)).toBe(true);
|
|
72
|
+
expect(src_1.Angle.toPositive(1.1, src_1.AngleUnits.Turn)).toBe(1.1);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
describe('math.angle.normalize', () => {
|
|
76
|
+
test('deg', () => {
|
|
77
|
+
expect(src_1.Angle.normalize(0, src_1.AngleUnits.Deg)).toBe(0);
|
|
78
|
+
expect(src_1.Angle.normalize(-0, src_1.AngleUnits.Deg)).toBe(0);
|
|
79
|
+
expect(src_1.Angle.normalize(-721, src_1.AngleUnits.Deg)).toBe(359);
|
|
80
|
+
expect(src_1.Angle.normalize(721, src_1.AngleUnits.Deg)).toBe(1);
|
|
81
|
+
expect(src_1.Angle.normalize(361, src_1.AngleUnits.Deg)).toBe(1);
|
|
82
|
+
expect(src_1.Angle.normalize(360, src_1.AngleUnits.Deg)).toBe(0);
|
|
83
|
+
expect(src_1.Angle.normalize(-360, src_1.AngleUnits.Deg)).toBe(0);
|
|
84
|
+
});
|
|
85
|
+
test('rad', () => {
|
|
86
|
+
expect(src_1.Angle.normalize(0, src_1.AngleUnits.Rad)).toBe(0);
|
|
87
|
+
expect(src_1.Angle.normalize(-0, src_1.AngleUnits.Rad)).toBe(0);
|
|
88
|
+
expect(src_1.Angle.normalize(-(Math.PI * 3), src_1.AngleUnits.Rad)).toBe(Math.PI);
|
|
89
|
+
expect(src_1.Angle.normalize(Math.PI * 3, src_1.AngleUnits.Rad)).toBe(Math.PI);
|
|
90
|
+
expect((0, src_1.approximately)(src_1.Angle.normalize(Math.PI * 2 + 0.01, src_1.AngleUnits.Rad), 0.01)).toBe(true);
|
|
91
|
+
expect(src_1.Angle.normalize(Math.PI * 2, src_1.AngleUnits.Rad)).toBe(0);
|
|
92
|
+
expect(src_1.Angle.normalize(-Math.PI * 2, src_1.AngleUnits.Rad)).toBe(0);
|
|
93
|
+
});
|
|
94
|
+
test('turn', () => {
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
describe('math.angle.toCSS', () => {
|
|
98
|
+
expect(src_1.Angle.toCSS(1, src_1.AngleUnits.Deg)).toEqual('rotate(1deg)');
|
|
99
|
+
expect(src_1.Angle.toCSS(1, src_1.AngleUnits.Rad)).toEqual('rotate(1rad)');
|
|
100
|
+
expect(src_1.Angle.toCSS(1, src_1.AngleUnits.Turn)).toEqual('rotate(1turn)');
|
|
101
|
+
expect(src_1.Angle.toCSS(-1, src_1.AngleUnits.Deg)).toEqual('rotate(-1deg)');
|
|
102
|
+
expect(src_1.Angle.toCSS(-1, src_1.AngleUnits.Rad)).toEqual('rotate(-1rad)');
|
|
103
|
+
expect(src_1.Angle.toCSS(-1, src_1.AngleUnits.Turn)).toEqual('rotate(-1turn)');
|
|
104
|
+
expect(src_1.Angle.toCSS(NaN, src_1.AngleUnits.Deg)).toEqual('');
|
|
105
|
+
expect(src_1.Angle.toCSS(Infinity, src_1.AngleUnits.Rad)).toEqual('');
|
|
106
|
+
expect(src_1.Angle.toCSS(-Infinity, src_1.AngleUnits.Turn)).toEqual('');
|
|
107
|
+
expect(src_1.Angle.toCSS('1e -08', src_1.AngleUnits.Deg)).toEqual('');
|
|
108
|
+
expect(src_1.Angle.toCSS(undefined, src_1.AngleUnits.Deg)).toEqual('');
|
|
109
|
+
expect(src_1.Angle.toCSS(null, src_1.AngleUnits.Deg)).toEqual('');
|
|
110
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const src_1 = require("../src");
|
|
4
|
+
test('approximately', () => {
|
|
5
|
+
expect((0, src_1.approximately)(0, 0)).toBe(true);
|
|
6
|
+
expect((0, src_1.approximately)(1 + 1e-8, 1)).toBe(true);
|
|
7
|
+
expect((0, src_1.approximately)(-1 - 1e-8, -1)).toBe(true);
|
|
8
|
+
expect((0, src_1.approximately)(1 + 1e-8 + 1e-9, 1)).toBe(false);
|
|
9
|
+
expect((0, src_1.approximately)(-1 - 1e-8 - 1e-9, -1)).toBe(false);
|
|
10
|
+
expect((0, src_1.approximately)(0, 0.1)).toBe(false);
|
|
11
|
+
expect((0, src_1.approximately)(0, 0.1, 0.1)).toBe(true);
|
|
12
|
+
});
|
|
13
|
+
test('toPositive', () => {
|
|
14
|
+
expect((0, src_1.toPositive)(-1, 360)).toEqual(359);
|
|
15
|
+
expect((0, src_1.toPositive)(1, 360)).toEqual(1);
|
|
16
|
+
expect((0, src_1.toPositive)(0, 1)).toEqual(0);
|
|
17
|
+
expect((0, src_1.toPositive)(-720, 360)).toEqual(0);
|
|
18
|
+
expect((0, src_1.toPositive)(-721, 360)).toEqual(359);
|
|
19
|
+
expect((0, src_1.toPositive)(-0, 0)).toEqual(0);
|
|
20
|
+
});
|
|
21
|
+
test('isCorrectNumber', () => {
|
|
22
|
+
expect((0, src_1.isCorrectNumber)(0)).toBe(true);
|
|
23
|
+
expect((0, src_1.isCorrectNumber)('0')).toBe(true);
|
|
24
|
+
expect((0, src_1.isCorrectNumber)('0e-08')).toBe(true);
|
|
25
|
+
expect((0, src_1.isCorrectNumber)('0e -08')).toBe(false);
|
|
26
|
+
expect((0, src_1.isCorrectNumber)({ 1: 2 })).toBe(false);
|
|
27
|
+
expect((0, src_1.isCorrectNumber)(null)).toBe(false);
|
|
28
|
+
expect((0, src_1.isCorrectNumber)(undefined)).toBe(false);
|
|
29
|
+
expect((0, src_1.isCorrectNumber)(Infinity)).toBe(false);
|
|
30
|
+
expect((0, src_1.isCorrectNumber)(-Infinity)).toBe(false);
|
|
31
|
+
expect((0, src_1.isCorrectNumber)(NaN)).toBe(false);
|
|
32
|
+
expect((0, src_1.isCorrectNumber)('')).toBe(false);
|
|
33
|
+
});
|
package/dist/bin/src/angle.js
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var _a;
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
3
|
exports.Angle = exports.AngleUnits = void 0;
|
|
5
|
-
|
|
4
|
+
const utils_1 = require("./utils");
|
|
6
5
|
var AngleUnits;
|
|
7
6
|
(function (AngleUnits) {
|
|
8
7
|
AngleUnits[AngleUnits["Deg"] = 0] = "Deg";
|
|
9
8
|
AngleUnits[AngleUnits["Rad"] = 1] = "Rad";
|
|
10
9
|
AngleUnits[AngleUnits["Turn"] = 2] = "Turn";
|
|
11
10
|
})(AngleUnits || (exports.AngleUnits = AngleUnits = {}));
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
Angle.toRad = function (angle, unit) {
|
|
16
|
-
if (unit === void 0) { unit = AngleUnits.Deg; }
|
|
11
|
+
class Angle {
|
|
12
|
+
static toRad(angle, unit = AngleUnits.Deg) {
|
|
17
13
|
switch (unit) {
|
|
18
14
|
case AngleUnits.Rad:
|
|
19
15
|
return angle;
|
|
@@ -22,9 +18,8 @@ var Angle = (function () {
|
|
|
22
18
|
case AngleUnits.Turn:
|
|
23
19
|
return Math.PI * 2 * angle;
|
|
24
20
|
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (unit === void 0) { unit = AngleUnits.Deg; }
|
|
21
|
+
}
|
|
22
|
+
static toTurn(angle, unit = AngleUnits.Deg) {
|
|
28
23
|
switch (unit) {
|
|
29
24
|
case AngleUnits.Turn:
|
|
30
25
|
return angle;
|
|
@@ -33,9 +28,8 @@ var Angle = (function () {
|
|
|
33
28
|
case AngleUnits.Rad:
|
|
34
29
|
return angle / (Math.PI * 2);
|
|
35
30
|
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (unit === void 0) { unit = AngleUnits.Rad; }
|
|
31
|
+
}
|
|
32
|
+
static toDeg(angle, unit = AngleUnits.Rad) {
|
|
39
33
|
switch (unit) {
|
|
40
34
|
case AngleUnits.Deg:
|
|
41
35
|
return angle;
|
|
@@ -44,8 +38,8 @@ var Angle = (function () {
|
|
|
44
38
|
case AngleUnits.Rad:
|
|
45
39
|
return angle * 180 / Math.PI;
|
|
46
40
|
}
|
|
47
|
-
}
|
|
48
|
-
|
|
41
|
+
}
|
|
42
|
+
static toPositive(angle, unit) {
|
|
49
43
|
switch (unit) {
|
|
50
44
|
case AngleUnits.Deg:
|
|
51
45
|
return (0, utils_1.toPositive)(angle, 360);
|
|
@@ -54,8 +48,8 @@ var Angle = (function () {
|
|
|
54
48
|
case AngleUnits.Rad:
|
|
55
49
|
return (0, utils_1.toPositive)(angle, Math.PI * 2);
|
|
56
50
|
}
|
|
57
|
-
}
|
|
58
|
-
|
|
51
|
+
}
|
|
52
|
+
static normalize(angle, unit) {
|
|
59
53
|
switch (unit) {
|
|
60
54
|
case AngleUnits.Deg:
|
|
61
55
|
return Angle.toPositive(angle, unit) % 360;
|
|
@@ -64,17 +58,16 @@ var Angle = (function () {
|
|
|
64
58
|
case AngleUnits.Turn:
|
|
65
59
|
return Angle.toPositive(angle, unit) % 1;
|
|
66
60
|
}
|
|
67
|
-
}
|
|
68
|
-
|
|
61
|
+
}
|
|
62
|
+
static toCSS(angle, unit) {
|
|
69
63
|
if (!(0, utils_1.isCorrectNumber)(angle))
|
|
70
64
|
return '';
|
|
71
|
-
return
|
|
65
|
+
return `rotate(${angle}${Angle.angleUnitCorrespondence[unit]})`;
|
|
66
|
+
}
|
|
67
|
+
static angleUnitCorrespondence = {
|
|
68
|
+
[AngleUnits.Rad]: 'rad',
|
|
69
|
+
[AngleUnits.Turn]: 'turn',
|
|
70
|
+
[AngleUnits.Deg]: 'deg',
|
|
72
71
|
};
|
|
73
|
-
|
|
74
|
-
_a[AngleUnits.Rad] = 'rad',
|
|
75
|
-
_a[AngleUnits.Turn] = 'turn',
|
|
76
|
-
_a[AngleUnits.Deg] = 'deg',
|
|
77
|
-
_a);
|
|
78
|
-
return Angle;
|
|
79
|
-
}());
|
|
72
|
+
}
|
|
80
73
|
exports.Angle = Angle;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Color = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
class Color {
|
|
5
|
+
red;
|
|
6
|
+
green;
|
|
7
|
+
blue;
|
|
8
|
+
constructor(red, green, blue) {
|
|
6
9
|
this.red = red;
|
|
7
10
|
this.green = green;
|
|
8
11
|
this.blue = blue;
|
|
@@ -10,9 +13,8 @@ var Color = (function () {
|
|
|
10
13
|
this.green = Math.max(Math.min(green, 255), 0);
|
|
11
14
|
this.blue = Math.max(Math.min(blue, 255), 0);
|
|
12
15
|
}
|
|
13
|
-
|
|
14
|
-
return
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
}());
|
|
16
|
+
toCSS() {
|
|
17
|
+
return `rgb(${this.red}, ${this.green}, ${this.blue})`;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
18
20
|
exports.Color = Color;
|
|
@@ -1,33 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
|
-
if (ar || !(i in from)) {
|
|
5
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
6
|
-
ar[i] = from[i];
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.ConicGradient = void 0;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
colors[_i] = arguments[_i];
|
|
19
|
-
}
|
|
20
|
-
this.colors = __spreadArray([], colors, true).sort(function (a, b) { return a.angle - b.angle; });
|
|
4
|
+
const color_1 = require("./color");
|
|
5
|
+
class ConicGradient {
|
|
6
|
+
colors;
|
|
7
|
+
constructor(...colors) {
|
|
8
|
+
this.colors = [...colors].sort((a, b) => a.angle - b.angle);
|
|
21
9
|
this.colors.push({
|
|
22
10
|
angle: 1,
|
|
23
11
|
color: this.colors[0].color
|
|
24
12
|
});
|
|
25
13
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
for (
|
|
30
|
-
var color = _a[_i];
|
|
14
|
+
getColorAtAngle(angle) {
|
|
15
|
+
let prev = undefined;
|
|
16
|
+
let next = undefined;
|
|
17
|
+
for (let color of this.colors) {
|
|
31
18
|
if (color.angle === angle)
|
|
32
19
|
return color.color;
|
|
33
20
|
if (color.angle < angle)
|
|
@@ -39,59 +26,56 @@ var ConicGradient = (function () {
|
|
|
39
26
|
}
|
|
40
27
|
if (!prev || !next)
|
|
41
28
|
return undefined;
|
|
42
|
-
|
|
29
|
+
const coef = (angle - prev.angle) / (next.angle - prev.angle);
|
|
43
30
|
return new color_1.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));
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
31
|
+
}
|
|
32
|
+
getAngleByColor(color) {
|
|
33
|
+
let prev;
|
|
34
|
+
let next = this.colors[0];
|
|
48
35
|
if (color.red === next.color.red && color.green === next.color.green && color.blue === next.color.blue)
|
|
49
36
|
return next.angle;
|
|
50
|
-
for (
|
|
37
|
+
for (let i = 1; i < this.colors.length; i++) {
|
|
51
38
|
next = this.colors[i];
|
|
52
39
|
prev = this.colors[i - 1];
|
|
53
40
|
if (color.red === next.color.red && color.green === next.color.green && color.blue === next.color.blue)
|
|
54
41
|
return next.angle;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
42
|
+
let redDif = next.color.red - prev.color.red;
|
|
43
|
+
let greenDif = next.color.green - prev.color.green;
|
|
44
|
+
let blueDif = next.color.blue - prev.color.blue;
|
|
45
|
+
let redDifColor = color.red - prev.color.red;
|
|
46
|
+
let greenDifColor = color.green - prev.color.green;
|
|
47
|
+
let blueDifColor = color.blue - prev.color.blue;
|
|
61
48
|
if (((redDifColor >= 0 && redDifColor <= redDif) || (redDifColor <= 0 && redDifColor >= redDif)) &&
|
|
62
49
|
((greenDifColor >= 0 && greenDifColor <= greenDif) || (greenDifColor <= 0 && greenDifColor >= greenDif)) &&
|
|
63
50
|
((blueDifColor >= 0 && blueDifColor <= blueDif) || (blueDifColor <= 0 && blueDifColor >= blueDif))) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
return (next.angle - prev.angle) * Math.min
|
|
51
|
+
const redCoef = ((color.red - prev.color.red) / (next.color.red - prev.color.red));
|
|
52
|
+
const greenCoef = ((color.green - prev.color.green) / (next.color.green - prev.color.green));
|
|
53
|
+
const blueCoef = ((color.blue - prev.color.blue) / (next.color.blue - prev.color.blue));
|
|
54
|
+
const coefs = [redCoef, greenCoef, blueCoef].filter(Boolean);
|
|
55
|
+
return (next.angle - prev.angle) * Math.min(...coefs) + prev.angle;
|
|
69
56
|
}
|
|
70
57
|
}
|
|
71
58
|
return undefined;
|
|
72
|
-
}
|
|
73
|
-
|
|
59
|
+
}
|
|
60
|
+
isColorInRange(color) {
|
|
74
61
|
return Boolean(this.getAngleByColor(color));
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
for (
|
|
79
|
-
var color = _a[_i];
|
|
62
|
+
}
|
|
63
|
+
toCanvas(ctx, center) {
|
|
64
|
+
const gradient = ctx.createConicGradient(0, ...center);
|
|
65
|
+
for (let color of this.colors) {
|
|
80
66
|
gradient.addColorStop(color.angle, color.color.toCSS());
|
|
81
67
|
}
|
|
82
68
|
return gradient;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
for (
|
|
87
|
-
var color = _a[_i];
|
|
69
|
+
}
|
|
70
|
+
toCSS() {
|
|
71
|
+
let s = '';
|
|
72
|
+
for (let color of this.colors) {
|
|
88
73
|
if (s)
|
|
89
74
|
s += ',';
|
|
90
|
-
s +=
|
|
75
|
+
s += `rgb(${color.color.red},${color.color.green},${color.color.blue})`;
|
|
91
76
|
}
|
|
92
|
-
s =
|
|
77
|
+
s = `conic-gradient(in srgb from 0.25turn at 50% 50%, ${s})`;
|
|
93
78
|
return s;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
}());
|
|
79
|
+
}
|
|
80
|
+
}
|
|
97
81
|
exports.ConicGradient = ConicGradient;
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Circle = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const matrix_1 = require("../matrix");
|
|
5
|
+
class Circle {
|
|
6
|
+
center;
|
|
7
|
+
r;
|
|
8
|
+
constructor(center, r) {
|
|
7
9
|
this.center = center;
|
|
8
10
|
this.r = r;
|
|
9
11
|
}
|
|
10
|
-
|
|
12
|
+
transform(matrix) {
|
|
11
13
|
this.center = matrix_1.Matrix2d.apply(matrix, this.center);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
}());
|
|
14
|
+
}
|
|
15
|
+
}
|
|
15
16
|
exports.Circle = Circle;
|
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Point2 = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
Point2.sum = function (p1, p2) {
|
|
4
|
+
class Point2 {
|
|
5
|
+
static sum(p1, p2) {
|
|
8
6
|
return [
|
|
9
7
|
p1[0] + p2[0],
|
|
10
8
|
p1[1] + p2[1],
|
|
11
9
|
];
|
|
12
|
-
}
|
|
13
|
-
|
|
10
|
+
}
|
|
11
|
+
static scale(v, factor) {
|
|
14
12
|
return [
|
|
15
13
|
v[0] * factor,
|
|
16
14
|
v[1] * factor,
|
|
17
15
|
];
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
}());
|
|
16
|
+
}
|
|
17
|
+
}
|
|
21
18
|
exports.Point2 = Point2;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.StraightLine = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const matrix_1 = require("../matrix");
|
|
5
|
+
class StraightLine {
|
|
6
|
+
p1;
|
|
7
|
+
p2;
|
|
8
|
+
constructor(p1, p2) {
|
|
7
9
|
this.p1 = p1;
|
|
8
10
|
this.p2 = p2;
|
|
9
11
|
}
|
|
10
|
-
|
|
11
|
-
if (transformThis === void 0) { transformThis = false; }
|
|
12
|
+
transform(matrix, transformThis = false) {
|
|
12
13
|
if (transformThis) {
|
|
13
14
|
return this;
|
|
14
15
|
}
|
|
15
16
|
return new StraightLine(matrix_1.Matrix2d.apply(matrix, this.p1), matrix_1.Matrix2d.apply(matrix, this.p2));
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
}());
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
19
|
exports.StraightLine = StraightLine;
|
package/dist/bin/src/matrix.js
CHANGED
|
@@ -2,16 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Matrix2d = exports.identityMatrix = void 0;
|
|
4
4
|
exports.identityMatrix = [1, 0, 0, 1, 0, 0];
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
Matrix2d.multiply = function (matrix) {
|
|
9
|
-
var matrices = [];
|
|
10
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
11
|
-
matrices[_i - 1] = arguments[_i];
|
|
12
|
-
}
|
|
13
|
-
for (var _a = 0, matrices_1 = matrices; _a < matrices_1.length; _a++) {
|
|
14
|
-
var m = matrices_1[_a];
|
|
5
|
+
class Matrix2d {
|
|
6
|
+
static multiply(matrix, ...matrices) {
|
|
7
|
+
for (let m of matrices) {
|
|
15
8
|
matrix = [
|
|
16
9
|
matrix[0] * m[0] + matrix[2] * m[1],
|
|
17
10
|
matrix[1] * m[0] + matrix[3] * m[1],
|
|
@@ -22,13 +15,12 @@ var Matrix2d = (function () {
|
|
|
22
15
|
];
|
|
23
16
|
}
|
|
24
17
|
return matrix;
|
|
25
|
-
}
|
|
26
|
-
|
|
18
|
+
}
|
|
19
|
+
static apply(matrix, point) {
|
|
27
20
|
return [
|
|
28
21
|
matrix[0] * point[0] + matrix[2] * point[1] + matrix[4],
|
|
29
22
|
matrix[1] * point[0] + matrix[3] * point[1] + matrix[5],
|
|
30
23
|
];
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
}());
|
|
24
|
+
}
|
|
25
|
+
}
|
|
34
26
|
exports.Matrix2d = Matrix2d;
|
package/dist/bin/src/operator.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Operator = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
if (unit === void 0) { unit = angle_1.AngleUnits.Deg; }
|
|
4
|
+
const angle_1 = require("./angle");
|
|
5
|
+
class Operator {
|
|
6
|
+
static temp1;
|
|
7
|
+
static temp2;
|
|
8
|
+
static rotateIdentity(angle, unit = angle_1.AngleUnits.Deg) {
|
|
10
9
|
angle = angle_1.Angle.toRad(angle, unit);
|
|
11
10
|
this.temp1 = Math.cos(angle);
|
|
12
11
|
this.temp2 = Math.sin(angle);
|
|
@@ -17,7 +16,6 @@ var Operator = (function () {
|
|
|
17
16
|
this.temp1,
|
|
18
17
|
0, 0
|
|
19
18
|
];
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
}());
|
|
19
|
+
}
|
|
20
|
+
}
|
|
23
21
|
exports.Operator = Operator;
|
package/dist/bin/src/utils.js
CHANGED
|
@@ -3,8 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.approximately = approximately;
|
|
4
4
|
exports.toPositive = toPositive;
|
|
5
5
|
exports.isCorrectNumber = isCorrectNumber;
|
|
6
|
-
function approximately(theValue, is, withPrecision) {
|
|
7
|
-
if (withPrecision === void 0) { withPrecision = 1e-8; }
|
|
6
|
+
function approximately(theValue, is, withPrecision = 1e-8) {
|
|
8
7
|
return Math.abs(theValue - is) <= withPrecision;
|
|
9
8
|
}
|
|
10
9
|
function toPositive(value, range) {
|
|
@@ -13,7 +12,7 @@ function toPositive(value, range) {
|
|
|
13
12
|
return Math.abs((range + value % range) % range);
|
|
14
13
|
}
|
|
15
14
|
function isCorrectNumber(value) {
|
|
16
|
-
|
|
15
|
+
let v = +value;
|
|
17
16
|
if (!isNaN(value) && isFinite(value)) {
|
|
18
17
|
v = parseFloat(value);
|
|
19
18
|
return !isNaN(v) && isFinite(v);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"angle.test.d.ts","sourceRoot":"","sources":["../../../__tests__/angle.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.test.d.ts","sourceRoot":"","sources":["../../../__tests__/utils.test.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,39 +1,42 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
2
|
+
"name": "@fbltd/math",
|
|
3
|
+
"version": "1.0.8",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "dist/bin/index.js",
|
|
6
|
+
"types": "dist/types/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"require": "./dist/bin/index.js",
|
|
11
|
+
"import": "./dist/bin/index.js",
|
|
12
|
+
"types": "./dist/types/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.ms"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"clean": "rm -r dist || echo ''",
|
|
21
|
+
"build": "node_modules/.bin/tsc",
|
|
22
|
+
"deploy": "npm run clean && npm run build && npm version patch && git push && npm publish && npm run clean",
|
|
23
|
+
"make": "node_modules/.bin/fbltd_make",
|
|
24
|
+
"test": "node_modules/.bin/fbltd_test"
|
|
25
|
+
},
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "git+https://github.com/GlennMiller1991/math.git"
|
|
29
|
+
},
|
|
30
|
+
"author": "",
|
|
31
|
+
"license": "ISC",
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://github.com/GlennMiller1991/math/issues"
|
|
34
|
+
},
|
|
35
|
+
"homepage": "https://github.com/GlennMiller1991/math#readme",
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@fbltd/bundler": "^2.0.46"
|
|
41
|
+
}
|
|
39
42
|
}
|