min-heap-typed 1.40.0-rc → 1.41.0

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 (347) hide show
  1. package/.dependency-cruiser.js +422 -422
  2. package/.eslintrc.js +59 -59
  3. package/.prettierrc.js +14 -14
  4. package/README.md +20 -3
  5. package/coverage/clover.xml +11 -7
  6. package/coverage/coverage-final.json +95 -1
  7. package/coverage/coverage-summary.json +59 -2
  8. package/coverage/lcov-report/base.css +278 -99
  9. package/coverage/lcov-report/index.html +69 -65
  10. package/coverage/lcov-report/index.ts.html +36 -35
  11. package/coverage/lcov-report/sorter.js +15 -5
  12. package/dist/data-structures/binary-tree/avl-tree.d.ts +106 -0
  13. package/dist/data-structures/binary-tree/avl-tree.js +347 -0
  14. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +149 -0
  15. package/dist/data-structures/binary-tree/binary-indexed-tree.js +269 -0
  16. package/dist/data-structures/binary-tree/binary-tree.d.ts +363 -0
  17. package/dist/data-structures/binary-tree/binary-tree.js +1135 -0
  18. package/dist/data-structures/binary-tree/bst.d.ts +167 -0
  19. package/dist/data-structures/binary-tree/bst.js +512 -0
  20. package/dist/data-structures/binary-tree/index.d.ts +7 -0
  21. package/dist/data-structures/binary-tree/index.js +23 -0
  22. package/dist/data-structures/binary-tree/rb-tree.d.ts +97 -0
  23. package/dist/data-structures/binary-tree/rb-tree.js +388 -0
  24. package/dist/data-structures/binary-tree/segment-tree.d.ts +67 -0
  25. package/dist/data-structures/binary-tree/segment-tree.js +180 -0
  26. package/dist/data-structures/binary-tree/tree-multiset.d.ts +126 -0
  27. package/dist/data-structures/binary-tree/tree-multiset.js +355 -0
  28. package/dist/data-structures/graph/abstract-graph.d.ts +313 -0
  29. package/dist/data-structures/graph/abstract-graph.js +884 -0
  30. package/dist/data-structures/graph/directed-graph.d.ts +194 -0
  31. package/dist/data-structures/graph/directed-graph.js +404 -0
  32. package/dist/data-structures/graph/index.d.ts +4 -0
  33. package/dist/data-structures/graph/index.js +20 -0
  34. package/dist/data-structures/graph/map-graph.d.ts +73 -0
  35. package/dist/data-structures/graph/map-graph.js +93 -0
  36. package/dist/data-structures/graph/undirected-graph.d.ts +120 -0
  37. package/dist/data-structures/graph/undirected-graph.js +239 -0
  38. package/dist/data-structures/hash/coordinate-map.d.ts +44 -0
  39. package/dist/data-structures/hash/coordinate-map.js +62 -0
  40. package/dist/data-structures/hash/coordinate-set.d.ts +36 -0
  41. package/dist/data-structures/hash/coordinate-set.js +52 -0
  42. package/dist/data-structures/hash/hash-map.d.ts +50 -0
  43. package/dist/data-structures/hash/hash-map.js +153 -0
  44. package/dist/data-structures/hash/hash-table.d.ts +103 -0
  45. package/dist/data-structures/hash/hash-table.js +236 -0
  46. package/dist/data-structures/hash/index.d.ts +6 -0
  47. package/dist/data-structures/hash/index.js +22 -0
  48. package/dist/data-structures/hash/tree-map.d.ts +2 -0
  49. package/dist/data-structures/hash/tree-map.js +6 -0
  50. package/dist/data-structures/hash/tree-set.d.ts +2 -0
  51. package/dist/data-structures/hash/tree-set.js +6 -0
  52. package/dist/data-structures/heap/heap.d.ts +235 -0
  53. package/dist/data-structures/heap/heap.js +515 -0
  54. package/dist/data-structures/heap/index.d.ts +3 -0
  55. package/dist/data-structures/heap/index.js +19 -0
  56. package/dist/data-structures/heap/max-heap.d.ts +15 -0
  57. package/dist/data-structures/heap/max-heap.js +26 -0
  58. package/dist/data-structures/heap/min-heap.d.ts +15 -0
  59. package/dist/data-structures/heap/min-heap.js +26 -0
  60. package/dist/data-structures/index.d.ts +11 -0
  61. package/dist/data-structures/index.js +27 -0
  62. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +253 -0
  63. package/dist/data-structures/linked-list/doubly-linked-list.js +569 -0
  64. package/dist/data-structures/linked-list/index.d.ts +3 -0
  65. package/dist/data-structures/linked-list/index.js +19 -0
  66. package/dist/data-structures/linked-list/singly-linked-list.d.ts +232 -0
  67. package/dist/data-structures/linked-list/singly-linked-list.js +533 -0
  68. package/dist/data-structures/linked-list/skip-linked-list.d.ts +80 -0
  69. package/dist/data-structures/linked-list/skip-linked-list.js +187 -0
  70. package/dist/data-structures/matrix/index.d.ts +4 -0
  71. package/dist/data-structures/matrix/index.js +20 -0
  72. package/dist/data-structures/matrix/matrix.d.ts +21 -0
  73. package/dist/data-structures/matrix/matrix.js +28 -0
  74. package/dist/data-structures/matrix/matrix2d.d.ts +107 -0
  75. package/dist/data-structures/matrix/matrix2d.js +199 -0
  76. package/dist/data-structures/matrix/navigator.d.ts +52 -0
  77. package/dist/data-structures/matrix/navigator.js +106 -0
  78. package/dist/data-structures/matrix/vector2d.d.ts +200 -0
  79. package/dist/data-structures/matrix/vector2d.js +290 -0
  80. package/dist/data-structures/priority-queue/index.d.ts +3 -0
  81. package/dist/data-structures/priority-queue/index.js +19 -0
  82. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +15 -0
  83. package/dist/data-structures/priority-queue/max-priority-queue.js +26 -0
  84. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +15 -0
  85. package/dist/data-structures/priority-queue/min-priority-queue.js +26 -0
  86. package/dist/data-structures/priority-queue/priority-queue.d.ts +15 -0
  87. package/dist/data-structures/priority-queue/priority-queue.js +17 -0
  88. package/dist/data-structures/queue/deque.d.ts +161 -0
  89. package/dist/data-structures/queue/deque.js +264 -0
  90. package/dist/data-structures/queue/index.d.ts +2 -0
  91. package/dist/data-structures/queue/index.js +18 -0
  92. package/dist/data-structures/queue/queue.d.ts +122 -0
  93. package/dist/data-structures/queue/queue.js +187 -0
  94. package/dist/data-structures/stack/index.d.ts +1 -0
  95. package/dist/data-structures/stack/index.js +17 -0
  96. package/dist/data-structures/stack/stack.d.ts +64 -0
  97. package/dist/data-structures/stack/stack.js +94 -0
  98. package/dist/data-structures/tree/index.d.ts +1 -0
  99. package/dist/data-structures/tree/index.js +17 -0
  100. package/dist/data-structures/tree/tree.d.ts +8 -0
  101. package/dist/data-structures/tree/tree.js +40 -0
  102. package/dist/data-structures/trie/index.d.ts +1 -0
  103. package/dist/data-structures/trie/index.js +17 -0
  104. package/dist/data-structures/trie/trie.d.ts +79 -0
  105. package/dist/data-structures/trie/trie.js +251 -0
  106. package/dist/index.d.ts +3 -1
  107. package/dist/index.js +18 -4
  108. package/dist/interfaces/binary-tree.d.ts +7 -0
  109. package/dist/interfaces/binary-tree.js +2 -0
  110. package/dist/interfaces/doubly-linked-list.d.ts +1 -0
  111. package/dist/interfaces/doubly-linked-list.js +2 -0
  112. package/dist/interfaces/graph.d.ts +5 -0
  113. package/dist/interfaces/graph.js +2 -0
  114. package/dist/interfaces/heap.d.ts +1 -0
  115. package/dist/interfaces/heap.js +2 -0
  116. package/dist/interfaces/index.d.ts +8 -0
  117. package/dist/interfaces/index.js +24 -0
  118. package/dist/interfaces/navigator.d.ts +1 -0
  119. package/dist/interfaces/navigator.js +2 -0
  120. package/dist/interfaces/priority-queue.d.ts +1 -0
  121. package/dist/interfaces/priority-queue.js +2 -0
  122. package/dist/interfaces/segment-tree.d.ts +1 -0
  123. package/dist/interfaces/segment-tree.js +2 -0
  124. package/dist/interfaces/singly-linked-list.d.ts +1 -0
  125. package/dist/interfaces/singly-linked-list.js +2 -0
  126. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +4 -0
  127. package/dist/types/data-structures/binary-tree/avl-tree.js +2 -0
  128. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +1 -0
  129. package/dist/types/data-structures/binary-tree/binary-indexed-tree.js +2 -0
  130. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +29 -0
  131. package/dist/types/data-structures/binary-tree/binary-tree.js +24 -0
  132. package/dist/types/data-structures/binary-tree/bst.d.ts +7 -0
  133. package/dist/types/data-structures/binary-tree/bst.js +2 -0
  134. package/dist/types/data-structures/binary-tree/index.d.ts +6 -0
  135. package/dist/types/data-structures/binary-tree/index.js +22 -0
  136. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +4 -0
  137. package/dist/types/data-structures/binary-tree/rb-tree.js +13 -0
  138. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +1 -0
  139. package/dist/types/data-structures/binary-tree/segment-tree.js +2 -0
  140. package/dist/types/data-structures/binary-tree/tree-multiset.d.ts +4 -0
  141. package/dist/types/data-structures/binary-tree/tree-multiset.js +2 -0
  142. package/dist/types/data-structures/graph/abstract-graph.d.ts +10 -0
  143. package/dist/types/data-structures/graph/abstract-graph.js +2 -0
  144. package/dist/types/data-structures/graph/directed-graph.d.ts +6 -0
  145. package/dist/types/data-structures/graph/directed-graph.js +9 -0
  146. package/dist/types/data-structures/graph/index.d.ts +3 -0
  147. package/dist/types/data-structures/graph/index.js +19 -0
  148. package/dist/types/data-structures/graph/map-graph.d.ts +1 -0
  149. package/dist/types/data-structures/graph/map-graph.js +2 -0
  150. package/dist/types/data-structures/graph/undirected-graph.d.ts +1 -0
  151. package/dist/types/data-structures/graph/undirected-graph.js +2 -0
  152. package/dist/types/data-structures/hash/coordinate-map.d.ts +1 -0
  153. package/dist/types/data-structures/hash/coordinate-map.js +2 -0
  154. package/dist/types/data-structures/hash/coordinate-set.d.ts +1 -0
  155. package/dist/types/data-structures/hash/coordinate-set.js +2 -0
  156. package/dist/types/data-structures/hash/hash-map.d.ts +1 -0
  157. package/dist/types/data-structures/hash/hash-map.js +2 -0
  158. package/dist/types/data-structures/hash/hash-table.d.ts +1 -0
  159. package/dist/types/data-structures/hash/hash-table.js +2 -0
  160. package/dist/types/data-structures/hash/index.d.ts +1 -0
  161. package/dist/types/data-structures/hash/index.js +2 -0
  162. package/dist/types/data-structures/hash/tree-map.d.ts +1 -0
  163. package/dist/types/data-structures/hash/tree-map.js +2 -0
  164. package/dist/types/data-structures/hash/tree-set.d.ts +1 -0
  165. package/dist/types/data-structures/hash/tree-set.js +2 -0
  166. package/dist/types/data-structures/heap/heap.d.ts +1 -0
  167. package/dist/types/data-structures/heap/heap.js +2 -0
  168. package/dist/types/data-structures/heap/index.d.ts +1 -0
  169. package/dist/types/data-structures/heap/index.js +17 -0
  170. package/dist/types/data-structures/heap/max-heap.d.ts +1 -0
  171. package/dist/types/data-structures/heap/max-heap.js +2 -0
  172. package/dist/types/data-structures/heap/min-heap.d.ts +1 -0
  173. package/dist/types/data-structures/heap/min-heap.js +2 -0
  174. package/dist/types/data-structures/index.d.ts +11 -0
  175. package/dist/types/data-structures/index.js +27 -0
  176. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +1 -0
  177. package/dist/types/data-structures/linked-list/doubly-linked-list.js +2 -0
  178. package/dist/types/data-structures/linked-list/index.d.ts +2 -0
  179. package/dist/types/data-structures/linked-list/index.js +18 -0
  180. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +1 -0
  181. package/dist/types/data-structures/linked-list/singly-linked-list.js +2 -0
  182. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +1 -0
  183. package/dist/types/data-structures/linked-list/skip-linked-list.js +2 -0
  184. package/dist/types/data-structures/matrix/index.d.ts +1 -0
  185. package/dist/types/data-structures/matrix/index.js +17 -0
  186. package/dist/types/data-structures/matrix/matrix.d.ts +1 -0
  187. package/dist/types/data-structures/matrix/matrix.js +2 -0
  188. package/dist/types/data-structures/matrix/matrix2d.d.ts +1 -0
  189. package/dist/types/data-structures/matrix/matrix2d.js +2 -0
  190. package/dist/types/data-structures/matrix/navigator.d.ts +14 -0
  191. package/dist/types/data-structures/matrix/navigator.js +2 -0
  192. package/dist/types/data-structures/matrix/vector2d.d.ts +1 -0
  193. package/dist/types/data-structures/matrix/vector2d.js +2 -0
  194. package/dist/types/data-structures/priority-queue/index.d.ts +3 -0
  195. package/dist/types/data-structures/priority-queue/index.js +19 -0
  196. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +1 -0
  197. package/dist/types/data-structures/priority-queue/max-priority-queue.js +2 -0
  198. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +1 -0
  199. package/dist/types/data-structures/priority-queue/min-priority-queue.js +2 -0
  200. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +1 -0
  201. package/dist/types/data-structures/priority-queue/priority-queue.js +2 -0
  202. package/dist/types/data-structures/queue/deque.d.ts +1 -0
  203. package/dist/types/data-structures/queue/deque.js +2 -0
  204. package/dist/types/data-structures/queue/index.d.ts +2 -0
  205. package/dist/types/data-structures/queue/index.js +18 -0
  206. package/dist/types/data-structures/queue/queue.d.ts +1 -0
  207. package/dist/types/data-structures/queue/queue.js +2 -0
  208. package/dist/types/data-structures/stack/index.d.ts +1 -0
  209. package/dist/types/data-structures/stack/index.js +17 -0
  210. package/dist/types/data-structures/stack/stack.d.ts +1 -0
  211. package/dist/types/data-structures/stack/stack.js +2 -0
  212. package/dist/types/data-structures/tree/index.d.ts +1 -0
  213. package/dist/types/data-structures/tree/index.js +17 -0
  214. package/dist/types/data-structures/tree/tree.d.ts +1 -0
  215. package/dist/types/data-structures/tree/tree.js +2 -0
  216. package/dist/types/data-structures/trie/index.d.ts +1 -0
  217. package/dist/types/data-structures/trie/index.js +17 -0
  218. package/dist/types/data-structures/trie/trie.d.ts +1 -0
  219. package/dist/types/data-structures/trie/trie.js +2 -0
  220. package/dist/types/helpers.d.ts +8 -0
  221. package/dist/types/helpers.js +9 -0
  222. package/dist/types/index.d.ts +3 -0
  223. package/dist/types/index.js +19 -0
  224. package/dist/types/utils/index.d.ts +2 -0
  225. package/dist/types/utils/index.js +18 -0
  226. package/dist/types/utils/utils.d.ts +7 -0
  227. package/dist/types/utils/utils.js +2 -0
  228. package/dist/types/utils/validate-type.d.ts +19 -0
  229. package/dist/types/utils/validate-type.js +2 -0
  230. package/dist/utils/index.d.ts +1 -0
  231. package/dist/utils/index.js +17 -0
  232. package/dist/utils/utils.d.ts +20 -0
  233. package/dist/utils/utils.js +73 -0
  234. package/jest.config.js +6 -6
  235. package/package.json +2 -2
  236. package/src/data-structures/binary-tree/avl-tree.ts +350 -0
  237. package/src/data-structures/binary-tree/binary-indexed-tree.ts +306 -0
  238. package/src/data-structures/binary-tree/binary-tree.ts +1284 -0
  239. package/src/data-structures/binary-tree/bst.ts +522 -0
  240. package/src/data-structures/binary-tree/index.ts +7 -0
  241. package/src/data-structures/binary-tree/rb-tree.ts +426 -0
  242. package/src/data-structures/binary-tree/segment-tree.ts +190 -0
  243. package/src/data-structures/binary-tree/tree-multiset.ts +379 -0
  244. package/src/data-structures/graph/abstract-graph.ts +1000 -0
  245. package/src/data-structures/graph/directed-graph.ts +449 -0
  246. package/src/data-structures/graph/index.ts +4 -0
  247. package/src/data-structures/graph/map-graph.ts +106 -0
  248. package/src/data-structures/graph/undirected-graph.ts +259 -0
  249. package/src/data-structures/hash/coordinate-map.ts +63 -0
  250. package/src/data-structures/hash/coordinate-set.ts +52 -0
  251. package/src/data-structures/hash/hash-map.ts +185 -0
  252. package/src/data-structures/hash/hash-table.ts +268 -0
  253. package/src/data-structures/hash/index.ts +6 -0
  254. package/src/data-structures/hash/tree-map.ts +2 -0
  255. package/src/data-structures/hash/tree-set.ts +2 -0
  256. package/src/data-structures/heap/heap.ts +589 -0
  257. package/src/data-structures/heap/index.ts +3 -0
  258. package/src/data-structures/heap/max-heap.ts +26 -0
  259. package/src/data-structures/heap/min-heap.ts +26 -0
  260. package/src/data-structures/index.ts +11 -0
  261. package/src/data-structures/linked-list/doubly-linked-list.ts +605 -0
  262. package/src/data-structures/linked-list/index.ts +3 -0
  263. package/src/data-structures/linked-list/singly-linked-list.ts +576 -0
  264. package/src/data-structures/linked-list/skip-linked-list.ts +221 -0
  265. package/src/data-structures/matrix/index.ts +4 -0
  266. package/src/data-structures/matrix/matrix.ts +27 -0
  267. package/src/data-structures/matrix/matrix2d.ts +211 -0
  268. package/src/data-structures/matrix/navigator.ts +121 -0
  269. package/src/data-structures/matrix/vector2d.ts +315 -0
  270. package/src/data-structures/priority-queue/index.ts +3 -0
  271. package/src/data-structures/priority-queue/max-priority-queue.ts +25 -0
  272. package/src/data-structures/priority-queue/min-priority-queue.ts +25 -0
  273. package/src/data-structures/priority-queue/priority-queue.ts +16 -0
  274. package/src/data-structures/queue/deque.ts +282 -0
  275. package/src/data-structures/queue/index.ts +2 -0
  276. package/src/data-structures/queue/queue.ts +209 -0
  277. package/src/data-structures/stack/index.ts +1 -0
  278. package/src/data-structures/stack/stack.ts +102 -0
  279. package/src/data-structures/tree/index.ts +1 -0
  280. package/src/data-structures/tree/tree.ts +41 -0
  281. package/src/data-structures/trie/index.ts +1 -0
  282. package/src/data-structures/trie/trie.ts +262 -0
  283. package/src/index.ts +4 -1
  284. package/src/interfaces/binary-tree.ts +10 -0
  285. package/src/interfaces/doubly-linked-list.ts +1 -0
  286. package/src/interfaces/graph.ts +7 -0
  287. package/src/interfaces/heap.ts +1 -0
  288. package/src/interfaces/index.ts +8 -0
  289. package/src/interfaces/navigator.ts +1 -0
  290. package/src/interfaces/priority-queue.ts +1 -0
  291. package/src/interfaces/segment-tree.ts +1 -0
  292. package/src/interfaces/singly-linked-list.ts +1 -0
  293. package/src/types/data-structures/binary-tree/avl-tree.ts +5 -0
  294. package/src/types/data-structures/binary-tree/binary-indexed-tree.ts +1 -0
  295. package/src/types/data-structures/binary-tree/binary-tree.ts +31 -0
  296. package/src/types/data-structures/binary-tree/bst.ts +11 -0
  297. package/src/types/data-structures/binary-tree/index.ts +6 -0
  298. package/src/types/data-structures/binary-tree/rb-tree.ts +8 -0
  299. package/src/types/data-structures/binary-tree/segment-tree.ts +1 -0
  300. package/src/types/data-structures/binary-tree/tree-multiset.ts +6 -0
  301. package/src/types/data-structures/graph/abstract-graph.ts +11 -0
  302. package/src/types/data-structures/graph/directed-graph.ts +8 -0
  303. package/src/types/data-structures/graph/index.ts +3 -0
  304. package/src/types/data-structures/graph/map-graph.ts +1 -0
  305. package/src/types/data-structures/graph/undirected-graph.ts +1 -0
  306. package/src/types/data-structures/hash/coordinate-map.ts +1 -0
  307. package/src/types/data-structures/hash/coordinate-set.ts +1 -0
  308. package/src/types/data-structures/hash/hash-map.ts +1 -0
  309. package/src/types/data-structures/hash/hash-table.ts +1 -0
  310. package/src/types/data-structures/hash/index.ts +1 -0
  311. package/src/types/data-structures/hash/tree-map.ts +1 -0
  312. package/src/types/data-structures/hash/tree-set.ts +1 -0
  313. package/src/types/data-structures/heap/heap.ts +1 -0
  314. package/src/types/data-structures/heap/index.ts +1 -0
  315. package/src/types/data-structures/heap/max-heap.ts +1 -0
  316. package/src/types/data-structures/heap/min-heap.ts +1 -0
  317. package/src/types/data-structures/index.ts +11 -0
  318. package/src/types/data-structures/linked-list/doubly-linked-list.ts +1 -0
  319. package/src/types/data-structures/linked-list/index.ts +2 -0
  320. package/src/types/data-structures/linked-list/singly-linked-list.ts +1 -0
  321. package/src/types/data-structures/linked-list/skip-linked-list.ts +1 -0
  322. package/src/types/data-structures/matrix/index.ts +1 -0
  323. package/src/types/data-structures/matrix/matrix.ts +1 -0
  324. package/src/types/data-structures/matrix/matrix2d.ts +1 -0
  325. package/src/types/data-structures/matrix/navigator.ts +14 -0
  326. package/src/types/data-structures/matrix/vector2d.ts +1 -0
  327. package/src/types/data-structures/priority-queue/index.ts +3 -0
  328. package/src/types/data-structures/priority-queue/max-priority-queue.ts +1 -0
  329. package/src/types/data-structures/priority-queue/min-priority-queue.ts +1 -0
  330. package/src/types/data-structures/priority-queue/priority-queue.ts +1 -0
  331. package/src/types/data-structures/queue/deque.ts +1 -0
  332. package/src/types/data-structures/queue/index.ts +2 -0
  333. package/src/types/data-structures/queue/queue.ts +1 -0
  334. package/src/types/data-structures/stack/index.ts +1 -0
  335. package/src/types/data-structures/stack/stack.ts +1 -0
  336. package/src/types/data-structures/tree/index.ts +1 -0
  337. package/src/types/data-structures/tree/tree.ts +1 -0
  338. package/src/types/data-structures/trie/index.ts +1 -0
  339. package/src/types/data-structures/trie/trie.ts +1 -0
  340. package/src/types/helpers.ts +11 -0
  341. package/src/types/index.ts +3 -0
  342. package/src/types/utils/index.ts +2 -0
  343. package/src/types/utils/utils.ts +6 -0
  344. package/src/types/utils/validate-type.ts +35 -0
  345. package/src/utils/index.ts +1 -0
  346. package/src/utils/utils.ts +86 -0
  347. package/tsconfig.json +1 -2
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Navigator = exports.Character = void 0;
4
+ class Character {
5
+ /**
6
+ * The constructor function takes in a direction and turning object and sets the direction and turn properties of the
7
+ * Character class.
8
+ * @param {Direction} direction - The direction parameter is used to specify the current direction of the character. It
9
+ * can be any value that represents a direction, such as "north", "south", "east", or "west".
10
+ * @param {Turning} turning - The `turning` parameter is an object that maps each direction to the corresponding
11
+ * turning direction. It is used to determine the new direction when the character turns.
12
+ */
13
+ constructor(direction, turning) {
14
+ this.direction = direction;
15
+ this.turn = () => new Character(turning[direction], turning);
16
+ }
17
+ }
18
+ exports.Character = Character;
19
+ class Navigator {
20
+ /**
21
+ * The constructor initializes the Navigator object with the given parameters and sets the current position as visited
22
+ * in the matrix.
23
+ * @param - - `matrix`: a 2D array representing the grid or map
24
+ */
25
+ constructor({ matrix, turning, onMove, init: { cur, charDir, VISITED } }) {
26
+ this._matrix = matrix;
27
+ this._cur = cur;
28
+ this._character = new Character(charDir, turning);
29
+ this.onMove = onMove;
30
+ this.onMove && this.onMove(this._cur);
31
+ this._VISITED = VISITED;
32
+ this._matrix[this._cur[0]][this._cur[1]] = this._VISITED;
33
+ }
34
+ /**
35
+ * The "start" function moves the character in its current direction until it encounters an obstacle, then it turns the
36
+ * character and repeats the process.
37
+ */
38
+ start() {
39
+ while (this.check(this._character.direction) || this.check(this._character.turn().direction)) {
40
+ const { direction } = this._character;
41
+ if (this.check(direction)) {
42
+ this.move(direction);
43
+ }
44
+ else if (this.check(this._character.turn().direction)) {
45
+ this._character = this._character.turn();
46
+ }
47
+ }
48
+ }
49
+ /**
50
+ * The function checks if there is a valid move in the specified direction in a matrix.
51
+ * @param {Direction} direction - The direction parameter is a string that represents the direction in which to check.
52
+ * It can be one of the following values: 'up', 'right', 'down', or 'left'.
53
+ * @returns a boolean value.
54
+ */
55
+ check(direction) {
56
+ let forward, row;
57
+ const matrix = this._matrix;
58
+ const [i, j] = this._cur;
59
+ switch (direction) {
60
+ case 'up':
61
+ row = matrix[i - 1];
62
+ if (!row)
63
+ return false;
64
+ forward = row[j];
65
+ break;
66
+ case 'right':
67
+ forward = matrix[i][j + 1];
68
+ break;
69
+ case 'down':
70
+ row = matrix[i + 1];
71
+ if (!row)
72
+ return false;
73
+ forward = row[j];
74
+ break;
75
+ case 'left':
76
+ forward = matrix[i][j - 1];
77
+ break;
78
+ }
79
+ return forward !== undefined && forward !== this._VISITED;
80
+ }
81
+ /**
82
+ * The `move` function updates the current position based on the given direction and updates the matrix accordingly.
83
+ * @param {Direction} direction - The `direction` parameter is a string that represents the direction in which to move.
84
+ * It can have one of the following values: 'up', 'right', 'down', or 'left'.
85
+ */
86
+ move(direction) {
87
+ switch (direction) {
88
+ case 'up':
89
+ this._cur[0]--;
90
+ break;
91
+ case 'right':
92
+ this._cur[1]++;
93
+ break;
94
+ case 'down':
95
+ this._cur[0]++;
96
+ break;
97
+ case 'left':
98
+ this._cur[1]--;
99
+ break;
100
+ }
101
+ const [i, j] = this._cur;
102
+ this._matrix[i][j] = this._VISITED;
103
+ this.onMove && this.onMove(this._cur);
104
+ }
105
+ }
106
+ exports.Navigator = Navigator;
@@ -0,0 +1,200 @@
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 declare class Vector2D {
9
+ x: number;
10
+ y: number;
11
+ w: number;
12
+ constructor(x?: number, y?: number, w?: number);
13
+ /**
14
+ * The function checks if the x and y values of a point are both zero.
15
+ * @returns A boolean value indicating whether both the x and y properties of the object are equal to 0.
16
+ */
17
+ get isZero(): boolean;
18
+ /**
19
+ * The above function calculates the length of a vector using the Pythagorean theorem.
20
+ * @returns The length of a vector, calculated using the Pythagorean theorem.
21
+ */
22
+ get length(): number;
23
+ /**
24
+ * The function calculates the square of the length of a vector.
25
+ * @returns The method is returning the sum of the squares of the x and y values.
26
+ */
27
+ get lengthSq(): number;
28
+ /**
29
+ * The "rounded" function returns a new Vector2D object with the x and y values rounded to the nearest whole number.
30
+ * @returns The method is returning a new instance of the Vector2D class with the x and y values rounded to the nearest
31
+ * whole number.
32
+ */
33
+ get rounded(): Vector2D;
34
+ /**
35
+ * The function "add" takes two Vector2D objects as parameters and returns a new Vector2D object with the sum of their
36
+ * x and y components.
37
+ * @param {Vector2D} vector1 - The parameter `vector1` is an instance of the `Vector2D` class. It represents a
38
+ * 2-dimensional vector with an `x` and `y` component.
39
+ * @param {Vector2D} vector2 - The parameter "vector2" is of type Vector2D. It represents a 2-dimensional vector with
40
+ * an x and y component.
41
+ * @returns The method is returning a new instance of the Vector2D class with the x and y components of the two input
42
+ * vectors added together.
43
+ */
44
+ static add(vector1: Vector2D, vector2: Vector2D): Vector2D;
45
+ /**
46
+ * The subtract function takes two Vector2D objects as parameters and returns a new Vector2D object with the x and y
47
+ * components subtracted.
48
+ * @param {Vector2D} vector1 - The parameter `vector1` is an instance of the `Vector2D` class, representing a
49
+ * 2-dimensional vector. It has properties `x` and `y` which represent the x and y components of the vector
50
+ * respectively.
51
+ * @param {Vector2D} vector2 - The parameter "vector2" is a Vector2D object. It represents the second vector that you
52
+ * want to subtract from the first vector.
53
+ * @returns The method is returning a new Vector2D object with the x and y components subtracted from vector1 and
54
+ * vector2.
55
+ */
56
+ static subtract(vector1: Vector2D, vector2: Vector2D): Vector2D;
57
+ /**
58
+ * The function subtracts a given value from the x and y components of a Vector2D object and returns a new Vector2D
59
+ * object.
60
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector with
61
+ * x and y components.
62
+ * @param {number} value - The "value" parameter is a number that will be subtracted from both the x and y components
63
+ * of the "vector" parameter.
64
+ * @returns A new Vector2D object with the x and y values subtracted by the given value.
65
+ */
66
+ static subtractValue(vector: Vector2D, value: number): Vector2D;
67
+ /**
68
+ * The function multiplies a Vector2D object by a given value.
69
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector with
70
+ * x and y components.
71
+ * @param {number} value - The "value" parameter is a number that represents the value by which the x and y components
72
+ * of the vector will be multiplied.
73
+ * @returns A new Vector2D object with the x and y values multiplied by the given value.
74
+ */
75
+ static multiply(vector: Vector2D, value: number): Vector2D;
76
+ /**
77
+ * The function divides the x and y components of a Vector2D by a given value and returns a new Vector2D.
78
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector with
79
+ * x and y components.
80
+ * @param {number} value - The value parameter is a number that will be used to divide the x and y components of the
81
+ * vector.
82
+ * @returns A new instance of the Vector2D class with the x and y values divided by the given value.
83
+ */
84
+ static divide(vector: Vector2D, value: number): Vector2D;
85
+ /**
86
+ * The function checks if two Vector2D objects are equal by comparing their x and y values.
87
+ * @param {Vector2D} vector1 - The parameter `vector1` is of type `Vector2D`, which represents a 2-dimensional vector.
88
+ * It has two properties: `x` and `y`, which represent the x and y components of the vector, respectively.
89
+ * @param {Vector2D} vector2 - The parameter "vector2" is of type Vector2D.
90
+ * @returns a boolean value, which indicates whether the two input vectors are equal or not.
91
+ */
92
+ static equals(vector1: Vector2D, vector2: Vector2D): boolean;
93
+ /**
94
+ * The function checks if two Vector2D objects are equal within a specified rounding factor.
95
+ * @param {Vector2D} vector1 - The first vector to compare.
96
+ * @param {Vector2D} vector2 - The parameter "vector2" is a Vector2D object, which represents a 2-dimensional vector.
97
+ * It is used as one of the inputs for the "equalsRounded" function.
98
+ * @param [roundingFactor=12] - The roundingFactor parameter is used to determine the threshold for considering two
99
+ * vectors as equal. If the absolute difference in the x and y components of the vectors is less than the
100
+ * roundingFactor, the vectors are considered equal.
101
+ * @returns a boolean value.
102
+ */
103
+ static equalsRounded(vector1: Vector2D, vector2: Vector2D, roundingFactor?: number): boolean;
104
+ /**
105
+ * 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
106
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D.
107
+ * @returns the normalized vector if its length is greater than a very small value (epsilon), otherwise it returns the
108
+ * original vector.
109
+ */
110
+ static normalize(vector: Vector2D): Vector2D;
111
+ /**
112
+ * 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
113
+ * @param {Vector2D} vector - A 2D vector represented by the Vector2D class.
114
+ * @param {number} max - The `max` parameter is a number that represents the maximum length that the `vector` should
115
+ * have.
116
+ * @returns either the original vector or a truncated version of the vector, depending on whether the length of the
117
+ * vector is greater than the maximum value specified.
118
+ */
119
+ static truncate(vector: Vector2D, max: number): Vector2D;
120
+ /**
121
+ * The function returns a new Vector2D object that is perpendicular to the input vector.The vector that is perpendicular to this one
122
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D.
123
+ * @returns A new Vector2D object is being returned.
124
+ */
125
+ static perp(vector: Vector2D): Vector2D;
126
+ /**
127
+ * The reverse function takes a Vector2D object and returns a new Vector2D object with the negated x and y values.
128
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector. It
129
+ * has two properties: "x" and "y", which represent the x and y components of the vector, respectively.
130
+ * @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
131
+ */
132
+ static reverse(vector: Vector2D): Vector2D;
133
+ /**
134
+ * The function takes a Vector2D object as input and returns a new Vector2D object with the absolute values of its x
135
+ * and y components.
136
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector. It
137
+ * has two properties: "x" and "y", which represent the x and y components of the vector, respectively.
138
+ * @returns The method is returning a new Vector2D object with the absolute values of the x and y components of the
139
+ * input vector.
140
+ */
141
+ static abs(vector: Vector2D): Vector2D;
142
+ /**
143
+ * The dot function calculates the dot product of two 2D vectors.The dot product of v1 and v2
144
+ * @param {Vector2D} vector1 - The parameter `vector1` represents a 2D vector with its x and y components.
145
+ * @param {Vector2D} vector2 - The "vector2" parameter is a Vector2D object. It represents a two-dimensional vector
146
+ * with an x and y component.
147
+ * @returns The dot product of the two input vectors.
148
+ */
149
+ static dot(vector1: Vector2D, vector2: Vector2D): number;
150
+ /**
151
+ * The function calculates the distance between two points in a two-dimensional space.
152
+ * @param {Vector2D} vector1 - The parameter `vector1` represents the first vector in 2D space, while `vector2`
153
+ * represents the second vector. Each vector has an `x` and `y` component, which represent their respective coordinates
154
+ * in the 2D space.
155
+ * @param {Vector2D} vector2 - The `vector2` parameter represents the second vector in the calculation of distance. It
156
+ * is an instance of the `Vector2D` class, which typically has properties `x` and `y` representing the coordinates of
157
+ * the vector in a 2D space.
158
+ * @returns The distance between vector1 and vector2.
159
+ */
160
+ static distance(vector1: Vector2D, vector2: Vector2D): number;
161
+ /**
162
+ * The function calculates the squared distance between two 2D vectors.
163
+ * @param {Vector2D} vector1 - The parameter `vector1` represents the first vector, which is an instance of the
164
+ * `Vector2D` class. It contains the x and y coordinates of the vector.
165
+ * @param {Vector2D} vector2 - The `vector2` parameter represents the second vector in a two-dimensional space. It has
166
+ * properties `x` and `y` which represent the coordinates of the vector.
167
+ * @returns the square of the distance between the two input vectors.
168
+ */
169
+ static distanceSq(vector1: Vector2D, vector2: Vector2D): number;
170
+ /**
171
+ * The sign function determines the sign of the cross product between two 2D vectors.
172
+ * (assuming the Y axis is pointing down, X axis to right like a Window app)
173
+ * @param {Vector2D} vector1 - The parameter `vector1` is of type `Vector2D`, which represents a 2-dimensional vector.
174
+ * It likely has properties `x` and `y` representing the x and y components of the vector, respectively.
175
+ * @param {Vector2D} vector2 - The above code defines a function called "sign" that takes two parameters: vector1 and
176
+ * vector2. Both vector1 and vector2 are of type Vector2D.
177
+ * @returns either -1 or 1. Returns positive if v2 is clockwise of this vector, negative if counterclockwise
178
+ */
179
+ static sign(vector1: Vector2D, vector2: Vector2D): number;
180
+ /**
181
+ * The function calculates the angle between a given vector and the negative y-axis.
182
+ * @param {Vector2D} vector - The "vector" parameter is an instance of the Vector2D class, which represents a
183
+ * 2-dimensional vector. It has two properties: "x" and "y", which represent the x and y components of the vector,
184
+ * respectively.
185
+ * @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
186
+ */
187
+ static angle(vector: Vector2D): number;
188
+ /**
189
+ * The function "random" generates a random Vector2D object with x and y values within the specified range.
190
+ * @param {number} maxX - The maxX parameter represents the maximum value for the x-coordinate of the random vector.
191
+ * @param {number} maxY - The `maxY` parameter represents the maximum value for the y-coordinate of the generated
192
+ * random vector.
193
+ * @returns a new instance of the Vector2D class with random x and y values.
194
+ */
195
+ static random(maxX: number, maxY: number): Vector2D;
196
+ /**
197
+ * The function sets the values of x and y to zero.
198
+ */
199
+ zero(): void;
200
+ }
@@ -0,0 +1,290 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Vector2D = void 0;
4
+ /**
5
+ * data-structure-typed
6
+ *
7
+ * @author Tyler Zeng
8
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
9
+ * @license MIT License
10
+ */
11
+ class Vector2D {
12
+ constructor(x = 0, y = 0, w = 1 // needed for matrix multiplication
13
+ ) {
14
+ this.x = x;
15
+ this.y = y;
16
+ this.w = w;
17
+ }
18
+ /**
19
+ * The function checks if the x and y values of a point are both zero.
20
+ * @returns A boolean value indicating whether both the x and y properties of the object are equal to 0.
21
+ */
22
+ get isZero() {
23
+ return this.x === 0 && this.y === 0;
24
+ }
25
+ /**
26
+ * The above function calculates the length of a vector using the Pythagorean theorem.
27
+ * @returns The length of a vector, calculated using the Pythagorean theorem.
28
+ */
29
+ get length() {
30
+ return Math.sqrt(this.x * this.x + this.y * this.y);
31
+ }
32
+ /**
33
+ * The function calculates the square of the length of a vector.
34
+ * @returns The method is returning the sum of the squares of the x and y values.
35
+ */
36
+ get lengthSq() {
37
+ return this.x * this.x + this.y * this.y;
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() {
45
+ return new Vector2D(Math.round(this.x), Math.round(this.y));
46
+ }
47
+ /**
48
+ * The function "add" takes two Vector2D objects as parameters and returns a new Vector2D object with the sum of their
49
+ * x and y components.
50
+ * @param {Vector2D} vector1 - The parameter `vector1` is an instance of the `Vector2D` class. It represents a
51
+ * 2-dimensional vector with an `x` and `y` component.
52
+ * @param {Vector2D} vector2 - The parameter "vector2" is of type Vector2D. It represents a 2-dimensional vector with
53
+ * an x and y component.
54
+ * @returns The method is returning a new instance of the Vector2D class with the x and y components of the two input
55
+ * vectors added together.
56
+ */
57
+ static add(vector1, vector2) {
58
+ return new Vector2D(vector1.x + vector2.x, vector1.y + vector2.y);
59
+ }
60
+ /**
61
+ * The subtract function takes two Vector2D objects as parameters and returns a new Vector2D object with the x and y
62
+ * components subtracted.
63
+ * @param {Vector2D} vector1 - The parameter `vector1` is an instance of the `Vector2D` class, representing a
64
+ * 2-dimensional vector. It has properties `x` and `y` which represent the x and y components of the vector
65
+ * respectively.
66
+ * @param {Vector2D} vector2 - The parameter "vector2" is a Vector2D object. It represents the second vector that you
67
+ * want to subtract from the first vector.
68
+ * @returns The method is returning a new Vector2D object with the x and y components subtracted from vector1 and
69
+ * vector2.
70
+ */
71
+ static subtract(vector1, vector2) {
72
+ return new Vector2D(vector1.x - vector2.x, vector1.y - vector2.y);
73
+ }
74
+ /**
75
+ * The function subtracts a given value from the x and y components of a Vector2D object and returns a new Vector2D
76
+ * object.
77
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector with
78
+ * x and y components.
79
+ * @param {number} value - The "value" parameter is a number that will be subtracted from both the x and y components
80
+ * of the "vector" parameter.
81
+ * @returns A new Vector2D object with the x and y values subtracted by the given value.
82
+ */
83
+ static subtractValue(vector, value) {
84
+ return new Vector2D(vector.x - value, vector.y - value);
85
+ }
86
+ /**
87
+ * The function multiplies a Vector2D object by a given value.
88
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector with
89
+ * x and y components.
90
+ * @param {number} value - The "value" parameter is a number that represents the value by which the x and y components
91
+ * of the vector will be multiplied.
92
+ * @returns A new Vector2D object with the x and y values multiplied by the given value.
93
+ */
94
+ static multiply(vector, value) {
95
+ return new Vector2D(vector.x * value, vector.y * value);
96
+ }
97
+ /**
98
+ * The function divides the x and y components of a Vector2D by a given value and returns a new Vector2D.
99
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector with
100
+ * x and y components.
101
+ * @param {number} value - The value parameter is a number that will be used to divide the x and y components of the
102
+ * vector.
103
+ * @returns A new instance of the Vector2D class with the x and y values divided by the given value.
104
+ */
105
+ static divide(vector, value) {
106
+ return new Vector2D(vector.x / value, vector.y / value);
107
+ }
108
+ /**
109
+ * The function checks if two Vector2D objects are equal by comparing their x and y values.
110
+ * @param {Vector2D} vector1 - The parameter `vector1` is of type `Vector2D`, which represents a 2-dimensional vector.
111
+ * It has two properties: `x` and `y`, which represent the x and y components of the vector, respectively.
112
+ * @param {Vector2D} vector2 - The parameter "vector2" is of type Vector2D.
113
+ * @returns a boolean value, which indicates whether the two input vectors are equal or not.
114
+ */
115
+ static equals(vector1, vector2) {
116
+ return vector1.x === vector2.x && vector1.y === vector2.y;
117
+ }
118
+ /**
119
+ * The function checks if two Vector2D objects are equal within a specified rounding factor.
120
+ * @param {Vector2D} vector1 - The first vector to compare.
121
+ * @param {Vector2D} vector2 - The parameter "vector2" is a Vector2D object, which represents a 2-dimensional vector.
122
+ * It is used as one of the inputs for the "equalsRounded" function.
123
+ * @param [roundingFactor=12] - The roundingFactor parameter is used to determine the threshold for considering two
124
+ * vectors as equal. If the absolute difference in the x and y components of the vectors is less than the
125
+ * roundingFactor, the vectors are considered equal.
126
+ * @returns a boolean value.
127
+ */
128
+ static equalsRounded(vector1, vector2, roundingFactor = 12) {
129
+ const vector = Vector2D.abs(Vector2D.subtract(vector1, vector2));
130
+ if (vector.x < roundingFactor && vector.y < roundingFactor) {
131
+ return true;
132
+ }
133
+ return false;
134
+ }
135
+ /**
136
+ * 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
137
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D.
138
+ * @returns the normalized vector if its length is greater than a very small value (epsilon), otherwise it returns the
139
+ * original vector.
140
+ */
141
+ static normalize(vector) {
142
+ const length = vector.length;
143
+ if (length > 2.220446049250313e-16) {
144
+ // Epsilon
145
+ return Vector2D.divide(vector, length);
146
+ }
147
+ return vector;
148
+ }
149
+ /**
150
+ * 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
151
+ * @param {Vector2D} vector - A 2D vector represented by the Vector2D class.
152
+ * @param {number} max - The `max` parameter is a number that represents the maximum length that the `vector` should
153
+ * have.
154
+ * @returns either the original vector or a truncated version of the vector, depending on whether the length of the
155
+ * vector is greater than the maximum value specified.
156
+ */
157
+ static truncate(vector, max) {
158
+ if (vector.length > max) {
159
+ return Vector2D.multiply(Vector2D.normalize(vector), max);
160
+ }
161
+ return vector;
162
+ }
163
+ /**
164
+ * The function returns a new Vector2D object that is perpendicular to the input vector.The vector that is perpendicular to this one
165
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D.
166
+ * @returns A new Vector2D object is being returned.
167
+ */
168
+ static perp(vector) {
169
+ return new Vector2D(-vector.y, vector.x);
170
+ }
171
+ /**
172
+ * The reverse function takes a Vector2D object and returns a new Vector2D object with the negated x and y values.
173
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector. It
174
+ * has two properties: "x" and "y", which represent the x and y components of the vector, respectively.
175
+ * @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
176
+ */
177
+ static reverse(vector) {
178
+ return new Vector2D(-vector.x, -vector.y);
179
+ }
180
+ /**
181
+ * The function takes a Vector2D object as input and returns a new Vector2D object with the absolute values of its x
182
+ * and y components.
183
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector. It
184
+ * has two properties: "x" and "y", which represent the x and y components of the vector, respectively.
185
+ * @returns The method is returning a new Vector2D object with the absolute values of the x and y components of the
186
+ * input vector.
187
+ */
188
+ static abs(vector) {
189
+ return new Vector2D(Math.abs(vector.x), Math.abs(vector.y));
190
+ }
191
+ /**
192
+ * The dot function calculates the dot product of two 2D vectors.The dot product of v1 and v2
193
+ * @param {Vector2D} vector1 - The parameter `vector1` represents a 2D vector with its x and y components.
194
+ * @param {Vector2D} vector2 - The "vector2" parameter is a Vector2D object. It represents a two-dimensional vector
195
+ * with an x and y component.
196
+ * @returns The dot product of the two input vectors.
197
+ */
198
+ static dot(vector1, vector2) {
199
+ return vector1.x * vector2.x + vector1.y * vector2.y;
200
+ }
201
+ // /**
202
+ // * Transform vectors based on the current tranformation matrices: translation, rotation and scale
203
+ // * @param vectors The vectors to transform
204
+ // */
205
+ // static transform(vector: Vector2D, transformation: Matrix2D): Vector2D {
206
+ // return Matrix2D.multiplyByVector(transformation, vector)
207
+ // }
208
+ // /**
209
+ // * Transform vectors based on the current tranformation matrices: translation, rotation and scale
210
+ // * @param vectors The vectors to transform
211
+ // */
212
+ // static transformList(vectors: Vector2D[], transformation: Matrix2D): Vector2D[] {
213
+ // return vectors.map(vector => Matrix2D.multiplyByVector(transformation, vector))
214
+ // }
215
+ /**
216
+ * The function calculates the distance between two points in a two-dimensional space.
217
+ * @param {Vector2D} vector1 - The parameter `vector1` represents the first vector in 2D space, while `vector2`
218
+ * represents the second vector. Each vector has an `x` and `y` component, which represent their respective coordinates
219
+ * in the 2D space.
220
+ * @param {Vector2D} vector2 - The `vector2` parameter represents the second vector in the calculation of distance. It
221
+ * is an instance of the `Vector2D` class, which typically has properties `x` and `y` representing the coordinates of
222
+ * the vector in a 2D space.
223
+ * @returns The distance between vector1 and vector2.
224
+ */
225
+ static distance(vector1, vector2) {
226
+ const ySeparation = vector2.y - vector1.y;
227
+ const xSeparation = vector2.x - vector1.x;
228
+ return Math.sqrt(ySeparation * ySeparation + xSeparation * xSeparation);
229
+ }
230
+ /**
231
+ * The function calculates the squared distance between two 2D vectors.
232
+ * @param {Vector2D} vector1 - The parameter `vector1` represents the first vector, which is an instance of the
233
+ * `Vector2D` class. It contains the x and y coordinates of the vector.
234
+ * @param {Vector2D} vector2 - The `vector2` parameter represents the second vector in a two-dimensional space. It has
235
+ * properties `x` and `y` which represent the coordinates of the vector.
236
+ * @returns the square of the distance between the two input vectors.
237
+ */
238
+ static distanceSq(vector1, vector2) {
239
+ const ySeparation = vector2.y - vector1.y;
240
+ const xSeparation = vector2.x - vector1.x;
241
+ return ySeparation * ySeparation + xSeparation * xSeparation;
242
+ }
243
+ /**
244
+ * The sign function determines the sign of the cross product between two 2D vectors.
245
+ * (assuming the Y axis is pointing down, X axis to right like a Window app)
246
+ * @param {Vector2D} vector1 - The parameter `vector1` is of type `Vector2D`, which represents a 2-dimensional vector.
247
+ * It likely has properties `x` and `y` representing the x and y components of the vector, respectively.
248
+ * @param {Vector2D} vector2 - The above code defines a function called "sign" that takes two parameters: vector1 and
249
+ * vector2. Both vector1 and vector2 are of type Vector2D.
250
+ * @returns either -1 or 1. Returns positive if v2 is clockwise of this vector, negative if counterclockwise
251
+ */
252
+ static sign(vector1, vector2) {
253
+ if (vector1.y * vector2.x > vector1.x * vector2.y) {
254
+ return -1;
255
+ }
256
+ return 1;
257
+ }
258
+ /**
259
+ * The function calculates the angle between a given vector and the negative y-axis.
260
+ * @param {Vector2D} vector - The "vector" parameter is an instance of the Vector2D class, which represents a
261
+ * 2-dimensional vector. It has two properties: "x" and "y", which represent the x and y components of the vector,
262
+ * respectively.
263
+ * @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
264
+ */
265
+ static angle(vector) {
266
+ const origin = new Vector2D(0, -1);
267
+ const radian = Math.acos(Vector2D.dot(vector, origin) / (vector.length * origin.length));
268
+ return Vector2D.sign(vector, origin) === 1 ? Math.PI * 2 - radian : radian;
269
+ }
270
+ /**
271
+ * The function "random" generates a random Vector2D object with x and y values within the specified range.
272
+ * @param {number} maxX - The maxX parameter represents the maximum value for the x-coordinate of the random vector.
273
+ * @param {number} maxY - The `maxY` parameter represents the maximum value for the y-coordinate of the generated
274
+ * random vector.
275
+ * @returns a new instance of the Vector2D class with random x and y values.
276
+ */
277
+ static random(maxX, maxY) {
278
+ const randX = Math.floor(Math.random() * maxX - maxX / 2);
279
+ const randY = Math.floor(Math.random() * maxY - maxY / 2);
280
+ return new Vector2D(randX, randY);
281
+ }
282
+ /**
283
+ * The function sets the values of x and y to zero.
284
+ */
285
+ zero() {
286
+ this.x = 0;
287
+ this.y = 0;
288
+ }
289
+ }
290
+ exports.Vector2D = Vector2D;
@@ -0,0 +1,3 @@
1
+ export * from './priority-queue';
2
+ export * from './min-priority-queue';
3
+ export * from './max-priority-queue';
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./priority-queue"), exports);
18
+ __exportStar(require("./min-priority-queue"), exports);
19
+ __exportStar(require("./max-priority-queue"), exports);
@@ -0,0 +1,15 @@
1
+ /**
2
+ * data-structure-typed
3
+ *
4
+ * @author Kirk Qi
5
+ * @copyright Copyright (c) 2022 Kirk Qi <qilinaus@gmail.com>
6
+ * @license MIT License
7
+ */
8
+ import { PriorityQueue } from './priority-queue';
9
+ import type { Comparator } from '../../types';
10
+ export declare class MaxPriorityQueue<E = any> extends PriorityQueue<E> {
11
+ constructor(options?: {
12
+ comparator: Comparator<E>;
13
+ nodes?: E[];
14
+ });
15
+ }
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MaxPriorityQueue = void 0;
4
+ /**
5
+ * data-structure-typed
6
+ *
7
+ * @author Kirk Qi
8
+ * @copyright Copyright (c) 2022 Kirk Qi <qilinaus@gmail.com>
9
+ * @license MIT License
10
+ */
11
+ const priority_queue_1 = require("./priority-queue");
12
+ class MaxPriorityQueue extends priority_queue_1.PriorityQueue {
13
+ constructor(options = {
14
+ comparator: (a, b) => {
15
+ if (!(typeof a === 'number' && typeof b === 'number')) {
16
+ throw new Error('The a, b params of compare function must be number');
17
+ }
18
+ else {
19
+ return b - a;
20
+ }
21
+ }
22
+ }) {
23
+ super(options);
24
+ }
25
+ }
26
+ exports.MaxPriorityQueue = MaxPriorityQueue;