data-structure-typed 0.8.17 → 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.
Files changed (219) hide show
  1. package/.idea/modules.xml +1 -1
  2. package/README.md +197 -2
  3. package/dist/data-structures/binary-tree/aa-tree.js +5 -2
  4. package/dist/data-structures/binary-tree/avl-tree.d.ts +1 -5
  5. package/dist/data-structures/binary-tree/avl-tree.js +93 -46
  6. package/dist/data-structures/binary-tree/b-tree.js +5 -2
  7. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +1 -1
  8. package/dist/data-structures/binary-tree/binary-indexed-tree.js +14 -13
  9. package/dist/data-structures/binary-tree/binary-tree.d.ts +20 -32
  10. package/dist/data-structures/binary-tree/binary-tree.js +480 -370
  11. package/dist/data-structures/binary-tree/bst.d.ts +4 -8
  12. package/dist/data-structures/binary-tree/bst.js +152 -107
  13. package/dist/data-structures/binary-tree/index.d.ts +7 -0
  14. package/dist/data-structures/binary-tree/index.js +7 -0
  15. package/dist/data-structures/binary-tree/rb-tree.js +5 -2
  16. package/dist/data-structures/binary-tree/segment-tree.d.ts +3 -3
  17. package/dist/data-structures/binary-tree/segment-tree.js +91 -61
  18. package/dist/data-structures/binary-tree/splay-tree.js +5 -2
  19. package/dist/data-structures/binary-tree/tree-multiset.d.ts +1 -5
  20. package/dist/data-structures/binary-tree/tree-multiset.js +31 -11
  21. package/dist/data-structures/binary-tree/two-three-tree.js +5 -2
  22. package/dist/data-structures/graph/abstract-graph.d.ts +5 -33
  23. package/dist/data-structures/graph/abstract-graph.js +546 -311
  24. package/dist/data-structures/graph/directed-graph.d.ts +5 -13
  25. package/dist/data-structures/graph/directed-graph.js +250 -128
  26. package/dist/data-structures/graph/undirected-graph.d.ts +4 -3
  27. package/dist/data-structures/graph/undirected-graph.js +166 -81
  28. package/dist/data-structures/hash/coordinate-map.d.ts +1 -1
  29. package/dist/data-structures/hash/coordinate-map.js +38 -20
  30. package/dist/data-structures/hash/coordinate-set.js +33 -15
  31. package/dist/data-structures/hash/index.d.ts +5 -0
  32. package/dist/data-structures/hash/index.js +5 -0
  33. package/dist/data-structures/heap/heap.d.ts +2 -8
  34. package/dist/data-structures/heap/heap.js +36 -31
  35. package/dist/data-structures/heap/max-heap.d.ts +3 -2
  36. package/dist/data-structures/heap/max-heap.js +27 -9
  37. package/dist/data-structures/heap/min-heap.d.ts +3 -2
  38. package/dist/data-structures/heap/min-heap.js +27 -9
  39. package/dist/data-structures/index.d.ts +2 -0
  40. package/dist/data-structures/index.js +2 -0
  41. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +0 -1
  42. package/dist/data-structures/linked-list/doubly-linked-list.js +56 -53
  43. package/dist/data-structures/linked-list/singly-linked-list.d.ts +8 -12
  44. package/dist/data-structures/linked-list/singly-linked-list.js +308 -174
  45. package/dist/data-structures/matrix/matrix.js +8 -7
  46. package/dist/data-structures/matrix/matrix2d.d.ts +5 -5
  47. package/dist/data-structures/matrix/matrix2d.js +80 -63
  48. package/dist/data-structures/matrix/navigator.d.ts +2 -16
  49. package/dist/data-structures/matrix/navigator.js +37 -18
  50. package/dist/data-structures/matrix/vector2d.d.ts +18 -18
  51. package/dist/data-structures/matrix/vector2d.js +117 -94
  52. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +3 -2
  53. package/dist/data-structures/priority-queue/max-priority-queue.js +25 -8
  54. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +3 -2
  55. package/dist/data-structures/priority-queue/min-priority-queue.js +25 -8
  56. package/dist/data-structures/priority-queue/priority-queue.d.ts +15 -21
  57. package/dist/data-structures/priority-queue/priority-queue.js +159 -116
  58. package/dist/data-structures/queue/deque.js +82 -56
  59. package/dist/data-structures/queue/index.d.ts +1 -0
  60. package/dist/data-structures/queue/index.js +1 -0
  61. package/dist/data-structures/queue/queue.d.ts +9 -10
  62. package/dist/data-structures/queue/queue.js +34 -34
  63. package/dist/data-structures/stack/stack.d.ts +9 -10
  64. package/dist/data-structures/stack/stack.js +31 -31
  65. package/dist/data-structures/trampoline.d.ts +14 -23
  66. package/dist/data-structures/trampoline.js +103 -25
  67. package/dist/data-structures/trie/trie.d.ts +13 -3
  68. package/dist/data-structures/trie/trie.js +234 -80
  69. package/dist/data-structures/types/abstract-graph.d.ts +29 -0
  70. package/dist/data-structures/types/abstract-graph.js +2 -0
  71. package/dist/data-structures/types/avl-tree.d.ts +5 -0
  72. package/dist/data-structures/types/avl-tree.js +2 -0
  73. package/dist/data-structures/types/binary-tree.d.ts +16 -0
  74. package/dist/data-structures/types/binary-tree.js +2 -0
  75. package/dist/data-structures/types/bst.d.ts +7 -0
  76. package/dist/data-structures/types/bst.js +2 -0
  77. package/dist/data-structures/types/directed-graph.d.ts +10 -0
  78. package/dist/data-structures/types/directed-graph.js +2 -0
  79. package/dist/data-structures/types/doubly-linked-list.d.ts +1 -0
  80. package/dist/data-structures/types/doubly-linked-list.js +2 -0
  81. package/dist/data-structures/types/heap.d.ts +7 -0
  82. package/dist/data-structures/types/heap.js +2 -0
  83. package/dist/data-structures/types/index.d.ts +13 -0
  84. package/dist/data-structures/types/index.js +29 -0
  85. package/dist/data-structures/types/navigator.d.ts +14 -0
  86. package/dist/data-structures/types/navigator.js +2 -0
  87. package/dist/data-structures/types/priority-queue.d.ts +7 -0
  88. package/dist/data-structures/types/priority-queue.js +2 -0
  89. package/dist/data-structures/types/segment-tree.d.ts +1 -0
  90. package/dist/data-structures/types/segment-tree.js +2 -0
  91. package/dist/data-structures/types/singly-linked-list.d.ts +5 -0
  92. package/dist/data-structures/types/singly-linked-list.js +2 -0
  93. package/dist/data-structures/types/tree-multiset.d.ts +5 -0
  94. package/dist/data-structures/types/tree-multiset.js +2 -0
  95. package/dist/{types → data-structures/types}/utils.d.ts +7 -1
  96. package/dist/{types → data-structures/types}/utils.js +20 -19
  97. package/dist/{utils.d.ts → utils/utils.d.ts} +6 -23
  98. package/dist/utils/utils.js +651 -0
  99. package/package.json +20 -42
  100. package/src/data-structures/binary-tree/avl-tree.ts +1 -6
  101. package/src/data-structures/binary-tree/binary-indexed-tree.ts +4 -4
  102. package/src/data-structures/binary-tree/binary-tree.ts +184 -139
  103. package/src/data-structures/binary-tree/bst.ts +15 -24
  104. package/src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif +0 -0
  105. package/src/data-structures/binary-tree/diagrams/bst-rotation.gif +0 -0
  106. package/src/data-structures/binary-tree/diagrams/segment-tree.png +0 -0
  107. package/src/data-structures/binary-tree/index.ts +7 -0
  108. package/src/data-structures/binary-tree/segment-tree.ts +20 -12
  109. package/src/data-structures/binary-tree/tree-multiset.ts +1 -4
  110. package/src/data-structures/diagrams/README.md +7 -0
  111. package/src/data-structures/graph/abstract-graph.ts +58 -94
  112. package/src/data-structures/graph/diagrams/adjacency-list-pros-cons.png +0 -0
  113. package/src/data-structures/graph/diagrams/adjacency-list.png +0 -0
  114. package/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.png +0 -0
  115. package/src/data-structures/graph/diagrams/adjacency-matrix.png +0 -0
  116. package/src/data-structures/graph/diagrams/dfs-can-do.png +0 -0
  117. package/src/data-structures/graph/diagrams/edge-list-pros-cons.png +0 -0
  118. package/src/data-structures/graph/diagrams/edge-list.png +0 -0
  119. package/src/data-structures/graph/diagrams/max-flow.png +0 -0
  120. package/src/data-structures/graph/diagrams/mst.png +0 -0
  121. package/src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png +0 -0
  122. package/src/data-structures/graph/diagrams/tarjan-complicate-simple.png +0 -0
  123. package/src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png +0 -0
  124. package/src/data-structures/graph/diagrams/tarjan.mp4 +0 -0
  125. package/src/data-structures/graph/directed-graph.ts +12 -28
  126. package/src/data-structures/graph/undirected-graph.ts +11 -10
  127. package/src/data-structures/hash/coordinate-map.ts +1 -1
  128. package/src/data-structures/hash/index.ts +5 -0
  129. package/src/data-structures/heap/heap.ts +2 -11
  130. package/src/data-structures/heap/max-heap.ts +3 -2
  131. package/src/data-structures/heap/min-heap.ts +3 -2
  132. package/src/data-structures/index.ts +2 -0
  133. package/src/data-structures/linked-list/doubly-linked-list.ts +1 -9
  134. package/src/data-structures/linked-list/singly-linked-list.ts +18 -32
  135. package/src/data-structures/matrix/matrix2d.ts +11 -11
  136. package/src/data-structures/matrix/navigator.ts +2 -14
  137. package/src/data-structures/matrix/vector2d.ts +52 -52
  138. package/src/data-structures/priority-queue/max-priority-queue.ts +4 -3
  139. package/src/data-structures/priority-queue/min-priority-queue.ts +4 -3
  140. package/src/data-structures/priority-queue/priority-queue.ts +70 -78
  141. package/src/data-structures/queue/deque.ts +2 -2
  142. package/src/data-structures/queue/index.ts +1 -0
  143. package/src/data-structures/queue/queue.ts +12 -13
  144. package/src/data-structures/stack/stack.ts +12 -13
  145. package/src/data-structures/trampoline.ts +31 -71
  146. package/src/data-structures/trie/trie.ts +61 -11
  147. package/src/data-structures/types/abstract-graph.ts +51 -0
  148. package/src/data-structures/types/avl-tree.ts +6 -0
  149. package/src/data-structures/types/binary-tree.ts +15 -0
  150. package/src/data-structures/types/bst.ts +5 -0
  151. package/src/data-structures/types/directed-graph.ts +18 -0
  152. package/src/data-structures/types/doubly-linked-list.ts +1 -0
  153. package/src/data-structures/types/heap.ts +8 -0
  154. package/src/data-structures/types/index.ts +13 -0
  155. package/src/data-structures/types/navigator.ts +12 -0
  156. package/src/data-structures/types/priority-queue.ts +9 -0
  157. package/src/data-structures/types/segment-tree.ts +1 -0
  158. package/src/data-structures/types/singly-linked-list.ts +15 -0
  159. package/src/data-structures/types/tree-multiset.ts +3 -0
  160. package/src/{types → data-structures/types}/utils.ts +20 -5
  161. package/src/utils/index.ts +1 -0
  162. package/src/{utils.ts → utils/utils.ts} +32 -132
  163. package/tsconfig.json +9 -6
  164. package/dist/types/data-structures/binary-tree/aa-tree.d.ts +0 -2
  165. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +0 -21
  166. package/dist/types/data-structures/binary-tree/b-tree.d.ts +0 -2
  167. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -8
  168. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +0 -140
  169. package/dist/types/data-structures/binary-tree/bst.d.ts +0 -32
  170. package/dist/types/data-structures/binary-tree/index.d.ts +0 -4
  171. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +0 -2
  172. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +0 -33
  173. package/dist/types/data-structures/binary-tree/splay-tree.d.ts +0 -2
  174. package/dist/types/data-structures/binary-tree/tree-multiset.d.ts +0 -11
  175. package/dist/types/data-structures/binary-tree/two-three-tree.d.ts +0 -2
  176. package/dist/types/data-structures/graph/abstract-graph.d.ts +0 -126
  177. package/dist/types/data-structures/graph/directed-graph.d.ts +0 -51
  178. package/dist/types/data-structures/graph/index.d.ts +0 -3
  179. package/dist/types/data-structures/graph/undirected-graph.d.ts +0 -24
  180. package/dist/types/data-structures/hash/coordinate-map.d.ts +0 -8
  181. package/dist/types/data-structures/hash/coordinate-set.d.ts +0 -7
  182. package/dist/types/data-structures/hash/hash-table.d.ts +0 -1
  183. package/dist/types/data-structures/hash/index.d.ts +0 -1
  184. package/dist/types/data-structures/hash/pair.d.ts +0 -1
  185. package/dist/types/data-structures/hash/tree-map.d.ts +0 -1
  186. package/dist/types/data-structures/hash/tree-set.d.ts +0 -1
  187. package/dist/types/data-structures/heap/heap.d.ts +0 -72
  188. package/dist/types/data-structures/heap/index.d.ts +0 -3
  189. package/dist/types/data-structures/heap/max-heap.d.ts +0 -14
  190. package/dist/types/data-structures/heap/min-heap.d.ts +0 -14
  191. package/dist/types/data-structures/index.d.ts +0 -9
  192. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +0 -59
  193. package/dist/types/data-structures/linked-list/index.d.ts +0 -2
  194. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +0 -358
  195. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +0 -1
  196. package/dist/types/data-structures/matrix/index.d.ts +0 -3
  197. package/dist/types/data-structures/matrix/matrix.d.ts +0 -9
  198. package/dist/types/data-structures/matrix/matrix2d.d.ts +0 -25
  199. package/dist/types/data-structures/matrix/navigator.d.ts +0 -31
  200. package/dist/types/data-structures/matrix/vector2d.d.ts +0 -74
  201. package/dist/types/data-structures/priority-queue/index.d.ts +0 -3
  202. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +0 -4
  203. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +0 -4
  204. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +0 -36
  205. package/dist/types/data-structures/queue/deque.d.ts +0 -37
  206. package/dist/types/data-structures/queue/index.d.ts +0 -1
  207. package/dist/types/data-structures/queue/queue.d.ts +0 -76
  208. package/dist/types/data-structures/stack/index.d.ts +0 -1
  209. package/dist/types/data-structures/stack/stack.d.ts +0 -69
  210. package/dist/types/data-structures/trampoline.d.ts +0 -25
  211. package/dist/types/data-structures/trie/index.d.ts +0 -1
  212. package/dist/types/data-structures/trie/trie.d.ts +0 -28
  213. package/dist/types/types/index.d.ts +0 -1
  214. package/dist/types/types/utils.d.ts +0 -46
  215. package/dist/utils.js +0 -569
  216. package/src/types/index.ts +0 -1
  217. package/src/types/patches/index.d.ts +0 -0
  218. /package/dist/{types → utils}/index.d.ts +0 -0
  219. /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
- class MatrixNTI2D {
6
- constructor(options) {
7
- const { row, col, initialVal } = options;
8
- this._matrix = new Array(row).fill(undefined).map(() => new Array(col).fill(initialVal || 0));
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
- const vector2d_1 = __importDefault(require("./vector2d"));
8
- class Matrix2D {
9
- constructor(value) {
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
- * Return the matrix values
25
- */
26
- get m() {
27
- return this._matrix;
28
- }
29
- static get empty() {
30
- return [[], [], []];
31
- }
32
- get toVector() {
33
- return new vector2d_1.default(this._matrix[0][0], this._matrix[1][0]);
34
- }
35
- /**
36
- * Initialize an identity matrix
37
- */
38
- static get identity() {
39
- return [
40
- [1, 0, 0],
41
- [0, 1, 0],
42
- [0, 0, 1]
43
- ];
44
- }
45
- static add(matrix1, matrix2) {
46
- const result = Matrix2D.empty;
47
- for (let i = 0; i < 3; i++) {
48
- for (let j = 0; j < 3; j++) {
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
- static subtract(matrix1, matrix2) {
55
- const result = Matrix2D.empty;
56
- for (let i = 0; i < 3; i++) {
57
- for (let j = 0; j < 3; j++) {
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
- static multiply(matrix1, matrix2) {
64
- const result = Matrix2D.empty;
65
- for (let i = 0; i < 3; i++) {
66
- for (let j = 0; j < 3; j++) {
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 (let k = 0; k < 3; k++) {
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
- static multiplyByValue(matrix, value) {
76
- const result = Matrix2D.empty;
77
- for (let i = 0; i < 3; i++) {
78
- for (let j = 0; j < 3; j++) {
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
- static multiplyByVector(matrix, vector) {
99
+ };
100
+ Matrix2D.multiplyByVector = function (matrix, vector) {
85
101
  return Matrix2D.multiply(matrix, new Matrix2D(vector)).toVector;
86
- }
87
- static view(width, height) {
88
- const scaleStep = 1; // Scale every vector * scaleStep
89
- const centerX = width / 2;
90
- const centerY = height / 2;
91
- const flipX = Math.cos(Math.PI); // rotate 180deg / 3.14radian around X-axis
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
- static scale(factor) {
113
+ };
114
+ Matrix2D.scale = function (factor) {
99
115
  return Matrix2D.multiplyByValue(new Matrix2D(), factor);
100
- }
101
- static rotate(radians) {
102
- const cos = Math.cos(radians);
103
- const sin = Math.sin(radians);
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
- static translate(vector) {
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 = 'up' | 'right' | 'down' | 'left';
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
- class Character {
5
- constructor(direction, turning) {
20
+ var Character = /** @class */ (function () {
21
+ function Character(direction, turning) {
6
22
  this.direction = direction;
7
- this.turn = () => new Character(turning[direction], turning);
23
+ this.turn = function () { return new Character(turning[direction], turning); };
8
24
  }
9
- }
25
+ return Character;
26
+ }());
10
27
  exports.Character = Character;
11
- class Navigator {
12
- constructor({ matrix, turning, onMove, init: { cur, charDir, VISITED } }) {
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
- const { direction } = this._character;
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
- let forward, row;
34
- const matrix = this._matrix;
35
- const [i, j] = this._cur;
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
- const [i, j] = this._cur;
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;