data-structure-typed 0.8.18 → 0.9.16
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/.idea/modules.xml +1 -1
- package/README.md +197 -2
- package/dist/data-structures/binary-tree/aa-tree.js +5 -2
- package/dist/data-structures/binary-tree/avl-tree.d.ts +1 -5
- package/dist/data-structures/binary-tree/avl-tree.js +93 -46
- package/dist/data-structures/binary-tree/b-tree.js +5 -2
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +1 -1
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +14 -13
- package/dist/data-structures/binary-tree/binary-tree.d.ts +20 -32
- package/dist/data-structures/binary-tree/binary-tree.js +480 -370
- package/dist/data-structures/binary-tree/bst.d.ts +4 -8
- package/dist/data-structures/binary-tree/bst.js +152 -107
- package/dist/data-structures/binary-tree/rb-tree.js +5 -2
- package/dist/data-structures/binary-tree/segment-tree.d.ts +3 -3
- package/dist/data-structures/binary-tree/segment-tree.js +91 -61
- package/dist/data-structures/binary-tree/splay-tree.js +5 -2
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +1 -5
- package/dist/data-structures/binary-tree/tree-multiset.js +31 -11
- package/dist/data-structures/binary-tree/two-three-tree.js +5 -2
- package/dist/data-structures/graph/abstract-graph.d.ts +5 -33
- package/dist/data-structures/graph/abstract-graph.js +546 -311
- package/dist/data-structures/graph/directed-graph.d.ts +5 -13
- package/dist/data-structures/graph/directed-graph.js +250 -128
- package/dist/data-structures/graph/undirected-graph.d.ts +4 -3
- package/dist/data-structures/graph/undirected-graph.js +166 -81
- package/dist/data-structures/hash/coordinate-map.d.ts +1 -1
- package/dist/data-structures/hash/coordinate-map.js +38 -20
- package/dist/data-structures/hash/coordinate-set.js +33 -15
- package/dist/data-structures/hash/index.d.ts +5 -0
- package/dist/data-structures/hash/index.js +5 -0
- package/dist/data-structures/heap/heap.d.ts +2 -8
- package/dist/data-structures/heap/heap.js +36 -31
- package/dist/data-structures/heap/max-heap.d.ts +3 -2
- package/dist/data-structures/heap/max-heap.js +27 -9
- package/dist/data-structures/heap/min-heap.d.ts +3 -2
- package/dist/data-structures/heap/min-heap.js +27 -9
- package/dist/data-structures/index.d.ts +1 -0
- package/dist/data-structures/index.js +1 -0
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +0 -1
- package/dist/data-structures/linked-list/doubly-linked-list.js +56 -53
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +8 -12
- package/dist/data-structures/linked-list/singly-linked-list.js +308 -174
- package/dist/data-structures/matrix/matrix.js +8 -7
- package/dist/data-structures/matrix/matrix2d.d.ts +5 -5
- package/dist/data-structures/matrix/matrix2d.js +80 -63
- package/dist/data-structures/matrix/navigator.d.ts +2 -16
- package/dist/data-structures/matrix/navigator.js +37 -18
- package/dist/data-structures/matrix/vector2d.d.ts +18 -18
- package/dist/data-structures/matrix/vector2d.js +117 -94
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +3 -2
- package/dist/data-structures/priority-queue/max-priority-queue.js +25 -8
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +3 -2
- package/dist/data-structures/priority-queue/min-priority-queue.js +25 -8
- package/dist/data-structures/priority-queue/priority-queue.d.ts +15 -21
- package/dist/data-structures/priority-queue/priority-queue.js +159 -116
- package/dist/data-structures/queue/deque.js +82 -56
- package/dist/data-structures/queue/queue.d.ts +9 -10
- package/dist/data-structures/queue/queue.js +34 -34
- package/dist/data-structures/stack/stack.d.ts +9 -10
- package/dist/data-structures/stack/stack.js +31 -31
- package/dist/data-structures/trampoline.d.ts +14 -23
- package/dist/data-structures/trampoline.js +103 -25
- package/dist/data-structures/trie/trie.d.ts +13 -3
- package/dist/data-structures/trie/trie.js +234 -80
- package/dist/data-structures/types/abstract-graph.d.ts +29 -0
- package/dist/data-structures/types/abstract-graph.js +2 -0
- package/dist/data-structures/types/avl-tree.d.ts +5 -0
- package/dist/data-structures/types/avl-tree.js +2 -0
- package/dist/data-structures/types/binary-tree.d.ts +16 -0
- package/dist/data-structures/types/binary-tree.js +2 -0
- package/dist/data-structures/types/bst.d.ts +7 -0
- package/dist/data-structures/types/bst.js +2 -0
- package/dist/data-structures/types/directed-graph.d.ts +10 -0
- package/dist/data-structures/types/directed-graph.js +2 -0
- package/dist/data-structures/types/doubly-linked-list.d.ts +1 -0
- package/dist/data-structures/types/doubly-linked-list.js +2 -0
- package/dist/data-structures/types/heap.d.ts +7 -0
- package/dist/data-structures/types/heap.js +2 -0
- package/dist/data-structures/types/index.d.ts +13 -0
- package/dist/data-structures/types/index.js +29 -0
- package/dist/data-structures/types/navigator.d.ts +14 -0
- package/dist/data-structures/types/navigator.js +2 -0
- package/dist/data-structures/types/priority-queue.d.ts +7 -0
- package/dist/data-structures/types/priority-queue.js +2 -0
- package/dist/data-structures/types/segment-tree.d.ts +1 -0
- package/dist/data-structures/types/segment-tree.js +2 -0
- package/dist/data-structures/types/singly-linked-list.d.ts +5 -0
- package/dist/data-structures/types/singly-linked-list.js +2 -0
- package/dist/data-structures/types/tree-multiset.d.ts +5 -0
- package/dist/data-structures/types/tree-multiset.js +2 -0
- package/dist/{types → data-structures/types}/utils.d.ts +7 -1
- package/dist/{types → data-structures/types}/utils.js +20 -19
- package/dist/{utils.d.ts → utils/utils.d.ts} +6 -23
- package/dist/utils/utils.js +651 -0
- package/package.json +20 -42
- package/src/data-structures/binary-tree/avl-tree.ts +1 -6
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +4 -4
- package/src/data-structures/binary-tree/binary-tree.ts +184 -139
- package/src/data-structures/binary-tree/bst.ts +15 -24
- package/src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif +0 -0
- package/src/data-structures/binary-tree/diagrams/bst-rotation.gif +0 -0
- package/src/data-structures/binary-tree/diagrams/segment-tree.png +0 -0
- package/src/data-structures/binary-tree/segment-tree.ts +20 -12
- package/src/data-structures/binary-tree/tree-multiset.ts +1 -4
- package/src/data-structures/diagrams/README.md +7 -0
- package/src/data-structures/graph/abstract-graph.ts +58 -94
- package/src/data-structures/graph/diagrams/adjacency-list-pros-cons.png +0 -0
- package/src/data-structures/graph/diagrams/adjacency-list.png +0 -0
- package/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.png +0 -0
- package/src/data-structures/graph/diagrams/adjacency-matrix.png +0 -0
- package/src/data-structures/graph/diagrams/dfs-can-do.png +0 -0
- package/src/data-structures/graph/diagrams/edge-list-pros-cons.png +0 -0
- package/src/data-structures/graph/diagrams/edge-list.png +0 -0
- package/src/data-structures/graph/diagrams/max-flow.png +0 -0
- package/src/data-structures/graph/diagrams/mst.png +0 -0
- package/src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png +0 -0
- package/src/data-structures/graph/diagrams/tarjan-complicate-simple.png +0 -0
- package/src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png +0 -0
- package/src/data-structures/graph/diagrams/tarjan.mp4 +0 -0
- package/src/data-structures/graph/directed-graph.ts +12 -28
- package/src/data-structures/graph/undirected-graph.ts +11 -10
- package/src/data-structures/hash/coordinate-map.ts +1 -1
- package/src/data-structures/hash/index.ts +5 -0
- package/src/data-structures/heap/heap.ts +2 -11
- package/src/data-structures/heap/max-heap.ts +3 -2
- package/src/data-structures/heap/min-heap.ts +3 -2
- package/src/data-structures/index.ts +1 -0
- package/src/data-structures/linked-list/doubly-linked-list.ts +1 -9
- package/src/data-structures/linked-list/singly-linked-list.ts +18 -32
- package/src/data-structures/matrix/matrix2d.ts +11 -11
- package/src/data-structures/matrix/navigator.ts +2 -14
- package/src/data-structures/matrix/vector2d.ts +52 -52
- package/src/data-structures/priority-queue/max-priority-queue.ts +4 -3
- package/src/data-structures/priority-queue/min-priority-queue.ts +4 -3
- package/src/data-structures/priority-queue/priority-queue.ts +70 -78
- package/src/data-structures/queue/deque.ts +2 -2
- package/src/data-structures/queue/queue.ts +12 -13
- package/src/data-structures/stack/stack.ts +12 -13
- package/src/data-structures/trampoline.ts +31 -71
- package/src/data-structures/trie/trie.ts +61 -11
- package/src/data-structures/types/abstract-graph.ts +51 -0
- package/src/data-structures/types/avl-tree.ts +6 -0
- package/src/data-structures/types/binary-tree.ts +15 -0
- package/src/data-structures/types/bst.ts +5 -0
- package/src/data-structures/types/directed-graph.ts +18 -0
- package/src/data-structures/types/doubly-linked-list.ts +1 -0
- package/src/data-structures/types/heap.ts +8 -0
- package/src/data-structures/types/index.ts +13 -0
- package/src/data-structures/types/navigator.ts +12 -0
- package/src/data-structures/types/priority-queue.ts +9 -0
- package/src/data-structures/types/segment-tree.ts +1 -0
- package/src/data-structures/types/singly-linked-list.ts +15 -0
- package/src/data-structures/types/tree-multiset.ts +3 -0
- package/src/{types → data-structures/types}/utils.ts +20 -5
- package/src/utils/index.ts +1 -0
- package/src/{utils.ts → utils/utils.ts} +32 -132
- package/tsconfig.json +9 -6
- package/dist/types/data-structures/binary-tree/aa-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +0 -21
- package/dist/types/data-structures/binary-tree/b-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -8
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +0 -140
- package/dist/types/data-structures/binary-tree/bst.d.ts +0 -32
- package/dist/types/data-structures/binary-tree/index.d.ts +0 -4
- package/dist/types/data-structures/binary-tree/rb-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +0 -33
- package/dist/types/data-structures/binary-tree/splay-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/tree-multiset.d.ts +0 -11
- package/dist/types/data-structures/binary-tree/two-three-tree.d.ts +0 -2
- package/dist/types/data-structures/graph/abstract-graph.d.ts +0 -126
- package/dist/types/data-structures/graph/directed-graph.d.ts +0 -51
- package/dist/types/data-structures/graph/index.d.ts +0 -3
- package/dist/types/data-structures/graph/undirected-graph.d.ts +0 -24
- package/dist/types/data-structures/hash/coordinate-map.d.ts +0 -8
- package/dist/types/data-structures/hash/coordinate-set.d.ts +0 -7
- package/dist/types/data-structures/hash/hash-table.d.ts +0 -1
- package/dist/types/data-structures/hash/index.d.ts +0 -1
- package/dist/types/data-structures/hash/pair.d.ts +0 -1
- package/dist/types/data-structures/hash/tree-map.d.ts +0 -1
- package/dist/types/data-structures/hash/tree-set.d.ts +0 -1
- package/dist/types/data-structures/heap/heap.d.ts +0 -72
- package/dist/types/data-structures/heap/index.d.ts +0 -3
- package/dist/types/data-structures/heap/max-heap.d.ts +0 -14
- package/dist/types/data-structures/heap/min-heap.d.ts +0 -14
- package/dist/types/data-structures/index.d.ts +0 -9
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +0 -59
- package/dist/types/data-structures/linked-list/index.d.ts +0 -2
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +0 -358
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +0 -1
- package/dist/types/data-structures/matrix/index.d.ts +0 -3
- package/dist/types/data-structures/matrix/matrix.d.ts +0 -9
- package/dist/types/data-structures/matrix/matrix2d.d.ts +0 -25
- package/dist/types/data-structures/matrix/navigator.d.ts +0 -31
- package/dist/types/data-structures/matrix/vector2d.d.ts +0 -74
- package/dist/types/data-structures/priority-queue/index.d.ts +0 -3
- package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +0 -4
- package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +0 -4
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +0 -36
- package/dist/types/data-structures/queue/deque.d.ts +0 -37
- package/dist/types/data-structures/queue/index.d.ts +0 -1
- package/dist/types/data-structures/queue/queue.d.ts +0 -76
- package/dist/types/data-structures/stack/index.d.ts +0 -1
- package/dist/types/data-structures/stack/stack.d.ts +0 -69
- package/dist/types/data-structures/trampoline.d.ts +0 -25
- package/dist/types/data-structures/trie/index.d.ts +0 -1
- package/dist/types/data-structures/trie/trie.d.ts +0 -28
- package/dist/types/types/index.d.ts +0 -1
- package/dist/types/types/utils.d.ts +0 -46
- package/dist/utils.js +0 -569
- package/src/types/index.ts +0 -1
- package/src/types/patches/index.d.ts +0 -0
- /package/dist/{types → utils}/index.d.ts +0 -0
- /package/dist/{types → utils}/index.js +0 -0
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MatrixNTI2D = void 0;
|
|
4
4
|
// todo need to be improved
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
this._matrix = new Array(row).fill(undefined).map(()
|
|
5
|
+
var MatrixNTI2D = /** @class */ (function () {
|
|
6
|
+
function MatrixNTI2D(options) {
|
|
7
|
+
var row = options.row, col = options.col, initialVal = options.initialVal;
|
|
8
|
+
this._matrix = new Array(row).fill(undefined).map(function () { return new Array(col).fill(initialVal || 0); });
|
|
9
9
|
}
|
|
10
|
-
toArray() {
|
|
10
|
+
MatrixNTI2D.prototype.toArray = function () {
|
|
11
11
|
return this._matrix;
|
|
12
|
-
}
|
|
13
|
-
|
|
12
|
+
};
|
|
13
|
+
return MatrixNTI2D;
|
|
14
|
+
}());
|
|
14
15
|
exports.MatrixNTI2D = MatrixNTI2D;
|
|
@@ -2,16 +2,16 @@ import Vector2D from './vector2d';
|
|
|
2
2
|
export declare class Matrix2D {
|
|
3
3
|
private readonly _matrix;
|
|
4
4
|
constructor(value?: number[][] | Vector2D);
|
|
5
|
-
/**
|
|
6
|
-
* Return the matrix values
|
|
7
|
-
*/
|
|
8
|
-
get m(): number[][];
|
|
9
5
|
static get empty(): number[][];
|
|
10
|
-
get toVector(): Vector2D;
|
|
11
6
|
/**
|
|
12
7
|
* Initialize an identity matrix
|
|
13
8
|
*/
|
|
14
9
|
static get identity(): number[][];
|
|
10
|
+
/**
|
|
11
|
+
* Return the matrix values
|
|
12
|
+
*/
|
|
13
|
+
get m(): number[][];
|
|
14
|
+
get toVector(): Vector2D;
|
|
15
15
|
static add(matrix1: Matrix2D, matrix2: Matrix2D): Matrix2D;
|
|
16
16
|
static subtract(matrix1: Matrix2D, matrix2: Matrix2D): Matrix2D;
|
|
17
17
|
static multiply(matrix1: Matrix2D, matrix2: Matrix2D): Matrix2D;
|
|
@@ -4,9 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.Matrix2D = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
var vector2d_1 = __importDefault(require("./vector2d"));
|
|
8
|
+
var Matrix2D = /** @class */ (function () {
|
|
9
|
+
function Matrix2D(value) {
|
|
10
10
|
if (typeof value === 'undefined') {
|
|
11
11
|
this._matrix = Matrix2D.identity;
|
|
12
12
|
}
|
|
@@ -20,100 +20,117 @@ class Matrix2D {
|
|
|
20
20
|
this._matrix = value;
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
23
|
+
Object.defineProperty(Matrix2D, "empty", {
|
|
24
|
+
get: function () {
|
|
25
|
+
return [[], [], []];
|
|
26
|
+
},
|
|
27
|
+
enumerable: false,
|
|
28
|
+
configurable: true
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(Matrix2D, "identity", {
|
|
31
|
+
/**
|
|
32
|
+
* Initialize an identity matrix
|
|
33
|
+
*/
|
|
34
|
+
get: function () {
|
|
35
|
+
return [
|
|
36
|
+
[1, 0, 0],
|
|
37
|
+
[0, 1, 0],
|
|
38
|
+
[0, 0, 1]
|
|
39
|
+
];
|
|
40
|
+
},
|
|
41
|
+
enumerable: false,
|
|
42
|
+
configurable: true
|
|
43
|
+
});
|
|
44
|
+
Object.defineProperty(Matrix2D.prototype, "m", {
|
|
45
|
+
/**
|
|
46
|
+
* Return the matrix values
|
|
47
|
+
*/
|
|
48
|
+
get: function () {
|
|
49
|
+
return this._matrix;
|
|
50
|
+
},
|
|
51
|
+
enumerable: false,
|
|
52
|
+
configurable: true
|
|
53
|
+
});
|
|
54
|
+
Object.defineProperty(Matrix2D.prototype, "toVector", {
|
|
55
|
+
get: function () {
|
|
56
|
+
return new vector2d_1.default(this._matrix[0][0], this._matrix[1][0]);
|
|
57
|
+
},
|
|
58
|
+
enumerable: false,
|
|
59
|
+
configurable: true
|
|
60
|
+
});
|
|
61
|
+
Matrix2D.add = function (matrix1, matrix2) {
|
|
62
|
+
var result = Matrix2D.empty;
|
|
63
|
+
for (var i = 0; i < 3; i++) {
|
|
64
|
+
for (var j = 0; j < 3; j++) {
|
|
49
65
|
result[i][j] = matrix1.m[i][j] + matrix2.m[i][j];
|
|
50
66
|
}
|
|
51
67
|
}
|
|
52
68
|
return new Matrix2D(result);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
for (
|
|
57
|
-
for (
|
|
69
|
+
};
|
|
70
|
+
Matrix2D.subtract = function (matrix1, matrix2) {
|
|
71
|
+
var result = Matrix2D.empty;
|
|
72
|
+
for (var i = 0; i < 3; i++) {
|
|
73
|
+
for (var j = 0; j < 3; j++) {
|
|
58
74
|
result[i][j] = matrix1.m[i][j] - matrix2.m[i][j];
|
|
59
75
|
}
|
|
60
76
|
}
|
|
61
77
|
return new Matrix2D(result);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
for (
|
|
66
|
-
for (
|
|
78
|
+
};
|
|
79
|
+
Matrix2D.multiply = function (matrix1, matrix2) {
|
|
80
|
+
var result = Matrix2D.empty;
|
|
81
|
+
for (var i = 0; i < 3; i++) {
|
|
82
|
+
for (var j = 0; j < 3; j++) {
|
|
67
83
|
result[i][j] = 0;
|
|
68
|
-
for (
|
|
84
|
+
for (var k = 0; k < 3; k++) {
|
|
69
85
|
result[i][j] += matrix1.m[i][k] * matrix2.m[k][j];
|
|
70
86
|
}
|
|
71
87
|
}
|
|
72
88
|
}
|
|
73
89
|
return new Matrix2D(result);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
for (
|
|
78
|
-
for (
|
|
90
|
+
};
|
|
91
|
+
Matrix2D.multiplyByValue = function (matrix, value) {
|
|
92
|
+
var result = Matrix2D.empty;
|
|
93
|
+
for (var i = 0; i < 3; i++) {
|
|
94
|
+
for (var j = 0; j < 3; j++) {
|
|
79
95
|
result[i][j] = matrix.m[i][j] * value;
|
|
80
96
|
}
|
|
81
97
|
}
|
|
82
98
|
return new Matrix2D(result);
|
|
83
|
-
}
|
|
84
|
-
|
|
99
|
+
};
|
|
100
|
+
Matrix2D.multiplyByVector = function (matrix, vector) {
|
|
85
101
|
return Matrix2D.multiply(matrix, new Matrix2D(vector)).toVector;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
102
|
+
};
|
|
103
|
+
Matrix2D.view = function (width, height) {
|
|
104
|
+
var scaleStep = 1; // Scale every vector * scaleStep
|
|
105
|
+
var centerX = width / 2;
|
|
106
|
+
var centerY = height / 2;
|
|
107
|
+
var flipX = Math.cos(Math.PI); // rotate 180deg / 3.14radian around X-axis
|
|
92
108
|
return new Matrix2D([
|
|
93
109
|
[scaleStep, 0, centerX],
|
|
94
110
|
[0, flipX * scaleStep, centerY],
|
|
95
111
|
[0, 0, 1]
|
|
96
112
|
]);
|
|
97
|
-
}
|
|
98
|
-
|
|
113
|
+
};
|
|
114
|
+
Matrix2D.scale = function (factor) {
|
|
99
115
|
return Matrix2D.multiplyByValue(new Matrix2D(), factor);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
116
|
+
};
|
|
117
|
+
Matrix2D.rotate = function (radians) {
|
|
118
|
+
var cos = Math.cos(radians);
|
|
119
|
+
var sin = Math.sin(radians);
|
|
104
120
|
return new Matrix2D([
|
|
105
121
|
[cos, -sin, 0],
|
|
106
122
|
[sin, cos, 0],
|
|
107
123
|
[0, 0, 1]
|
|
108
124
|
]);
|
|
109
|
-
}
|
|
110
|
-
|
|
125
|
+
};
|
|
126
|
+
Matrix2D.translate = function (vector) {
|
|
111
127
|
return new Matrix2D([
|
|
112
128
|
[1, 0, vector.x],
|
|
113
129
|
[0, 1, vector.y],
|
|
114
130
|
[0, 0, vector.w]
|
|
115
131
|
]);
|
|
116
|
-
}
|
|
117
|
-
|
|
132
|
+
};
|
|
133
|
+
return Matrix2D;
|
|
134
|
+
}());
|
|
118
135
|
exports.Matrix2D = Matrix2D;
|
|
119
136
|
exports.default = Matrix2D;
|
|
@@ -1,31 +1,17 @@
|
|
|
1
|
-
type Direction
|
|
2
|
-
type Turning = {
|
|
3
|
-
[key in Direction]: Direction;
|
|
4
|
-
};
|
|
1
|
+
import type { Direction, NavigatorParams, Turning } from '../types';
|
|
5
2
|
export declare class Character {
|
|
6
3
|
direction: Direction;
|
|
7
4
|
turn: () => Character;
|
|
8
5
|
constructor(direction: Direction, turning: Turning);
|
|
9
6
|
}
|
|
10
|
-
interface NavigatorParams<T> {
|
|
11
|
-
matrix: T[][];
|
|
12
|
-
turning: Turning;
|
|
13
|
-
onMove: (cur: [number, number]) => void;
|
|
14
|
-
init: {
|
|
15
|
-
cur: [number, number];
|
|
16
|
-
charDir: Direction;
|
|
17
|
-
VISITED: T;
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
7
|
export declare class Navigator<T = number> {
|
|
8
|
+
onMove: (cur: [number, number]) => void;
|
|
21
9
|
private readonly _matrix;
|
|
22
10
|
private readonly _cur;
|
|
23
11
|
private _character;
|
|
24
12
|
private readonly _VISITED;
|
|
25
|
-
onMove: (cur: [number, number]) => void;
|
|
26
13
|
constructor({ matrix, turning, onMove, init: { cur, charDir, VISITED } }: NavigatorParams<T>);
|
|
27
14
|
start(): void;
|
|
28
15
|
check(direction: Direction): boolean;
|
|
29
16
|
move(direction: Direction): void;
|
|
30
17
|
}
|
|
31
|
-
export {};
|
|
@@ -1,15 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
+
if (!m) return o;
|
|
5
|
+
var i = m.call(o), r, ar = [], e;
|
|
6
|
+
try {
|
|
7
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
+
}
|
|
9
|
+
catch (error) { e = { error: error }; }
|
|
10
|
+
finally {
|
|
11
|
+
try {
|
|
12
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
+
}
|
|
14
|
+
finally { if (e) throw e.error; }
|
|
15
|
+
}
|
|
16
|
+
return ar;
|
|
17
|
+
};
|
|
2
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
19
|
exports.Navigator = exports.Character = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
20
|
+
var Character = /** @class */ (function () {
|
|
21
|
+
function Character(direction, turning) {
|
|
6
22
|
this.direction = direction;
|
|
7
|
-
this.turn = ()
|
|
23
|
+
this.turn = function () { return new Character(turning[direction], turning); };
|
|
8
24
|
}
|
|
9
|
-
|
|
25
|
+
return Character;
|
|
26
|
+
}());
|
|
10
27
|
exports.Character = Character;
|
|
11
|
-
|
|
12
|
-
|
|
28
|
+
var Navigator = /** @class */ (function () {
|
|
29
|
+
function Navigator(_a) {
|
|
30
|
+
var matrix = _a.matrix, turning = _a.turning, onMove = _a.onMove, _b = _a.init, cur = _b.cur, charDir = _b.charDir, VISITED = _b.VISITED;
|
|
13
31
|
this._matrix = matrix;
|
|
14
32
|
this._cur = cur;
|
|
15
33
|
this._character = new Character(charDir, turning);
|
|
@@ -18,9 +36,9 @@ class Navigator {
|
|
|
18
36
|
this._VISITED = VISITED;
|
|
19
37
|
this._matrix[this._cur[0]][this._cur[1]] = this._VISITED;
|
|
20
38
|
}
|
|
21
|
-
start() {
|
|
39
|
+
Navigator.prototype.start = function () {
|
|
22
40
|
while (this.check(this._character.direction) || this.check(this._character.turn().direction)) {
|
|
23
|
-
|
|
41
|
+
var direction = this._character.direction;
|
|
24
42
|
if (this.check(direction)) {
|
|
25
43
|
this.move(direction);
|
|
26
44
|
}
|
|
@@ -28,11 +46,11 @@ class Navigator {
|
|
|
28
46
|
this._character = this._character.turn();
|
|
29
47
|
}
|
|
30
48
|
}
|
|
31
|
-
}
|
|
32
|
-
check(direction) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
49
|
+
};
|
|
50
|
+
Navigator.prototype.check = function (direction) {
|
|
51
|
+
var forward, row;
|
|
52
|
+
var matrix = this._matrix;
|
|
53
|
+
var _a = __read(this._cur, 2), i = _a[0], j = _a[1];
|
|
36
54
|
switch (direction) {
|
|
37
55
|
case 'up':
|
|
38
56
|
row = matrix[i - 1];
|
|
@@ -54,8 +72,8 @@ class Navigator {
|
|
|
54
72
|
break;
|
|
55
73
|
}
|
|
56
74
|
return forward !== undefined && forward !== this._VISITED;
|
|
57
|
-
}
|
|
58
|
-
move(direction) {
|
|
75
|
+
};
|
|
76
|
+
Navigator.prototype.move = function (direction) {
|
|
59
77
|
switch (direction) {
|
|
60
78
|
case 'up':
|
|
61
79
|
this._cur[0]--;
|
|
@@ -70,9 +88,10 @@ class Navigator {
|
|
|
70
88
|
this._cur[1]--;
|
|
71
89
|
break;
|
|
72
90
|
}
|
|
73
|
-
|
|
91
|
+
var _a = __read(this._cur, 2), i = _a[0], j = _a[1];
|
|
74
92
|
this._matrix[i][j] = this._VISITED;
|
|
75
93
|
this.onMove && this.onMove(this._cur);
|
|
76
|
-
}
|
|
77
|
-
|
|
94
|
+
};
|
|
95
|
+
return Navigator;
|
|
96
|
+
}());
|
|
78
97
|
exports.Navigator = Navigator;
|
|
@@ -1,7 +1,24 @@
|
|
|
1
|
-
declare class Vector2D {
|
|
1
|
+
export declare class Vector2D {
|
|
2
2
|
x: number;
|
|
3
3
|
y: number;
|
|
4
4
|
w: number;
|
|
5
|
+
constructor(x?: number, y?: number, w?: number);
|
|
6
|
+
/**
|
|
7
|
+
* Set x and y both to zero
|
|
8
|
+
*/
|
|
9
|
+
get isZero(): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* The length / magnitude of the vector
|
|
12
|
+
*/
|
|
13
|
+
get length(): number;
|
|
14
|
+
/**
|
|
15
|
+
* The squared length of the vector
|
|
16
|
+
*/
|
|
17
|
+
get lengthSq(): number;
|
|
18
|
+
/**
|
|
19
|
+
* Return the vector with rounded values
|
|
20
|
+
*/
|
|
21
|
+
get rounded(): Vector2D;
|
|
5
22
|
static add(vector1: Vector2D, vector2: Vector2D): Vector2D;
|
|
6
23
|
static subtract(vector1: Vector2D, vector2: Vector2D): Vector2D;
|
|
7
24
|
static subtractValue(vector: Vector2D, value: number): Vector2D;
|
|
@@ -49,26 +66,9 @@ declare class Vector2D {
|
|
|
49
66
|
*/
|
|
50
67
|
static angle(vector: Vector2D): number;
|
|
51
68
|
static random(maxX: number, maxY: number): Vector2D;
|
|
52
|
-
constructor(x?: number, y?: number, w?: number);
|
|
53
69
|
/**
|
|
54
70
|
* Check wether both x and y are zero
|
|
55
71
|
*/
|
|
56
72
|
zero(): void;
|
|
57
|
-
/**
|
|
58
|
-
* Set x and y both to zero
|
|
59
|
-
*/
|
|
60
|
-
get isZero(): boolean;
|
|
61
|
-
/**
|
|
62
|
-
* The length / magnitude of the vector
|
|
63
|
-
*/
|
|
64
|
-
get length(): number;
|
|
65
|
-
/**
|
|
66
|
-
* The squared length of the vector
|
|
67
|
-
*/
|
|
68
|
-
get lengthSq(): number;
|
|
69
|
-
/**
|
|
70
|
-
* Return the vector with rounded values
|
|
71
|
-
*/
|
|
72
|
-
get rounded(): Vector2D;
|
|
73
73
|
}
|
|
74
74
|
export default Vector2D;
|