data-structure-typed 0.8.18 → 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.
- package/.idea/modules.xml +1 -1
- package/README.md +197 -2
- package/dist/data-structures/binary-tree/aa-tree.js +5 -2
- package/dist/data-structures/binary-tree/avl-tree.d.ts +1 -5
- package/dist/data-structures/binary-tree/avl-tree.js +93 -46
- package/dist/data-structures/binary-tree/b-tree.js +5 -2
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +1 -1
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +14 -13
- package/dist/data-structures/binary-tree/binary-tree.d.ts +20 -32
- package/dist/data-structures/binary-tree/binary-tree.js +480 -370
- package/dist/data-structures/binary-tree/bst.d.ts +4 -8
- package/dist/data-structures/binary-tree/bst.js +152 -107
- package/dist/data-structures/binary-tree/rb-tree.js +5 -2
- package/dist/data-structures/binary-tree/segment-tree.d.ts +3 -3
- package/dist/data-structures/binary-tree/segment-tree.js +91 -61
- package/dist/data-structures/binary-tree/splay-tree.js +5 -2
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +1 -5
- package/dist/data-structures/binary-tree/tree-multiset.js +31 -11
- package/dist/data-structures/binary-tree/two-three-tree.js +5 -2
- package/dist/data-structures/graph/abstract-graph.d.ts +5 -33
- package/dist/data-structures/graph/abstract-graph.js +546 -311
- package/dist/data-structures/graph/directed-graph.d.ts +5 -13
- package/dist/data-structures/graph/directed-graph.js +250 -128
- package/dist/data-structures/graph/undirected-graph.d.ts +4 -3
- package/dist/data-structures/graph/undirected-graph.js +166 -81
- package/dist/data-structures/hash/coordinate-map.d.ts +1 -1
- package/dist/data-structures/hash/coordinate-map.js +38 -20
- package/dist/data-structures/hash/coordinate-set.js +33 -15
- package/dist/data-structures/hash/index.d.ts +5 -0
- package/dist/data-structures/hash/index.js +5 -0
- package/dist/data-structures/heap/heap.d.ts +2 -8
- package/dist/data-structures/heap/heap.js +36 -31
- package/dist/data-structures/heap/max-heap.d.ts +3 -2
- package/dist/data-structures/heap/max-heap.js +27 -9
- package/dist/data-structures/heap/min-heap.d.ts +3 -2
- package/dist/data-structures/heap/min-heap.js +27 -9
- package/dist/data-structures/index.d.ts +1 -0
- package/dist/data-structures/index.js +1 -0
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +0 -1
- package/dist/data-structures/linked-list/doubly-linked-list.js +56 -53
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +8 -12
- package/dist/data-structures/linked-list/singly-linked-list.js +308 -174
- package/dist/data-structures/matrix/matrix.js +8 -7
- package/dist/data-structures/matrix/matrix2d.d.ts +5 -5
- package/dist/data-structures/matrix/matrix2d.js +80 -63
- package/dist/data-structures/matrix/navigator.d.ts +2 -16
- package/dist/data-structures/matrix/navigator.js +37 -18
- package/dist/data-structures/matrix/vector2d.d.ts +18 -18
- package/dist/data-structures/matrix/vector2d.js +117 -94
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +3 -2
- package/dist/data-structures/priority-queue/max-priority-queue.js +25 -8
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +3 -2
- package/dist/data-structures/priority-queue/min-priority-queue.js +25 -8
- package/dist/data-structures/priority-queue/priority-queue.d.ts +15 -21
- package/dist/data-structures/priority-queue/priority-queue.js +159 -116
- package/dist/data-structures/queue/deque.js +82 -56
- package/dist/data-structures/queue/queue.d.ts +9 -10
- package/dist/data-structures/queue/queue.js +34 -34
- package/dist/data-structures/stack/stack.d.ts +9 -10
- package/dist/data-structures/stack/stack.js +31 -31
- package/dist/data-structures/trampoline.d.ts +14 -23
- package/dist/data-structures/trampoline.js +103 -25
- package/dist/data-structures/trie/trie.d.ts +13 -3
- package/dist/data-structures/trie/trie.js +234 -80
- package/dist/data-structures/types/abstract-graph.d.ts +29 -0
- package/dist/data-structures/types/abstract-graph.js +2 -0
- package/dist/data-structures/types/avl-tree.d.ts +5 -0
- package/dist/data-structures/types/avl-tree.js +2 -0
- package/dist/data-structures/types/binary-tree.d.ts +16 -0
- package/dist/data-structures/types/binary-tree.js +2 -0
- package/dist/data-structures/types/bst.d.ts +7 -0
- package/dist/data-structures/types/bst.js +2 -0
- package/dist/data-structures/types/directed-graph.d.ts +10 -0
- package/dist/data-structures/types/directed-graph.js +2 -0
- package/dist/data-structures/types/doubly-linked-list.d.ts +1 -0
- package/dist/data-structures/types/doubly-linked-list.js +2 -0
- package/dist/data-structures/types/heap.d.ts +7 -0
- package/dist/data-structures/types/heap.js +2 -0
- package/dist/data-structures/types/index.d.ts +13 -0
- package/dist/data-structures/types/index.js +29 -0
- package/dist/data-structures/types/navigator.d.ts +14 -0
- package/dist/data-structures/types/navigator.js +2 -0
- package/dist/data-structures/types/priority-queue.d.ts +7 -0
- package/dist/data-structures/types/priority-queue.js +2 -0
- package/dist/data-structures/types/segment-tree.d.ts +1 -0
- package/dist/data-structures/types/segment-tree.js +2 -0
- package/dist/data-structures/types/singly-linked-list.d.ts +5 -0
- package/dist/data-structures/types/singly-linked-list.js +2 -0
- package/dist/data-structures/types/tree-multiset.d.ts +5 -0
- package/dist/data-structures/types/tree-multiset.js +2 -0
- package/dist/{types → data-structures/types}/utils.d.ts +7 -1
- package/dist/{types → data-structures/types}/utils.js +20 -19
- package/dist/{utils.d.ts → utils/utils.d.ts} +6 -23
- package/dist/utils/utils.js +651 -0
- package/package.json +20 -42
- package/src/data-structures/binary-tree/avl-tree.ts +1 -6
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +4 -4
- package/src/data-structures/binary-tree/binary-tree.ts +184 -139
- package/src/data-structures/binary-tree/bst.ts +15 -24
- package/src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif +0 -0
- package/src/data-structures/binary-tree/diagrams/bst-rotation.gif +0 -0
- package/src/data-structures/binary-tree/diagrams/segment-tree.png +0 -0
- package/src/data-structures/binary-tree/segment-tree.ts +20 -12
- package/src/data-structures/binary-tree/tree-multiset.ts +1 -4
- package/src/data-structures/diagrams/README.md +7 -0
- package/src/data-structures/graph/abstract-graph.ts +58 -94
- package/src/data-structures/graph/diagrams/adjacency-list-pros-cons.png +0 -0
- package/src/data-structures/graph/diagrams/adjacency-list.png +0 -0
- package/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.png +0 -0
- package/src/data-structures/graph/diagrams/adjacency-matrix.png +0 -0
- package/src/data-structures/graph/diagrams/dfs-can-do.png +0 -0
- package/src/data-structures/graph/diagrams/edge-list-pros-cons.png +0 -0
- package/src/data-structures/graph/diagrams/edge-list.png +0 -0
- package/src/data-structures/graph/diagrams/max-flow.png +0 -0
- package/src/data-structures/graph/diagrams/mst.png +0 -0
- package/src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png +0 -0
- package/src/data-structures/graph/diagrams/tarjan-complicate-simple.png +0 -0
- package/src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png +0 -0
- package/src/data-structures/graph/diagrams/tarjan.mp4 +0 -0
- package/src/data-structures/graph/directed-graph.ts +12 -28
- package/src/data-structures/graph/undirected-graph.ts +11 -10
- package/src/data-structures/hash/coordinate-map.ts +1 -1
- package/src/data-structures/hash/index.ts +5 -0
- package/src/data-structures/heap/heap.ts +2 -11
- package/src/data-structures/heap/max-heap.ts +3 -2
- package/src/data-structures/heap/min-heap.ts +3 -2
- package/src/data-structures/index.ts +1 -0
- package/src/data-structures/linked-list/doubly-linked-list.ts +1 -9
- package/src/data-structures/linked-list/singly-linked-list.ts +18 -32
- package/src/data-structures/matrix/matrix2d.ts +11 -11
- package/src/data-structures/matrix/navigator.ts +2 -14
- package/src/data-structures/matrix/vector2d.ts +52 -52
- package/src/data-structures/priority-queue/max-priority-queue.ts +4 -3
- package/src/data-structures/priority-queue/min-priority-queue.ts +4 -3
- package/src/data-structures/priority-queue/priority-queue.ts +70 -78
- package/src/data-structures/queue/deque.ts +2 -2
- package/src/data-structures/queue/queue.ts +12 -13
- package/src/data-structures/stack/stack.ts +12 -13
- package/src/data-structures/trampoline.ts +31 -71
- package/src/data-structures/trie/trie.ts +61 -11
- package/src/data-structures/types/abstract-graph.ts +51 -0
- package/src/data-structures/types/avl-tree.ts +6 -0
- package/src/data-structures/types/binary-tree.ts +15 -0
- package/src/data-structures/types/bst.ts +5 -0
- package/src/data-structures/types/directed-graph.ts +18 -0
- package/src/data-structures/types/doubly-linked-list.ts +1 -0
- package/src/data-structures/types/heap.ts +8 -0
- package/src/data-structures/types/index.ts +13 -0
- package/src/data-structures/types/navigator.ts +12 -0
- package/src/data-structures/types/priority-queue.ts +9 -0
- package/src/data-structures/types/segment-tree.ts +1 -0
- package/src/data-structures/types/singly-linked-list.ts +15 -0
- package/src/data-structures/types/tree-multiset.ts +3 -0
- package/src/{types → data-structures/types}/utils.ts +20 -5
- package/src/utils/index.ts +1 -0
- package/src/{utils.ts → utils/utils.ts} +32 -132
- package/tsconfig.json +9 -6
- package/dist/types/data-structures/binary-tree/aa-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +0 -21
- package/dist/types/data-structures/binary-tree/b-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -8
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +0 -140
- package/dist/types/data-structures/binary-tree/bst.d.ts +0 -32
- package/dist/types/data-structures/binary-tree/index.d.ts +0 -4
- package/dist/types/data-structures/binary-tree/rb-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +0 -33
- package/dist/types/data-structures/binary-tree/splay-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/tree-multiset.d.ts +0 -11
- package/dist/types/data-structures/binary-tree/two-three-tree.d.ts +0 -2
- package/dist/types/data-structures/graph/abstract-graph.d.ts +0 -126
- package/dist/types/data-structures/graph/directed-graph.d.ts +0 -51
- package/dist/types/data-structures/graph/index.d.ts +0 -3
- package/dist/types/data-structures/graph/undirected-graph.d.ts +0 -24
- package/dist/types/data-structures/hash/coordinate-map.d.ts +0 -8
- package/dist/types/data-structures/hash/coordinate-set.d.ts +0 -7
- package/dist/types/data-structures/hash/hash-table.d.ts +0 -1
- package/dist/types/data-structures/hash/index.d.ts +0 -1
- package/dist/types/data-structures/hash/pair.d.ts +0 -1
- package/dist/types/data-structures/hash/tree-map.d.ts +0 -1
- package/dist/types/data-structures/hash/tree-set.d.ts +0 -1
- package/dist/types/data-structures/heap/heap.d.ts +0 -72
- package/dist/types/data-structures/heap/index.d.ts +0 -3
- package/dist/types/data-structures/heap/max-heap.d.ts +0 -14
- package/dist/types/data-structures/heap/min-heap.d.ts +0 -14
- package/dist/types/data-structures/index.d.ts +0 -9
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +0 -59
- package/dist/types/data-structures/linked-list/index.d.ts +0 -2
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +0 -358
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +0 -1
- package/dist/types/data-structures/matrix/index.d.ts +0 -3
- package/dist/types/data-structures/matrix/matrix.d.ts +0 -9
- package/dist/types/data-structures/matrix/matrix2d.d.ts +0 -25
- package/dist/types/data-structures/matrix/navigator.d.ts +0 -31
- package/dist/types/data-structures/matrix/vector2d.d.ts +0 -74
- package/dist/types/data-structures/priority-queue/index.d.ts +0 -3
- package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +0 -4
- package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +0 -4
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +0 -36
- package/dist/types/data-structures/queue/deque.d.ts +0 -37
- package/dist/types/data-structures/queue/index.d.ts +0 -1
- package/dist/types/data-structures/queue/queue.d.ts +0 -76
- package/dist/types/data-structures/stack/index.d.ts +0 -1
- package/dist/types/data-structures/stack/stack.d.ts +0 -69
- package/dist/types/data-structures/trampoline.d.ts +0 -25
- package/dist/types/data-structures/trie/index.d.ts +0 -1
- package/dist/types/data-structures/trie/trie.d.ts +0 -28
- package/dist/types/types/index.d.ts +0 -1
- package/dist/types/types/utils.d.ts +0 -46
- package/dist/utils.js +0 -569
- package/src/types/index.ts +0 -1
- package/src/types/patches/index.d.ts +0 -0
- /package/dist/{types → utils}/index.d.ts +0 -0
- /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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
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
|
-
|
|
59
|
+
};
|
|
60
|
+
Vector2D.subtractValue = function (vector, value) {
|
|
11
61
|
return new Vector2D(vector.x - value, vector.y - value);
|
|
12
|
-
}
|
|
13
|
-
|
|
62
|
+
};
|
|
63
|
+
Vector2D.multiply = function (vector, value) {
|
|
14
64
|
return new Vector2D(vector.x * value, vector.y * value);
|
|
15
|
-
}
|
|
16
|
-
|
|
65
|
+
};
|
|
66
|
+
Vector2D.divide = function (vector, value) {
|
|
17
67
|
return new Vector2D(vector.x / value, vector.y / value);
|
|
18
|
-
}
|
|
19
|
-
|
|
68
|
+
};
|
|
69
|
+
Vector2D.equals = function (vector1, vector2) {
|
|
20
70
|
return vector1.x === vector2.x && vector1.y === vector2.y;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
33
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
108
|
+
Vector2D.reverse = function (vector) {
|
|
58
109
|
return new Vector2D(-vector.x, -vector.y);
|
|
59
|
-
}
|
|
60
|
-
|
|
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
|
-
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
-
|
|
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
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
35
|
-
|
|
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
|
}
|