data-structure-typed 0.8.18 → 1.3.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 (272) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +690 -2
  3. package/dist/bundle.js +2 -0
  4. package/dist/bundle.js.LICENSE.txt +13 -0
  5. package/dist/data-structures/binary-tree/abstract-binary-tree.d.ts +364 -0
  6. package/dist/data-structures/binary-tree/abstract-binary-tree.js +1308 -0
  7. package/dist/data-structures/binary-tree/avl-tree.d.ts +85 -18
  8. package/dist/data-structures/binary-tree/avl-tree.js +110 -37
  9. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +40 -2
  10. package/dist/data-structures/binary-tree/binary-indexed-tree.js +44 -2
  11. package/dist/data-structures/binary-tree/binary-tree.d.ts +29 -138
  12. package/dist/data-structures/binary-tree/binary-tree.js +27 -979
  13. package/dist/data-structures/binary-tree/bst.d.ts +118 -28
  14. package/dist/data-structures/binary-tree/bst.js +162 -124
  15. package/dist/data-structures/binary-tree/index.d.ts +1 -0
  16. package/dist/data-structures/binary-tree/index.js +1 -0
  17. package/dist/data-structures/binary-tree/rb-tree.d.ts +18 -1
  18. package/dist/data-structures/binary-tree/rb-tree.js +40 -2
  19. package/dist/data-structures/binary-tree/segment-tree.d.ts +63 -13
  20. package/dist/data-structures/binary-tree/segment-tree.js +80 -17
  21. package/dist/data-structures/binary-tree/tree-multiset.d.ts +213 -10
  22. package/dist/data-structures/binary-tree/tree-multiset.js +682 -9
  23. package/dist/data-structures/graph/abstract-graph.d.ts +270 -64
  24. package/dist/data-structures/graph/abstract-graph.js +365 -92
  25. package/dist/data-structures/graph/directed-graph.d.ts +175 -26
  26. package/dist/data-structures/graph/directed-graph.js +249 -95
  27. package/dist/data-structures/graph/index.d.ts +1 -0
  28. package/dist/data-structures/graph/index.js +1 -0
  29. package/dist/data-structures/graph/map-graph.d.ts +79 -0
  30. package/dist/data-structures/graph/map-graph.js +111 -0
  31. package/dist/data-structures/graph/undirected-graph.d.ts +111 -8
  32. package/dist/data-structures/graph/undirected-graph.js +154 -44
  33. package/dist/data-structures/hash/coordinate-map.d.ts +39 -2
  34. package/dist/data-structures/hash/coordinate-map.js +44 -3
  35. package/dist/data-structures/hash/coordinate-set.d.ts +32 -2
  36. package/dist/data-structures/hash/coordinate-set.js +34 -0
  37. package/dist/data-structures/hash/hash-table.d.ts +2 -1
  38. package/dist/data-structures/hash/hash-table.js +4 -0
  39. package/dist/data-structures/hash/index.d.ts +5 -0
  40. package/dist/data-structures/hash/index.js +5 -0
  41. package/dist/data-structures/hash/pair.d.ts +2 -1
  42. package/dist/data-structures/hash/pair.js +4 -0
  43. package/dist/data-structures/hash/tree-map.d.ts +2 -1
  44. package/dist/data-structures/hash/tree-map.js +4 -0
  45. package/dist/data-structures/hash/tree-set.d.ts +2 -1
  46. package/dist/data-structures/hash/tree-set.js +4 -0
  47. package/dist/data-structures/heap/heap.d.ts +62 -51
  48. package/dist/data-structures/heap/heap.js +106 -63
  49. package/dist/data-structures/heap/max-heap.d.ts +13 -4
  50. package/dist/data-structures/heap/max-heap.js +10 -2
  51. package/dist/data-structures/heap/min-heap.d.ts +14 -4
  52. package/dist/data-structures/heap/min-heap.js +11 -2
  53. package/dist/data-structures/index.d.ts +1 -0
  54. package/dist/data-structures/index.js +1 -0
  55. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +193 -57
  56. package/dist/data-structures/linked-list/doubly-linked-list.js +461 -194
  57. package/dist/data-structures/linked-list/index.d.ts +1 -0
  58. package/dist/data-structures/linked-list/index.js +1 -0
  59. package/dist/data-structures/linked-list/singly-linked-list.d.ts +117 -319
  60. package/dist/data-structures/linked-list/singly-linked-list.js +338 -557
  61. package/dist/data-structures/linked-list/skip-linked-list.d.ts +2 -1
  62. package/dist/data-structures/linked-list/skip-linked-list.js +4 -0
  63. package/dist/data-structures/matrix/matrix.d.ts +12 -0
  64. package/dist/data-structures/matrix/matrix.js +14 -0
  65. package/dist/data-structures/matrix/matrix2d.d.ts +87 -4
  66. package/dist/data-structures/matrix/matrix2d.js +91 -8
  67. package/dist/data-structures/matrix/navigator.d.ts +37 -16
  68. package/dist/data-structures/matrix/navigator.js +28 -0
  69. package/dist/data-structures/matrix/vector2d.d.ts +156 -29
  70. package/dist/data-structures/matrix/vector2d.js +184 -55
  71. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +12 -1
  72. package/dist/data-structures/priority-queue/max-priority-queue.js +28 -4
  73. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +12 -1
  74. package/dist/data-structures/priority-queue/min-priority-queue.js +29 -4
  75. package/dist/data-structures/priority-queue/priority-queue.d.ts +166 -22
  76. package/dist/data-structures/priority-queue/priority-queue.js +219 -75
  77. package/dist/data-structures/queue/deque.d.ts +141 -13
  78. package/dist/data-structures/queue/deque.js +151 -7
  79. package/dist/data-structures/queue/queue.d.ts +68 -42
  80. package/dist/data-structures/queue/queue.js +95 -51
  81. package/dist/data-structures/stack/stack.d.ts +30 -36
  82. package/dist/data-structures/stack/stack.js +31 -37
  83. package/dist/data-structures/tree/index.d.ts +1 -0
  84. package/dist/data-structures/tree/index.js +17 -0
  85. package/dist/data-structures/tree/tree.d.ts +14 -0
  86. package/dist/{types/utils.js → data-structures/tree/tree.js} +26 -19
  87. package/dist/data-structures/trie/trie.d.ts +39 -6
  88. package/dist/data-structures/trie/trie.js +81 -12
  89. package/dist/index.d.ts +3 -0
  90. package/dist/index.js +3 -0
  91. package/dist/interfaces/abstract-binary-tree.d.ts +90 -0
  92. package/dist/interfaces/abstract-binary-tree.js +2 -0
  93. package/dist/interfaces/abstract-graph.d.ts +17 -0
  94. package/dist/interfaces/abstract-graph.js +2 -0
  95. package/dist/interfaces/avl-tree.d.ts +9 -0
  96. package/dist/interfaces/avl-tree.js +2 -0
  97. package/dist/interfaces/binary-tree.d.ts +6 -0
  98. package/dist/interfaces/binary-tree.js +2 -0
  99. package/dist/interfaces/bst.d.ts +17 -0
  100. package/dist/interfaces/bst.js +2 -0
  101. package/dist/interfaces/directed-graph.d.ts +12 -0
  102. package/dist/interfaces/directed-graph.js +2 -0
  103. package/dist/interfaces/doubly-linked-list.js +2 -0
  104. package/dist/interfaces/heap.js +2 -0
  105. package/dist/interfaces/index.d.ts +15 -0
  106. package/dist/interfaces/index.js +31 -0
  107. package/dist/interfaces/navigator.js +2 -0
  108. package/dist/interfaces/priority-queue.js +2 -0
  109. package/dist/interfaces/rb-tree.d.ts +8 -0
  110. package/dist/interfaces/rb-tree.js +2 -0
  111. package/dist/interfaces/segment-tree.js +2 -0
  112. package/dist/interfaces/singly-linked-list.js +2 -0
  113. package/dist/interfaces/tree-multiset.d.ts +7 -0
  114. package/dist/interfaces/tree-multiset.js +2 -0
  115. package/dist/interfaces/undirected-graph.d.ts +5 -0
  116. package/dist/interfaces/undirected-graph.js +2 -0
  117. package/dist/types/data-structures/abstract-binary-tree.d.ts +34 -0
  118. package/dist/types/data-structures/abstract-binary-tree.js +25 -0
  119. package/dist/types/data-structures/abstract-graph.d.ts +11 -0
  120. package/dist/types/data-structures/abstract-graph.js +2 -0
  121. package/dist/types/data-structures/avl-tree.d.ts +4 -0
  122. package/dist/types/data-structures/avl-tree.js +2 -0
  123. package/dist/types/data-structures/binary-tree.d.ts +4 -0
  124. package/dist/types/data-structures/binary-tree.js +2 -0
  125. package/dist/types/data-structures/bst.d.ts +13 -0
  126. package/dist/types/data-structures/bst.js +9 -0
  127. package/dist/types/data-structures/directed-graph.d.ts +6 -0
  128. package/dist/types/data-structures/directed-graph.js +9 -0
  129. package/dist/types/data-structures/doubly-linked-list.js +2 -0
  130. package/dist/types/data-structures/heap.d.ts +3 -0
  131. package/dist/types/data-structures/heap.js +2 -0
  132. package/dist/types/data-structures/index.d.ts +13 -7
  133. package/dist/types/data-structures/index.js +31 -0
  134. package/dist/types/data-structures/map-graph.d.ts +1 -0
  135. package/dist/types/data-structures/map-graph.js +2 -0
  136. package/dist/types/data-structures/navigator.d.ts +14 -0
  137. package/dist/types/data-structures/navigator.js +2 -0
  138. package/dist/types/data-structures/priority-queue.d.ts +7 -0
  139. package/dist/types/data-structures/priority-queue.js +2 -0
  140. package/dist/types/data-structures/rb-tree.d.ts +8 -0
  141. package/dist/types/data-structures/rb-tree.js +8 -0
  142. package/dist/types/data-structures/segment-tree.d.ts +1 -0
  143. package/dist/types/data-structures/segment-tree.js +2 -0
  144. package/dist/types/data-structures/singly-linked-list.js +2 -0
  145. package/dist/types/data-structures/tree-multiset.d.ts +4 -0
  146. package/dist/types/data-structures/tree-multiset.js +2 -0
  147. package/dist/types/helpers.d.ts +1 -0
  148. package/dist/types/helpers.js +2 -0
  149. package/dist/types/index.d.ts +2 -0
  150. package/dist/types/index.js +2 -0
  151. package/dist/types/utils/index.d.ts +2 -0
  152. package/dist/types/utils/index.js +18 -0
  153. package/dist/types/utils/utils.d.ts +7 -0
  154. package/dist/types/utils/utils.js +2 -0
  155. package/dist/types/utils/validate-type.d.ts +19 -0
  156. package/dist/types/utils/validate-type.js +2 -0
  157. package/dist/utils/index.js +17 -0
  158. package/dist/utils/utils.d.ts +19 -0
  159. package/dist/{data-structures/trampoline.js → utils/utils.js} +26 -12
  160. package/package.json +106 -55
  161. package/.idea/data-structure-typed.iml +0 -12
  162. package/.idea/modules.xml +0 -8
  163. package/.idea/vcs.xml +0 -6
  164. package/dist/data-structures/trampoline.d.ts +0 -25
  165. package/dist/types/data-structures/binary-tree/aa-tree.d.ts +0 -2
  166. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +0 -21
  167. package/dist/types/data-structures/binary-tree/b-tree.d.ts +0 -2
  168. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -8
  169. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +0 -140
  170. package/dist/types/data-structures/binary-tree/bst.d.ts +0 -32
  171. package/dist/types/data-structures/binary-tree/index.d.ts +0 -4
  172. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +0 -2
  173. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +0 -33
  174. package/dist/types/data-structures/binary-tree/splay-tree.d.ts +0 -2
  175. package/dist/types/data-structures/binary-tree/tree-multiset.d.ts +0 -11
  176. package/dist/types/data-structures/binary-tree/two-three-tree.d.ts +0 -2
  177. package/dist/types/data-structures/graph/abstract-graph.d.ts +0 -126
  178. package/dist/types/data-structures/graph/directed-graph.d.ts +0 -51
  179. package/dist/types/data-structures/graph/index.d.ts +0 -3
  180. package/dist/types/data-structures/graph/undirected-graph.d.ts +0 -24
  181. package/dist/types/data-structures/hash/coordinate-map.d.ts +0 -8
  182. package/dist/types/data-structures/hash/coordinate-set.d.ts +0 -7
  183. package/dist/types/data-structures/hash/index.d.ts +0 -1
  184. package/dist/types/data-structures/heap/heap.d.ts +0 -72
  185. package/dist/types/data-structures/heap/index.d.ts +0 -3
  186. package/dist/types/data-structures/heap/max-heap.d.ts +0 -14
  187. package/dist/types/data-structures/heap/min-heap.d.ts +0 -14
  188. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +0 -59
  189. package/dist/types/data-structures/linked-list/index.d.ts +0 -2
  190. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +0 -358
  191. package/dist/types/data-structures/matrix/index.d.ts +0 -3
  192. package/dist/types/data-structures/matrix/matrix.d.ts +0 -9
  193. package/dist/types/data-structures/matrix/matrix2d.d.ts +0 -25
  194. package/dist/types/data-structures/matrix/navigator.d.ts +0 -31
  195. package/dist/types/data-structures/matrix/vector2d.d.ts +0 -74
  196. package/dist/types/data-structures/priority-queue/index.d.ts +0 -3
  197. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +0 -4
  198. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +0 -4
  199. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +0 -36
  200. package/dist/types/data-structures/queue/deque.d.ts +0 -37
  201. package/dist/types/data-structures/queue/index.d.ts +0 -1
  202. package/dist/types/data-structures/queue/queue.d.ts +0 -76
  203. package/dist/types/data-structures/stack/index.d.ts +0 -1
  204. package/dist/types/data-structures/stack/stack.d.ts +0 -69
  205. package/dist/types/data-structures/trampoline.d.ts +0 -25
  206. package/dist/types/data-structures/trie/index.d.ts +0 -1
  207. package/dist/types/data-structures/trie/trie.d.ts +0 -28
  208. package/dist/types/types/utils.d.ts +0 -46
  209. package/dist/types/utils.d.ts +0 -46
  210. package/dist/utils.d.ts +0 -122
  211. package/dist/utils.js +0 -569
  212. package/src/data-structures/binary-tree/aa-tree.ts +0 -3
  213. package/src/data-structures/binary-tree/avl-tree.ts +0 -232
  214. package/src/data-structures/binary-tree/b-tree.ts +0 -3
  215. package/src/data-structures/binary-tree/binary-indexed-tree.ts +0 -33
  216. package/src/data-structures/binary-tree/binary-tree.ts +0 -1088
  217. package/src/data-structures/binary-tree/bst.ts +0 -404
  218. package/src/data-structures/binary-tree/index.ts +0 -11
  219. package/src/data-structures/binary-tree/rb-tree.ts +0 -3
  220. package/src/data-structures/binary-tree/segment-tree.ts +0 -164
  221. package/src/data-structures/binary-tree/splay-tree.ts +0 -3
  222. package/src/data-structures/binary-tree/tree-multiset.ts +0 -21
  223. package/src/data-structures/binary-tree/two-three-tree.ts +0 -3
  224. package/src/data-structures/graph/abstract-graph.ts +0 -789
  225. package/src/data-structures/graph/directed-graph.ts +0 -322
  226. package/src/data-structures/graph/index.ts +0 -3
  227. package/src/data-structures/graph/undirected-graph.ts +0 -154
  228. package/src/data-structures/hash/coordinate-map.ts +0 -24
  229. package/src/data-structures/hash/coordinate-set.ts +0 -20
  230. package/src/data-structures/hash/hash-table.ts +0 -1
  231. package/src/data-structures/hash/index.ts +0 -1
  232. package/src/data-structures/heap/heap.ts +0 -136
  233. package/src/data-structures/heap/index.ts +0 -3
  234. package/src/data-structures/heap/max-heap.ts +0 -22
  235. package/src/data-structures/heap/min-heap.ts +0 -24
  236. package/src/data-structures/index.ts +0 -11
  237. package/src/data-structures/linked-list/doubly-linked-list.ts +0 -258
  238. package/src/data-structures/linked-list/index.ts +0 -2
  239. package/src/data-structures/linked-list/singly-linked-list.ts +0 -750
  240. package/src/data-structures/linked-list/skip-linked-list.ts +0 -1
  241. package/src/data-structures/matrix/index.ts +0 -4
  242. package/src/data-structures/matrix/matrix.ts +0 -13
  243. package/src/data-structures/matrix/matrix2d.ts +0 -125
  244. package/src/data-structures/matrix/navigator.ts +0 -99
  245. package/src/data-structures/matrix/vector2d.ts +0 -189
  246. package/src/data-structures/priority-queue/index.ts +0 -3
  247. package/src/data-structures/priority-queue/max-priority-queue.ts +0 -12
  248. package/src/data-structures/priority-queue/min-priority-queue.ts +0 -12
  249. package/src/data-structures/priority-queue/priority-queue.ts +0 -208
  250. package/src/data-structures/queue/deque.ts +0 -139
  251. package/src/data-structures/queue/index.ts +0 -2
  252. package/src/data-structures/queue/queue.ts +0 -123
  253. package/src/data-structures/stack/index.ts +0 -1
  254. package/src/data-structures/stack/stack.ts +0 -104
  255. package/src/data-structures/trampoline.ts +0 -91
  256. package/src/data-structures/trie/index.ts +0 -1
  257. package/src/data-structures/trie/trie.ts +0 -153
  258. package/src/index.ts +0 -1
  259. package/src/types/index.ts +0 -1
  260. package/src/types/patches/index.d.ts +0 -0
  261. package/src/types/utils.ts +0 -158
  262. package/src/utils.ts +0 -605
  263. package/tsconfig.json +0 -53
  264. /package/dist/{types/data-structures/hash/hash-table.d.ts → interfaces/doubly-linked-list.d.ts} +0 -0
  265. /package/dist/{types/data-structures/hash/pair.d.ts → interfaces/heap.d.ts} +0 -0
  266. /package/dist/{types/data-structures/hash/tree-map.d.ts → interfaces/navigator.d.ts} +0 -0
  267. /package/dist/{types/data-structures/hash/tree-set.d.ts → interfaces/priority-queue.d.ts} +0 -0
  268. /package/dist/{types/data-structures/linked-list/skip-linked-list.d.ts → interfaces/segment-tree.d.ts} +0 -0
  269. /package/{src/data-structures/hash/pair.ts → dist/interfaces/singly-linked-list.d.ts} +0 -0
  270. /package/{src/data-structures/hash/tree-map.ts → dist/types/data-structures/doubly-linked-list.d.ts} +0 -0
  271. /package/{src/data-structures/hash/tree-set.ts → dist/types/data-structures/singly-linked-list.d.ts} +0 -0
  272. /package/dist/{types/types → utils}/index.d.ts +0 -0
@@ -1,74 +1,201 @@
1
- declare class Vector2D {
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 {
2
9
  x: number;
3
10
  y: number;
4
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
+ */
5
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
+ */
6
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
+ */
7
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
+ */
8
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
+ */
9
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
+ */
10
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
+ */
11
103
  static equalsRounded(vector1: Vector2D, vector2: Vector2D, roundingFactor?: number): boolean;
12
104
  /**
13
- * Normalizes the vector if it matches a certain condition
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.
14
109
  */
15
110
  static normalize(vector: Vector2D): Vector2D;
16
111
  /**
17
- * Adjusts x and y so that the length of the vector does not exceed max
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.
18
118
  */
19
119
  static truncate(vector: Vector2D, max: number): Vector2D;
20
120
  /**
21
- * The vector that is perpendicular to this one
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.
22
124
  */
23
125
  static perp(vector: Vector2D): Vector2D;
24
126
  /**
25
- * returns the vector that is the reverse of this vector
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
26
131
  */
27
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
+ */
28
141
  static abs(vector: Vector2D): Vector2D;
29
142
  /**
30
- * The dot product of v1 and v2
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.
31
148
  */
32
149
  static dot(vector1: Vector2D, vector2: Vector2D): number;
33
150
  /**
34
- * The distance between this and the vector
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.
35
159
  */
36
160
  static distance(vector1: Vector2D, vector2: Vector2D): number;
37
161
  /**
38
- * The distance between this and the vector squared
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.
39
168
  */
40
169
  static distanceSq(vector1: Vector2D, vector2: Vector2D): number;
41
170
  /**
42
- * Returns positive if v2 is clockwise of this vector, negative if counterclockwise
171
+ * The sign function determines the sign of the cross product between two 2D vectors.
43
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
44
178
  */
45
179
  static sign(vector1: Vector2D, vector2: Vector2D): number;
46
180
  /**
47
- * Returns the angle between origin and the given vector in radians
48
- * @param vector
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
49
186
  */
50
187
  static angle(vector: Vector2D): number;
51
- static random(maxX: number, maxY: number): Vector2D;
52
- constructor(x?: number, y?: number, w?: number);
53
- /**
54
- * Check wether both x and y are zero
55
- */
56
- zero(): void;
57
- /**
58
- * Set x and y both to zero
59
- */
60
- get isZero(): boolean;
61
188
  /**
62
- * The length / magnitude of the vector
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.
63
194
  */
64
- get length(): number;
65
- /**
66
- * The squared length of the vector
67
- */
68
- get lengthSq(): number;
195
+ static random(maxX: number, maxY: number): Vector2D;
69
196
  /**
70
- * Return the vector with rounded values
197
+ * The function sets the values of x and y to zero.
71
198
  */
72
- get rounded(): Vector2D;
199
+ zero(): void;
73
200
  }
74
201
  export default Vector2D;
@@ -1,24 +1,130 @@
1
1
  "use strict";
2
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
+ */
3
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
+ */
4
57
  static add(vector1, vector2) {
5
58
  return new Vector2D(vector1.x + vector2.x, vector1.y + vector2.y);
6
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
+ */
7
71
  static subtract(vector1, vector2) {
8
72
  return new Vector2D(vector1.x - vector2.x, vector1.y - vector2.y);
9
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
+ */
10
83
  static subtractValue(vector, value) {
11
84
  return new Vector2D(vector.x - value, vector.y - value);
12
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
+ */
13
94
  static multiply(vector, value) {
14
95
  return new Vector2D(vector.x * value, vector.y * value);
15
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
+ */
16
105
  static divide(vector, value) {
17
106
  return new Vector2D(vector.x / value, vector.y / value);
18
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
+ */
19
115
  static equals(vector1, vector2) {
20
116
  return vector1.x === vector2.x && vector1.y === vector2.y;
21
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
+ */
22
128
  static equalsRounded(vector1, vector2, roundingFactor = 12) {
23
129
  const vector = Vector2D.abs(Vector2D.subtract(vector1, vector2));
24
130
  if (vector.x < roundingFactor && vector.y < roundingFactor) {
@@ -27,7 +133,10 @@ class Vector2D {
27
133
  return false;
28
134
  }
29
135
  /**
30
- * Normalizes the vector if it matches a certain condition
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.
31
140
  */
32
141
  static normalize(vector) {
33
142
  const length = vector.length;
@@ -37,7 +146,12 @@ class Vector2D {
37
146
  return vector;
38
147
  }
39
148
  /**
40
- * Adjusts x and y so that the length of the vector does not exceed max
149
+ * 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
150
+ * @param {Vector2D} vector - A 2D vector represented by the Vector2D class.
151
+ * @param {number} max - The `max` parameter is a number that represents the maximum length that the `vector` should
152
+ * have.
153
+ * @returns either the original vector or a truncated version of the vector, depending on whether the length of the
154
+ * vector is greater than the maximum value specified.
41
155
  */
42
156
  static truncate(vector, max) {
43
157
  if (vector.length > max) {
@@ -46,28 +160,66 @@ class Vector2D {
46
160
  return vector;
47
161
  }
48
162
  /**
49
- * The vector that is perpendicular to this one
163
+ * The function returns a new Vector2D object that is perpendicular to the input vector.The vector that is perpendicular to this one
164
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D.
165
+ * @returns A new Vector2D object is being returned.
50
166
  */
51
167
  static perp(vector) {
52
168
  return new Vector2D(-vector.y, vector.x);
53
169
  }
54
170
  /**
55
- * returns the vector that is the reverse of this vector
171
+ * The reverse function takes a Vector2D object and returns a new Vector2D object with the negated x and y values.
172
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector. It
173
+ * has two properties: "x" and "y", which represent the x and y components of the vector, respectively.
174
+ * @returns A new Vector2D object with the negated x and y values of the input vector. Returns the vector that is the reverse of this vector
56
175
  */
57
176
  static reverse(vector) {
58
177
  return new Vector2D(-vector.x, -vector.y);
59
178
  }
179
+ /**
180
+ * The function takes a Vector2D object as input and returns a new Vector2D object with the absolute values of its x
181
+ * and y components.
182
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector. It
183
+ * has two properties: "x" and "y", which represent the x and y components of the vector, respectively.
184
+ * @returns The method is returning a new Vector2D object with the absolute values of the x and y components of the
185
+ * input vector.
186
+ */
60
187
  static abs(vector) {
61
188
  return new Vector2D(Math.abs(vector.x), Math.abs(vector.y));
62
189
  }
63
190
  /**
64
- * The dot product of v1 and v2
191
+ * The dot function calculates the dot product of two 2D vectors.The dot product of v1 and v2
192
+ * @param {Vector2D} vector1 - The parameter `vector1` represents a 2D vector with its x and y components.
193
+ * @param {Vector2D} vector2 - The "vector2" parameter is a Vector2D object. It represents a two-dimensional vector
194
+ * with an x and y component.
195
+ * @returns The dot product of the two input vectors.
65
196
  */
66
197
  static dot(vector1, vector2) {
67
198
  return (vector1.x * vector2.x) + (vector1.y * vector2.y);
68
199
  }
200
+ // /**
201
+ // * Transform vectors based on the current tranformation matrices: translation, rotation and scale
202
+ // * @param vectors The vectors to transform
203
+ // */
204
+ // static transform(vector: Vector2D, transformation: Matrix2D): Vector2D {
205
+ // return Matrix2D.multiplyByVector(transformation, vector)
206
+ // }
207
+ // /**
208
+ // * Transform vectors based on the current tranformation matrices: translation, rotation and scale
209
+ // * @param vectors The vectors to transform
210
+ // */
211
+ // static transformList(vectors: Vector2D[], transformation: Matrix2D): Vector2D[] {
212
+ // return vectors.map(vector => Matrix2D.multiplyByVector(transformation, vector))
213
+ // }
69
214
  /**
70
- * The distance between this and the vector
215
+ * The function calculates the distance between two points in a two-dimensional space.
216
+ * @param {Vector2D} vector1 - The parameter `vector1` represents the first vector in 2D space, while `vector2`
217
+ * represents the second vector. Each vector has an `x` and `y` component, which represent their respective coordinates
218
+ * in the 2D space.
219
+ * @param {Vector2D} vector2 - The `vector2` parameter represents the second vector in the calculation of distance. It
220
+ * is an instance of the `Vector2D` class, which typically has properties `x` and `y` representing the coordinates of
221
+ * the vector in a 2D space.
222
+ * @returns The distance between vector1 and vector2.
71
223
  */
72
224
  static distance(vector1, vector2) {
73
225
  const ySeparation = vector2.y - vector1.y;
@@ -75,7 +227,12 @@ class Vector2D {
75
227
  return Math.sqrt((ySeparation * ySeparation) + (xSeparation * xSeparation));
76
228
  }
77
229
  /**
78
- * The distance between this and the vector squared
230
+ * The function calculates the squared distance between two 2D vectors.
231
+ * @param {Vector2D} vector1 - The parameter `vector1` represents the first vector, which is an instance of the
232
+ * `Vector2D` class. It contains the x and y coordinates of the vector.
233
+ * @param {Vector2D} vector2 - The `vector2` parameter represents the second vector in a two-dimensional space. It has
234
+ * properties `x` and `y` which represent the coordinates of the vector.
235
+ * @returns the square of the distance between the two input vectors.
79
236
  */
80
237
  static distanceSq(vector1, vector2) {
81
238
  const ySeparation = vector2.y - vector1.y;
@@ -83,8 +240,13 @@ class Vector2D {
83
240
  return (ySeparation * ySeparation) + (xSeparation * xSeparation);
84
241
  }
85
242
  /**
86
- * Returns positive if v2 is clockwise of this vector, negative if counterclockwise
243
+ * The sign function determines the sign of the cross product between two 2D vectors.
87
244
  * (assuming the Y axis is pointing down, X axis to right like a Window app)
245
+ * @param {Vector2D} vector1 - The parameter `vector1` is of type `Vector2D`, which represents a 2-dimensional vector.
246
+ * It likely has properties `x` and `y` representing the x and y components of the vector, respectively.
247
+ * @param {Vector2D} vector2 - The above code defines a function called "sign" that takes two parameters: vector1 and
248
+ * vector2. Both vector1 and vector2 are of type Vector2D.
249
+ * @returns either -1 or 1. Returns positive if v2 is clockwise of this vector, negative if counterclockwise
88
250
  */
89
251
  static sign(vector1, vector2) {
90
252
  if (vector1.y * vector2.x > vector1.x * vector2.y) {
@@ -93,69 +255,36 @@ class Vector2D {
93
255
  return 1;
94
256
  }
95
257
  /**
96
- * Returns the angle between origin and the given vector in radians
97
- * @param vector
258
+ * The function calculates the angle between a given vector and the negative y-axis.
259
+ * @param {Vector2D} vector - The "vector" parameter is an instance of the Vector2D class, which represents a
260
+ * 2-dimensional vector. It has two properties: "x" and "y", which represent the x and y components of the vector,
261
+ * respectively.
262
+ * @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
98
263
  */
99
264
  static angle(vector) {
100
265
  const origin = new Vector2D(0, -1);
101
266
  const radian = Math.acos(Vector2D.dot(vector, origin) / (vector.length * origin.length));
102
267
  return Vector2D.sign(vector, origin) === 1 ? ((Math.PI * 2) - radian) : radian;
103
268
  }
269
+ /**
270
+ * The function "random" generates a random Vector2D object with x and y values within the specified range.
271
+ * @param {number} maxX - The maxX parameter represents the maximum value for the x-coordinate of the random vector.
272
+ * @param {number} maxY - The `maxY` parameter represents the maximum value for the y-coordinate of the generated
273
+ * random vector.
274
+ * @returns a new instance of the Vector2D class with random x and y values.
275
+ */
104
276
  static random(maxX, maxY) {
105
277
  const randX = Math.floor(Math.random() * maxX - (maxX / 2));
106
278
  const randY = Math.floor(Math.random() * maxY - (maxY / 2));
107
279
  return new Vector2D(randX, randY);
108
280
  }
109
- // /**
110
- // * Transform vectors based on the current tranformation matrices: translation, rotation and scale
111
- // * @param vectors The vectors to transform
112
- // */
113
- // public static transform(vector: Vector2D, transformation: Matrix2D): Vector2D {
114
- // return Matrix2D.multiplyByVector(transformation, vector)
115
- // }
116
- // /**
117
- // * Transform vectors based on the current tranformation matrices: translation, rotation and scale
118
- // * @param vectors The vectors to transform
119
- // */
120
- // public static transformList(vectors: Vector2D[], transformation: Matrix2D): Vector2D[] {
121
- // return vectors.map(vector => Matrix2D.multiplyByVector(transformation, vector))
122
- // }
123
- constructor(x = 0, y = 0, w = 1 // needed for matrix multiplication
124
- ) {
125
- this.x = x;
126
- this.y = y;
127
- this.w = w;
128
- }
129
281
  /**
130
- * Check wether both x and y are zero
282
+ * The function sets the values of x and y to zero.
131
283
  */
132
284
  zero() {
133
285
  this.x = 0;
134
286
  this.y = 0;
135
287
  }
136
- /**
137
- * Set x and y both to zero
138
- */
139
- get isZero() {
140
- return this.x === 0 && this.y === 0;
141
- }
142
- /**
143
- * The length / magnitude of the vector
144
- */
145
- get length() {
146
- return Math.sqrt((this.x * this.x) + (this.y * this.y));
147
- }
148
- /**
149
- * The squared length of the vector
150
- */
151
- get lengthSq() {
152
- return (this.x * this.x) + (this.y * this.y);
153
- }
154
- /**
155
- * Return the vector with rounded values
156
- */
157
- get rounded() {
158
- return new Vector2D(Math.round(this.x), Math.round(this.y));
159
- }
160
288
  }
289
+ exports.Vector2D = Vector2D;
161
290
  exports.default = Vector2D;
@@ -1,4 +1,15 @@
1
- import { PriorityQueue, PriorityQueueOptions } from './priority-queue';
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 { PriorityQueue } from './priority-queue';
9
+ import type { PriorityQueueOptions } from '../../types';
2
10
  export declare class MaxPriorityQueue<T = number> extends PriorityQueue<T> {
11
+ constructor(options?: Omit<PriorityQueueOptions<number>, 'comparator'>);
3
12
  constructor(options: PriorityQueueOptions<T>);
13
+ static heapify<T extends number>(options?: Omit<PriorityQueueOptions<T>, 'comparator'>): MaxPriorityQueue<T>;
14
+ static heapify<T>(options: PriorityQueueOptions<T>): MaxPriorityQueue<T>;
4
15
  }
@@ -1,15 +1,39 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MaxPriorityQueue = 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
+ */
4
11
  const priority_queue_1 = require("./priority-queue");
5
12
  class MaxPriorityQueue extends priority_queue_1.PriorityQueue {
13
+ /**
14
+ * The constructor initializes a priority queue with an optional comparator function.
15
+ * @param [options] - The `options` parameter is an optional object that can contain various properties to configure
16
+ * the priority queue.
17
+ */
6
18
  constructor(options) {
7
- super({
8
- nodes: options.nodes, comparator: (a, b) => {
19
+ super(Object.assign(Object.assign({}, options), { comparator: (options === null || options === void 0 ? void 0 : options.comparator) ? options.comparator : (a, b) => {
9
20
  const aKey = a, bKey = b;
10
21
  return bKey - aKey;
11
- }
12
- });
22
+ } }));
23
+ }
24
+ /**
25
+ * The function `heapify` creates a max priority queue from the given options and returns it.
26
+ * @param options - The `options` parameter is an object that contains configuration options for creating a priority
27
+ * queue. It can have the following properties:
28
+ * @returns a MaxPriorityQueue object.
29
+ */
30
+ static heapify(options) {
31
+ const maxPQ = new MaxPriorityQueue(Object.assign(Object.assign({}, options), { comparator: (options === null || options === void 0 ? void 0 : options.comparator) ? options.comparator : (a, b) => {
32
+ const aKey = a, bKey = b;
33
+ return bKey - aKey;
34
+ } }));
35
+ maxPQ._fix();
36
+ return maxPQ;
13
37
  }
14
38
  }
15
39
  exports.MaxPriorityQueue = MaxPriorityQueue;
@@ -1,4 +1,15 @@
1
- import { PriorityQueue, PriorityQueueOptions } from './priority-queue';
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 { PriorityQueue } from './priority-queue';
9
+ import type { PriorityQueueOptions } from '../../types';
2
10
  export declare class MinPriorityQueue<T = number> extends PriorityQueue<T> {
11
+ constructor(options?: Omit<PriorityQueueOptions<number>, 'comparator'>);
3
12
  constructor(options: PriorityQueueOptions<T>);
13
+ static heapify<T extends number>(options?: Omit<PriorityQueueOptions<T>, 'comparator'>): MinPriorityQueue<T>;
14
+ static heapify<T>(options: PriorityQueueOptions<T>): MinPriorityQueue<T>;
4
15
  }