data-structure-typed 0.8.18 → 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 (287) hide show
  1. package/.dependency-cruiser.js +449 -0
  2. package/.idea/data-structure-typed.iml +2 -0
  3. package/.idea/modules.xml +1 -1
  4. package/README.md +298 -2
  5. package/dist/data-structures/binary-tree/aa-tree.js +5 -2
  6. package/dist/data-structures/binary-tree/avl-tree.d.ts +58 -5
  7. package/dist/data-structures/binary-tree/avl-tree.js +150 -46
  8. package/dist/data-structures/binary-tree/b-tree.js +5 -2
  9. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +28 -1
  10. package/dist/data-structures/binary-tree/binary-indexed-tree.js +41 -13
  11. package/dist/data-structures/binary-tree/binary-tree.d.ts +230 -36
  12. package/dist/data-structures/binary-tree/binary-tree.js +747 -369
  13. package/dist/data-structures/binary-tree/bst.d.ts +20 -8
  14. package/dist/data-structures/binary-tree/bst.js +164 -107
  15. package/dist/data-structures/binary-tree/rb-tree.js +5 -2
  16. package/dist/data-structures/binary-tree/segment-tree.d.ts +7 -3
  17. package/dist/data-structures/binary-tree/segment-tree.js +95 -61
  18. package/dist/data-structures/binary-tree/splay-tree.js +5 -2
  19. package/dist/data-structures/binary-tree/tree-multiset.d.ts +5 -5
  20. package/dist/data-structures/binary-tree/tree-multiset.js +35 -11
  21. package/dist/data-structures/binary-tree/two-three-tree.js +5 -2
  22. package/dist/data-structures/graph/abstract-graph.d.ts +168 -46
  23. package/dist/data-structures/graph/abstract-graph.js +712 -323
  24. package/dist/data-structures/graph/directed-graph.d.ts +114 -12
  25. package/dist/data-structures/graph/directed-graph.js +372 -128
  26. package/dist/data-structures/graph/undirected-graph.d.ts +67 -3
  27. package/dist/data-structures/graph/undirected-graph.js +233 -81
  28. package/dist/data-structures/hash/coordinate-map.d.ts +33 -1
  29. package/dist/data-structures/hash/coordinate-map.js +70 -20
  30. package/dist/data-structures/hash/coordinate-set.d.ts +25 -0
  31. package/dist/data-structures/hash/coordinate-set.js +58 -15
  32. package/dist/data-structures/hash/index.d.ts +5 -0
  33. package/dist/data-structures/hash/index.js +5 -0
  34. package/dist/data-structures/heap/heap.d.ts +26 -37
  35. package/dist/data-structures/heap/heap.js +56 -60
  36. package/dist/data-structures/heap/max-heap.d.ts +8 -2
  37. package/dist/data-structures/heap/max-heap.js +32 -9
  38. package/dist/data-structures/heap/min-heap.d.ts +9 -2
  39. package/dist/data-structures/heap/min-heap.js +33 -9
  40. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +14 -7
  41. package/dist/data-structures/linked-list/doubly-linked-list.js +101 -61
  42. package/dist/data-structures/linked-list/singly-linked-list.d.ts +18 -19
  43. package/dist/data-structures/linked-list/singly-linked-list.js +312 -174
  44. package/dist/data-structures/matrix/matrix.d.ts +9 -0
  45. package/dist/data-structures/matrix/matrix.js +19 -7
  46. package/dist/data-structures/matrix/matrix2d.d.ts +84 -4
  47. package/dist/data-structures/matrix/matrix2d.js +158 -61
  48. package/dist/data-structures/matrix/navigator.d.ts +34 -16
  49. package/dist/data-structures/matrix/navigator.js +65 -18
  50. package/dist/data-structures/matrix/vector2d.d.ts +153 -29
  51. package/dist/data-structures/matrix/vector2d.js +249 -102
  52. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +11 -2
  53. package/dist/data-structures/priority-queue/max-priority-queue.js +33 -8
  54. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +11 -2
  55. package/dist/data-structures/priority-queue/min-priority-queue.js +33 -8
  56. package/dist/data-structures/priority-queue/priority-queue.d.ts +145 -21
  57. package/dist/data-structures/priority-queue/priority-queue.js +285 -116
  58. package/dist/data-structures/queue/deque.d.ts +69 -0
  59. package/dist/data-structures/queue/deque.js +151 -56
  60. package/dist/data-structures/queue/queue.d.ts +34 -37
  61. package/dist/data-structures/queue/queue.js +59 -61
  62. package/dist/data-structures/stack/stack.d.ts +29 -35
  63. package/dist/data-structures/stack/stack.js +51 -56
  64. package/dist/data-structures/trie/trie.d.ts +36 -6
  65. package/dist/data-structures/trie/trie.js +256 -83
  66. package/dist/data-structures/types/abstract-graph.d.ts +29 -0
  67. package/dist/data-structures/types/abstract-graph.js +2 -0
  68. package/dist/data-structures/types/avl-tree.d.ts +5 -0
  69. package/dist/data-structures/types/avl-tree.js +2 -0
  70. package/dist/data-structures/types/binary-tree.d.ts +16 -0
  71. package/dist/data-structures/types/binary-tree.js +2 -0
  72. package/dist/data-structures/types/bst.d.ts +7 -0
  73. package/dist/data-structures/types/bst.js +2 -0
  74. package/dist/data-structures/types/directed-graph.d.ts +10 -0
  75. package/dist/data-structures/types/directed-graph.js +2 -0
  76. package/dist/data-structures/types/doubly-linked-list.d.ts +1 -0
  77. package/dist/data-structures/types/doubly-linked-list.js +2 -0
  78. package/dist/data-structures/types/heap.d.ts +7 -0
  79. package/dist/data-structures/types/heap.js +2 -0
  80. package/dist/data-structures/types/index.d.ts +13 -0
  81. package/dist/data-structures/types/index.js +29 -0
  82. package/dist/data-structures/types/navigator.d.ts +14 -0
  83. package/dist/data-structures/types/navigator.js +2 -0
  84. package/dist/data-structures/types/priority-queue.d.ts +7 -0
  85. package/dist/data-structures/types/priority-queue.js +2 -0
  86. package/dist/data-structures/types/segment-tree.d.ts +1 -0
  87. package/dist/data-structures/types/segment-tree.js +2 -0
  88. package/dist/data-structures/types/singly-linked-list.js +2 -0
  89. package/dist/data-structures/types/tree-multiset.d.ts +5 -0
  90. package/dist/data-structures/types/tree-multiset.js +2 -0
  91. package/dist/utils/trampoline.d.ts +14 -0
  92. package/dist/utils/trampoline.js +130 -0
  93. package/dist/utils/types/index.js +17 -0
  94. package/dist/{types → utils}/types/utils.d.ts +15 -1
  95. package/dist/{types → utils/types}/utils.js +21 -19
  96. package/dist/{utils.d.ts → utils/utils.d.ts} +5 -22
  97. package/dist/utils/utils.js +651 -0
  98. package/docs/.nojekyll +1 -0
  99. package/docs/assets/highlight.css +85 -0
  100. package/docs/assets/main.js +58 -0
  101. package/docs/assets/search.js +1 -0
  102. package/docs/assets/style.css +1367 -0
  103. package/docs/classes/AVLTree.html +2046 -0
  104. package/docs/classes/AVLTreeNode.html +423 -0
  105. package/docs/classes/AaTree.html +117 -0
  106. package/docs/classes/AbstractEdge.html +198 -0
  107. package/docs/classes/AbstractGraph.html +891 -0
  108. package/docs/classes/AbstractVertex.html +164 -0
  109. package/docs/classes/ArrayDeque.html +384 -0
  110. package/docs/classes/BST.html +1893 -0
  111. package/docs/classes/BSTNode.html +425 -0
  112. package/docs/classes/BTree.html +117 -0
  113. package/docs/classes/BinaryIndexedTree.html +244 -0
  114. package/docs/classes/BinaryTree.html +1754 -0
  115. package/docs/classes/BinaryTreeNode.html +396 -0
  116. package/docs/classes/Character.html +165 -0
  117. package/docs/classes/CoordinateMap.html +394 -0
  118. package/docs/classes/CoordinateSet.html +355 -0
  119. package/docs/classes/Deque.html +617 -0
  120. package/docs/classes/DirectedEdge.html +247 -0
  121. package/docs/classes/DirectedGraph.html +1207 -0
  122. package/docs/classes/DirectedVertex.html +154 -0
  123. package/docs/classes/DoublyLinkedList.html +619 -0
  124. package/docs/classes/DoublyLinkedListNode.html +160 -0
  125. package/docs/classes/Heap.html +315 -0
  126. package/docs/classes/Matrix2D.html +447 -0
  127. package/docs/classes/MatrixNTI2D.html +181 -0
  128. package/docs/classes/MaxHeap.html +325 -0
  129. package/docs/classes/MaxPriorityQueue.html +668 -0
  130. package/docs/classes/MinHeap.html +326 -0
  131. package/docs/classes/MinPriorityQueue.html +668 -0
  132. package/docs/classes/Navigator.html +285 -0
  133. package/docs/classes/ObjectDeque.html +289 -0
  134. package/docs/classes/PriorityQueue.html +643 -0
  135. package/docs/classes/Queue.html +337 -0
  136. package/docs/classes/RBTree.html +117 -0
  137. package/docs/classes/SegmentTree.html +234 -0
  138. package/docs/classes/SegmentTreeNode.html +302 -0
  139. package/docs/classes/SinglyLinkedList.html +1035 -0
  140. package/docs/classes/SinglyLinkedListNode.html +304 -0
  141. package/docs/classes/SplayTree.html +117 -0
  142. package/docs/classes/Stack.html +313 -0
  143. package/docs/classes/TreeMultiSet.html +1897 -0
  144. package/docs/classes/Trie.html +317 -0
  145. package/docs/classes/TrieNode.html +221 -0
  146. package/docs/classes/TwoThreeTree.html +117 -0
  147. package/docs/classes/UndirectedEdge.html +220 -0
  148. package/docs/classes/UndirectedGraph.html +1006 -0
  149. package/docs/classes/UndirectedVertex.html +154 -0
  150. package/docs/classes/Vector2D.html +746 -0
  151. package/docs/enums/CP.html +126 -0
  152. package/docs/enums/FamilyPosition.html +126 -0
  153. package/docs/enums/LoopType.html +119 -0
  154. package/docs/index.html +288 -0
  155. package/docs/modules.html +146 -0
  156. package/jest.config.js +5 -0
  157. package/package.json +33 -47
  158. package/rename_clear_files.sh +29 -0
  159. package/src/assets/complexities-diff.jpg +0 -0
  160. package/src/assets/data-structure-complexities.jpg +0 -0
  161. package/src/data-structures/binary-tree/avl-tree.ts +58 -6
  162. package/src/data-structures/binary-tree/binary-indexed-tree.ts +31 -4
  163. package/src/data-structures/binary-tree/binary-tree.ts +460 -145
  164. package/src/data-structures/binary-tree/bst.ts +31 -25
  165. package/src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif +0 -0
  166. package/src/data-structures/binary-tree/diagrams/bst-rotation.gif +0 -0
  167. package/src/data-structures/binary-tree/diagrams/segment-tree.png +0 -0
  168. package/src/data-structures/binary-tree/segment-tree.ts +25 -12
  169. package/src/data-structures/binary-tree/tree-multiset.ts +5 -4
  170. package/src/data-structures/diagrams/README.md +5 -0
  171. package/src/data-structures/graph/abstract-graph.ts +224 -108
  172. package/src/data-structures/graph/diagrams/adjacency-list-pros-cons.jpg +0 -0
  173. package/src/data-structures/graph/diagrams/adjacency-list.jpg +0 -0
  174. package/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.jpg +0 -0
  175. package/src/data-structures/graph/diagrams/adjacency-matrix.jpg +0 -0
  176. package/src/data-structures/graph/diagrams/dfs-can-do.jpg +0 -0
  177. package/src/data-structures/graph/diagrams/edge-list-pros-cons.jpg +0 -0
  178. package/src/data-structures/graph/diagrams/edge-list.jpg +0 -0
  179. package/src/data-structures/graph/diagrams/max-flow.jpg +0 -0
  180. package/src/data-structures/graph/diagrams/mst.jpg +0 -0
  181. package/src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png +0 -0
  182. package/src/data-structures/graph/diagrams/tarjan-complicate-simple.png +0 -0
  183. package/src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png +0 -0
  184. package/src/data-structures/graph/diagrams/tarjan.mp4 +0 -0
  185. package/src/data-structures/graph/diagrams/tarjan.webp +0 -0
  186. package/src/data-structures/graph/directed-graph.ts +132 -26
  187. package/src/data-structures/graph/undirected-graph.ts +78 -11
  188. package/src/data-structures/hash/coordinate-map.ts +33 -1
  189. package/src/data-structures/hash/coordinate-set.ts +25 -0
  190. package/src/data-structures/hash/index.ts +5 -0
  191. package/src/data-structures/heap/heap.ts +27 -41
  192. package/src/data-structures/heap/max-heap.ts +8 -2
  193. package/src/data-structures/heap/min-heap.ts +9 -2
  194. package/src/data-structures/linked-list/doubly-linked-list.ts +50 -17
  195. package/src/data-structures/linked-list/singly-linked-list.ts +56 -39
  196. package/src/data-structures/matrix/matrix.ts +11 -0
  197. package/src/data-structures/matrix/matrix2d.ts +90 -10
  198. package/src/data-structures/matrix/navigator.ts +34 -14
  199. package/src/data-structures/matrix/vector2d.ts +187 -63
  200. package/src/data-structures/priority-queue/max-priority-queue.ts +12 -3
  201. package/src/data-structures/priority-queue/min-priority-queue.ts +12 -3
  202. package/src/data-structures/priority-queue/priority-queue.ts +200 -78
  203. package/src/data-structures/queue/deque.ts +71 -2
  204. package/src/data-structures/queue/queue.ts +37 -40
  205. package/src/data-structures/stack/stack.ts +32 -38
  206. package/src/data-structures/trie/trie.ts +83 -14
  207. package/src/data-structures/types/abstract-graph.ts +51 -0
  208. package/src/data-structures/types/avl-tree.ts +6 -0
  209. package/src/data-structures/types/binary-tree.ts +15 -0
  210. package/src/data-structures/types/bst.ts +5 -0
  211. package/src/data-structures/types/directed-graph.ts +18 -0
  212. package/src/data-structures/types/doubly-linked-list.ts +1 -0
  213. package/src/data-structures/types/heap.ts +8 -0
  214. package/src/data-structures/types/index.ts +13 -0
  215. package/src/data-structures/types/navigator.ts +13 -0
  216. package/src/data-structures/types/priority-queue.ts +9 -0
  217. package/src/data-structures/types/segment-tree.ts +1 -0
  218. package/src/data-structures/types/singly-linked-list.ts +1 -0
  219. package/src/data-structures/types/tree-multiset.ts +3 -0
  220. package/src/utils/index.ts +1 -0
  221. package/src/utils/trampoline.ts +51 -0
  222. package/src/utils/types/index.ts +1 -0
  223. package/src/{types → utils/types}/utils.ts +27 -5
  224. package/src/{utils.ts → utils/utils.ts} +41 -131
  225. package/tests/unit/data-structures/binary-tree/bst.test.ts +185 -0
  226. package/tests/unit/data-structures/graph/directed-graph.test.ts +71 -0
  227. package/{dist/types/data-structures/graph/index.d.ts → tests/unit/data-structures/graph/index.ts} +1 -1
  228. package/tests/unit/data-structures/graph/undirected-graph.ts +0 -0
  229. package/tsconfig.json +9 -6
  230. package/dist/data-structures/trampoline.d.ts +0 -25
  231. package/dist/data-structures/trampoline.js +0 -52
  232. package/dist/types/data-structures/binary-tree/aa-tree.d.ts +0 -2
  233. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +0 -21
  234. package/dist/types/data-structures/binary-tree/b-tree.d.ts +0 -2
  235. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -8
  236. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +0 -140
  237. package/dist/types/data-structures/binary-tree/bst.d.ts +0 -32
  238. package/dist/types/data-structures/binary-tree/index.d.ts +0 -4
  239. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +0 -2
  240. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +0 -33
  241. package/dist/types/data-structures/binary-tree/splay-tree.d.ts +0 -2
  242. package/dist/types/data-structures/binary-tree/tree-multiset.d.ts +0 -11
  243. package/dist/types/data-structures/binary-tree/two-three-tree.d.ts +0 -2
  244. package/dist/types/data-structures/graph/abstract-graph.d.ts +0 -126
  245. package/dist/types/data-structures/graph/directed-graph.d.ts +0 -51
  246. package/dist/types/data-structures/graph/undirected-graph.d.ts +0 -24
  247. package/dist/types/data-structures/hash/coordinate-map.d.ts +0 -8
  248. package/dist/types/data-structures/hash/coordinate-set.d.ts +0 -7
  249. package/dist/types/data-structures/hash/index.d.ts +0 -1
  250. package/dist/types/data-structures/hash/pair.d.ts +0 -1
  251. package/dist/types/data-structures/hash/tree-map.d.ts +0 -1
  252. package/dist/types/data-structures/hash/tree-set.d.ts +0 -1
  253. package/dist/types/data-structures/heap/heap.d.ts +0 -72
  254. package/dist/types/data-structures/heap/index.d.ts +0 -3
  255. package/dist/types/data-structures/heap/max-heap.d.ts +0 -14
  256. package/dist/types/data-structures/heap/min-heap.d.ts +0 -14
  257. package/dist/types/data-structures/index.d.ts +0 -9
  258. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +0 -59
  259. package/dist/types/data-structures/linked-list/index.d.ts +0 -2
  260. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +0 -358
  261. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +0 -1
  262. package/dist/types/data-structures/matrix/index.d.ts +0 -3
  263. package/dist/types/data-structures/matrix/matrix.d.ts +0 -9
  264. package/dist/types/data-structures/matrix/matrix2d.d.ts +0 -25
  265. package/dist/types/data-structures/matrix/navigator.d.ts +0 -31
  266. package/dist/types/data-structures/matrix/vector2d.d.ts +0 -74
  267. package/dist/types/data-structures/priority-queue/index.d.ts +0 -3
  268. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +0 -4
  269. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +0 -4
  270. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +0 -36
  271. package/dist/types/data-structures/queue/deque.d.ts +0 -37
  272. package/dist/types/data-structures/queue/index.d.ts +0 -1
  273. package/dist/types/data-structures/queue/queue.d.ts +0 -76
  274. package/dist/types/data-structures/stack/index.d.ts +0 -1
  275. package/dist/types/data-structures/stack/stack.d.ts +0 -69
  276. package/dist/types/data-structures/trampoline.d.ts +0 -25
  277. package/dist/types/data-structures/trie/index.d.ts +0 -1
  278. package/dist/types/data-structures/trie/trie.d.ts +0 -28
  279. package/dist/types/utils.d.ts +0 -46
  280. package/dist/utils.js +0 -569
  281. package/src/data-structures/trampoline.ts +0 -91
  282. package/src/types/index.ts +0 -1
  283. /package/dist/{types/data-structures/hash/hash-table.d.ts → data-structures/types/singly-linked-list.d.ts} +0 -0
  284. /package/dist/{types → utils}/index.d.ts +0 -0
  285. /package/dist/{types → utils}/index.js +0 -0
  286. /package/dist/{types → utils}/types/index.d.ts +0 -0
  287. /package/{src/types/patches/index.d.ts → tests/unit/data-structures/graph/abstract-graph.ts} +0 -0
@@ -1,74 +1,198 @@
1
- declare class Vector2D {
1
+ /**
2
+ * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
3
+ * @license MIT
4
+ */
5
+ export declare class Vector2D {
2
6
  x: number;
3
7
  y: number;
4
8
  w: number;
9
+ constructor(x?: number, y?: number, w?: number);
10
+ /**
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.
13
+ */
14
+ get isZero(): boolean;
15
+ /**
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.
18
+ */
19
+ get length(): number;
20
+ /**
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.
23
+ */
24
+ get lengthSq(): number;
25
+ /**
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.
29
+ */
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
+ */
5
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
+ */
6
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
+ */
7
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
+ */
8
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
+ */
9
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
+ */
10
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
+ */
11
100
  static equalsRounded(vector1: Vector2D, vector2: Vector2D, roundingFactor?: number): boolean;
12
101
  /**
13
- * 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.
14
106
  */
15
107
  static normalize(vector: Vector2D): Vector2D;
16
108
  /**
17
- * 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.
18
115
  */
19
116
  static truncate(vector: Vector2D, max: number): Vector2D;
20
117
  /**
21
- * 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.
22
121
  */
23
122
  static perp(vector: Vector2D): Vector2D;
24
123
  /**
25
- * 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
26
128
  */
27
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
+ */
28
138
  static abs(vector: Vector2D): Vector2D;
29
139
  /**
30
- * 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.
31
145
  */
32
146
  static dot(vector1: Vector2D, vector2: Vector2D): number;
33
147
  /**
34
- * 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.
35
156
  */
36
157
  static distance(vector1: Vector2D, vector2: Vector2D): number;
37
158
  /**
38
- * 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.
39
165
  */
40
166
  static distanceSq(vector1: Vector2D, vector2: Vector2D): number;
41
167
  /**
42
- * 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.
43
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
44
175
  */
45
176
  static sign(vector1: Vector2D, vector2: Vector2D): number;
46
177
  /**
47
- * Returns the angle between origin and the given vector in radians
48
- * @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
49
183
  */
50
184
  static angle(vector: Vector2D): number;
51
- static random(maxX: number, maxY: number): Vector2D;
52
- constructor(x?: number, y?: number, w?: number);
53
- /**
54
- * Check wether both x and y are zero
55
- */
56
- zero(): void;
57
- /**
58
- * Set x and y both to zero
59
- */
60
- get isZero(): boolean;
61
185
  /**
62
- * The length / magnitude of the vector
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.
63
191
  */
64
- get length(): number;
65
- /**
66
- * The squared length of the vector
67
- */
68
- get lengthSq(): number;
192
+ static random(maxX: number, maxY: number): Vector2D;
69
193
  /**
70
- * Return the vector with rounded values
194
+ * The function sets the values of x and y to zero.
71
195
  */
72
- get rounded(): Vector2D;
196
+ zero(): void;
73
197
  }
74
198
  export default Vector2D;
@@ -1,111 +1,219 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- class Vector2D {
4
- static add(vector1, vector2) {
5
- return new Vector2D(vector1.x + vector2.x, vector1.y + vector2.y);
3
+ exports.Vector2D = void 0;
4
+ /**
5
+ * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT
7
+ */
8
+ var Vector2D = /** @class */ (function () {
9
+ function Vector2D(x, y, w // needed for matrix multiplication
10
+ ) {
11
+ if (x === void 0) { x = 0; }
12
+ if (y === void 0) { y = 0; }
13
+ if (w === void 0) { w = 1; }
14
+ this.x = x;
15
+ this.y = y;
16
+ this.w = w;
6
17
  }
7
- static subtract(vector1, vector2) {
18
+ Object.defineProperty(Vector2D.prototype, "isZero", {
19
+ /**
20
+ * The function checks if the x and y values of a point are both zero.
21
+ * @returns A boolean value indicating whether both the x and y properties of the object are equal to 0.
22
+ */
23
+ get: function () {
24
+ return this.x === 0 && this.y === 0;
25
+ },
26
+ enumerable: false,
27
+ configurable: true
28
+ });
29
+ Object.defineProperty(Vector2D.prototype, "length", {
30
+ /**
31
+ * The above function calculates the length of a vector using the Pythagorean theorem.
32
+ * @returns The length of a vector, calculated using the Pythagorean theorem.
33
+ */
34
+ get: function () {
35
+ return Math.sqrt((this.x * this.x) + (this.y * this.y));
36
+ },
37
+ enumerable: false,
38
+ configurable: true
39
+ });
40
+ Object.defineProperty(Vector2D.prototype, "lengthSq", {
41
+ /**
42
+ * The function calculates the square of the length of a vector.
43
+ * @returns The method is returning the sum of the squares of the x and y values.
44
+ */
45
+ get: function () {
46
+ return (this.x * this.x) + (this.y * this.y);
47
+ },
48
+ enumerable: false,
49
+ configurable: true
50
+ });
51
+ Object.defineProperty(Vector2D.prototype, "rounded", {
52
+ /**
53
+ * The "rounded" function returns a new Vector2D object with the x and y values rounded to the nearest whole number.
54
+ * @returns The method is returning a new instance of the Vector2D class with the x and y values rounded to the nearest
55
+ * whole number.
56
+ */
57
+ get: function () {
58
+ return new Vector2D(Math.round(this.x), Math.round(this.y));
59
+ },
60
+ enumerable: false,
61
+ configurable: true
62
+ });
63
+ /**
64
+ * The function "add" takes two Vector2D objects as parameters and returns a new Vector2D object with the sum of their
65
+ * x and y components.
66
+ * @param {Vector2D} vector1 - The parameter `vector1` is an instance of the `Vector2D` class. It represents a
67
+ * 2-dimensional vector with an `x` and `y` component.
68
+ * @param {Vector2D} vector2 - The parameter "vector2" is of type Vector2D. It represents a 2-dimensional vector with
69
+ * an x and y component.
70
+ * @returns The method is returning a new instance of the Vector2D class with the x and y components of the two input
71
+ * vectors added together.
72
+ */
73
+ Vector2D.add = function (vector1, vector2) {
74
+ return new Vector2D(vector1.x + vector2.x, vector1.y + vector2.y);
75
+ };
76
+ /**
77
+ * The subtract function takes two Vector2D objects as parameters and returns a new Vector2D object with the x and y
78
+ * components subtracted.
79
+ * @param {Vector2D} vector1 - The parameter `vector1` is an instance of the `Vector2D` class, representing a
80
+ * 2-dimensional vector. It has properties `x` and `y` which represent the x and y components of the vector
81
+ * respectively.
82
+ * @param {Vector2D} vector2 - The parameter "vector2" is a Vector2D object. It represents the second vector that you
83
+ * want to subtract from the first vector.
84
+ * @returns The method is returning a new Vector2D object with the x and y components subtracted from vector1 and
85
+ * vector2.
86
+ */
87
+ Vector2D.subtract = function (vector1, vector2) {
8
88
  return new Vector2D(vector1.x - vector2.x, vector1.y - vector2.y);
9
- }
10
- static subtractValue(vector, value) {
89
+ };
90
+ /**
91
+ * The function subtracts a given value from the x and y components of a Vector2D object and returns a new Vector2D
92
+ * object.
93
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector with
94
+ * x and y components.
95
+ * @param {number} value - The "value" parameter is a number that will be subtracted from both the x and y components
96
+ * of the "vector" parameter.
97
+ * @returns A new Vector2D object with the x and y values subtracted by the given value.
98
+ */
99
+ Vector2D.subtractValue = function (vector, value) {
11
100
  return new Vector2D(vector.x - value, vector.y - value);
12
- }
13
- static multiply(vector, value) {
101
+ };
102
+ /**
103
+ * The function multiplies a Vector2D object by a given value.
104
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector with
105
+ * x and y components.
106
+ * @param {number} value - The "value" parameter is a number that represents the value by which the x and y components
107
+ * of the vector will be multiplied.
108
+ * @returns A new Vector2D object with the x and y values multiplied by the given value.
109
+ */
110
+ Vector2D.multiply = function (vector, value) {
14
111
  return new Vector2D(vector.x * value, vector.y * value);
15
- }
16
- static divide(vector, value) {
112
+ };
113
+ /**
114
+ * The function divides the x and y components of a Vector2D by a given value and returns a new Vector2D.
115
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector with
116
+ * x and y components.
117
+ * @param {number} value - The value parameter is a number that will be used to divide the x and y components of the
118
+ * vector.
119
+ * @returns A new instance of the Vector2D class with the x and y values divided by the given value.
120
+ */
121
+ Vector2D.divide = function (vector, value) {
17
122
  return new Vector2D(vector.x / value, vector.y / value);
18
- }
19
- static equals(vector1, vector2) {
123
+ };
124
+ /**
125
+ * The function checks if two Vector2D objects are equal by comparing their x and y values.
126
+ * @param {Vector2D} vector1 - The parameter `vector1` is of type `Vector2D`, which represents a 2-dimensional vector.
127
+ * It has two properties: `x` and `y`, which represent the x and y components of the vector, respectively.
128
+ * @param {Vector2D} vector2 - The parameter "vector2" is of type Vector2D.
129
+ * @returns a boolean value, which indicates whether the two input vectors are equal or not.
130
+ */
131
+ Vector2D.equals = function (vector1, vector2) {
20
132
  return vector1.x === vector2.x && vector1.y === vector2.y;
21
- }
22
- static equalsRounded(vector1, vector2, roundingFactor = 12) {
23
- const vector = Vector2D.abs(Vector2D.subtract(vector1, vector2));
133
+ };
134
+ /**
135
+ * The function checks if two Vector2D objects are equal within a specified rounding factor.
136
+ * @param {Vector2D} vector1 - The first vector to compare.
137
+ * @param {Vector2D} vector2 - The parameter "vector2" is a Vector2D object, which represents a 2-dimensional vector.
138
+ * It is used as one of the inputs for the "equalsRounded" function.
139
+ * @param [roundingFactor=12] - The roundingFactor parameter is used to determine the threshold for considering two
140
+ * vectors as equal. If the absolute difference in the x and y components of the vectors is less than the
141
+ * roundingFactor, the vectors are considered equal.
142
+ * @returns a boolean value.
143
+ */
144
+ Vector2D.equalsRounded = function (vector1, vector2, roundingFactor) {
145
+ if (roundingFactor === void 0) { roundingFactor = 12; }
146
+ var vector = Vector2D.abs(Vector2D.subtract(vector1, vector2));
24
147
  if (vector.x < roundingFactor && vector.y < roundingFactor) {
25
148
  return true;
26
149
  }
27
150
  return false;
28
- }
151
+ };
29
152
  /**
30
- * Normalizes the vector if it matches a certain condition
153
+ * 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
154
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D.
155
+ * @returns the normalized vector if its length is greater than a very small value (epsilon), otherwise it returns the
156
+ * original vector.
31
157
  */
32
- static normalize(vector) {
33
- const length = vector.length;
158
+ Vector2D.normalize = function (vector) {
159
+ var length = vector.length;
34
160
  if (length > 2.220446049250313e-16) { // Epsilon
35
161
  return Vector2D.divide(vector, length);
36
162
  }
37
163
  return vector;
38
- }
164
+ };
39
165
  /**
40
- * Adjusts x and y so that the length of the vector does not exceed max
166
+ * 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
167
+ * @param {Vector2D} vector - A 2D vector represented by the Vector2D class.
168
+ * @param {number} max - The `max` parameter is a number that represents the maximum length that the `vector` should
169
+ * have.
170
+ * @returns either the original vector or a truncated version of the vector, depending on whether the length of the
171
+ * vector is greater than the maximum value specified.
41
172
  */
42
- static truncate(vector, max) {
173
+ Vector2D.truncate = function (vector, max) {
43
174
  if (vector.length > max) {
44
175
  return Vector2D.multiply(Vector2D.normalize(vector), max);
45
176
  }
46
177
  return vector;
47
- }
178
+ };
48
179
  /**
49
- * The vector that is perpendicular to this one
180
+ * The function returns a new Vector2D object that is perpendicular to the input vector.The vector that is perpendicular to this one
181
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D.
182
+ * @returns A new Vector2D object is being returned.
50
183
  */
51
- static perp(vector) {
184
+ Vector2D.perp = function (vector) {
52
185
  return new Vector2D(-vector.y, vector.x);
53
- }
186
+ };
54
187
  /**
55
- * returns the vector that is the reverse of this vector
188
+ * The reverse function takes a Vector2D object and returns a new Vector2D object with the negated x and y values.
189
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector. It
190
+ * has two properties: "x" and "y", which represent the x and y components of the vector, respectively.
191
+ * @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
56
192
  */
57
- static reverse(vector) {
193
+ Vector2D.reverse = function (vector) {
58
194
  return new Vector2D(-vector.x, -vector.y);
59
- }
60
- static abs(vector) {
61
- return new Vector2D(Math.abs(vector.x), Math.abs(vector.y));
62
- }
63
- /**
64
- * The dot product of v1 and v2
65
- */
66
- static dot(vector1, vector2) {
67
- return (vector1.x * vector2.x) + (vector1.y * vector2.y);
68
- }
195
+ };
69
196
  /**
70
- * The distance between this and the vector
197
+ * The function takes a Vector2D object as input and returns a new Vector2D object with the absolute values of its x
198
+ * and y components.
199
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector. It
200
+ * has two properties: "x" and "y", which represent the x and y components of the vector, respectively.
201
+ * @returns The method is returning a new Vector2D object with the absolute values of the x and y components of the
202
+ * input vector.
71
203
  */
72
- static distance(vector1, vector2) {
73
- const ySeparation = vector2.y - vector1.y;
74
- const xSeparation = vector2.x - vector1.x;
75
- return Math.sqrt((ySeparation * ySeparation) + (xSeparation * xSeparation));
76
- }
77
- /**
78
- * The distance between this and the vector squared
79
- */
80
- static distanceSq(vector1, vector2) {
81
- const ySeparation = vector2.y - vector1.y;
82
- const xSeparation = vector2.x - vector1.x;
83
- return (ySeparation * ySeparation) + (xSeparation * xSeparation);
84
- }
85
- /**
86
- * Returns positive if v2 is clockwise of this vector, negative if counterclockwise
87
- * (assuming the Y axis is pointing down, X axis to right like a Window app)
88
- */
89
- static sign(vector1, vector2) {
90
- if (vector1.y * vector2.x > vector1.x * vector2.y) {
91
- return -1;
92
- }
93
- return 1;
94
- }
204
+ Vector2D.abs = function (vector) {
205
+ return new Vector2D(Math.abs(vector.x), Math.abs(vector.y));
206
+ };
95
207
  /**
96
- * Returns the angle between origin and the given vector in radians
97
- * @param vector
208
+ * The dot function calculates the dot product of two 2D vectors.The dot product of v1 and v2
209
+ * @param {Vector2D} vector1 - The parameter `vector1` represents a 2D vector with its x and y components.
210
+ * @param {Vector2D} vector2 - The "vector2" parameter is a Vector2D object. It represents a two-dimensional vector
211
+ * with an x and y component.
212
+ * @returns The dot product of the two input vectors.
98
213
  */
99
- static angle(vector) {
100
- const origin = new Vector2D(0, -1);
101
- const radian = Math.acos(Vector2D.dot(vector, origin) / (vector.length * origin.length));
102
- return Vector2D.sign(vector, origin) === 1 ? ((Math.PI * 2) - radian) : radian;
103
- }
104
- static random(maxX, maxY) {
105
- const randX = Math.floor(Math.random() * maxX - (maxX / 2));
106
- const randY = Math.floor(Math.random() * maxY - (maxY / 2));
107
- return new Vector2D(randX, randY);
108
- }
214
+ Vector2D.dot = function (vector1, vector2) {
215
+ return (vector1.x * vector2.x) + (vector1.y * vector2.y);
216
+ };
109
217
  // /**
110
218
  // * Transform vectors based on the current tranformation matrices: translation, rotation and scale
111
219
  // * @param vectors The vectors to transform
@@ -120,42 +228,81 @@ class Vector2D {
120
228
  // public static transformList(vectors: Vector2D[], transformation: Matrix2D): Vector2D[] {
121
229
  // return vectors.map(vector => Matrix2D.multiplyByVector(transformation, vector))
122
230
  // }
123
- constructor(x = 0, y = 0, w = 1 // needed for matrix multiplication
124
- ) {
125
- this.x = x;
126
- this.y = y;
127
- this.w = w;
128
- }
129
231
  /**
130
- * Check wether both x and y are zero
232
+ * The function calculates the distance between two points in a two-dimensional space.
233
+ * @param {Vector2D} vector1 - The parameter `vector1` represents the first vector in 2D space, while `vector2`
234
+ * represents the second vector. Each vector has an `x` and `y` component, which represent their respective coordinates
235
+ * in the 2D space.
236
+ * @param {Vector2D} vector2 - The `vector2` parameter represents the second vector in the calculation of distance. It
237
+ * is an instance of the `Vector2D` class, which typically has properties `x` and `y` representing the coordinates of
238
+ * the vector in a 2D space.
239
+ * @returns The distance between vector1 and vector2.
131
240
  */
132
- zero() {
133
- this.x = 0;
134
- this.y = 0;
135
- }
241
+ Vector2D.distance = function (vector1, vector2) {
242
+ var ySeparation = vector2.y - vector1.y;
243
+ var xSeparation = vector2.x - vector1.x;
244
+ return Math.sqrt((ySeparation * ySeparation) + (xSeparation * xSeparation));
245
+ };
136
246
  /**
137
- * Set x and y both to zero
247
+ * The function calculates the squared distance between two 2D vectors.
248
+ * @param {Vector2D} vector1 - The parameter `vector1` represents the first vector, which is an instance of the
249
+ * `Vector2D` class. It contains the x and y coordinates of the vector.
250
+ * @param {Vector2D} vector2 - The `vector2` parameter represents the second vector in a two-dimensional space. It has
251
+ * properties `x` and `y` which represent the coordinates of the vector.
252
+ * @returns the square of the distance between the two input vectors.
138
253
  */
139
- get isZero() {
140
- return this.x === 0 && this.y === 0;
141
- }
254
+ Vector2D.distanceSq = function (vector1, vector2) {
255
+ var ySeparation = vector2.y - vector1.y;
256
+ var xSeparation = vector2.x - vector1.x;
257
+ return (ySeparation * ySeparation) + (xSeparation * xSeparation);
258
+ };
142
259
  /**
143
- * The length / magnitude of the vector
260
+ * The sign function determines the sign of the cross product between two 2D vectors.
261
+ * (assuming the Y axis is pointing down, X axis to right like a Window app)
262
+ * @param {Vector2D} vector1 - The parameter `vector1` is of type `Vector2D`, which represents a 2-dimensional vector.
263
+ * It likely has properties `x` and `y` representing the x and y components of the vector, respectively.
264
+ * @param {Vector2D} vector2 - The above code defines a function called "sign" that takes two parameters: vector1 and
265
+ * vector2. Both vector1 and vector2 are of type Vector2D.
266
+ * @returns either -1 or 1. Returns positive if v2 is clockwise of this vector, negative if counterclockwise
144
267
  */
145
- get length() {
146
- return Math.sqrt((this.x * this.x) + (this.y * this.y));
147
- }
268
+ Vector2D.sign = function (vector1, vector2) {
269
+ if (vector1.y * vector2.x > vector1.x * vector2.y) {
270
+ return -1;
271
+ }
272
+ return 1;
273
+ };
148
274
  /**
149
- * The squared length of the vector
275
+ * The function calculates the angle between a given vector and the negative y-axis.
276
+ * @param {Vector2D} vector - The "vector" parameter is an instance of the Vector2D class, which represents a
277
+ * 2-dimensional vector. It has two properties: "x" and "y", which represent the x and y components of the vector,
278
+ * respectively.
279
+ * @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
150
280
  */
151
- get lengthSq() {
152
- return (this.x * this.x) + (this.y * this.y);
153
- }
281
+ Vector2D.angle = function (vector) {
282
+ var origin = new Vector2D(0, -1);
283
+ var radian = Math.acos(Vector2D.dot(vector, origin) / (vector.length * origin.length));
284
+ return Vector2D.sign(vector, origin) === 1 ? ((Math.PI * 2) - radian) : radian;
285
+ };
154
286
  /**
155
- * Return the vector with rounded values
287
+ * The function "random" generates a random Vector2D object with x and y values within the specified range.
288
+ * @param {number} maxX - The maxX parameter represents the maximum value for the x-coordinate of the random vector.
289
+ * @param {number} maxY - The `maxY` parameter represents the maximum value for the y-coordinate of the generated
290
+ * random vector.
291
+ * @returns a new instance of the Vector2D class with random x and y values.
156
292
  */
157
- get rounded() {
158
- return new Vector2D(Math.round(this.x), Math.round(this.y));
159
- }
160
- }
293
+ Vector2D.random = function (maxX, maxY) {
294
+ var randX = Math.floor(Math.random() * maxX - (maxX / 2));
295
+ var randY = Math.floor(Math.random() * maxY - (maxY / 2));
296
+ return new Vector2D(randX, randY);
297
+ };
298
+ /**
299
+ * The function sets the values of x and y to zero.
300
+ */
301
+ Vector2D.prototype.zero = function () {
302
+ this.x = 0;
303
+ this.y = 0;
304
+ };
305
+ return Vector2D;
306
+ }());
307
+ exports.Vector2D = Vector2D;
161
308
  exports.default = Vector2D;
@@ -1,4 +1,13 @@
1
- import { PriorityQueue, PriorityQueueOptions } from './priority-queue';
1
+ /**
2
+ * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
3
+ * @license MIT
4
+ */
5
+ import { PriorityQueue } from './priority-queue';
6
+ import type { PriorityQueueOptions } from '../types';
2
7
  export declare class MaxPriorityQueue<T = number> extends PriorityQueue<T> {
3
- constructor(options: PriorityQueueOptions<T>);
8
+ /**
9
+ * The constructor initializes a PriorityQueue with optional nodes and a comparator function.
10
+ * @param [options] - An optional object that contains the following properties:
11
+ */
12
+ constructor(options?: PriorityQueueOptions<T>);
4
13
  }