data-structure-typed 0.8.17 → 0.9.16

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 (219) hide show
  1. package/.idea/modules.xml +1 -1
  2. package/README.md +197 -2
  3. package/dist/data-structures/binary-tree/aa-tree.js +5 -2
  4. package/dist/data-structures/binary-tree/avl-tree.d.ts +1 -5
  5. package/dist/data-structures/binary-tree/avl-tree.js +93 -46
  6. package/dist/data-structures/binary-tree/b-tree.js +5 -2
  7. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +1 -1
  8. package/dist/data-structures/binary-tree/binary-indexed-tree.js +14 -13
  9. package/dist/data-structures/binary-tree/binary-tree.d.ts +20 -32
  10. package/dist/data-structures/binary-tree/binary-tree.js +480 -370
  11. package/dist/data-structures/binary-tree/bst.d.ts +4 -8
  12. package/dist/data-structures/binary-tree/bst.js +152 -107
  13. package/dist/data-structures/binary-tree/index.d.ts +7 -0
  14. package/dist/data-structures/binary-tree/index.js +7 -0
  15. package/dist/data-structures/binary-tree/rb-tree.js +5 -2
  16. package/dist/data-structures/binary-tree/segment-tree.d.ts +3 -3
  17. package/dist/data-structures/binary-tree/segment-tree.js +91 -61
  18. package/dist/data-structures/binary-tree/splay-tree.js +5 -2
  19. package/dist/data-structures/binary-tree/tree-multiset.d.ts +1 -5
  20. package/dist/data-structures/binary-tree/tree-multiset.js +31 -11
  21. package/dist/data-structures/binary-tree/two-three-tree.js +5 -2
  22. package/dist/data-structures/graph/abstract-graph.d.ts +5 -33
  23. package/dist/data-structures/graph/abstract-graph.js +546 -311
  24. package/dist/data-structures/graph/directed-graph.d.ts +5 -13
  25. package/dist/data-structures/graph/directed-graph.js +250 -128
  26. package/dist/data-structures/graph/undirected-graph.d.ts +4 -3
  27. package/dist/data-structures/graph/undirected-graph.js +166 -81
  28. package/dist/data-structures/hash/coordinate-map.d.ts +1 -1
  29. package/dist/data-structures/hash/coordinate-map.js +38 -20
  30. package/dist/data-structures/hash/coordinate-set.js +33 -15
  31. package/dist/data-structures/hash/index.d.ts +5 -0
  32. package/dist/data-structures/hash/index.js +5 -0
  33. package/dist/data-structures/heap/heap.d.ts +2 -8
  34. package/dist/data-structures/heap/heap.js +36 -31
  35. package/dist/data-structures/heap/max-heap.d.ts +3 -2
  36. package/dist/data-structures/heap/max-heap.js +27 -9
  37. package/dist/data-structures/heap/min-heap.d.ts +3 -2
  38. package/dist/data-structures/heap/min-heap.js +27 -9
  39. package/dist/data-structures/index.d.ts +2 -0
  40. package/dist/data-structures/index.js +2 -0
  41. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +0 -1
  42. package/dist/data-structures/linked-list/doubly-linked-list.js +56 -53
  43. package/dist/data-structures/linked-list/singly-linked-list.d.ts +8 -12
  44. package/dist/data-structures/linked-list/singly-linked-list.js +308 -174
  45. package/dist/data-structures/matrix/matrix.js +8 -7
  46. package/dist/data-structures/matrix/matrix2d.d.ts +5 -5
  47. package/dist/data-structures/matrix/matrix2d.js +80 -63
  48. package/dist/data-structures/matrix/navigator.d.ts +2 -16
  49. package/dist/data-structures/matrix/navigator.js +37 -18
  50. package/dist/data-structures/matrix/vector2d.d.ts +18 -18
  51. package/dist/data-structures/matrix/vector2d.js +117 -94
  52. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +3 -2
  53. package/dist/data-structures/priority-queue/max-priority-queue.js +25 -8
  54. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +3 -2
  55. package/dist/data-structures/priority-queue/min-priority-queue.js +25 -8
  56. package/dist/data-structures/priority-queue/priority-queue.d.ts +15 -21
  57. package/dist/data-structures/priority-queue/priority-queue.js +159 -116
  58. package/dist/data-structures/queue/deque.js +82 -56
  59. package/dist/data-structures/queue/index.d.ts +1 -0
  60. package/dist/data-structures/queue/index.js +1 -0
  61. package/dist/data-structures/queue/queue.d.ts +9 -10
  62. package/dist/data-structures/queue/queue.js +34 -34
  63. package/dist/data-structures/stack/stack.d.ts +9 -10
  64. package/dist/data-structures/stack/stack.js +31 -31
  65. package/dist/data-structures/trampoline.d.ts +14 -23
  66. package/dist/data-structures/trampoline.js +103 -25
  67. package/dist/data-structures/trie/trie.d.ts +13 -3
  68. package/dist/data-structures/trie/trie.js +234 -80
  69. package/dist/data-structures/types/abstract-graph.d.ts +29 -0
  70. package/dist/data-structures/types/abstract-graph.js +2 -0
  71. package/dist/data-structures/types/avl-tree.d.ts +5 -0
  72. package/dist/data-structures/types/avl-tree.js +2 -0
  73. package/dist/data-structures/types/binary-tree.d.ts +16 -0
  74. package/dist/data-structures/types/binary-tree.js +2 -0
  75. package/dist/data-structures/types/bst.d.ts +7 -0
  76. package/dist/data-structures/types/bst.js +2 -0
  77. package/dist/data-structures/types/directed-graph.d.ts +10 -0
  78. package/dist/data-structures/types/directed-graph.js +2 -0
  79. package/dist/data-structures/types/doubly-linked-list.d.ts +1 -0
  80. package/dist/data-structures/types/doubly-linked-list.js +2 -0
  81. package/dist/data-structures/types/heap.d.ts +7 -0
  82. package/dist/data-structures/types/heap.js +2 -0
  83. package/dist/data-structures/types/index.d.ts +13 -0
  84. package/dist/data-structures/types/index.js +29 -0
  85. package/dist/data-structures/types/navigator.d.ts +14 -0
  86. package/dist/data-structures/types/navigator.js +2 -0
  87. package/dist/data-structures/types/priority-queue.d.ts +7 -0
  88. package/dist/data-structures/types/priority-queue.js +2 -0
  89. package/dist/data-structures/types/segment-tree.d.ts +1 -0
  90. package/dist/data-structures/types/segment-tree.js +2 -0
  91. package/dist/data-structures/types/singly-linked-list.d.ts +5 -0
  92. package/dist/data-structures/types/singly-linked-list.js +2 -0
  93. package/dist/data-structures/types/tree-multiset.d.ts +5 -0
  94. package/dist/data-structures/types/tree-multiset.js +2 -0
  95. package/dist/{types → data-structures/types}/utils.d.ts +7 -1
  96. package/dist/{types → data-structures/types}/utils.js +20 -19
  97. package/dist/{utils.d.ts → utils/utils.d.ts} +6 -23
  98. package/dist/utils/utils.js +651 -0
  99. package/package.json +20 -42
  100. package/src/data-structures/binary-tree/avl-tree.ts +1 -6
  101. package/src/data-structures/binary-tree/binary-indexed-tree.ts +4 -4
  102. package/src/data-structures/binary-tree/binary-tree.ts +184 -139
  103. package/src/data-structures/binary-tree/bst.ts +15 -24
  104. package/src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif +0 -0
  105. package/src/data-structures/binary-tree/diagrams/bst-rotation.gif +0 -0
  106. package/src/data-structures/binary-tree/diagrams/segment-tree.png +0 -0
  107. package/src/data-structures/binary-tree/index.ts +7 -0
  108. package/src/data-structures/binary-tree/segment-tree.ts +20 -12
  109. package/src/data-structures/binary-tree/tree-multiset.ts +1 -4
  110. package/src/data-structures/diagrams/README.md +7 -0
  111. package/src/data-structures/graph/abstract-graph.ts +58 -94
  112. package/src/data-structures/graph/diagrams/adjacency-list-pros-cons.png +0 -0
  113. package/src/data-structures/graph/diagrams/adjacency-list.png +0 -0
  114. package/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.png +0 -0
  115. package/src/data-structures/graph/diagrams/adjacency-matrix.png +0 -0
  116. package/src/data-structures/graph/diagrams/dfs-can-do.png +0 -0
  117. package/src/data-structures/graph/diagrams/edge-list-pros-cons.png +0 -0
  118. package/src/data-structures/graph/diagrams/edge-list.png +0 -0
  119. package/src/data-structures/graph/diagrams/max-flow.png +0 -0
  120. package/src/data-structures/graph/diagrams/mst.png +0 -0
  121. package/src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png +0 -0
  122. package/src/data-structures/graph/diagrams/tarjan-complicate-simple.png +0 -0
  123. package/src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png +0 -0
  124. package/src/data-structures/graph/diagrams/tarjan.mp4 +0 -0
  125. package/src/data-structures/graph/directed-graph.ts +12 -28
  126. package/src/data-structures/graph/undirected-graph.ts +11 -10
  127. package/src/data-structures/hash/coordinate-map.ts +1 -1
  128. package/src/data-structures/hash/index.ts +5 -0
  129. package/src/data-structures/heap/heap.ts +2 -11
  130. package/src/data-structures/heap/max-heap.ts +3 -2
  131. package/src/data-structures/heap/min-heap.ts +3 -2
  132. package/src/data-structures/index.ts +2 -0
  133. package/src/data-structures/linked-list/doubly-linked-list.ts +1 -9
  134. package/src/data-structures/linked-list/singly-linked-list.ts +18 -32
  135. package/src/data-structures/matrix/matrix2d.ts +11 -11
  136. package/src/data-structures/matrix/navigator.ts +2 -14
  137. package/src/data-structures/matrix/vector2d.ts +52 -52
  138. package/src/data-structures/priority-queue/max-priority-queue.ts +4 -3
  139. package/src/data-structures/priority-queue/min-priority-queue.ts +4 -3
  140. package/src/data-structures/priority-queue/priority-queue.ts +70 -78
  141. package/src/data-structures/queue/deque.ts +2 -2
  142. package/src/data-structures/queue/index.ts +1 -0
  143. package/src/data-structures/queue/queue.ts +12 -13
  144. package/src/data-structures/stack/stack.ts +12 -13
  145. package/src/data-structures/trampoline.ts +31 -71
  146. package/src/data-structures/trie/trie.ts +61 -11
  147. package/src/data-structures/types/abstract-graph.ts +51 -0
  148. package/src/data-structures/types/avl-tree.ts +6 -0
  149. package/src/data-structures/types/binary-tree.ts +15 -0
  150. package/src/data-structures/types/bst.ts +5 -0
  151. package/src/data-structures/types/directed-graph.ts +18 -0
  152. package/src/data-structures/types/doubly-linked-list.ts +1 -0
  153. package/src/data-structures/types/heap.ts +8 -0
  154. package/src/data-structures/types/index.ts +13 -0
  155. package/src/data-structures/types/navigator.ts +12 -0
  156. package/src/data-structures/types/priority-queue.ts +9 -0
  157. package/src/data-structures/types/segment-tree.ts +1 -0
  158. package/src/data-structures/types/singly-linked-list.ts +15 -0
  159. package/src/data-structures/types/tree-multiset.ts +3 -0
  160. package/src/{types → data-structures/types}/utils.ts +20 -5
  161. package/src/utils/index.ts +1 -0
  162. package/src/{utils.ts → utils/utils.ts} +32 -132
  163. package/tsconfig.json +9 -6
  164. package/dist/types/data-structures/binary-tree/aa-tree.d.ts +0 -2
  165. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +0 -21
  166. package/dist/types/data-structures/binary-tree/b-tree.d.ts +0 -2
  167. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -8
  168. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +0 -140
  169. package/dist/types/data-structures/binary-tree/bst.d.ts +0 -32
  170. package/dist/types/data-structures/binary-tree/index.d.ts +0 -4
  171. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +0 -2
  172. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +0 -33
  173. package/dist/types/data-structures/binary-tree/splay-tree.d.ts +0 -2
  174. package/dist/types/data-structures/binary-tree/tree-multiset.d.ts +0 -11
  175. package/dist/types/data-structures/binary-tree/two-three-tree.d.ts +0 -2
  176. package/dist/types/data-structures/graph/abstract-graph.d.ts +0 -126
  177. package/dist/types/data-structures/graph/directed-graph.d.ts +0 -51
  178. package/dist/types/data-structures/graph/index.d.ts +0 -3
  179. package/dist/types/data-structures/graph/undirected-graph.d.ts +0 -24
  180. package/dist/types/data-structures/hash/coordinate-map.d.ts +0 -8
  181. package/dist/types/data-structures/hash/coordinate-set.d.ts +0 -7
  182. package/dist/types/data-structures/hash/hash-table.d.ts +0 -1
  183. package/dist/types/data-structures/hash/index.d.ts +0 -1
  184. package/dist/types/data-structures/hash/pair.d.ts +0 -1
  185. package/dist/types/data-structures/hash/tree-map.d.ts +0 -1
  186. package/dist/types/data-structures/hash/tree-set.d.ts +0 -1
  187. package/dist/types/data-structures/heap/heap.d.ts +0 -72
  188. package/dist/types/data-structures/heap/index.d.ts +0 -3
  189. package/dist/types/data-structures/heap/max-heap.d.ts +0 -14
  190. package/dist/types/data-structures/heap/min-heap.d.ts +0 -14
  191. package/dist/types/data-structures/index.d.ts +0 -9
  192. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +0 -59
  193. package/dist/types/data-structures/linked-list/index.d.ts +0 -2
  194. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +0 -358
  195. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +0 -1
  196. package/dist/types/data-structures/matrix/index.d.ts +0 -3
  197. package/dist/types/data-structures/matrix/matrix.d.ts +0 -9
  198. package/dist/types/data-structures/matrix/matrix2d.d.ts +0 -25
  199. package/dist/types/data-structures/matrix/navigator.d.ts +0 -31
  200. package/dist/types/data-structures/matrix/vector2d.d.ts +0 -74
  201. package/dist/types/data-structures/priority-queue/index.d.ts +0 -3
  202. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +0 -4
  203. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +0 -4
  204. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +0 -36
  205. package/dist/types/data-structures/queue/deque.d.ts +0 -37
  206. package/dist/types/data-structures/queue/index.d.ts +0 -1
  207. package/dist/types/data-structures/queue/queue.d.ts +0 -76
  208. package/dist/types/data-structures/stack/index.d.ts +0 -1
  209. package/dist/types/data-structures/stack/stack.d.ts +0 -69
  210. package/dist/types/data-structures/trampoline.d.ts +0 -25
  211. package/dist/types/data-structures/trie/index.d.ts +0 -1
  212. package/dist/types/data-structures/trie/trie.d.ts +0 -28
  213. package/dist/types/types/index.d.ts +0 -1
  214. package/dist/types/types/utils.d.ts +0 -46
  215. package/dist/utils.js +0 -569
  216. package/src/types/index.ts +0 -1
  217. package/src/types/patches/index.d.ts +0 -0
  218. /package/dist/{types → utils}/index.d.ts +0 -0
  219. /package/dist/{types → utils}/index.js +0 -0
@@ -1,161 +1,184 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- class Vector2D {
4
- static add(vector1, vector2) {
5
- return new Vector2D(vector1.x + vector2.x, vector1.y + vector2.y);
3
+ exports.Vector2D = void 0;
4
+ var Vector2D = /** @class */ (function () {
5
+ function Vector2D(x, y, w // needed for matrix multiplication
6
+ ) {
7
+ if (x === void 0) { x = 0; }
8
+ if (y === void 0) { y = 0; }
9
+ if (w === void 0) { w = 1; }
10
+ this.x = x;
11
+ this.y = y;
12
+ this.w = w;
6
13
  }
7
- static subtract(vector1, vector2) {
14
+ Object.defineProperty(Vector2D.prototype, "isZero", {
15
+ /**
16
+ * Set x and y both to zero
17
+ */
18
+ get: function () {
19
+ return this.x === 0 && this.y === 0;
20
+ },
21
+ enumerable: false,
22
+ configurable: true
23
+ });
24
+ Object.defineProperty(Vector2D.prototype, "length", {
25
+ /**
26
+ * The length / magnitude of the vector
27
+ */
28
+ get: function () {
29
+ return Math.sqrt((this.x * this.x) + (this.y * this.y));
30
+ },
31
+ enumerable: false,
32
+ configurable: true
33
+ });
34
+ Object.defineProperty(Vector2D.prototype, "lengthSq", {
35
+ /**
36
+ * The squared length of the vector
37
+ */
38
+ get: function () {
39
+ return (this.x * this.x) + (this.y * this.y);
40
+ },
41
+ enumerable: false,
42
+ configurable: true
43
+ });
44
+ Object.defineProperty(Vector2D.prototype, "rounded", {
45
+ /**
46
+ * Return the vector with rounded values
47
+ */
48
+ get: function () {
49
+ return new Vector2D(Math.round(this.x), Math.round(this.y));
50
+ },
51
+ enumerable: false,
52
+ configurable: true
53
+ });
54
+ Vector2D.add = function (vector1, vector2) {
55
+ return new Vector2D(vector1.x + vector2.x, vector1.y + vector2.y);
56
+ };
57
+ Vector2D.subtract = function (vector1, vector2) {
8
58
  return new Vector2D(vector1.x - vector2.x, vector1.y - vector2.y);
9
- }
10
- static subtractValue(vector, value) {
59
+ };
60
+ Vector2D.subtractValue = function (vector, value) {
11
61
  return new Vector2D(vector.x - value, vector.y - value);
12
- }
13
- static multiply(vector, value) {
62
+ };
63
+ Vector2D.multiply = function (vector, value) {
14
64
  return new Vector2D(vector.x * value, vector.y * value);
15
- }
16
- static divide(vector, value) {
65
+ };
66
+ Vector2D.divide = function (vector, value) {
17
67
  return new Vector2D(vector.x / value, vector.y / value);
18
- }
19
- static equals(vector1, vector2) {
68
+ };
69
+ Vector2D.equals = function (vector1, vector2) {
20
70
  return vector1.x === vector2.x && vector1.y === vector2.y;
21
- }
22
- static equalsRounded(vector1, vector2, roundingFactor = 12) {
23
- const vector = Vector2D.abs(Vector2D.subtract(vector1, vector2));
71
+ };
72
+ Vector2D.equalsRounded = function (vector1, vector2, roundingFactor) {
73
+ if (roundingFactor === void 0) { roundingFactor = 12; }
74
+ var vector = Vector2D.abs(Vector2D.subtract(vector1, vector2));
24
75
  if (vector.x < roundingFactor && vector.y < roundingFactor) {
25
76
  return true;
26
77
  }
27
78
  return false;
28
- }
79
+ };
29
80
  /**
30
81
  * Normalizes the vector if it matches a certain condition
31
82
  */
32
- static normalize(vector) {
33
- const length = vector.length;
83
+ Vector2D.normalize = function (vector) {
84
+ var length = vector.length;
34
85
  if (length > 2.220446049250313e-16) { // Epsilon
35
86
  return Vector2D.divide(vector, length);
36
87
  }
37
88
  return vector;
38
- }
89
+ };
39
90
  /**
40
91
  * Adjusts x and y so that the length of the vector does not exceed max
41
92
  */
42
- static truncate(vector, max) {
93
+ Vector2D.truncate = function (vector, max) {
43
94
  if (vector.length > max) {
44
95
  return Vector2D.multiply(Vector2D.normalize(vector), max);
45
96
  }
46
97
  return vector;
47
- }
98
+ };
48
99
  /**
49
100
  * The vector that is perpendicular to this one
50
101
  */
51
- static perp(vector) {
102
+ Vector2D.perp = function (vector) {
52
103
  return new Vector2D(-vector.y, vector.x);
53
- }
104
+ };
54
105
  /**
55
106
  * returns the vector that is the reverse of this vector
56
107
  */
57
- static reverse(vector) {
108
+ Vector2D.reverse = function (vector) {
58
109
  return new Vector2D(-vector.x, -vector.y);
59
- }
60
- static abs(vector) {
110
+ };
111
+ Vector2D.abs = function (vector) {
61
112
  return new Vector2D(Math.abs(vector.x), Math.abs(vector.y));
62
- }
113
+ };
63
114
  /**
64
115
  * The dot product of v1 and v2
65
116
  */
66
- static dot(vector1, vector2) {
117
+ Vector2D.dot = function (vector1, vector2) {
67
118
  return (vector1.x * vector2.x) + (vector1.y * vector2.y);
68
- }
119
+ };
120
+ // /**
121
+ // * Transform vectors based on the current tranformation matrices: translation, rotation and scale
122
+ // * @param vectors The vectors to transform
123
+ // */
124
+ // public static transform(vector: Vector2D, transformation: Matrix2D): Vector2D {
125
+ // return Matrix2D.multiplyByVector(transformation, vector)
126
+ // }
127
+ // /**
128
+ // * Transform vectors based on the current tranformation matrices: translation, rotation and scale
129
+ // * @param vectors The vectors to transform
130
+ // */
131
+ // public static transformList(vectors: Vector2D[], transformation: Matrix2D): Vector2D[] {
132
+ // return vectors.map(vector => Matrix2D.multiplyByVector(transformation, vector))
133
+ // }
69
134
  /**
70
135
  * The distance between this and the vector
71
136
  */
72
- static distance(vector1, vector2) {
73
- const ySeparation = vector2.y - vector1.y;
74
- const xSeparation = vector2.x - vector1.x;
137
+ Vector2D.distance = function (vector1, vector2) {
138
+ var ySeparation = vector2.y - vector1.y;
139
+ var xSeparation = vector2.x - vector1.x;
75
140
  return Math.sqrt((ySeparation * ySeparation) + (xSeparation * xSeparation));
76
- }
141
+ };
77
142
  /**
78
143
  * The distance between this and the vector squared
79
144
  */
80
- static distanceSq(vector1, vector2) {
81
- const ySeparation = vector2.y - vector1.y;
82
- const xSeparation = vector2.x - vector1.x;
145
+ Vector2D.distanceSq = function (vector1, vector2) {
146
+ var ySeparation = vector2.y - vector1.y;
147
+ var xSeparation = vector2.x - vector1.x;
83
148
  return (ySeparation * ySeparation) + (xSeparation * xSeparation);
84
- }
149
+ };
85
150
  /**
86
151
  * Returns positive if v2 is clockwise of this vector, negative if counterclockwise
87
152
  * (assuming the Y axis is pointing down, X axis to right like a Window app)
88
153
  */
89
- static sign(vector1, vector2) {
154
+ Vector2D.sign = function (vector1, vector2) {
90
155
  if (vector1.y * vector2.x > vector1.x * vector2.y) {
91
156
  return -1;
92
157
  }
93
158
  return 1;
94
- }
159
+ };
95
160
  /**
96
161
  * Returns the angle between origin and the given vector in radians
97
162
  * @param vector
98
163
  */
99
- static angle(vector) {
100
- const origin = new Vector2D(0, -1);
101
- const radian = Math.acos(Vector2D.dot(vector, origin) / (vector.length * origin.length));
164
+ Vector2D.angle = function (vector) {
165
+ var origin = new Vector2D(0, -1);
166
+ var radian = Math.acos(Vector2D.dot(vector, origin) / (vector.length * origin.length));
102
167
  return Vector2D.sign(vector, origin) === 1 ? ((Math.PI * 2) - radian) : radian;
103
- }
104
- static random(maxX, maxY) {
105
- const randX = Math.floor(Math.random() * maxX - (maxX / 2));
106
- const randY = Math.floor(Math.random() * maxY - (maxY / 2));
168
+ };
169
+ Vector2D.random = function (maxX, maxY) {
170
+ var randX = Math.floor(Math.random() * maxX - (maxX / 2));
171
+ var randY = Math.floor(Math.random() * maxY - (maxY / 2));
107
172
  return new Vector2D(randX, randY);
108
- }
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
- }
173
+ };
129
174
  /**
130
175
  * Check wether both x and y are zero
131
176
  */
132
- zero() {
177
+ Vector2D.prototype.zero = function () {
133
178
  this.x = 0;
134
179
  this.y = 0;
135
- }
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
- }
180
+ };
181
+ return Vector2D;
182
+ }());
183
+ exports.Vector2D = Vector2D;
161
184
  exports.default = Vector2D;
@@ -1,4 +1,5 @@
1
- import { PriorityQueue, PriorityQueueOptions } from './priority-queue';
1
+ import { PriorityQueue } from './priority-queue';
2
+ import type { PriorityQueueOptions } from '../types';
2
3
  export declare class MaxPriorityQueue<T = number> extends PriorityQueue<T> {
3
- constructor(options: PriorityQueueOptions<T>);
4
+ constructor(options?: PriorityQueueOptions<T>);
4
5
  }
@@ -1,15 +1,32 @@
1
1
  "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
2
17
  Object.defineProperty(exports, "__esModule", { value: true });
3
18
  exports.MaxPriorityQueue = void 0;
4
- const priority_queue_1 = require("./priority-queue");
5
- class MaxPriorityQueue extends priority_queue_1.PriorityQueue {
6
- constructor(options) {
7
- super({
8
- nodes: options.nodes, comparator: (a, b) => {
9
- const aKey = a, bKey = b;
19
+ var priority_queue_1 = require("./priority-queue");
20
+ var MaxPriorityQueue = /** @class */ (function (_super) {
21
+ __extends(MaxPriorityQueue, _super);
22
+ function MaxPriorityQueue(options) {
23
+ return _super.call(this, {
24
+ nodes: options === null || options === void 0 ? void 0 : options.nodes, comparator: (options === null || options === void 0 ? void 0 : options.comparator) ? options.comparator : function (a, b) {
25
+ var aKey = a, bKey = b;
10
26
  return bKey - aKey;
11
27
  }
12
- });
28
+ }) || this;
13
29
  }
14
- }
30
+ return MaxPriorityQueue;
31
+ }(priority_queue_1.PriorityQueue));
15
32
  exports.MaxPriorityQueue = MaxPriorityQueue;
@@ -1,4 +1,5 @@
1
- import { PriorityQueue, PriorityQueueOptions } from './priority-queue';
1
+ import { PriorityQueue } from './priority-queue';
2
+ import type { PriorityQueueOptions } from '../types';
2
3
  export declare class MinPriorityQueue<T = number> extends PriorityQueue<T> {
3
- constructor(options: PriorityQueueOptions<T>);
4
+ constructor(options?: PriorityQueueOptions<T>);
4
5
  }
@@ -1,15 +1,32 @@
1
1
  "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
2
17
  Object.defineProperty(exports, "__esModule", { value: true });
3
18
  exports.MinPriorityQueue = void 0;
4
- const priority_queue_1 = require("./priority-queue");
5
- class MinPriorityQueue extends priority_queue_1.PriorityQueue {
6
- constructor(options) {
7
- super({
8
- nodes: options.nodes, comparator: (a, b) => {
9
- const aKey = a, bKey = b;
19
+ var priority_queue_1 = require("./priority-queue");
20
+ var MinPriorityQueue = /** @class */ (function (_super) {
21
+ __extends(MinPriorityQueue, _super);
22
+ function MinPriorityQueue(options) {
23
+ return _super.call(this, {
24
+ nodes: options === null || options === void 0 ? void 0 : options.nodes, comparator: (options === null || options === void 0 ? void 0 : options.comparator) ? options.comparator : function (a, b) {
25
+ var aKey = a, bKey = b;
10
26
  return aKey - bKey;
11
27
  }
12
- });
28
+ }) || this;
13
29
  }
14
- }
30
+ return MinPriorityQueue;
31
+ }(priority_queue_1.PriorityQueue));
15
32
  exports.MinPriorityQueue = MinPriorityQueue;
@@ -1,25 +1,10 @@
1
- export type PriorityQueueComparator<T> = (a: T, b: T) => number;
2
- export interface PriorityQueueOptions<T> {
3
- nodes?: T[];
4
- isFix?: boolean;
5
- comparator: PriorityQueueComparator<T>;
6
- }
7
- export type PriorityQueueDFSOrderPattern = 'pre' | 'in' | 'post';
1
+ import type { PriorityQueueComparator, PriorityQueueDFSOrderPattern, PriorityQueueOptions } from '../types';
8
2
  export declare class PriorityQueue<T = number> {
9
3
  protected nodes: T[];
10
- get size(): number;
11
- protected readonly _comparator: PriorityQueueComparator<T>;
12
4
  constructor(options: PriorityQueueOptions<T>);
13
- protected _compare(a: number, b: number): boolean;
14
- protected _swap(a: number, b: number): void;
15
- protected _isValidIndex(index: number): boolean;
16
- protected _getParent(child: number): number;
17
- protected _getLeft(parent: number): number;
18
- protected _getRight(parent: number): number;
19
- protected _getComparedChild(parent: number): number;
20
- protected _heapifyUp(start: number): void;
21
- protected _heapifyDown(start: number): void;
22
- protected _fix(): void;
5
+ get size(): number;
6
+ static heapify<T>(options: PriorityQueueOptions<T>): PriorityQueue<T>;
7
+ static isPriorityQueueified<T>(options: Omit<PriorityQueueOptions<T>, 'isFix'>): boolean;
23
8
  offer(node: T): void;
24
9
  peek(): T | null;
25
10
  poll(): T | null;
@@ -31,6 +16,15 @@ export declare class PriorityQueue<T = number> {
31
16
  isValid(): boolean;
32
17
  sort(): T[];
33
18
  DFS(dfsMode: PriorityQueueDFSOrderPattern): (T | null)[];
34
- static heapify<T>(options: PriorityQueueOptions<T>): PriorityQueue<T>;
35
- static isPriorityQueueified<T>(options: Omit<PriorityQueueOptions<T>, 'isFix'>): boolean;
19
+ protected readonly _comparator: PriorityQueueComparator<T>;
20
+ protected _compare(a: number, b: number): boolean;
21
+ protected _swap(a: number, b: number): void;
22
+ protected _isValidIndex(index: number): boolean;
23
+ protected _getParent(child: number): number;
24
+ protected _getLeft(parent: number): number;
25
+ protected _getRight(parent: number): number;
26
+ protected _getComparedChild(parent: number): number;
27
+ protected _heapifyUp(start: number): void;
28
+ protected _heapifyDown(start: number): void;
29
+ protected _fix(): void;
36
30
  }