data-structure-typed 0.9.16 → 1.12.9

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 (199) hide show
  1. package/.dependency-cruiser.js +449 -0
  2. package/.idea/data-structure-typed.iml +2 -0
  3. package/README.md +102 -1
  4. package/dist/data-structures/binary-tree/avl-tree.d.ts +57 -0
  5. package/dist/data-structures/binary-tree/avl-tree.js +57 -0
  6. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +27 -0
  7. package/dist/data-structures/binary-tree/binary-indexed-tree.js +27 -0
  8. package/dist/data-structures/binary-tree/binary-tree.d.ts +215 -9
  9. package/dist/data-structures/binary-tree/binary-tree.js +283 -15
  10. package/dist/data-structures/binary-tree/bst.d.ts +16 -0
  11. package/dist/data-structures/binary-tree/bst.js +12 -0
  12. package/dist/data-structures/binary-tree/segment-tree.d.ts +4 -0
  13. package/dist/data-structures/binary-tree/segment-tree.js +4 -0
  14. package/dist/data-structures/binary-tree/tree-multiset.d.ts +4 -0
  15. package/dist/data-structures/binary-tree/tree-multiset.js +4 -0
  16. package/dist/data-structures/graph/abstract-graph.d.ts +163 -13
  17. package/dist/data-structures/graph/abstract-graph.js +166 -12
  18. package/dist/data-structures/graph/directed-graph.d.ts +111 -1
  19. package/dist/data-structures/graph/directed-graph.js +122 -0
  20. package/dist/data-structures/graph/undirected-graph.d.ts +63 -0
  21. package/dist/data-structures/graph/undirected-graph.js +67 -0
  22. package/dist/data-structures/hash/coordinate-map.d.ts +32 -0
  23. package/dist/data-structures/hash/coordinate-map.js +32 -0
  24. package/dist/data-structures/hash/coordinate-set.d.ts +25 -0
  25. package/dist/data-structures/hash/coordinate-set.js +25 -0
  26. package/dist/data-structures/heap/heap.d.ts +26 -31
  27. package/dist/data-structures/heap/heap.js +23 -32
  28. package/dist/data-structures/heap/max-heap.d.ts +6 -1
  29. package/dist/data-structures/heap/max-heap.js +6 -1
  30. package/dist/data-structures/heap/min-heap.d.ts +7 -1
  31. package/dist/data-structures/heap/min-heap.js +7 -1
  32. package/dist/data-structures/index.d.ts +0 -1
  33. package/dist/data-structures/index.js +0 -1
  34. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +14 -6
  35. package/dist/data-structures/linked-list/doubly-linked-list.js +45 -8
  36. package/dist/data-structures/linked-list/singly-linked-list.d.ts +11 -8
  37. package/dist/data-structures/linked-list/singly-linked-list.js +4 -0
  38. package/dist/data-structures/matrix/matrix.d.ts +9 -0
  39. package/dist/data-structures/matrix/matrix.js +11 -0
  40. package/dist/data-structures/matrix/matrix2d.d.ts +82 -2
  41. package/dist/data-structures/matrix/matrix2d.js +82 -2
  42. package/dist/data-structures/matrix/navigator.d.ts +32 -0
  43. package/dist/data-structures/matrix/navigator.js +28 -0
  44. package/dist/data-structures/matrix/vector2d.d.ts +139 -15
  45. package/dist/data-structures/matrix/vector2d.js +139 -15
  46. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +8 -0
  47. package/dist/data-structures/priority-queue/max-priority-queue.js +8 -0
  48. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +8 -0
  49. package/dist/data-structures/priority-queue/min-priority-queue.js +8 -0
  50. package/dist/data-structures/priority-queue/priority-queue.d.ts +130 -0
  51. package/dist/data-structures/priority-queue/priority-queue.js +126 -0
  52. package/dist/data-structures/queue/deque.d.ts +69 -0
  53. package/dist/data-structures/queue/deque.js +69 -0
  54. package/dist/data-structures/queue/queue.d.ts +30 -32
  55. package/dist/data-structures/queue/queue.js +30 -32
  56. package/dist/data-structures/stack/stack.d.ts +26 -31
  57. package/dist/data-structures/stack/stack.js +26 -31
  58. package/dist/data-structures/trie/trie.d.ts +26 -6
  59. package/dist/data-structures/trie/trie.js +26 -7
  60. package/dist/data-structures/types/avl-tree.d.ts +1 -1
  61. package/dist/data-structures/types/binary-tree.d.ts +1 -1
  62. package/dist/data-structures/types/index.d.ts +1 -1
  63. package/dist/data-structures/types/index.js +1 -1
  64. package/dist/data-structures/types/singly-linked-list.d.ts +1 -5
  65. package/dist/data-structures/types/tree-multiset.d.ts +1 -1
  66. package/dist/{data-structures → utils}/trampoline.d.ts +5 -7
  67. package/dist/utils/types/index.d.ts +1 -0
  68. package/dist/utils/types/index.js +17 -0
  69. package/dist/{data-structures → utils}/types/utils.d.ts +8 -0
  70. package/dist/{data-structures → utils}/types/utils.js +1 -0
  71. package/dist/utils/utils.d.ts +1 -1
  72. package/docs/.nojekyll +1 -0
  73. package/docs/assets/highlight.css +85 -0
  74. package/docs/assets/main.js +58 -0
  75. package/docs/assets/search.js +1 -0
  76. package/docs/assets/style.css +1367 -0
  77. package/docs/classes/AVLTree.html +2046 -0
  78. package/docs/classes/AVLTreeNode.html +423 -0
  79. package/docs/classes/AaTree.html +117 -0
  80. package/docs/classes/AbstractEdge.html +198 -0
  81. package/docs/classes/AbstractGraph.html +891 -0
  82. package/docs/classes/AbstractVertex.html +164 -0
  83. package/docs/classes/ArrayDeque.html +384 -0
  84. package/docs/classes/BST.html +1893 -0
  85. package/docs/classes/BSTNode.html +425 -0
  86. package/docs/classes/BTree.html +117 -0
  87. package/docs/classes/BinaryIndexedTree.html +244 -0
  88. package/docs/classes/BinaryTree.html +1754 -0
  89. package/docs/classes/BinaryTreeNode.html +396 -0
  90. package/docs/classes/Character.html +165 -0
  91. package/docs/classes/CoordinateMap.html +394 -0
  92. package/docs/classes/CoordinateSet.html +355 -0
  93. package/docs/classes/Deque.html +617 -0
  94. package/docs/classes/DirectedEdge.html +247 -0
  95. package/docs/classes/DirectedGraph.html +1207 -0
  96. package/docs/classes/DirectedVertex.html +154 -0
  97. package/docs/classes/DoublyLinkedList.html +619 -0
  98. package/docs/classes/DoublyLinkedListNode.html +160 -0
  99. package/docs/classes/Heap.html +315 -0
  100. package/docs/classes/Matrix2D.html +447 -0
  101. package/docs/classes/MatrixNTI2D.html +181 -0
  102. package/docs/classes/MaxHeap.html +325 -0
  103. package/docs/classes/MaxPriorityQueue.html +668 -0
  104. package/docs/classes/MinHeap.html +326 -0
  105. package/docs/classes/MinPriorityQueue.html +668 -0
  106. package/docs/classes/Navigator.html +285 -0
  107. package/docs/classes/ObjectDeque.html +289 -0
  108. package/docs/classes/PriorityQueue.html +643 -0
  109. package/docs/classes/Queue.html +337 -0
  110. package/docs/classes/RBTree.html +117 -0
  111. package/docs/classes/SegmentTree.html +234 -0
  112. package/docs/classes/SegmentTreeNode.html +302 -0
  113. package/docs/classes/SinglyLinkedList.html +1035 -0
  114. package/docs/classes/SinglyLinkedListNode.html +304 -0
  115. package/docs/classes/SplayTree.html +117 -0
  116. package/docs/classes/Stack.html +313 -0
  117. package/docs/classes/TreeMultiSet.html +1897 -0
  118. package/docs/classes/Trie.html +317 -0
  119. package/docs/classes/TrieNode.html +221 -0
  120. package/docs/classes/TwoThreeTree.html +117 -0
  121. package/docs/classes/UndirectedEdge.html +220 -0
  122. package/docs/classes/UndirectedGraph.html +1006 -0
  123. package/docs/classes/UndirectedVertex.html +154 -0
  124. package/docs/classes/Vector2D.html +746 -0
  125. package/docs/enums/CP.html +126 -0
  126. package/docs/enums/FamilyPosition.html +126 -0
  127. package/docs/enums/LoopType.html +119 -0
  128. package/docs/index.html +288 -0
  129. package/docs/modules.html +146 -0
  130. package/jest.config.js +5 -0
  131. package/package.json +19 -11
  132. package/rename_clear_files.sh +29 -0
  133. package/src/assets/complexities-diff.jpg +0 -0
  134. package/src/assets/data-structure-complexities.jpg +0 -0
  135. package/src/data-structures/binary-tree/avl-tree.ts +57 -0
  136. package/src/data-structures/binary-tree/binary-indexed-tree.ts +27 -0
  137. package/src/data-structures/binary-tree/binary-tree.ts +288 -18
  138. package/src/data-structures/binary-tree/bst.ts +16 -1
  139. package/src/data-structures/binary-tree/segment-tree.ts +5 -0
  140. package/src/data-structures/binary-tree/tree-multiset.ts +4 -0
  141. package/src/data-structures/diagrams/README.md +5 -7
  142. package/src/data-structures/graph/abstract-graph.ts +167 -15
  143. package/src/data-structures/graph/diagrams/adjacency-list-pros-cons.jpg +0 -0
  144. package/src/data-structures/graph/diagrams/adjacency-list.jpg +0 -0
  145. package/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.jpg +0 -0
  146. package/src/data-structures/graph/diagrams/adjacency-matrix.jpg +0 -0
  147. package/src/data-structures/graph/diagrams/dfs-can-do.jpg +0 -0
  148. package/src/data-structures/graph/diagrams/edge-list-pros-cons.jpg +0 -0
  149. package/src/data-structures/graph/diagrams/edge-list.jpg +0 -0
  150. package/src/data-structures/graph/diagrams/max-flow.jpg +0 -0
  151. package/src/data-structures/graph/diagrams/mst.jpg +0 -0
  152. package/src/data-structures/graph/diagrams/tarjan.webp +0 -0
  153. package/src/data-structures/graph/directed-graph.ts +127 -5
  154. package/src/data-structures/graph/undirected-graph.ts +67 -1
  155. package/src/data-structures/hash/coordinate-map.ts +32 -0
  156. package/src/data-structures/hash/coordinate-set.ts +25 -0
  157. package/src/data-structures/heap/heap.ts +27 -32
  158. package/src/data-structures/heap/max-heap.ts +6 -1
  159. package/src/data-structures/heap/min-heap.ts +7 -1
  160. package/src/data-structures/index.ts +0 -1
  161. package/src/data-structures/linked-list/doubly-linked-list.ts +49 -8
  162. package/src/data-structures/linked-list/singly-linked-list.ts +39 -8
  163. package/src/data-structures/matrix/matrix.ts +11 -0
  164. package/src/data-structures/matrix/matrix2d.ts +82 -2
  165. package/src/data-structures/matrix/navigator.ts +32 -0
  166. package/src/data-structures/matrix/vector2d.ts +139 -15
  167. package/src/data-structures/priority-queue/max-priority-queue.ts +8 -0
  168. package/src/data-structures/priority-queue/min-priority-queue.ts +8 -0
  169. package/src/data-structures/priority-queue/priority-queue.ts +130 -0
  170. package/src/data-structures/queue/deque.ts +69 -0
  171. package/src/data-structures/queue/queue.ts +30 -32
  172. package/src/data-structures/stack/stack.ts +26 -31
  173. package/src/data-structures/trie/trie.ts +26 -7
  174. package/src/data-structures/types/avl-tree.ts +1 -1
  175. package/src/data-structures/types/binary-tree.ts +1 -1
  176. package/src/data-structures/types/bst.ts +1 -1
  177. package/src/data-structures/types/index.ts +1 -1
  178. package/src/data-structures/types/navigator.ts +1 -0
  179. package/src/data-structures/types/singly-linked-list.ts +1 -15
  180. package/src/data-structures/types/tree-multiset.ts +1 -1
  181. package/src/{data-structures → utils}/trampoline.ts +6 -6
  182. package/src/utils/types/index.ts +1 -0
  183. package/src/{data-structures → utils}/types/utils.ts +7 -0
  184. package/src/utils/utils.ts +12 -2
  185. package/tests/unit/data-structures/binary-tree/bst.test.ts +185 -0
  186. package/tests/unit/data-structures/graph/abstract-graph.ts +0 -0
  187. package/tests/unit/data-structures/graph/directed-graph.test.ts +71 -0
  188. package/tests/unit/data-structures/graph/index.ts +3 -0
  189. package/tests/unit/data-structures/graph/undirected-graph.ts +0 -0
  190. package/src/data-structures/graph/diagrams/adjacency-list-pros-cons.png +0 -0
  191. package/src/data-structures/graph/diagrams/adjacency-list.png +0 -0
  192. package/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.png +0 -0
  193. package/src/data-structures/graph/diagrams/adjacency-matrix.png +0 -0
  194. package/src/data-structures/graph/diagrams/dfs-can-do.png +0 -0
  195. package/src/data-structures/graph/diagrams/edge-list-pros-cons.png +0 -0
  196. package/src/data-structures/graph/diagrams/edge-list.png +0 -0
  197. package/src/data-structures/graph/diagrams/max-flow.png +0 -0
  198. package/src/data-structures/graph/diagrams/mst.png +0 -0
  199. /package/dist/{data-structures → utils}/trampoline.js +0 -0
@@ -1,5 +1,14 @@
1
+ /**
2
+ * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
3
+ * @license MIT
4
+ */
1
5
  export declare class MatrixNTI2D<T = number> {
2
6
  private readonly _matrix;
7
+ /**
8
+ * The constructor creates a matrix with the specified number of rows and columns, and initializes all elements to a
9
+ * given initial value or 0 if not provided.
10
+ * @param options - An object containing the following properties:
11
+ */
3
12
  constructor(options: {
4
13
  row: number;
5
14
  col: number;
@@ -1,12 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MatrixNTI2D = void 0;
4
+ /**
5
+ * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT
7
+ */
4
8
  // todo need to be improved
5
9
  var MatrixNTI2D = /** @class */ (function () {
10
+ /**
11
+ * The constructor creates a matrix with the specified number of rows and columns, and initializes all elements to a
12
+ * given initial value or 0 if not provided.
13
+ * @param options - An object containing the following properties:
14
+ */
6
15
  function MatrixNTI2D(options) {
7
16
  var row = options.row, col = options.col, initialVal = options.initialVal;
8
17
  this._matrix = new Array(row).fill(undefined).map(function () { return new Array(col).fill(initialVal || 0); });
9
18
  }
19
+ /* The `toArray` method returns the matrix as a two-dimensional array. It converts the internal representation of the
20
+ matrix, which is an array of arrays, into a format that is more commonly used in JavaScript. */
10
21
  MatrixNTI2D.prototype.toArray = function () {
11
22
  return this._matrix;
12
23
  };
@@ -1,25 +1,105 @@
1
+ /**
2
+ * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
3
+ * @license MIT
4
+ */
1
5
  import Vector2D from './vector2d';
2
6
  export declare class Matrix2D {
3
7
  private readonly _matrix;
8
+ /**
9
+ * The constructor function initializes a Matrix2D object with either a default identity matrix, or a provided matrix
10
+ * or Vector2D object.
11
+ * @param {number[][] | Vector2D} [value] - The `value` parameter can be either a 2D array of numbers (`number[][]`) or
12
+ * an instance of the `Vector2D` class.
13
+ */
4
14
  constructor(value?: number[][] | Vector2D);
15
+ /**
16
+ * The function returns a 2D array with three empty arrays.
17
+ * @returns An empty 2-dimensional array with 3 empty arrays inside.
18
+ */
5
19
  static get empty(): number[][];
6
20
  /**
7
- * Initialize an identity matrix
21
+ * The above function returns a 3x3 identity matrix.
22
+ * @returns The method is returning a 2-dimensional array of numbers representing the identity matrix.
8
23
  */
9
24
  static get identity(): number[][];
10
25
  /**
11
- * Return the matrix values
26
+ * The function returns a two-dimensional array of numbers.
27
+ * @returns The getter method is returning the value of the private variable `_matrix`, which is a two-dimensional
28
+ * array of numbers.
12
29
  */
13
30
  get m(): number[][];
31
+ /**
32
+ * The function "toVector" returns a new Vector2D object with the values from the first and second elements of the
33
+ * _matrix array.
34
+ * @returns A new instance of the Vector2D class is being returned. The values of the returned vector are taken from
35
+ * the first column of the matrix.
36
+ */
14
37
  get toVector(): Vector2D;
38
+ /**
39
+ * The function takes two 2D matrices as input and returns their sum as a new 2D matrix.
40
+ * @param {Matrix2D} matrix1 - Matrix2D - The first matrix to be added.
41
+ * @param {Matrix2D} matrix2 - The parameter `matrix2` is a Matrix2D object.
42
+ * @returns a new instance of the Matrix2D class, which is created using the result array.
43
+ */
15
44
  static add(matrix1: Matrix2D, matrix2: Matrix2D): Matrix2D;
45
+ /**
46
+ * The function subtracts two 2D matrices and returns the result as a new Matrix2D object.
47
+ * @param {Matrix2D} matrix1 - Matrix2D - The first matrix to subtract from.
48
+ * @param {Matrix2D} matrix2 - Matrix2D is a class representing a 2D matrix. It has a property `m` which is a 2D array
49
+ * representing the matrix elements.
50
+ * @returns a new instance of the Matrix2D class, which is created using the result array.
51
+ */
16
52
  static subtract(matrix1: Matrix2D, matrix2: Matrix2D): Matrix2D;
53
+ /**
54
+ * The function multiplies two 2D matrices and returns the result as a new Matrix2D object.
55
+ * @param {Matrix2D} matrix1 - A 2D matrix represented by the Matrix2D class.
56
+ * @param {Matrix2D} matrix2 - The parameter `matrix2` is a 2D matrix of size 3x3.
57
+ * @returns a new instance of the Matrix2D class, created using the result array.
58
+ */
17
59
  static multiply(matrix1: Matrix2D, matrix2: Matrix2D): Matrix2D;
60
+ /**
61
+ * The function multiplies each element of a 2D matrix by a given value and returns the resulting matrix.
62
+ * @param {Matrix2D} matrix - The `matrix` parameter is an instance of the `Matrix2D` class, which represents a 2D
63
+ * matrix. It contains a property `m` that is a 2D array representing the matrix elements.
64
+ * @param {number} value - The `value` parameter is a number that you want to multiply each element of the `matrix` by.
65
+ * @returns a new instance of the Matrix2D class, which is created using the result array.
66
+ */
18
67
  static multiplyByValue(matrix: Matrix2D, value: number): Matrix2D;
68
+ /**
69
+ * The function multiplies a 2D matrix by a 2D vector and returns the result as a 2D vector.
70
+ * @param {Matrix2D} matrix - The parameter "matrix" is of type Matrix2D. It represents a 2-dimensional matrix.
71
+ * @param {Vector2D} vector - The "vector" parameter is a 2D vector, represented by an object of type Vector2D.
72
+ * @returns a Vector2D.
73
+ */
19
74
  static multiplyByVector(matrix: Matrix2D, vector: Vector2D): Vector2D;
75
+ /**
76
+ * The function returns a 2D matrix that scales and flips a vector around the center of a given width and height.
77
+ * @param {number} width - The width parameter represents the width of the view or the canvas. It is a number that
78
+ * specifies the width in pixels or any other unit of measurement.
79
+ * @param {number} height - The height parameter represents the height of the view or the canvas. It is used to
80
+ * calculate the centerY value, which is the vertical center of the view.
81
+ * @returns a Matrix2D object.
82
+ */
20
83
  static view(width: number, height: number): Matrix2D;
84
+ /**
85
+ * The function scales a matrix by a given factor.
86
+ * @param {number} factor - The factor parameter is a number that represents the scaling factor by which the matrix
87
+ * should be scaled.
88
+ * @returns the result of multiplying a new instance of Matrix2D by the given factor.
89
+ */
21
90
  static scale(factor: number): Matrix2D;
91
+ /**
92
+ * The function "rotate" takes an angle in radians and returns a 2D transformation matrix for rotating objects.
93
+ * @param {number} radians - The "radians" parameter is the angle in radians by which you want to rotate an object.
94
+ * @returns The code is returning a new instance of a Matrix2D object.
95
+ */
22
96
  static rotate(radians: number): Matrix2D;
97
+ /**
98
+ * The translate function takes a 2D vector and returns a 2D matrix that represents a translation transformation.
99
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D. It represents a 2D vector with components x
100
+ * and y, and an optional w component.
101
+ * @returns The method is returning a new instance of the Matrix2D class.
102
+ */
23
103
  static translate(vector: Vector2D): Matrix2D;
24
104
  }
25
105
  export default Matrix2D;
@@ -4,8 +4,18 @@ 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
+ * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
9
+ * @license MIT
10
+ */
7
11
  var vector2d_1 = __importDefault(require("./vector2d"));
8
12
  var Matrix2D = /** @class */ (function () {
13
+ /**
14
+ * The constructor function initializes a Matrix2D object with either a default identity matrix, or a provided matrix
15
+ * or Vector2D object.
16
+ * @param {number[][] | Vector2D} [value] - The `value` parameter can be either a 2D array of numbers (`number[][]`) or
17
+ * an instance of the `Vector2D` class.
18
+ */
9
19
  function Matrix2D(value) {
10
20
  if (typeof value === 'undefined') {
11
21
  this._matrix = Matrix2D.identity;
@@ -21,6 +31,10 @@ var Matrix2D = /** @class */ (function () {
21
31
  }
22
32
  }
23
33
  Object.defineProperty(Matrix2D, "empty", {
34
+ /**
35
+ * The function returns a 2D array with three empty arrays.
36
+ * @returns An empty 2-dimensional array with 3 empty arrays inside.
37
+ */
24
38
  get: function () {
25
39
  return [[], [], []];
26
40
  },
@@ -29,7 +43,8 @@ var Matrix2D = /** @class */ (function () {
29
43
  });
30
44
  Object.defineProperty(Matrix2D, "identity", {
31
45
  /**
32
- * Initialize an identity matrix
46
+ * The above function returns a 3x3 identity matrix.
47
+ * @returns The method is returning a 2-dimensional array of numbers representing the identity matrix.
33
48
  */
34
49
  get: function () {
35
50
  return [
@@ -43,7 +58,9 @@ var Matrix2D = /** @class */ (function () {
43
58
  });
44
59
  Object.defineProperty(Matrix2D.prototype, "m", {
45
60
  /**
46
- * Return the matrix values
61
+ * The function returns a two-dimensional array of numbers.
62
+ * @returns The getter method is returning the value of the private variable `_matrix`, which is a two-dimensional
63
+ * array of numbers.
47
64
  */
48
65
  get: function () {
49
66
  return this._matrix;
@@ -52,12 +69,24 @@ var Matrix2D = /** @class */ (function () {
52
69
  configurable: true
53
70
  });
54
71
  Object.defineProperty(Matrix2D.prototype, "toVector", {
72
+ /**
73
+ * The function "toVector" returns a new Vector2D object with the values from the first and second elements of the
74
+ * _matrix array.
75
+ * @returns A new instance of the Vector2D class is being returned. The values of the returned vector are taken from
76
+ * the first column of the matrix.
77
+ */
55
78
  get: function () {
56
79
  return new vector2d_1.default(this._matrix[0][0], this._matrix[1][0]);
57
80
  },
58
81
  enumerable: false,
59
82
  configurable: true
60
83
  });
84
+ /**
85
+ * The function takes two 2D matrices as input and returns their sum as a new 2D matrix.
86
+ * @param {Matrix2D} matrix1 - Matrix2D - The first matrix to be added.
87
+ * @param {Matrix2D} matrix2 - The parameter `matrix2` is a Matrix2D object.
88
+ * @returns a new instance of the Matrix2D class, which is created using the result array.
89
+ */
61
90
  Matrix2D.add = function (matrix1, matrix2) {
62
91
  var result = Matrix2D.empty;
63
92
  for (var i = 0; i < 3; i++) {
@@ -67,6 +96,13 @@ var Matrix2D = /** @class */ (function () {
67
96
  }
68
97
  return new Matrix2D(result);
69
98
  };
99
+ /**
100
+ * The function subtracts two 2D matrices and returns the result as a new Matrix2D object.
101
+ * @param {Matrix2D} matrix1 - Matrix2D - The first matrix to subtract from.
102
+ * @param {Matrix2D} matrix2 - Matrix2D is a class representing a 2D matrix. It has a property `m` which is a 2D array
103
+ * representing the matrix elements.
104
+ * @returns a new instance of the Matrix2D class, which is created using the result array.
105
+ */
70
106
  Matrix2D.subtract = function (matrix1, matrix2) {
71
107
  var result = Matrix2D.empty;
72
108
  for (var i = 0; i < 3; i++) {
@@ -76,6 +112,12 @@ var Matrix2D = /** @class */ (function () {
76
112
  }
77
113
  return new Matrix2D(result);
78
114
  };
115
+ /**
116
+ * The function multiplies two 2D matrices and returns the result as a new Matrix2D object.
117
+ * @param {Matrix2D} matrix1 - A 2D matrix represented by the Matrix2D class.
118
+ * @param {Matrix2D} matrix2 - The parameter `matrix2` is a 2D matrix of size 3x3.
119
+ * @returns a new instance of the Matrix2D class, created using the result array.
120
+ */
79
121
  Matrix2D.multiply = function (matrix1, matrix2) {
80
122
  var result = Matrix2D.empty;
81
123
  for (var i = 0; i < 3; i++) {
@@ -88,6 +130,13 @@ var Matrix2D = /** @class */ (function () {
88
130
  }
89
131
  return new Matrix2D(result);
90
132
  };
133
+ /**
134
+ * The function multiplies each element of a 2D matrix by a given value and returns the resulting matrix.
135
+ * @param {Matrix2D} matrix - The `matrix` parameter is an instance of the `Matrix2D` class, which represents a 2D
136
+ * matrix. It contains a property `m` that is a 2D array representing the matrix elements.
137
+ * @param {number} value - The `value` parameter is a number that you want to multiply each element of the `matrix` by.
138
+ * @returns a new instance of the Matrix2D class, which is created using the result array.
139
+ */
91
140
  Matrix2D.multiplyByValue = function (matrix, value) {
92
141
  var result = Matrix2D.empty;
93
142
  for (var i = 0; i < 3; i++) {
@@ -97,9 +146,23 @@ var Matrix2D = /** @class */ (function () {
97
146
  }
98
147
  return new Matrix2D(result);
99
148
  };
149
+ /**
150
+ * The function multiplies a 2D matrix by a 2D vector and returns the result as a 2D vector.
151
+ * @param {Matrix2D} matrix - The parameter "matrix" is of type Matrix2D. It represents a 2-dimensional matrix.
152
+ * @param {Vector2D} vector - The "vector" parameter is a 2D vector, represented by an object of type Vector2D.
153
+ * @returns a Vector2D.
154
+ */
100
155
  Matrix2D.multiplyByVector = function (matrix, vector) {
101
156
  return Matrix2D.multiply(matrix, new Matrix2D(vector)).toVector;
102
157
  };
158
+ /**
159
+ * The function returns a 2D matrix that scales and flips a vector around the center of a given width and height.
160
+ * @param {number} width - The width parameter represents the width of the view or the canvas. It is a number that
161
+ * specifies the width in pixels or any other unit of measurement.
162
+ * @param {number} height - The height parameter represents the height of the view or the canvas. It is used to
163
+ * calculate the centerY value, which is the vertical center of the view.
164
+ * @returns a Matrix2D object.
165
+ */
103
166
  Matrix2D.view = function (width, height) {
104
167
  var scaleStep = 1; // Scale every vector * scaleStep
105
168
  var centerX = width / 2;
@@ -111,9 +174,20 @@ var Matrix2D = /** @class */ (function () {
111
174
  [0, 0, 1]
112
175
  ]);
113
176
  };
177
+ /**
178
+ * The function scales a matrix by a given factor.
179
+ * @param {number} factor - The factor parameter is a number that represents the scaling factor by which the matrix
180
+ * should be scaled.
181
+ * @returns the result of multiplying a new instance of Matrix2D by the given factor.
182
+ */
114
183
  Matrix2D.scale = function (factor) {
115
184
  return Matrix2D.multiplyByValue(new Matrix2D(), factor);
116
185
  };
186
+ /**
187
+ * The function "rotate" takes an angle in radians and returns a 2D transformation matrix for rotating objects.
188
+ * @param {number} radians - The "radians" parameter is the angle in radians by which you want to rotate an object.
189
+ * @returns The code is returning a new instance of a Matrix2D object.
190
+ */
117
191
  Matrix2D.rotate = function (radians) {
118
192
  var cos = Math.cos(radians);
119
193
  var sin = Math.sin(radians);
@@ -123,6 +197,12 @@ var Matrix2D = /** @class */ (function () {
123
197
  [0, 0, 1]
124
198
  ]);
125
199
  };
200
+ /**
201
+ * The translate function takes a 2D vector and returns a 2D matrix that represents a translation transformation.
202
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D. It represents a 2D vector with components x
203
+ * and y, and an optional w component.
204
+ * @returns The method is returning a new instance of the Matrix2D class.
205
+ */
126
206
  Matrix2D.translate = function (vector) {
127
207
  return new Matrix2D([
128
208
  [1, 0, vector.x],
@@ -1,7 +1,19 @@
1
+ /**
2
+ * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
3
+ * @license MIT
4
+ */
1
5
  import type { Direction, NavigatorParams, Turning } from '../types';
2
6
  export declare class Character {
3
7
  direction: Direction;
4
8
  turn: () => Character;
9
+ /**
10
+ * The constructor function takes in a direction and turning object and sets the direction and turn properties of the
11
+ * Character class.
12
+ * @param {Direction} direction - The direction parameter is used to specify the current direction of the character. It
13
+ * can be any value that represents a direction, such as "north", "south", "east", or "west".
14
+ * @param {Turning} turning - The `turning` parameter is an object that maps each direction to the corresponding
15
+ * turning direction. It is used to determine the new direction when the character turns.
16
+ */
5
17
  constructor(direction: Direction, turning: Turning);
6
18
  }
7
19
  export declare class Navigator<T = number> {
@@ -10,8 +22,28 @@ export declare class Navigator<T = number> {
10
22
  private readonly _cur;
11
23
  private _character;
12
24
  private readonly _VISITED;
25
+ /**
26
+ * The constructor initializes the Navigator object with the given parameters and sets the current position as visited
27
+ * in the matrix.
28
+ * @param - - `matrix`: a 2D array representing the grid or map
29
+ */
13
30
  constructor({ matrix, turning, onMove, init: { cur, charDir, VISITED } }: NavigatorParams<T>);
31
+ /**
32
+ * The "start" function moves the character in its current direction until it encounters an obstacle, then it turns the
33
+ * character and repeats the process.
34
+ */
14
35
  start(): void;
36
+ /**
37
+ * The function checks if there is a valid move in the specified direction in a matrix.
38
+ * @param {Direction} direction - The direction parameter is a string that represents the direction in which to check.
39
+ * It can be one of the following values: 'up', 'right', 'down', or 'left'.
40
+ * @returns a boolean value.
41
+ */
15
42
  check(direction: Direction): boolean;
43
+ /**
44
+ * The `move` function updates the current position based on the given direction and updates the matrix accordingly.
45
+ * @param {Direction} direction - The `direction` parameter is a string that represents the direction in which to move.
46
+ * It can have one of the following values: 'up', 'right', 'down', or 'left'.
47
+ */
16
48
  move(direction: Direction): void;
17
49
  }
@@ -18,6 +18,14 @@ var __read = (this && this.__read) || function (o, n) {
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
19
  exports.Navigator = exports.Character = void 0;
20
20
  var Character = /** @class */ (function () {
21
+ /**
22
+ * The constructor function takes in a direction and turning object and sets the direction and turn properties of the
23
+ * Character class.
24
+ * @param {Direction} direction - The direction parameter is used to specify the current direction of the character. It
25
+ * can be any value that represents a direction, such as "north", "south", "east", or "west".
26
+ * @param {Turning} turning - The `turning` parameter is an object that maps each direction to the corresponding
27
+ * turning direction. It is used to determine the new direction when the character turns.
28
+ */
21
29
  function Character(direction, turning) {
22
30
  this.direction = direction;
23
31
  this.turn = function () { return new Character(turning[direction], turning); };
@@ -26,6 +34,11 @@ var Character = /** @class */ (function () {
26
34
  }());
27
35
  exports.Character = Character;
28
36
  var Navigator = /** @class */ (function () {
37
+ /**
38
+ * The constructor initializes the Navigator object with the given parameters and sets the current position as visited
39
+ * in the matrix.
40
+ * @param - - `matrix`: a 2D array representing the grid or map
41
+ */
29
42
  function Navigator(_a) {
30
43
  var matrix = _a.matrix, turning = _a.turning, onMove = _a.onMove, _b = _a.init, cur = _b.cur, charDir = _b.charDir, VISITED = _b.VISITED;
31
44
  this._matrix = matrix;
@@ -36,6 +49,10 @@ var Navigator = /** @class */ (function () {
36
49
  this._VISITED = VISITED;
37
50
  this._matrix[this._cur[0]][this._cur[1]] = this._VISITED;
38
51
  }
52
+ /**
53
+ * The "start" function moves the character in its current direction until it encounters an obstacle, then it turns the
54
+ * character and repeats the process.
55
+ */
39
56
  Navigator.prototype.start = function () {
40
57
  while (this.check(this._character.direction) || this.check(this._character.turn().direction)) {
41
58
  var direction = this._character.direction;
@@ -47,6 +64,12 @@ var Navigator = /** @class */ (function () {
47
64
  }
48
65
  }
49
66
  };
67
+ /**
68
+ * The function checks if there is a valid move in the specified direction in a matrix.
69
+ * @param {Direction} direction - The direction parameter is a string that represents the direction in which to check.
70
+ * It can be one of the following values: 'up', 'right', 'down', or 'left'.
71
+ * @returns a boolean value.
72
+ */
50
73
  Navigator.prototype.check = function (direction) {
51
74
  var forward, row;
52
75
  var matrix = this._matrix;
@@ -73,6 +96,11 @@ var Navigator = /** @class */ (function () {
73
96
  }
74
97
  return forward !== undefined && forward !== this._VISITED;
75
98
  };
99
+ /**
100
+ * The `move` function updates the current position based on the given direction and updates the matrix accordingly.
101
+ * @param {Direction} direction - The `direction` parameter is a string that represents the direction in which to move.
102
+ * It can have one of the following values: 'up', 'right', 'down', or 'left'.
103
+ */
76
104
  Navigator.prototype.move = function (direction) {
77
105
  switch (direction) {
78
106
  case 'up':
@@ -1,73 +1,197 @@
1
+ /**
2
+ * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
3
+ * @license MIT
4
+ */
1
5
  export declare class Vector2D {
2
6
  x: number;
3
7
  y: number;
4
8
  w: number;
5
9
  constructor(x?: number, y?: number, w?: number);
6
10
  /**
7
- * Set x and y both to zero
11
+ * The function checks if the x and y values of a point are both zero.
12
+ * @returns A boolean value indicating whether both the x and y properties of the object are equal to 0.
8
13
  */
9
14
  get isZero(): boolean;
10
15
  /**
11
- * The length / magnitude of the vector
16
+ * The above function calculates the length of a vector using the Pythagorean theorem.
17
+ * @returns The length of a vector, calculated using the Pythagorean theorem.
12
18
  */
13
19
  get length(): number;
14
20
  /**
15
- * The squared length of the vector
21
+ * The function calculates the square of the length of a vector.
22
+ * @returns The method is returning the sum of the squares of the x and y values.
16
23
  */
17
24
  get lengthSq(): number;
18
25
  /**
19
- * Return the vector with rounded values
26
+ * The "rounded" function returns a new Vector2D object with the x and y values rounded to the nearest whole number.
27
+ * @returns The method is returning a new instance of the Vector2D class with the x and y values rounded to the nearest
28
+ * whole number.
20
29
  */
21
30
  get rounded(): Vector2D;
31
+ /**
32
+ * The function "add" takes two Vector2D objects as parameters and returns a new Vector2D object with the sum of their
33
+ * x and y components.
34
+ * @param {Vector2D} vector1 - The parameter `vector1` is an instance of the `Vector2D` class. It represents a
35
+ * 2-dimensional vector with an `x` and `y` component.
36
+ * @param {Vector2D} vector2 - The parameter "vector2" is of type Vector2D. It represents a 2-dimensional vector with
37
+ * an x and y component.
38
+ * @returns The method is returning a new instance of the Vector2D class with the x and y components of the two input
39
+ * vectors added together.
40
+ */
22
41
  static add(vector1: Vector2D, vector2: Vector2D): Vector2D;
42
+ /**
43
+ * The subtract function takes two Vector2D objects as parameters and returns a new Vector2D object with the x and y
44
+ * components subtracted.
45
+ * @param {Vector2D} vector1 - The parameter `vector1` is an instance of the `Vector2D` class, representing a
46
+ * 2-dimensional vector. It has properties `x` and `y` which represent the x and y components of the vector
47
+ * respectively.
48
+ * @param {Vector2D} vector2 - The parameter "vector2" is a Vector2D object. It represents the second vector that you
49
+ * want to subtract from the first vector.
50
+ * @returns The method is returning a new Vector2D object with the x and y components subtracted from vector1 and
51
+ * vector2.
52
+ */
23
53
  static subtract(vector1: Vector2D, vector2: Vector2D): Vector2D;
54
+ /**
55
+ * The function subtracts a given value from the x and y components of a Vector2D object and returns a new Vector2D
56
+ * object.
57
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector with
58
+ * x and y components.
59
+ * @param {number} value - The "value" parameter is a number that will be subtracted from both the x and y components
60
+ * of the "vector" parameter.
61
+ * @returns A new Vector2D object with the x and y values subtracted by the given value.
62
+ */
24
63
  static subtractValue(vector: Vector2D, value: number): Vector2D;
64
+ /**
65
+ * The function multiplies a Vector2D object by a given value.
66
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector with
67
+ * x and y components.
68
+ * @param {number} value - The "value" parameter is a number that represents the value by which the x and y components
69
+ * of the vector will be multiplied.
70
+ * @returns A new Vector2D object with the x and y values multiplied by the given value.
71
+ */
25
72
  static multiply(vector: Vector2D, value: number): Vector2D;
73
+ /**
74
+ * The function divides the x and y components of a Vector2D by a given value and returns a new Vector2D.
75
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector with
76
+ * x and y components.
77
+ * @param {number} value - The value parameter is a number that will be used to divide the x and y components of the
78
+ * vector.
79
+ * @returns A new instance of the Vector2D class with the x and y values divided by the given value.
80
+ */
26
81
  static divide(vector: Vector2D, value: number): Vector2D;
82
+ /**
83
+ * The function checks if two Vector2D objects are equal by comparing their x and y values.
84
+ * @param {Vector2D} vector1 - The parameter `vector1` is of type `Vector2D`, which represents a 2-dimensional vector.
85
+ * It has two properties: `x` and `y`, which represent the x and y components of the vector, respectively.
86
+ * @param {Vector2D} vector2 - The parameter "vector2" is of type Vector2D.
87
+ * @returns a boolean value, which indicates whether the two input vectors are equal or not.
88
+ */
27
89
  static equals(vector1: Vector2D, vector2: Vector2D): boolean;
90
+ /**
91
+ * The function checks if two Vector2D objects are equal within a specified rounding factor.
92
+ * @param {Vector2D} vector1 - The first vector to compare.
93
+ * @param {Vector2D} vector2 - The parameter "vector2" is a Vector2D object, which represents a 2-dimensional vector.
94
+ * It is used as one of the inputs for the "equalsRounded" function.
95
+ * @param [roundingFactor=12] - The roundingFactor parameter is used to determine the threshold for considering two
96
+ * vectors as equal. If the absolute difference in the x and y components of the vectors is less than the
97
+ * roundingFactor, the vectors are considered equal.
98
+ * @returns a boolean value.
99
+ */
28
100
  static equalsRounded(vector1: Vector2D, vector2: Vector2D, roundingFactor?: number): boolean;
29
101
  /**
30
- * Normalizes the vector if it matches a certain condition
102
+ * The normalize function takes a vector as input and returns a normalized version of the vector.Normalizes the vector if it matches a certain condition
103
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D.
104
+ * @returns the normalized vector if its length is greater than a very small value (epsilon), otherwise it returns the
105
+ * original vector.
31
106
  */
32
107
  static normalize(vector: Vector2D): Vector2D;
33
108
  /**
34
- * Adjusts x and y so that the length of the vector does not exceed max
109
+ * The function truncates a vector to a maximum length if it exceeds that length.Adjusts x and y so that the length of the vector does not exceed max
110
+ * @param {Vector2D} vector - A 2D vector represented by the Vector2D class.
111
+ * @param {number} max - The `max` parameter is a number that represents the maximum length that the `vector` should
112
+ * have.
113
+ * @returns either the original vector or a truncated version of the vector, depending on whether the length of the
114
+ * vector is greater than the maximum value specified.
35
115
  */
36
116
  static truncate(vector: Vector2D, max: number): Vector2D;
37
117
  /**
38
- * The vector that is perpendicular to this one
118
+ * The function returns a new Vector2D object that is perpendicular to the input vector.The vector that is perpendicular to this one
119
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D.
120
+ * @returns A new Vector2D object is being returned.
39
121
  */
40
122
  static perp(vector: Vector2D): Vector2D;
41
123
  /**
42
- * returns the vector that is the reverse of this vector
124
+ * The reverse function takes a Vector2D object and returns a new Vector2D object with the negated x and y values.
125
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector. It
126
+ * has two properties: "x" and "y", which represent the x and y components of the vector, respectively.
127
+ * @returns A new Vector2D object with the negated x and y values of the input vector. Returns the vector that is the reverse of this vector
43
128
  */
44
129
  static reverse(vector: Vector2D): Vector2D;
130
+ /**
131
+ * The function takes a Vector2D object as input and returns a new Vector2D object with the absolute values of its x
132
+ * and y components.
133
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector. It
134
+ * has two properties: "x" and "y", which represent the x and y components of the vector, respectively.
135
+ * @returns The method is returning a new Vector2D object with the absolute values of the x and y components of the
136
+ * input vector.
137
+ */
45
138
  static abs(vector: Vector2D): Vector2D;
46
139
  /**
47
- * The dot product of v1 and v2
140
+ * The dot function calculates the dot product of two 2D vectors.The dot product of v1 and v2
141
+ * @param {Vector2D} vector1 - The parameter `vector1` represents a 2D vector with its x and y components.
142
+ * @param {Vector2D} vector2 - The "vector2" parameter is a Vector2D object. It represents a two-dimensional vector
143
+ * with an x and y component.
144
+ * @returns The dot product of the two input vectors.
48
145
  */
49
146
  static dot(vector1: Vector2D, vector2: Vector2D): number;
50
147
  /**
51
- * The distance between this and the vector
148
+ * The function calculates the distance between two points in a two-dimensional space.
149
+ * @param {Vector2D} vector1 - The parameter `vector1` represents the first vector in 2D space, while `vector2`
150
+ * represents the second vector. Each vector has an `x` and `y` component, which represent their respective coordinates
151
+ * in the 2D space.
152
+ * @param {Vector2D} vector2 - The `vector2` parameter represents the second vector in the calculation of distance. It
153
+ * is an instance of the `Vector2D` class, which typically has properties `x` and `y` representing the coordinates of
154
+ * the vector in a 2D space.
155
+ * @returns The distance between vector1 and vector2.
52
156
  */
53
157
  static distance(vector1: Vector2D, vector2: Vector2D): number;
54
158
  /**
55
- * The distance between this and the vector squared
159
+ * The function calculates the squared distance between two 2D vectors.
160
+ * @param {Vector2D} vector1 - The parameter `vector1` represents the first vector, which is an instance of the
161
+ * `Vector2D` class. It contains the x and y coordinates of the vector.
162
+ * @param {Vector2D} vector2 - The `vector2` parameter represents the second vector in a two-dimensional space. It has
163
+ * properties `x` and `y` which represent the coordinates of the vector.
164
+ * @returns the square of the distance between the two input vectors.
56
165
  */
57
166
  static distanceSq(vector1: Vector2D, vector2: Vector2D): number;
58
167
  /**
59
- * Returns positive if v2 is clockwise of this vector, negative if counterclockwise
168
+ * The sign function determines the sign of the cross product between two 2D vectors.
60
169
  * (assuming the Y axis is pointing down, X axis to right like a Window app)
170
+ * @param {Vector2D} vector1 - The parameter `vector1` is of type `Vector2D`, which represents a 2-dimensional vector.
171
+ * It likely has properties `x` and `y` representing the x and y components of the vector, respectively.
172
+ * @param {Vector2D} vector2 - The above code defines a function called "sign" that takes two parameters: vector1 and
173
+ * vector2. Both vector1 and vector2 are of type Vector2D.
174
+ * @returns either -1 or 1. Returns positive if v2 is clockwise of this vector, negative if counterclockwise
61
175
  */
62
176
  static sign(vector1: Vector2D, vector2: Vector2D): number;
63
177
  /**
64
- * Returns the angle between origin and the given vector in radians
65
- * @param vector
178
+ * The function calculates the angle between a given vector and the negative y-axis.
179
+ * @param {Vector2D} vector - The "vector" parameter is an instance of the Vector2D class, which represents a
180
+ * 2-dimensional vector. It has two properties: "x" and "y", which represent the x and y components of the vector,
181
+ * respectively.
182
+ * @returns the angle between the given vector and the vector (0, -1) in radians.Returns the angle between origin and the given vector in radians
66
183
  */
67
184
  static angle(vector: Vector2D): number;
185
+ /**
186
+ * The function "random" generates a random Vector2D object with x and y values within the specified range.
187
+ * @param {number} maxX - The maxX parameter represents the maximum value for the x-coordinate of the random vector.
188
+ * @param {number} maxY - The `maxY` parameter represents the maximum value for the y-coordinate of the generated
189
+ * random vector.
190
+ * @returns a new instance of the Vector2D class with random x and y values.
191
+ */
68
192
  static random(maxX: number, maxY: number): Vector2D;
69
193
  /**
70
- * Check wether both x and y are zero
194
+ * The function sets the values of x and y to zero.
71
195
  */
72
196
  zero(): void;
73
197
  }