data-structure-typed 1.32.1 → 1.32.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 (342) hide show
  1. package/.idea/data-structure-typed.iml +19 -0
  2. package/.idea/inspectionProfiles/Project_Default.xml +6 -0
  3. package/.idea/misc.xml +6 -0
  4. package/.idea/modules.xml +8 -0
  5. package/.idea/vcs.xml +6 -0
  6. package/CHANGELOG.md +1 -1
  7. package/README.md +415 -255
  8. package/coverage/coverage-final.json +4 -4
  9. package/docs/index.html +268 -21
  10. package/package.json +48 -16
  11. package/test/unit/data-structures/binary-tree/tree-multiset.test.ts +46 -1
  12. package/.auto-changelog-template.hbs +0 -36
  13. package/coverage/clover.xml +0 -3393
  14. package/coverage/lcov-report/base.css +0 -224
  15. package/coverage/lcov-report/block-navigation.js +0 -87
  16. package/coverage/lcov-report/favicon.png +0 -0
  17. package/coverage/lcov-report/index.html +0 -386
  18. package/coverage/lcov-report/prettify.css +0 -1
  19. package/coverage/lcov-report/prettify.js +0 -2
  20. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  21. package/coverage/lcov-report/sorter.js +0 -196
  22. package/coverage/lcov-report/src/data-structures/binary-tree/aa-tree.ts.html +0 -88
  23. package/coverage/lcov-report/src/data-structures/binary-tree/abstract-binary-tree.ts.html +0 -4978
  24. package/coverage/lcov-report/src/data-structures/binary-tree/avl-tree.ts.html +0 -1015
  25. package/coverage/lcov-report/src/data-structures/binary-tree/b-tree.ts.html +0 -88
  26. package/coverage/lcov-report/src/data-structures/binary-tree/binary-indexed-tree.ts.html +0 -313
  27. package/coverage/lcov-report/src/data-structures/binary-tree/binary-tree.ts.html +0 -226
  28. package/coverage/lcov-report/src/data-structures/binary-tree/bst.ts.html +0 -1696
  29. package/coverage/lcov-report/src/data-structures/binary-tree/index.html +0 -296
  30. package/coverage/lcov-report/src/data-structures/binary-tree/index.ts.html +0 -121
  31. package/coverage/lcov-report/src/data-structures/binary-tree/rb-tree.ts.html +0 -388
  32. package/coverage/lcov-report/src/data-structures/binary-tree/segment-tree.ts.html +0 -811
  33. package/coverage/lcov-report/src/data-structures/binary-tree/splay-tree.ts.html +0 -88
  34. package/coverage/lcov-report/src/data-structures/binary-tree/tree-multiset.ts.html +0 -2185
  35. package/coverage/lcov-report/src/data-structures/binary-tree/two-three-tree.ts.html +0 -88
  36. package/coverage/lcov-report/src/data-structures/graph/abstract-graph.ts.html +0 -3205
  37. package/coverage/lcov-report/src/data-structures/graph/directed-graph.ts.html +0 -1495
  38. package/coverage/lcov-report/src/data-structures/graph/index.html +0 -176
  39. package/coverage/lcov-report/src/data-structures/graph/index.ts.html +0 -97
  40. package/coverage/lcov-report/src/data-structures/graph/map-graph.ts.html +0 -472
  41. package/coverage/lcov-report/src/data-structures/graph/undirected-graph.ts.html +0 -907
  42. package/coverage/lcov-report/src/data-structures/hash/coordinate-map.ts.html +0 -286
  43. package/coverage/lcov-report/src/data-structures/hash/coordinate-set.ts.html +0 -253
  44. package/coverage/lcov-report/src/data-structures/hash/hash-table.ts.html +0 -88
  45. package/coverage/lcov-report/src/data-structures/hash/index.html +0 -206
  46. package/coverage/lcov-report/src/data-structures/hash/index.ts.html +0 -103
  47. package/coverage/lcov-report/src/data-structures/hash/pair.ts.html +0 -88
  48. package/coverage/lcov-report/src/data-structures/hash/tree-map.ts.html +0 -88
  49. package/coverage/lcov-report/src/data-structures/hash/tree-set.ts.html +0 -88
  50. package/coverage/lcov-report/src/data-structures/heap/heap.ts.html +0 -721
  51. package/coverage/lcov-report/src/data-structures/heap/index.html +0 -161
  52. package/coverage/lcov-report/src/data-structures/heap/index.ts.html +0 -94
  53. package/coverage/lcov-report/src/data-structures/heap/max-heap.ts.html +0 -178
  54. package/coverage/lcov-report/src/data-structures/heap/min-heap.ts.html +0 -181
  55. package/coverage/lcov-report/src/data-structures/index.html +0 -116
  56. package/coverage/lcov-report/src/data-structures/index.ts.html +0 -118
  57. package/coverage/lcov-report/src/data-structures/linked-list/doubly-linked-list.ts.html +0 -1804
  58. package/coverage/lcov-report/src/data-structures/linked-list/index.html +0 -161
  59. package/coverage/lcov-report/src/data-structures/linked-list/index.ts.html +0 -94
  60. package/coverage/lcov-report/src/data-structures/linked-list/singly-linked-list.ts.html +0 -1588
  61. package/coverage/lcov-report/src/data-structures/linked-list/skip-linked-list.ts.html +0 -88
  62. package/coverage/lcov-report/src/data-structures/matrix/index.html +0 -176
  63. package/coverage/lcov-report/src/data-structures/matrix/index.ts.html +0 -97
  64. package/coverage/lcov-report/src/data-structures/matrix/matrix.ts.html +0 -166
  65. package/coverage/lcov-report/src/data-structures/matrix/matrix2d.ts.html +0 -721
  66. package/coverage/lcov-report/src/data-structures/matrix/navigator.ts.html +0 -448
  67. package/coverage/lcov-report/src/data-structures/matrix/vector2d.ts.html +0 -1033
  68. package/coverage/lcov-report/src/data-structures/priority-queue/index.html +0 -161
  69. package/coverage/lcov-report/src/data-structures/priority-queue/index.ts.html +0 -94
  70. package/coverage/lcov-report/src/data-structures/priority-queue/max-priority-queue.ts.html +0 -253
  71. package/coverage/lcov-report/src/data-structures/priority-queue/min-priority-queue.ts.html +0 -256
  72. package/coverage/lcov-report/src/data-structures/priority-queue/priority-queue.ts.html +0 -1162
  73. package/coverage/lcov-report/src/data-structures/queue/deque.ts.html +0 -976
  74. package/coverage/lcov-report/src/data-structures/queue/index.html +0 -146
  75. package/coverage/lcov-report/src/data-structures/queue/index.ts.html +0 -91
  76. package/coverage/lcov-report/src/data-structures/queue/queue.ts.html +0 -658
  77. package/coverage/lcov-report/src/data-structures/stack/index.html +0 -131
  78. package/coverage/lcov-report/src/data-structures/stack/index.ts.html +0 -88
  79. package/coverage/lcov-report/src/data-structures/stack/stack.ts.html +0 -379
  80. package/coverage/lcov-report/src/data-structures/tree/index.html +0 -131
  81. package/coverage/lcov-report/src/data-structures/tree/index.ts.html +0 -88
  82. package/coverage/lcov-report/src/data-structures/tree/tree.ts.html +0 -292
  83. package/coverage/lcov-report/src/data-structures/trie/index.html +0 -131
  84. package/coverage/lcov-report/src/data-structures/trie/index.ts.html +0 -88
  85. package/coverage/lcov-report/src/data-structures/trie/trie.ts.html +0 -760
  86. package/coverage/lcov-report/src/index.html +0 -116
  87. package/coverage/lcov-report/src/index.ts.html +0 -97
  88. package/coverage/lcov-report/src/interfaces/index.html +0 -116
  89. package/coverage/lcov-report/src/interfaces/index.ts.html +0 -130
  90. package/coverage/lcov-report/src/types/data-structures/abstract-binary-tree.ts.html +0 -235
  91. package/coverage/lcov-report/src/types/data-structures/bst.ts.html +0 -124
  92. package/coverage/lcov-report/src/types/data-structures/directed-graph.ts.html +0 -109
  93. package/coverage/lcov-report/src/types/data-structures/index.html +0 -176
  94. package/coverage/lcov-report/src/types/data-structures/index.ts.html +0 -130
  95. package/coverage/lcov-report/src/types/data-structures/rb-tree.ts.html +0 -106
  96. package/coverage/lcov-report/src/types/index.html +0 -116
  97. package/coverage/lcov-report/src/types/index.ts.html +0 -94
  98. package/coverage/lcov-report/src/types/utils/index.html +0 -116
  99. package/coverage/lcov-report/src/types/utils/index.ts.html +0 -91
  100. package/coverage/lcov-report/src/utils/index.html +0 -131
  101. package/coverage/lcov-report/src/utils/index.ts.html +0 -88
  102. package/coverage/lcov-report/src/utils/utils.ts.html +0 -322
  103. package/coverage/lcov-report/test/utils/index.html +0 -146
  104. package/coverage/lcov-report/test/utils/index.ts.html +0 -91
  105. package/coverage/lcov-report/test/utils/magnitude.ts.html +0 -148
  106. package/coverage/lcov-report/test/utils/number.ts.html +0 -94
  107. package/coverage/lcov.info +0 -6676
  108. package/docs/assets/highlight.css +0 -127
  109. package/docs/assets/main.js +0 -58
  110. package/docs/assets/search.js +0 -1
  111. package/docs/assets/style.css +0 -1367
  112. package/docs/classes/AVLTree.html +0 -2182
  113. package/docs/classes/AVLTreeNode.html +0 -399
  114. package/docs/classes/AaTree.html +0 -202
  115. package/docs/classes/AbstractBinaryTree.html +0 -1836
  116. package/docs/classes/AbstractBinaryTreeNode.html +0 -441
  117. package/docs/classes/AbstractEdge.html +0 -345
  118. package/docs/classes/AbstractGraph.html +0 -1105
  119. package/docs/classes/AbstractVertex.html +0 -299
  120. package/docs/classes/ArrayDeque.html +0 -469
  121. package/docs/classes/BST.html +0 -2026
  122. package/docs/classes/BSTNode.html +0 -400
  123. package/docs/classes/BTree.html +0 -202
  124. package/docs/classes/BinaryIndexedTree.html +0 -371
  125. package/docs/classes/BinaryTree.html +0 -1867
  126. package/docs/classes/BinaryTreeNode.html +0 -399
  127. package/docs/classes/Character.html +0 -250
  128. package/docs/classes/CoordinateMap.html +0 -513
  129. package/docs/classes/CoordinateSet.html +0 -474
  130. package/docs/classes/Deque.html +0 -1005
  131. package/docs/classes/DirectedEdge.html +0 -404
  132. package/docs/classes/DirectedGraph.html +0 -1530
  133. package/docs/classes/DirectedVertex.html +0 -286
  134. package/docs/classes/DoublyLinkedList.html +0 -998
  135. package/docs/classes/DoublyLinkedListNode.html +0 -327
  136. package/docs/classes/HashTable.html +0 -202
  137. package/docs/classes/Heap.html +0 -647
  138. package/docs/classes/HeapItem.html +0 -296
  139. package/docs/classes/LinkedListQueue.html +0 -884
  140. package/docs/classes/MapEdge.html +0 -391
  141. package/docs/classes/MapGraph.html +0 -1583
  142. package/docs/classes/MapVertex.html +0 -356
  143. package/docs/classes/Matrix2D.html +0 -532
  144. package/docs/classes/MatrixNTI2D.html +0 -270
  145. package/docs/classes/MaxHeap.html +0 -671
  146. package/docs/classes/MaxPriorityQueue.html +0 -866
  147. package/docs/classes/MinHeap.html +0 -672
  148. package/docs/classes/MinPriorityQueue.html +0 -868
  149. package/docs/classes/Navigator.html +0 -343
  150. package/docs/classes/ObjectDeque.html +0 -527
  151. package/docs/classes/Pair.html +0 -202
  152. package/docs/classes/PriorityQueue.html +0 -790
  153. package/docs/classes/Queue.html +0 -521
  154. package/docs/classes/RBTree.html +0 -2024
  155. package/docs/classes/RBTreeNode.html +0 -431
  156. package/docs/classes/SegmentTree.html +0 -464
  157. package/docs/classes/SegmentTreeNode.html +0 -387
  158. package/docs/classes/SinglyLinkedList.html +0 -830
  159. package/docs/classes/SinglyLinkedListNode.html +0 -300
  160. package/docs/classes/SkipLinkedList.html +0 -202
  161. package/docs/classes/SplayTree.html +0 -202
  162. package/docs/classes/Stack.html +0 -398
  163. package/docs/classes/TreeMap.html +0 -202
  164. package/docs/classes/TreeMultiset.html +0 -2510
  165. package/docs/classes/TreeMultisetNode.html +0 -447
  166. package/docs/classes/TreeNode.html +0 -344
  167. package/docs/classes/TreeSet.html +0 -202
  168. package/docs/classes/Trie.html +0 -402
  169. package/docs/classes/TrieNode.html +0 -310
  170. package/docs/classes/TwoThreeTree.html +0 -202
  171. package/docs/classes/UndirectedEdge.html +0 -374
  172. package/docs/classes/UndirectedGraph.html +0 -1285
  173. package/docs/classes/UndirectedVertex.html +0 -284
  174. package/docs/classes/Vector2D.html +0 -835
  175. package/docs/enums/CP.html +0 -211
  176. package/docs/enums/FamilyPosition.html +0 -239
  177. package/docs/enums/LoopType.html +0 -212
  178. package/docs/enums/RBColor.html +0 -204
  179. package/docs/enums/TopologicalProperty.html +0 -211
  180. package/docs/functions/arrayRemove.html +0 -208
  181. package/docs/functions/isThunk.html +0 -186
  182. package/docs/functions/toThunk.html +0 -186
  183. package/docs/functions/trampoline.html +0 -186
  184. package/docs/functions/trampolineAsync.html +0 -186
  185. package/docs/functions/uuidV4.html +0 -181
  186. package/docs/interfaces/IAVLTree.html +0 -1245
  187. package/docs/interfaces/IAbstractBinaryTree.html +0 -1101
  188. package/docs/interfaces/IAbstractBinaryTreeNode.html +0 -335
  189. package/docs/interfaces/IAbstractGraph.html +0 -433
  190. package/docs/interfaces/IBST.html +0 -1245
  191. package/docs/interfaces/IDirectedGraph.html +0 -570
  192. package/docs/interfaces/IRBTree.html +0 -1247
  193. package/docs/interfaces/IUNDirectedGraph.html +0 -463
  194. package/docs/types/AVLTreeNodeNested.html +0 -182
  195. package/docs/types/AVLTreeOptions.html +0 -180
  196. package/docs/types/AbstractBinaryTreeNodeNested.html +0 -182
  197. package/docs/types/AbstractBinaryTreeNodeProperties.html +0 -182
  198. package/docs/types/AbstractBinaryTreeNodeProperty.html +0 -182
  199. package/docs/types/AbstractBinaryTreeOptions.html +0 -182
  200. package/docs/types/BSTComparator.html +0 -192
  201. package/docs/types/BSTNodeNested.html +0 -182
  202. package/docs/types/BSTOptions.html +0 -182
  203. package/docs/types/BinaryTreeDeletedResult.html +0 -189
  204. package/docs/types/BinaryTreeNodeId.html +0 -177
  205. package/docs/types/BinaryTreeNodeNested.html +0 -182
  206. package/docs/types/BinaryTreeNodePropertyName.html +0 -177
  207. package/docs/types/BinaryTreeOptions.html +0 -180
  208. package/docs/types/DFSOrderPattern.html +0 -177
  209. package/docs/types/DijkstraResult.html +0 -199
  210. package/docs/types/Direction.html +0 -177
  211. package/docs/types/DummyAny.html +0 -190
  212. package/docs/types/EdgeId.html +0 -177
  213. package/docs/types/HeapOptions.html +0 -198
  214. package/docs/types/IAVLTreeNode.html +0 -184
  215. package/docs/types/IBSTNode.html +0 -184
  216. package/docs/types/IBinaryTree.html +0 -182
  217. package/docs/types/IBinaryTreeNode.html +0 -184
  218. package/docs/types/IRBTreeNode.html +0 -184
  219. package/docs/types/ITreeMultiset.html +0 -182
  220. package/docs/types/ITreeMultisetNode.html +0 -184
  221. package/docs/types/KeyValueObject.html +0 -182
  222. package/docs/types/KeyValueObjectWithId.html +0 -184
  223. package/docs/types/MapGraphCoordinate.html +0 -177
  224. package/docs/types/NavigatorParams.html +0 -211
  225. package/docs/types/NodeOrPropertyName.html +0 -177
  226. package/docs/types/NonNumberNonObjectButDefined.html +0 -177
  227. package/docs/types/ObjectWithNonNumberId.html +0 -184
  228. package/docs/types/ObjectWithNumberId.html +0 -184
  229. package/docs/types/ObjectWithoutId.html +0 -177
  230. package/docs/types/PriorityQueueComparator.html +0 -197
  231. package/docs/types/PriorityQueueDFSOrderPattern.html +0 -177
  232. package/docs/types/PriorityQueueOptions.html +0 -191
  233. package/docs/types/RBTreeNodeNested.html +0 -182
  234. package/docs/types/RBTreeOptions.html +0 -180
  235. package/docs/types/RestrictValById.html +0 -177
  236. package/docs/types/SegmentTreeNodeVal.html +0 -177
  237. package/docs/types/SpecifyOptional.html +0 -184
  238. package/docs/types/Thunk.html +0 -185
  239. package/docs/types/ToThunkFn.html +0 -185
  240. package/docs/types/TopologicalStatus.html +0 -177
  241. package/docs/types/TreeMultisetNodeNested.html +0 -182
  242. package/docs/types/TreeMultisetOptions.html +0 -180
  243. package/docs/types/TrlAsyncFn.html +0 -190
  244. package/docs/types/TrlFn.html +0 -190
  245. package/docs/types/Turning.html +0 -177
  246. package/docs/types/VertexId.html +0 -177
  247. package/docs/variables/THUNK_SYMBOL.html +0 -177
  248. package/rename_clear_files.sh +0 -29
  249. package/src/data-structures/binary-tree/aa-tree.ts +0 -1
  250. package/src/data-structures/binary-tree/abstract-binary-tree.ts +0 -1631
  251. package/src/data-structures/binary-tree/avl-tree.ts +0 -310
  252. package/src/data-structures/binary-tree/b-tree.ts +0 -1
  253. package/src/data-structures/binary-tree/binary-indexed-tree.ts +0 -76
  254. package/src/data-structures/binary-tree/binary-tree.ts +0 -47
  255. package/src/data-structures/binary-tree/bst.ts +0 -537
  256. package/src/data-structures/binary-tree/index.ts +0 -12
  257. package/src/data-structures/binary-tree/rb-tree.ts +0 -101
  258. package/src/data-structures/binary-tree/segment-tree.ts +0 -242
  259. package/src/data-structures/binary-tree/splay-tree.ts +0 -1
  260. package/src/data-structures/binary-tree/tree-multiset.ts +0 -700
  261. package/src/data-structures/binary-tree/two-three-tree.ts +0 -1
  262. package/src/data-structures/diagrams/README.md +0 -5
  263. package/src/data-structures/graph/abstract-graph.ts +0 -1040
  264. package/src/data-structures/graph/directed-graph.ts +0 -470
  265. package/src/data-structures/graph/index.ts +0 -4
  266. package/src/data-structures/graph/map-graph.ts +0 -129
  267. package/src/data-structures/graph/undirected-graph.ts +0 -274
  268. package/src/data-structures/hash/coordinate-map.ts +0 -67
  269. package/src/data-structures/hash/coordinate-set.ts +0 -56
  270. package/src/data-structures/hash/hash-table.ts +0 -1
  271. package/src/data-structures/hash/index.ts +0 -6
  272. package/src/data-structures/hash/pair.ts +0 -1
  273. package/src/data-structures/hash/tree-map.ts +0 -1
  274. package/src/data-structures/hash/tree-set.ts +0 -1
  275. package/src/data-structures/heap/heap.ts +0 -212
  276. package/src/data-structures/heap/index.ts +0 -3
  277. package/src/data-structures/heap/max-heap.ts +0 -31
  278. package/src/data-structures/heap/min-heap.ts +0 -32
  279. package/src/data-structures/index.ts +0 -11
  280. package/src/data-structures/linked-list/doubly-linked-list.ts +0 -573
  281. package/src/data-structures/linked-list/index.ts +0 -3
  282. package/src/data-structures/linked-list/singly-linked-list.ts +0 -501
  283. package/src/data-structures/linked-list/skip-linked-list.ts +0 -1
  284. package/src/data-structures/matrix/index.ts +0 -4
  285. package/src/data-structures/matrix/matrix.ts +0 -27
  286. package/src/data-structures/matrix/matrix2d.ts +0 -212
  287. package/src/data-structures/matrix/navigator.ts +0 -121
  288. package/src/data-structures/matrix/vector2d.ts +0 -316
  289. package/src/data-structures/priority-queue/index.ts +0 -3
  290. package/src/data-structures/priority-queue/max-priority-queue.ts +0 -56
  291. package/src/data-structures/priority-queue/min-priority-queue.ts +0 -57
  292. package/src/data-structures/priority-queue/priority-queue.ts +0 -359
  293. package/src/data-structures/queue/deque.ts +0 -297
  294. package/src/data-structures/queue/index.ts +0 -2
  295. package/src/data-structures/queue/queue.ts +0 -191
  296. package/src/data-structures/stack/index.ts +0 -1
  297. package/src/data-structures/stack/stack.ts +0 -98
  298. package/src/data-structures/tree/index.ts +0 -1
  299. package/src/data-structures/tree/tree.ts +0 -69
  300. package/src/data-structures/trie/index.ts +0 -1
  301. package/src/data-structures/trie/trie.ts +0 -225
  302. package/src/index.ts +0 -4
  303. package/src/interfaces/abstract-binary-tree.ts +0 -191
  304. package/src/interfaces/abstract-graph.ts +0 -31
  305. package/src/interfaces/avl-tree.ts +0 -25
  306. package/src/interfaces/binary-tree.ts +0 -6
  307. package/src/interfaces/bst.ts +0 -31
  308. package/src/interfaces/directed-graph.ts +0 -20
  309. package/src/interfaces/doubly-linked-list.ts +0 -1
  310. package/src/interfaces/heap.ts +0 -1
  311. package/src/interfaces/index.ts +0 -15
  312. package/src/interfaces/navigator.ts +0 -1
  313. package/src/interfaces/priority-queue.ts +0 -1
  314. package/src/interfaces/rb-tree.ts +0 -9
  315. package/src/interfaces/segment-tree.ts +0 -1
  316. package/src/interfaces/singly-linked-list.ts +0 -1
  317. package/src/interfaces/tree-multiset.ts +0 -7
  318. package/src/interfaces/undirected-graph.ts +0 -6
  319. package/src/types/data-structures/abstract-binary-tree.ts +0 -50
  320. package/src/types/data-structures/abstract-graph.ts +0 -11
  321. package/src/types/data-structures/avl-tree.ts +0 -5
  322. package/src/types/data-structures/binary-tree.ts +0 -5
  323. package/src/types/data-structures/bst.ts +0 -13
  324. package/src/types/data-structures/directed-graph.ts +0 -8
  325. package/src/types/data-structures/doubly-linked-list.ts +0 -1
  326. package/src/types/data-structures/heap.ts +0 -5
  327. package/src/types/data-structures/index.ts +0 -15
  328. package/src/types/data-structures/map-graph.ts +0 -1
  329. package/src/types/data-structures/navigator.ts +0 -13
  330. package/src/types/data-structures/priority-queue.ts +0 -9
  331. package/src/types/data-structures/rb-tree.ts +0 -8
  332. package/src/types/data-structures/segment-tree.ts +0 -1
  333. package/src/types/data-structures/singly-linked-list.ts +0 -1
  334. package/src/types/data-structures/tree-multiset.ts +0 -6
  335. package/src/types/helpers.ts +0 -1
  336. package/src/types/index.ts +0 -3
  337. package/src/types/utils/index.ts +0 -2
  338. package/src/types/utils/utils.ts +0 -6
  339. package/src/types/utils/validate-type.ts +0 -35
  340. package/src/utils/index.ts +0 -1
  341. package/src/utils/utils.ts +0 -79
  342. package/tsconfig.build.json +0 -33
@@ -1,212 +0,0 @@
1
- /**
2
- * data-structure-typed
3
- *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
- * @license MIT License
7
- */
8
- import Vector2D from './vector2d';
9
-
10
- export class Matrix2D {
11
- private readonly _matrix: number[][];
12
-
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
- */
19
- constructor(value?: number[][] | Vector2D) {
20
- if (typeof value === 'undefined') {
21
- this._matrix = Matrix2D.identity;
22
- } else if (value instanceof Vector2D) {
23
- this._matrix = Matrix2D.identity;
24
- this._matrix[0][0] = value.x;
25
- this._matrix[1][0] = value.y;
26
- this._matrix[2][0] = value.w;
27
- } else {
28
- this._matrix = value;
29
- }
30
- }
31
-
32
- /**
33
- * The function returns a 2D array with three empty arrays.
34
- * @returns An empty 2-dimensional array with 3 empty arrays inside.
35
- */
36
- static get empty(): number[][] {
37
- return [[], [], []];
38
- }
39
-
40
- /**
41
- * The above function returns a 3x3 identity matrix.
42
- * @returns The method is returning a 2-dimensional array of numbers representing the identity matrix.
43
- */
44
- static get identity(): number[][] {
45
- return [
46
- [1, 0, 0],
47
- [0, 1, 0],
48
- [0, 0, 1]
49
- ];
50
- }
51
-
52
- /**
53
- * The function returns a two-dimensional array of numbers.
54
- * @returns The getter method is returning the value of the private variable `_matrix`, which is a two-dimensional
55
- * array of numbers.
56
- */
57
- get m(): number[][] {
58
- return this._matrix;
59
- }
60
-
61
- /**
62
- * The function "toVector" returns a new Vector2D object with the values from the first and second elements of the
63
- * _matrix array.
64
- * @returns A new instance of the Vector2D class is being returned. The values of the returned vector are taken from
65
- * the first column of the matrix.
66
- */
67
- get toVector(): Vector2D {
68
- return new Vector2D(this._matrix[0][0], this._matrix[1][0]);
69
- }
70
-
71
- /**
72
- * The function takes two 2D matrices as input and returns their sum as a new 2D matrix.
73
- * @param {Matrix2D} matrix1 - Matrix2D - The first matrix to be added.
74
- * @param {Matrix2D} matrix2 - The parameter `matrix2` is a Matrix2D object.
75
- * @returns a new instance of the Matrix2D class, which is created using the result array.
76
- */
77
- static add(matrix1: Matrix2D, matrix2: Matrix2D): Matrix2D {
78
- const result = Matrix2D.empty;
79
- for (let i = 0; i < 3; i++) {
80
- for (let j = 0; j < 3; j++) {
81
- result[i][j] = matrix1.m[i][j] + matrix2.m[i][j];
82
- }
83
- }
84
- return new Matrix2D(result);
85
- }
86
-
87
- /**
88
- * The function subtracts two 2D matrices and returns the result as a new Matrix2D object.
89
- * @param {Matrix2D} matrix1 - Matrix2D - The first matrix to subtract from.
90
- * @param {Matrix2D} matrix2 - Matrix2D is a class representing a 2D matrix. It has a property `m` which is a 2D array
91
- * representing the matrix elements.
92
- * @returns a new instance of the Matrix2D class, which is created using the result array.
93
- */
94
- static subtract(matrix1: Matrix2D, matrix2: Matrix2D): Matrix2D {
95
- const result = Matrix2D.empty;
96
- for (let i = 0; i < 3; i++) {
97
- for (let j = 0; j < 3; j++) {
98
- result[i][j] = matrix1.m[i][j] - matrix2.m[i][j];
99
- }
100
- }
101
- return new Matrix2D(result);
102
- }
103
-
104
- /**
105
- * The function multiplies two 2D matrices and returns the result as a new Matrix2D object.
106
- * @param {Matrix2D} matrix1 - A 2D matrix represented by the Matrix2D class.
107
- * @param {Matrix2D} matrix2 - The parameter `matrix2` is a 2D matrix of size 3x3.
108
- * @returns a new instance of the Matrix2D class, created using the result array.
109
- */
110
- static multiply(matrix1: Matrix2D, matrix2: Matrix2D): Matrix2D {
111
- const result = Matrix2D.empty;
112
- for (let i = 0; i < 3; i++) {
113
- for (let j = 0; j < 3; j++) {
114
- result[i][j] = 0;
115
- for (let k = 0; k < 3; k++) {
116
- result[i][j] += matrix1.m[i][k] * matrix2.m[k][j];
117
- }
118
- }
119
- }
120
- return new Matrix2D(result);
121
- }
122
-
123
- /**
124
- * The function multiplies each element of a 2D matrix by a given value and returns the resulting matrix.
125
- * @param {Matrix2D} matrix - The `matrix` parameter is an instance of the `Matrix2D` class, which represents a 2D
126
- * matrix. It contains a property `m` that is a 2D array representing the matrix elements.
127
- * @param {number} value - The `value` parameter is a number that you want to multiply each element of the `matrix` by.
128
- * @returns a new instance of the Matrix2D class, which is created using the result array.
129
- */
130
- static multiplyByValue(matrix: Matrix2D, value: number): Matrix2D {
131
- const result = Matrix2D.empty;
132
- for (let i = 0; i < 3; i++) {
133
- for (let j = 0; j < 3; j++) {
134
- result[i][j] = matrix.m[i][j] * value;
135
- }
136
- }
137
- return new Matrix2D(result);
138
- }
139
-
140
- /**
141
- * The function multiplies a 2D matrix by a 2D vector and returns the result as a 2D vector.
142
- * @param {Matrix2D} matrix - The parameter "matrix" is of type Matrix2D. It represents a 2-dimensional matrix.
143
- * @param {Vector2D} vector - The "vector" parameter is a 2D vector, represented by an object of type Vector2D.
144
- * @returns a Vector2D.
145
- */
146
- static multiplyByVector(matrix: Matrix2D, vector: Vector2D): Vector2D {
147
- return Matrix2D.multiply(matrix, new Matrix2D(vector)).toVector;
148
- }
149
-
150
- /**
151
- * The function returns a 2D matrix that scales and flips a vector around the center of a given width and height.
152
- * @param {number} width - The width parameter represents the width of the view or the canvas. It is a number that
153
- * specifies the width in pixels or any other unit of measurement.
154
- * @param {number} height - The height parameter represents the height of the view or the canvas. It is used to
155
- * calculate the centerY value, which is the vertical center of the view.
156
- * @returns a Matrix2D object.
157
- */
158
- static view(width: number, height: number): Matrix2D {
159
- const scaleStep = 1; // Scale every vector * scaleStep
160
- const centerX = width / 2;
161
- const centerY = height / 2;
162
- const flipX = Math.cos(Math.PI); // rotate 180deg / 3.14radian around X-axis
163
-
164
- return new Matrix2D([
165
- [scaleStep, 0, centerX],
166
- [0, flipX * scaleStep, centerY],
167
- [0, 0, 1]
168
- ]);
169
- }
170
-
171
- /**
172
- * The function scales a matrix by a given factor.
173
- * @param {number} factor - The factor parameter is a number that represents the scaling factor by which the matrix
174
- * should be scaled.
175
- * @returns the result of multiplying a new instance of Matrix2D by the given factor.
176
- */
177
- static scale(factor: number) {
178
- return Matrix2D.multiplyByValue(new Matrix2D(), factor);
179
- }
180
-
181
- /**
182
- * The function "rotate" takes an angle in radians and returns a 2D transformation matrix for rotating objects.
183
- * @param {number} radians - The "radians" parameter is the angle in radians by which you want to rotate an object.
184
- * @returns The code is returning a new instance of a Matrix2D object.
185
- */
186
- static rotate(radians: number) {
187
- const cos = Math.cos(radians);
188
- const sin = Math.sin(radians);
189
-
190
- return new Matrix2D([
191
- [cos, -sin, 0],
192
- [sin, cos, 0],
193
- [0, 0, 1]
194
- ]);
195
- }
196
-
197
- /**
198
- * The translate function takes a 2D vector and returns a 2D matrix that represents a translation transformation.
199
- * @param {Vector2D} vector - The parameter "vector" is of type Vector2D. It represents a 2D vector with components x
200
- * and y, and an optional w component.
201
- * @returns The method is returning a new instance of the Matrix2D class.
202
- */
203
- static translate(vector: Vector2D): Matrix2D {
204
- return new Matrix2D([
205
- [1, 0, vector.x],
206
- [0, 1, vector.y],
207
- [0, 0, vector.w]
208
- ]);
209
- }
210
- }
211
-
212
- export default Matrix2D;
@@ -1,121 +0,0 @@
1
- /**
2
- * data-structure-typed
3
- *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
- * @license MIT License
7
- */
8
- import type {Direction, NavigatorParams, Turning} from '../../types';
9
-
10
- export class Character {
11
- direction: Direction;
12
- turn: () => Character;
13
-
14
- /**
15
- * The constructor function takes in a direction and turning object and sets the direction and turn properties of the
16
- * Character class.
17
- * @param {Direction} direction - The direction parameter is used to specify the current direction of the character. It
18
- * can be any value that represents a direction, such as "north", "south", "east", or "west".
19
- * @param {Turning} turning - The `turning` parameter is an object that maps each direction to the corresponding
20
- * turning direction. It is used to determine the new direction when the character turns.
21
- */
22
- constructor(direction: Direction, turning: Turning) {
23
- this.direction = direction;
24
- this.turn = () => new Character(turning[direction], turning);
25
- }
26
- }
27
-
28
- export class Navigator<T = number> {
29
- onMove: (cur: [number, number]) => void;
30
- private readonly _matrix: T[][];
31
- private readonly _cur: [number, number];
32
- private _character: Character;
33
- private readonly _VISITED: T;
34
-
35
- /**
36
- * The constructor initializes the Navigator object with the given parameters and sets the current position as visited
37
- * in the matrix.
38
- * @param - - `matrix`: a 2D array representing the grid or map
39
- */
40
- constructor({matrix, turning, onMove, init: {cur, charDir, VISITED}}: NavigatorParams<T>) {
41
- this._matrix = matrix;
42
- this._cur = cur;
43
- this._character = new Character(charDir, turning);
44
- this.onMove = onMove;
45
- this.onMove && this.onMove(this._cur);
46
- this._VISITED = VISITED;
47
- this._matrix[this._cur[0]][this._cur[1]] = this._VISITED;
48
- }
49
-
50
- /**
51
- * The "start" function moves the character in its current direction until it encounters an obstacle, then it turns the
52
- * character and repeats the process.
53
- */
54
- start() {
55
- while (this.check(this._character.direction) || this.check(this._character.turn().direction)) {
56
- const {direction} = this._character;
57
- if (this.check(direction)) {
58
- this.move(direction);
59
- } else if (this.check(this._character.turn().direction)) {
60
- this._character = this._character.turn();
61
- }
62
- }
63
- }
64
-
65
- /**
66
- * The function checks if there is a valid move in the specified direction in a matrix.
67
- * @param {Direction} direction - The direction parameter is a string that represents the direction in which to check.
68
- * It can be one of the following values: 'up', 'right', 'down', or 'left'.
69
- * @returns a boolean value.
70
- */
71
- check(direction: Direction) {
72
- let forward: T | undefined, row: T[] | undefined;
73
- const matrix = this._matrix;
74
- const [i, j] = this._cur;
75
- switch (direction) {
76
- case 'up':
77
- row = matrix[i - 1];
78
- if (!row) return false;
79
- forward = row[j];
80
- break;
81
- case 'right':
82
- forward = matrix[i][j + 1];
83
- break;
84
- case 'down':
85
- row = matrix[i + 1];
86
- if (!row) return false;
87
- forward = row[j];
88
- break;
89
- case 'left':
90
- forward = matrix[i][j - 1];
91
- break;
92
- }
93
- return forward !== undefined && forward !== this._VISITED;
94
- }
95
-
96
- /**
97
- * The `move` function updates the current position based on the given direction and updates the matrix accordingly.
98
- * @param {Direction} direction - The `direction` parameter is a string that represents the direction in which to move.
99
- * It can have one of the following values: 'up', 'right', 'down', or 'left'.
100
- */
101
- move(direction: Direction) {
102
- switch (direction) {
103
- case 'up':
104
- this._cur[0]--;
105
- break;
106
- case 'right':
107
- this._cur[1]++;
108
- break;
109
- case 'down':
110
- this._cur[0]++;
111
- break;
112
- case 'left':
113
- this._cur[1]--;
114
- break;
115
- }
116
-
117
- const [i, j] = this._cur;
118
- this._matrix[i][j] = this._VISITED;
119
- this.onMove && this.onMove(this._cur);
120
- }
121
- }
@@ -1,316 +0,0 @@
1
- /**
2
- * data-structure-typed
3
- *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
- * @license MIT License
7
- */
8
- export class Vector2D {
9
- constructor(
10
- public x: number = 0,
11
- public y: number = 0,
12
- public w: number = 1 // needed for matrix multiplication
13
- ) {}
14
-
15
- /**
16
- * The function checks if the x and y values of a point are both zero.
17
- * @returns A boolean value indicating whether both the x and y properties of the object are equal to 0.
18
- */
19
- get isZero(): boolean {
20
- return this.x === 0 && this.y === 0;
21
- }
22
-
23
- /**
24
- * The above function calculates the length of a vector using the Pythagorean theorem.
25
- * @returns The length of a vector, calculated using the Pythagorean theorem.
26
- */
27
- get length(): number {
28
- return Math.sqrt(this.x * this.x + this.y * this.y);
29
- }
30
-
31
- /**
32
- * The function calculates the square of the length of a vector.
33
- * @returns The method is returning the sum of the squares of the x and y values.
34
- */
35
- get lengthSq(): number {
36
- return this.x * this.x + this.y * this.y;
37
- }
38
-
39
- /**
40
- * The "rounded" function returns a new Vector2D object with the x and y values rounded to the nearest whole number.
41
- * @returns The method is returning a new instance of the Vector2D class with the x and y values rounded to the nearest
42
- * whole number.
43
- */
44
- get rounded(): Vector2D {
45
- return new Vector2D(Math.round(this.x), Math.round(this.y));
46
- }
47
-
48
- /**
49
- * The function "add" takes two Vector2D objects as parameters and returns a new Vector2D object with the sum of their
50
- * x and y components.
51
- * @param {Vector2D} vector1 - The parameter `vector1` is an instance of the `Vector2D` class. It represents a
52
- * 2-dimensional vector with an `x` and `y` component.
53
- * @param {Vector2D} vector2 - The parameter "vector2" is of type Vector2D. It represents a 2-dimensional vector with
54
- * an x and y component.
55
- * @returns The method is returning a new instance of the Vector2D class with the x and y components of the two input
56
- * vectors added together.
57
- */
58
- static add(vector1: Vector2D, vector2: Vector2D): Vector2D {
59
- return new Vector2D(vector1.x + vector2.x, vector1.y + vector2.y);
60
- }
61
-
62
- /**
63
- * The subtract function takes two Vector2D objects as parameters and returns a new Vector2D object with the x and y
64
- * components subtracted.
65
- * @param {Vector2D} vector1 - The parameter `vector1` is an instance of the `Vector2D` class, representing a
66
- * 2-dimensional vector. It has properties `x` and `y` which represent the x and y components of the vector
67
- * respectively.
68
- * @param {Vector2D} vector2 - The parameter "vector2" is a Vector2D object. It represents the second vector that you
69
- * want to subtract from the first vector.
70
- * @returns The method is returning a new Vector2D object with the x and y components subtracted from vector1 and
71
- * vector2.
72
- */
73
- static subtract(vector1: Vector2D, vector2: Vector2D): Vector2D {
74
- return new Vector2D(vector1.x - vector2.x, vector1.y - vector2.y);
75
- }
76
-
77
- /**
78
- * The function subtracts a given value from the x and y components of a Vector2D object and returns a new Vector2D
79
- * object.
80
- * @param {Vector2D} vector - The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector with
81
- * x and y components.
82
- * @param {number} value - The "value" parameter is a number that will be subtracted from both the x and y components
83
- * of the "vector" parameter.
84
- * @returns A new Vector2D object with the x and y values subtracted by the given value.
85
- */
86
- static subtractValue(vector: Vector2D, value: number): Vector2D {
87
- return new Vector2D(vector.x - value, vector.y - value);
88
- }
89
-
90
- /**
91
- * The function multiplies a Vector2D object by a given value.
92
- * @param {Vector2D} vector - The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector with
93
- * x and y components.
94
- * @param {number} value - The "value" parameter is a number that represents the value by which the x and y components
95
- * of the vector will be multiplied.
96
- * @returns A new Vector2D object with the x and y values multiplied by the given value.
97
- */
98
- static multiply(vector: Vector2D, value: number): Vector2D {
99
- return new Vector2D(vector.x * value, vector.y * value);
100
- }
101
-
102
- /**
103
- * The function divides the x and y components of a Vector2D by a given value and returns a new Vector2D.
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 will be used to divide the x and y components of the
107
- * vector.
108
- * @returns A new instance of the Vector2D class with the x and y values divided by the given value.
109
- */
110
- static divide(vector: Vector2D, value: number): Vector2D {
111
- return new Vector2D(vector.x / value, vector.y / value);
112
- }
113
-
114
- /**
115
- * The function checks if two Vector2D objects are equal by comparing their x and y values.
116
- * @param {Vector2D} vector1 - The parameter `vector1` is of type `Vector2D`, which represents a 2-dimensional vector.
117
- * It has two properties: `x` and `y`, which represent the x and y components of the vector, respectively.
118
- * @param {Vector2D} vector2 - The parameter "vector2" is of type Vector2D.
119
- * @returns a boolean value, which indicates whether the two input vectors are equal or not.
120
- */
121
- static equals(vector1: Vector2D, vector2: Vector2D): boolean {
122
- return vector1.x === vector2.x && vector1.y === vector2.y;
123
- }
124
-
125
- /**
126
- * The function checks if two Vector2D objects are equal within a specified rounding factor.
127
- * @param {Vector2D} vector1 - The first vector to compare.
128
- * @param {Vector2D} vector2 - The parameter "vector2" is a Vector2D object, which represents a 2-dimensional vector.
129
- * It is used as one of the inputs for the "equalsRounded" function.
130
- * @param [roundingFactor=12] - The roundingFactor parameter is used to determine the threshold for considering two
131
- * vectors as equal. If the absolute difference in the x and y components of the vectors is less than the
132
- * roundingFactor, the vectors are considered equal.
133
- * @returns a boolean value.
134
- */
135
- static equalsRounded(vector1: Vector2D, vector2: Vector2D, roundingFactor = 12): boolean {
136
- const vector = Vector2D.abs(Vector2D.subtract(vector1, vector2));
137
- if (vector.x < roundingFactor && vector.y < roundingFactor) {
138
- return true;
139
- }
140
-
141
- return false;
142
- }
143
-
144
- /**
145
- * 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
146
- * @param {Vector2D} vector - The parameter "vector" is of type Vector2D.
147
- * @returns the normalized vector if its length is greater than a very small value (epsilon), otherwise it returns the
148
- * original vector.
149
- */
150
- static normalize(vector: Vector2D): Vector2D {
151
- const length = vector.length;
152
- if (length > 2.220446049250313e-16) {
153
- // Epsilon
154
- return Vector2D.divide(vector, length);
155
- }
156
-
157
- return vector;
158
- }
159
-
160
- /**
161
- * 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
162
- * @param {Vector2D} vector - A 2D vector represented by the Vector2D class.
163
- * @param {number} max - The `max` parameter is a number that represents the maximum length that the `vector` should
164
- * have.
165
- * @returns either the original vector or a truncated version of the vector, depending on whether the length of the
166
- * vector is greater than the maximum value specified.
167
- */
168
- static truncate(vector: Vector2D, max: number): Vector2D {
169
- if (vector.length > max) {
170
- return Vector2D.multiply(Vector2D.normalize(vector), max);
171
- }
172
-
173
- return vector;
174
- }
175
-
176
- /**
177
- * The function returns a new Vector2D object that is perpendicular to the input vector.The vector that is perpendicular to this one
178
- * @param {Vector2D} vector - The parameter "vector" is of type Vector2D.
179
- * @returns A new Vector2D object is being returned.
180
- */
181
- static perp(vector: Vector2D): Vector2D {
182
- return new Vector2D(-vector.y, vector.x);
183
- }
184
-
185
- /**
186
- * The reverse function takes a Vector2D object and returns a new Vector2D object with the negated x and y values.
187
- * @param {Vector2D} vector - The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector. It
188
- * has two properties: "x" and "y", which represent the x and y components of the vector, respectively.
189
- * @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
190
- */
191
- static reverse(vector: Vector2D): Vector2D {
192
- return new Vector2D(-vector.x, -vector.y);
193
- }
194
-
195
- /**
196
- * The function takes a Vector2D object as input and returns a new Vector2D object with the absolute values of its x
197
- * and y components.
198
- * @param {Vector2D} vector - The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector. It
199
- * has two properties: "x" and "y", which represent the x and y components of the vector, respectively.
200
- * @returns The method is returning a new Vector2D object with the absolute values of the x and y components of the
201
- * input vector.
202
- */
203
- static abs(vector: Vector2D): Vector2D {
204
- return new Vector2D(Math.abs(vector.x), Math.abs(vector.y));
205
- }
206
-
207
- /**
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.
213
- */
214
- static dot(vector1: Vector2D, vector2: Vector2D): number {
215
- return vector1.x * vector2.x + vector1.y * vector2.y;
216
- }
217
-
218
- // /**
219
- // * Transform vectors based on the current tranformation matrices: translation, rotation and scale
220
- // * @param vectors The vectors to transform
221
- // */
222
- // static transform(vector: Vector2D, transformation: Matrix2D): Vector2D {
223
- // return Matrix2D.multiplyByVector(transformation, vector)
224
- // }
225
-
226
- // /**
227
- // * Transform vectors based on the current tranformation matrices: translation, rotation and scale
228
- // * @param vectors The vectors to transform
229
- // */
230
- // static transformList(vectors: Vector2D[], transformation: Matrix2D): Vector2D[] {
231
- // return vectors.map(vector => Matrix2D.multiplyByVector(transformation, vector))
232
- // }
233
-
234
- /**
235
- * The function calculates the distance between two points in a two-dimensional space.
236
- * @param {Vector2D} vector1 - The parameter `vector1` represents the first vector in 2D space, while `vector2`
237
- * represents the second vector. Each vector has an `x` and `y` component, which represent their respective coordinates
238
- * in the 2D space.
239
- * @param {Vector2D} vector2 - The `vector2` parameter represents the second vector in the calculation of distance. It
240
- * is an instance of the `Vector2D` class, which typically has properties `x` and `y` representing the coordinates of
241
- * the vector in a 2D space.
242
- * @returns The distance between vector1 and vector2.
243
- */
244
- static distance(vector1: Vector2D, vector2: Vector2D): number {
245
- const ySeparation = vector2.y - vector1.y;
246
- const xSeparation = vector2.x - vector1.x;
247
- return Math.sqrt(ySeparation * ySeparation + xSeparation * xSeparation);
248
- }
249
-
250
- /**
251
- * The function calculates the squared distance between two 2D vectors.
252
- * @param {Vector2D} vector1 - The parameter `vector1` represents the first vector, which is an instance of the
253
- * `Vector2D` class. It contains the x and y coordinates of the vector.
254
- * @param {Vector2D} vector2 - The `vector2` parameter represents the second vector in a two-dimensional space. It has
255
- * properties `x` and `y` which represent the coordinates of the vector.
256
- * @returns the square of the distance between the two input vectors.
257
- */
258
- static distanceSq(vector1: Vector2D, vector2: Vector2D): number {
259
- const ySeparation = vector2.y - vector1.y;
260
- const xSeparation = vector2.x - vector1.x;
261
- return ySeparation * ySeparation + xSeparation * xSeparation;
262
- }
263
-
264
- /**
265
- * The sign function determines the sign of the cross product between two 2D vectors.
266
- * (assuming the Y axis is pointing down, X axis to right like a Window app)
267
- * @param {Vector2D} vector1 - The parameter `vector1` is of type `Vector2D`, which represents a 2-dimensional vector.
268
- * It likely has properties `x` and `y` representing the x and y components of the vector, respectively.
269
- * @param {Vector2D} vector2 - The above code defines a function called "sign" that takes two parameters: vector1 and
270
- * vector2. Both vector1 and vector2 are of type Vector2D.
271
- * @returns either -1 or 1. Returns positive if v2 is clockwise of this vector, negative if counterclockwise
272
- */
273
- static sign(vector1: Vector2D, vector2: Vector2D): number {
274
- if (vector1.y * vector2.x > vector1.x * vector2.y) {
275
- return -1;
276
- }
277
-
278
- return 1;
279
- }
280
-
281
- /**
282
- * The function calculates the angle between a given vector and the negative y-axis.
283
- * @param {Vector2D} vector - The "vector" parameter is an instance of the Vector2D class, which represents a
284
- * 2-dimensional vector. It has two properties: "x" and "y", which represent the x and y components of the vector,
285
- * respectively.
286
- * @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
287
- */
288
- static angle(vector: Vector2D): number {
289
- const origin = new Vector2D(0, -1);
290
- const radian = Math.acos(Vector2D.dot(vector, origin) / (vector.length * origin.length));
291
- return Vector2D.sign(vector, origin) === 1 ? Math.PI * 2 - radian : radian;
292
- }
293
-
294
- /**
295
- * The function "random" generates a random Vector2D object with x and y values within the specified range.
296
- * @param {number} maxX - The maxX parameter represents the maximum value for the x-coordinate of the random vector.
297
- * @param {number} maxY - The `maxY` parameter represents the maximum value for the y-coordinate of the generated
298
- * random vector.
299
- * @returns a new instance of the Vector2D class with random x and y values.
300
- */
301
- static random(maxX: number, maxY: number): Vector2D {
302
- const randX = Math.floor(Math.random() * maxX - maxX / 2);
303
- const randY = Math.floor(Math.random() * maxY - maxY / 2);
304
- return new Vector2D(randX, randY);
305
- }
306
-
307
- /**
308
- * The function sets the values of x and y to zero.
309
- */
310
- zero(): void {
311
- this.x = 0;
312
- this.y = 0;
313
- }
314
- }
315
-
316
- export default Vector2D;
@@ -1,3 +0,0 @@
1
- export * from './priority-queue';
2
- export * from './min-priority-queue';
3
- export * from './max-priority-queue';