data-structure-typed 0.9.16 → 1.3.1
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/LICENSE +21 -0
- package/README.md +665 -172
- package/dist/bundle.js +2 -0
- package/dist/bundle.js.LICENSE.txt +13 -0
- package/dist/data-structures/binary-tree/aa-tree.js +2 -5
- package/dist/data-structures/binary-tree/abstract-binary-tree.d.ts +364 -0
- package/dist/data-structures/binary-tree/abstract-binary-tree.js +1308 -0
- package/dist/data-structures/binary-tree/avl-tree.d.ts +85 -14
- package/dist/data-structures/binary-tree/avl-tree.js +142 -116
- package/dist/data-structures/binary-tree/b-tree.js +2 -5
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +39 -1
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +54 -13
- package/dist/data-structures/binary-tree/binary-tree.d.ts +29 -126
- package/dist/data-structures/binary-tree/binary-tree.js +31 -1093
- package/dist/data-structures/binary-tree/bst.d.ts +117 -23
- package/dist/data-structures/binary-tree/bst.js +233 -240
- package/dist/data-structures/binary-tree/index.d.ts +1 -0
- package/dist/data-structures/binary-tree/index.js +1 -0
- package/dist/data-structures/binary-tree/rb-tree.d.ts +18 -1
- package/dist/data-structures/binary-tree/rb-tree.js +40 -5
- package/dist/data-structures/binary-tree/segment-tree.d.ts +61 -11
- package/dist/data-structures/binary-tree/segment-tree.js +126 -93
- package/dist/data-structures/binary-tree/splay-tree.js +2 -5
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +213 -6
- package/dist/data-structures/binary-tree/tree-multiset.js +687 -34
- package/dist/data-structures/binary-tree/two-three-tree.js +2 -5
- package/dist/data-structures/graph/abstract-graph.d.ts +270 -36
- package/dist/data-structures/graph/abstract-graph.js +610 -572
- package/dist/data-structures/graph/directed-graph.d.ts +173 -16
- package/dist/data-structures/graph/directed-graph.js +345 -313
- package/dist/data-structures/graph/index.d.ts +1 -0
- package/dist/data-structures/graph/index.js +1 -0
- package/dist/data-structures/graph/map-graph.d.ts +79 -0
- package/dist/data-structures/graph/map-graph.js +111 -0
- package/dist/data-structures/graph/undirected-graph.d.ts +111 -9
- package/dist/data-structures/graph/undirected-graph.js +203 -178
- package/dist/data-structures/hash/coordinate-map.d.ts +38 -1
- package/dist/data-structures/hash/coordinate-map.js +59 -36
- package/dist/data-structures/hash/coordinate-set.d.ts +32 -2
- package/dist/data-structures/hash/coordinate-set.js +49 -33
- package/dist/data-structures/hash/hash-table.d.ts +2 -1
- package/dist/data-structures/hash/hash-table.js +4 -0
- package/dist/data-structures/hash/pair.d.ts +2 -1
- package/dist/data-structures/hash/pair.js +4 -0
- package/dist/data-structures/hash/tree-map.d.ts +2 -1
- package/dist/data-structures/hash/tree-map.js +4 -0
- package/dist/data-structures/hash/tree-set.d.ts +2 -1
- package/dist/data-structures/hash/tree-set.js +4 -0
- package/dist/data-structures/heap/heap.d.ts +62 -45
- package/dist/data-structures/heap/heap.js +124 -86
- package/dist/data-structures/heap/max-heap.d.ts +13 -5
- package/dist/data-structures/heap/max-heap.js +18 -28
- package/dist/data-structures/heap/min-heap.d.ts +14 -5
- package/dist/data-structures/heap/min-heap.js +19 -28
- package/dist/data-structures/index.d.ts +1 -1
- package/dist/data-structures/index.js +1 -1
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +193 -56
- package/dist/data-structures/linked-list/doubly-linked-list.js +484 -220
- package/dist/data-structures/linked-list/index.d.ts +1 -0
- package/dist/data-structures/linked-list/index.js +1 -0
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +117 -315
- package/dist/data-structures/linked-list/singly-linked-list.js +374 -727
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +2 -1
- package/dist/data-structures/linked-list/skip-linked-list.js +4 -0
- package/dist/data-structures/matrix/matrix.d.ts +12 -0
- package/dist/data-structures/matrix/matrix.js +21 -8
- package/dist/data-structures/matrix/matrix2d.d.ts +85 -2
- package/dist/data-structures/matrix/matrix2d.js +146 -80
- package/dist/data-structures/matrix/navigator.d.ts +36 -1
- package/dist/data-structures/matrix/navigator.js +46 -37
- package/dist/data-structures/matrix/vector2d.d.ts +142 -15
- package/dist/data-structures/matrix/vector2d.js +215 -109
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +12 -2
- package/dist/data-structures/priority-queue/max-priority-queue.js +33 -26
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +12 -2
- package/dist/data-structures/priority-queue/min-priority-queue.js +34 -26
- package/dist/data-structures/priority-queue/priority-queue.d.ts +153 -3
- package/dist/data-structures/priority-queue/priority-queue.js +244 -143
- package/dist/data-structures/queue/deque.d.ts +141 -13
- package/dist/data-structures/queue/deque.js +200 -82
- package/dist/data-structures/queue/queue.d.ts +65 -38
- package/dist/data-structures/queue/queue.js +110 -66
- package/dist/data-structures/stack/stack.d.ts +27 -32
- package/dist/data-structures/stack/stack.js +47 -53
- package/dist/data-structures/tree/index.d.ts +1 -0
- package/dist/data-structures/tree/index.js +17 -0
- package/dist/data-structures/tree/tree.d.ts +14 -0
- package/dist/data-structures/tree/tree.js +60 -0
- package/dist/data-structures/trie/trie.d.ts +33 -10
- package/dist/data-structures/trie/trie.js +123 -208
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/interfaces/abstract-binary-tree.d.ts +90 -0
- package/dist/interfaces/abstract-graph.d.ts +17 -0
- package/dist/interfaces/avl-tree.d.ts +9 -0
- package/dist/interfaces/binary-tree.d.ts +6 -0
- package/dist/interfaces/bst.d.ts +17 -0
- package/dist/interfaces/directed-graph.d.ts +12 -0
- package/{src/data-structures/types/index.ts → dist/interfaces/index.d.ts} +10 -8
- package/dist/interfaces/index.js +31 -0
- package/{src/data-structures/hash/hash-table.ts → dist/interfaces/priority-queue.d.ts} +1 -1
- package/dist/interfaces/rb-tree.d.ts +8 -0
- package/dist/interfaces/segment-tree.d.ts +1 -0
- package/dist/interfaces/singly-linked-list.d.ts +1 -0
- package/dist/interfaces/singly-linked-list.js +2 -0
- package/dist/interfaces/tree-multiset.d.ts +7 -0
- package/dist/interfaces/tree-multiset.js +2 -0
- package/dist/interfaces/undirected-graph.d.ts +5 -0
- package/dist/interfaces/undirected-graph.js +2 -0
- package/dist/types/data-structures/abstract-binary-tree.d.ts +34 -0
- package/dist/types/data-structures/abstract-binary-tree.js +25 -0
- package/dist/types/data-structures/abstract-graph.d.ts +11 -0
- package/dist/types/data-structures/abstract-graph.js +2 -0
- package/dist/types/data-structures/avl-tree.d.ts +4 -0
- package/dist/types/data-structures/avl-tree.js +2 -0
- package/dist/types/data-structures/binary-tree.d.ts +4 -0
- package/dist/types/data-structures/binary-tree.js +2 -0
- package/dist/types/data-structures/bst.d.ts +13 -0
- package/dist/types/data-structures/bst.js +9 -0
- package/dist/types/data-structures/directed-graph.d.ts +6 -0
- package/dist/types/data-structures/directed-graph.js +9 -0
- package/dist/types/data-structures/doubly-linked-list.d.ts +1 -0
- package/dist/types/data-structures/doubly-linked-list.js +2 -0
- package/dist/types/data-structures/heap.d.ts +3 -0
- package/dist/types/data-structures/heap.js +2 -0
- package/dist/{data-structures/types → types/data-structures}/index.d.ts +3 -1
- package/dist/{data-structures/types → types/data-structures}/index.js +3 -1
- package/dist/types/data-structures/map-graph.d.ts +1 -0
- package/dist/types/data-structures/map-graph.js +2 -0
- package/dist/{data-structures/types → types/data-structures}/navigator.d.ts +2 -2
- package/dist/types/data-structures/navigator.js +2 -0
- package/dist/{data-structures/types → types/data-structures}/priority-queue.d.ts +2 -2
- package/dist/types/data-structures/priority-queue.js +2 -0
- package/dist/types/data-structures/rb-tree.d.ts +8 -0
- package/dist/types/data-structures/rb-tree.js +8 -0
- package/dist/types/data-structures/segment-tree.js +2 -0
- package/dist/types/data-structures/singly-linked-list.d.ts +1 -0
- package/dist/types/data-structures/singly-linked-list.js +2 -0
- package/dist/types/data-structures/tree-multiset.d.ts +4 -0
- package/dist/types/data-structures/tree-multiset.js +2 -0
- package/dist/types/helpers.d.ts +1 -0
- package/dist/types/helpers.js +2 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.js +19 -0
- package/dist/types/utils/index.d.ts +2 -0
- package/dist/types/utils/index.js +18 -0
- package/dist/types/utils/utils.d.ts +7 -0
- package/dist/types/utils/utils.js +2 -0
- package/dist/types/utils/validate-type.d.ts +19 -0
- package/dist/types/utils/validate-type.js +2 -0
- package/dist/utils/utils.d.ts +17 -103
- package/dist/utils/utils.js +40 -625
- package/package.json +134 -23
- package/.idea/data-structure-typed.iml +0 -12
- package/.idea/modules.xml +0 -8
- package/.idea/vcs.xml +0 -6
- package/dist/data-structures/trampoline.d.ts +0 -16
- package/dist/data-structures/trampoline.js +0 -130
- package/dist/data-structures/types/abstract-graph.d.ts +0 -29
- package/dist/data-structures/types/avl-tree.d.ts +0 -5
- package/dist/data-structures/types/binary-tree.d.ts +0 -16
- package/dist/data-structures/types/bst.d.ts +0 -7
- package/dist/data-structures/types/directed-graph.d.ts +0 -10
- package/dist/data-structures/types/doubly-linked-list.d.ts +0 -1
- package/dist/data-structures/types/heap.d.ts +0 -7
- package/dist/data-structures/types/singly-linked-list.d.ts +0 -5
- package/dist/data-structures/types/tree-multiset.d.ts +0 -5
- package/dist/data-structures/types/utils.d.ts +0 -52
- package/dist/data-structures/types/utils.js +0 -54
- package/src/data-structures/binary-tree/aa-tree.ts +0 -3
- package/src/data-structures/binary-tree/avl-tree.ts +0 -227
- package/src/data-structures/binary-tree/b-tree.ts +0 -3
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +0 -33
- package/src/data-structures/binary-tree/binary-tree.ts +0 -1133
- package/src/data-structures/binary-tree/bst.ts +0 -395
- 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/index.ts +0 -11
- package/src/data-structures/binary-tree/rb-tree.ts +0 -3
- package/src/data-structures/binary-tree/segment-tree.ts +0 -172
- package/src/data-structures/binary-tree/splay-tree.ts +0 -3
- package/src/data-structures/binary-tree/tree-multiset.ts +0 -18
- package/src/data-structures/binary-tree/two-three-tree.ts +0 -3
- package/src/data-structures/diagrams/README.md +0 -7
- package/src/data-structures/graph/abstract-graph.ts +0 -753
- 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 +0 -306
- package/src/data-structures/graph/index.ts +0 -3
- package/src/data-structures/graph/undirected-graph.ts +0 -155
- package/src/data-structures/hash/coordinate-map.ts +0 -24
- package/src/data-structures/hash/coordinate-set.ts +0 -20
- package/src/data-structures/hash/index.ts +0 -6
- package/src/data-structures/heap/heap.ts +0 -127
- package/src/data-structures/heap/index.ts +0 -3
- package/src/data-structures/heap/max-heap.ts +0 -23
- package/src/data-structures/heap/min-heap.ts +0 -25
- package/src/data-structures/index.ts +0 -12
- package/src/data-structures/linked-list/doubly-linked-list.ts +0 -250
- package/src/data-structures/linked-list/index.ts +0 -2
- package/src/data-structures/linked-list/singly-linked-list.ts +0 -736
- package/src/data-structures/linked-list/skip-linked-list.ts +0 -1
- package/src/data-structures/matrix/index.ts +0 -4
- package/src/data-structures/matrix/matrix.ts +0 -13
- package/src/data-structures/matrix/matrix2d.ts +0 -125
- package/src/data-structures/matrix/navigator.ts +0 -87
- package/src/data-structures/matrix/vector2d.ts +0 -189
- package/src/data-structures/priority-queue/index.ts +0 -3
- package/src/data-structures/priority-queue/max-priority-queue.ts +0 -13
- package/src/data-structures/priority-queue/min-priority-queue.ts +0 -13
- package/src/data-structures/priority-queue/priority-queue.ts +0 -200
- package/src/data-structures/queue/deque.ts +0 -139
- package/src/data-structures/queue/index.ts +0 -2
- package/src/data-structures/queue/queue.ts +0 -122
- package/src/data-structures/stack/index.ts +0 -1
- package/src/data-structures/stack/stack.ts +0 -103
- package/src/data-structures/trampoline.ts +0 -51
- package/src/data-structures/trie/index.ts +0 -1
- package/src/data-structures/trie/trie.ts +0 -203
- package/src/data-structures/types/abstract-graph.ts +0 -51
- package/src/data-structures/types/avl-tree.ts +0 -6
- package/src/data-structures/types/binary-tree.ts +0 -15
- package/src/data-structures/types/bst.ts +0 -5
- package/src/data-structures/types/directed-graph.ts +0 -18
- package/src/data-structures/types/doubly-linked-list.ts +0 -1
- package/src/data-structures/types/heap.ts +0 -8
- package/src/data-structures/types/navigator.ts +0 -12
- package/src/data-structures/types/priority-queue.ts +0 -9
- package/src/data-structures/types/segment-tree.ts +0 -1
- package/src/data-structures/types/singly-linked-list.ts +0 -15
- package/src/data-structures/types/tree-multiset.ts +0 -3
- package/src/data-structures/types/utils.ts +0 -173
- package/src/index.ts +0 -1
- package/src/utils/index.ts +0 -1
- package/src/utils/utils.ts +0 -505
- package/tsconfig.json +0 -56
- /package/dist/{data-structures/types/abstract-graph.js → interfaces/abstract-binary-tree.js} +0 -0
- /package/dist/{data-structures/types/avl-tree.js → interfaces/abstract-graph.js} +0 -0
- /package/dist/{data-structures/types/binary-tree.js → interfaces/avl-tree.js} +0 -0
- /package/dist/{data-structures/types/bst.js → interfaces/binary-tree.js} +0 -0
- /package/dist/{data-structures/types/directed-graph.js → interfaces/bst.js} +0 -0
- /package/dist/{data-structures/types/doubly-linked-list.js → interfaces/directed-graph.js} +0 -0
- /package/{src/data-structures/hash/pair.ts → dist/interfaces/doubly-linked-list.d.ts} +0 -0
- /package/dist/{data-structures/types/heap.js → interfaces/doubly-linked-list.js} +0 -0
- /package/{src/data-structures/hash/tree-map.ts → dist/interfaces/heap.d.ts} +0 -0
- /package/dist/{data-structures/types/navigator.js → interfaces/heap.js} +0 -0
- /package/{src/data-structures/hash/tree-set.ts → dist/interfaces/navigator.d.ts} +0 -0
- /package/dist/{data-structures/types/priority-queue.js → interfaces/navigator.js} +0 -0
- /package/dist/{data-structures/types/segment-tree.js → interfaces/priority-queue.js} +0 -0
- /package/dist/{data-structures/types/singly-linked-list.js → interfaces/rb-tree.js} +0 -0
- /package/dist/{data-structures/types/tree-multiset.js → interfaces/segment-tree.js} +0 -0
- /package/dist/{data-structures/types → types/data-structures}/segment-tree.d.ts +0 -0
|
@@ -1,73 +1,200 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* data-structure-typed
|
|
3
|
+
*
|
|
4
|
+
* @author Tyler Zeng
|
|
5
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
|
+
* @license MIT License
|
|
7
|
+
*/
|
|
1
8
|
export declare class Vector2D {
|
|
2
9
|
x: number;
|
|
3
10
|
y: number;
|
|
4
11
|
w: number;
|
|
5
12
|
constructor(x?: number, y?: number, w?: number);
|
|
6
13
|
/**
|
|
7
|
-
*
|
|
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.
|
|
8
16
|
*/
|
|
9
17
|
get isZero(): boolean;
|
|
10
18
|
/**
|
|
11
|
-
* The
|
|
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.
|
|
12
21
|
*/
|
|
13
22
|
get length(): number;
|
|
14
23
|
/**
|
|
15
|
-
* The
|
|
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.
|
|
16
26
|
*/
|
|
17
27
|
get lengthSq(): number;
|
|
18
28
|
/**
|
|
19
|
-
*
|
|
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.
|
|
20
32
|
*/
|
|
21
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
|
+
*/
|
|
22
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
|
+
*/
|
|
23
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
|
+
*/
|
|
24
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
|
+
*/
|
|
25
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
|
+
*/
|
|
26
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
|
+
*/
|
|
27
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
|
+
*/
|
|
28
103
|
static equalsRounded(vector1: Vector2D, vector2: Vector2D, roundingFactor?: number): boolean;
|
|
29
104
|
/**
|
|
30
|
-
* 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.
|
|
31
109
|
*/
|
|
32
110
|
static normalize(vector: Vector2D): Vector2D;
|
|
33
111
|
/**
|
|
34
|
-
* 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.
|
|
35
118
|
*/
|
|
36
119
|
static truncate(vector: Vector2D, max: number): Vector2D;
|
|
37
120
|
/**
|
|
38
|
-
* 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.
|
|
39
124
|
*/
|
|
40
125
|
static perp(vector: Vector2D): Vector2D;
|
|
41
126
|
/**
|
|
42
|
-
* returns
|
|
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
|
|
43
131
|
*/
|
|
44
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
|
+
*/
|
|
45
141
|
static abs(vector: Vector2D): Vector2D;
|
|
46
142
|
/**
|
|
47
|
-
* 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.
|
|
48
148
|
*/
|
|
49
149
|
static dot(vector1: Vector2D, vector2: Vector2D): number;
|
|
50
150
|
/**
|
|
51
|
-
* The distance between
|
|
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.
|
|
52
159
|
*/
|
|
53
160
|
static distance(vector1: Vector2D, vector2: Vector2D): number;
|
|
54
161
|
/**
|
|
55
|
-
* The distance between
|
|
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.
|
|
56
168
|
*/
|
|
57
169
|
static distanceSq(vector1: Vector2D, vector2: Vector2D): number;
|
|
58
170
|
/**
|
|
59
|
-
*
|
|
171
|
+
* The sign function determines the sign of the cross product between two 2D vectors.
|
|
60
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
|
|
61
178
|
*/
|
|
62
179
|
static sign(vector1: Vector2D, vector2: Vector2D): number;
|
|
63
180
|
/**
|
|
64
|
-
*
|
|
65
|
-
* @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
|
|
66
186
|
*/
|
|
67
187
|
static angle(vector: Vector2D): number;
|
|
188
|
+
/**
|
|
189
|
+
* The function "random" generates a random Vector2D object with x and y values within the specified range.
|
|
190
|
+
* @param {number} maxX - The maxX parameter represents the maximum value for the x-coordinate of the random vector.
|
|
191
|
+
* @param {number} maxY - The `maxY` parameter represents the maximum value for the y-coordinate of the generated
|
|
192
|
+
* random vector.
|
|
193
|
+
* @returns a new instance of the Vector2D class with random x and y values.
|
|
194
|
+
*/
|
|
68
195
|
static random(maxX: number, maxY: number): Vector2D;
|
|
69
196
|
/**
|
|
70
|
-
*
|
|
197
|
+
* The function sets the values of x and y to zero.
|
|
71
198
|
*/
|
|
72
199
|
zero(): void;
|
|
73
200
|
}
|
|
@@ -1,184 +1,290 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Vector2D = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
/**
|
|
5
|
+
* data-structure-typed
|
|
6
|
+
*
|
|
7
|
+
* @author Tyler Zeng
|
|
8
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
9
|
+
* @license MIT License
|
|
10
|
+
*/
|
|
11
|
+
class Vector2D {
|
|
12
|
+
constructor(x = 0, y = 0, w = 1 // needed for matrix multiplication
|
|
6
13
|
) {
|
|
7
|
-
if (x === void 0) { x = 0; }
|
|
8
|
-
if (y === void 0) { y = 0; }
|
|
9
|
-
if (w === void 0) { w = 1; }
|
|
10
14
|
this.x = x;
|
|
11
15
|
this.y = y;
|
|
12
16
|
this.w = w;
|
|
13
17
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
Vector2D.add = function (vector1, vector2) {
|
|
18
|
+
/**
|
|
19
|
+
* The function checks if the x and y values of a point are both zero.
|
|
20
|
+
* @returns A boolean value indicating whether both the x and y properties of the object are equal to 0.
|
|
21
|
+
*/
|
|
22
|
+
get isZero() {
|
|
23
|
+
return this.x === 0 && this.y === 0;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The above function calculates the length of a vector using the Pythagorean theorem.
|
|
27
|
+
* @returns The length of a vector, calculated using the Pythagorean theorem.
|
|
28
|
+
*/
|
|
29
|
+
get length() {
|
|
30
|
+
return Math.sqrt((this.x * this.x) + (this.y * this.y));
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The function calculates the square of the length of a vector.
|
|
34
|
+
* @returns The method is returning the sum of the squares of the x and y values.
|
|
35
|
+
*/
|
|
36
|
+
get lengthSq() {
|
|
37
|
+
return (this.x * this.x) + (this.y * this.y);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The "rounded" function returns a new Vector2D object with the x and y values rounded to the nearest whole number.
|
|
41
|
+
* @returns The method is returning a new instance of the Vector2D class with the x and y values rounded to the nearest
|
|
42
|
+
* whole number.
|
|
43
|
+
*/
|
|
44
|
+
get rounded() {
|
|
45
|
+
return new Vector2D(Math.round(this.x), Math.round(this.y));
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The function "add" takes two Vector2D objects as parameters and returns a new Vector2D object with the sum of their
|
|
49
|
+
* x and y components.
|
|
50
|
+
* @param {Vector2D} vector1 - The parameter `vector1` is an instance of the `Vector2D` class. It represents a
|
|
51
|
+
* 2-dimensional vector with an `x` and `y` component.
|
|
52
|
+
* @param {Vector2D} vector2 - The parameter "vector2" is of type Vector2D. It represents a 2-dimensional vector with
|
|
53
|
+
* an x and y component.
|
|
54
|
+
* @returns The method is returning a new instance of the Vector2D class with the x and y components of the two input
|
|
55
|
+
* vectors added together.
|
|
56
|
+
*/
|
|
57
|
+
static add(vector1, vector2) {
|
|
55
58
|
return new Vector2D(vector1.x + vector2.x, vector1.y + vector2.y);
|
|
56
|
-
}
|
|
57
|
-
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The subtract function takes two Vector2D objects as parameters and returns a new Vector2D object with the x and y
|
|
62
|
+
* components subtracted.
|
|
63
|
+
* @param {Vector2D} vector1 - The parameter `vector1` is an instance of the `Vector2D` class, representing a
|
|
64
|
+
* 2-dimensional vector. It has properties `x` and `y` which represent the x and y components of the vector
|
|
65
|
+
* respectively.
|
|
66
|
+
* @param {Vector2D} vector2 - The parameter "vector2" is a Vector2D object. It represents the second vector that you
|
|
67
|
+
* want to subtract from the first vector.
|
|
68
|
+
* @returns The method is returning a new Vector2D object with the x and y components subtracted from vector1 and
|
|
69
|
+
* vector2.
|
|
70
|
+
*/
|
|
71
|
+
static subtract(vector1, vector2) {
|
|
58
72
|
return new Vector2D(vector1.x - vector2.x, vector1.y - vector2.y);
|
|
59
|
-
}
|
|
60
|
-
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* The function subtracts a given value from the x and y components of a Vector2D object and returns a new Vector2D
|
|
76
|
+
* object.
|
|
77
|
+
* @param {Vector2D} vector - The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector with
|
|
78
|
+
* x and y components.
|
|
79
|
+
* @param {number} value - The "value" parameter is a number that will be subtracted from both the x and y components
|
|
80
|
+
* of the "vector" parameter.
|
|
81
|
+
* @returns A new Vector2D object with the x and y values subtracted by the given value.
|
|
82
|
+
*/
|
|
83
|
+
static subtractValue(vector, value) {
|
|
61
84
|
return new Vector2D(vector.x - value, vector.y - value);
|
|
62
|
-
}
|
|
63
|
-
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The function multiplies a Vector2D object by a given value.
|
|
88
|
+
* @param {Vector2D} vector - The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector with
|
|
89
|
+
* x and y components.
|
|
90
|
+
* @param {number} value - The "value" parameter is a number that represents the value by which the x and y components
|
|
91
|
+
* of the vector will be multiplied.
|
|
92
|
+
* @returns A new Vector2D object with the x and y values multiplied by the given value.
|
|
93
|
+
*/
|
|
94
|
+
static multiply(vector, value) {
|
|
64
95
|
return new Vector2D(vector.x * value, vector.y * value);
|
|
65
|
-
}
|
|
66
|
-
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* The function divides the x and y components of a Vector2D by a given value and returns a new Vector2D.
|
|
99
|
+
* @param {Vector2D} vector - The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector with
|
|
100
|
+
* x and y components.
|
|
101
|
+
* @param {number} value - The value parameter is a number that will be used to divide the x and y components of the
|
|
102
|
+
* vector.
|
|
103
|
+
* @returns A new instance of the Vector2D class with the x and y values divided by the given value.
|
|
104
|
+
*/
|
|
105
|
+
static divide(vector, value) {
|
|
67
106
|
return new Vector2D(vector.x / value, vector.y / value);
|
|
68
|
-
}
|
|
69
|
-
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* The function checks if two Vector2D objects are equal by comparing their x and y values.
|
|
110
|
+
* @param {Vector2D} vector1 - The parameter `vector1` is of type `Vector2D`, which represents a 2-dimensional vector.
|
|
111
|
+
* It has two properties: `x` and `y`, which represent the x and y components of the vector, respectively.
|
|
112
|
+
* @param {Vector2D} vector2 - The parameter "vector2" is of type Vector2D.
|
|
113
|
+
* @returns a boolean value, which indicates whether the two input vectors are equal or not.
|
|
114
|
+
*/
|
|
115
|
+
static equals(vector1, vector2) {
|
|
70
116
|
return vector1.x === vector2.x && vector1.y === vector2.y;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* The function checks if two Vector2D objects are equal within a specified rounding factor.
|
|
120
|
+
* @param {Vector2D} vector1 - The first vector to compare.
|
|
121
|
+
* @param {Vector2D} vector2 - The parameter "vector2" is a Vector2D object, which represents a 2-dimensional vector.
|
|
122
|
+
* It is used as one of the inputs for the "equalsRounded" function.
|
|
123
|
+
* @param [roundingFactor=12] - The roundingFactor parameter is used to determine the threshold for considering two
|
|
124
|
+
* vectors as equal. If the absolute difference in the x and y components of the vectors is less than the
|
|
125
|
+
* roundingFactor, the vectors are considered equal.
|
|
126
|
+
* @returns a boolean value.
|
|
127
|
+
*/
|
|
128
|
+
static equalsRounded(vector1, vector2, roundingFactor = 12) {
|
|
129
|
+
const vector = Vector2D.abs(Vector2D.subtract(vector1, vector2));
|
|
75
130
|
if (vector.x < roundingFactor && vector.y < roundingFactor) {
|
|
76
131
|
return true;
|
|
77
132
|
}
|
|
78
133
|
return false;
|
|
79
|
-
}
|
|
134
|
+
}
|
|
80
135
|
/**
|
|
81
|
-
* 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.
|
|
82
140
|
*/
|
|
83
|
-
|
|
84
|
-
|
|
141
|
+
static normalize(vector) {
|
|
142
|
+
const length = vector.length;
|
|
85
143
|
if (length > 2.220446049250313e-16) { // Epsilon
|
|
86
144
|
return Vector2D.divide(vector, length);
|
|
87
145
|
}
|
|
88
146
|
return vector;
|
|
89
|
-
}
|
|
147
|
+
}
|
|
90
148
|
/**
|
|
91
|
-
* 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.
|
|
92
155
|
*/
|
|
93
|
-
|
|
156
|
+
static truncate(vector, max) {
|
|
94
157
|
if (vector.length > max) {
|
|
95
158
|
return Vector2D.multiply(Vector2D.normalize(vector), max);
|
|
96
159
|
}
|
|
97
160
|
return vector;
|
|
98
|
-
}
|
|
161
|
+
}
|
|
99
162
|
/**
|
|
100
|
-
* 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.
|
|
101
166
|
*/
|
|
102
|
-
|
|
167
|
+
static perp(vector) {
|
|
103
168
|
return new Vector2D(-vector.y, vector.x);
|
|
104
|
-
}
|
|
169
|
+
}
|
|
105
170
|
/**
|
|
106
|
-
* returns
|
|
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
|
|
107
175
|
*/
|
|
108
|
-
|
|
176
|
+
static reverse(vector) {
|
|
109
177
|
return new Vector2D(-vector.x, -vector.y);
|
|
110
|
-
}
|
|
111
|
-
|
|
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
|
+
*/
|
|
187
|
+
static abs(vector) {
|
|
112
188
|
return new Vector2D(Math.abs(vector.x), Math.abs(vector.y));
|
|
113
|
-
}
|
|
189
|
+
}
|
|
114
190
|
/**
|
|
115
|
-
* 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.
|
|
116
196
|
*/
|
|
117
|
-
|
|
197
|
+
static dot(vector1, vector2) {
|
|
118
198
|
return (vector1.x * vector2.x) + (vector1.y * vector2.y);
|
|
119
|
-
}
|
|
199
|
+
}
|
|
120
200
|
// /**
|
|
121
201
|
// * Transform vectors based on the current tranformation matrices: translation, rotation and scale
|
|
122
202
|
// * @param vectors The vectors to transform
|
|
123
203
|
// */
|
|
124
|
-
//
|
|
204
|
+
// static transform(vector: Vector2D, transformation: Matrix2D): Vector2D {
|
|
125
205
|
// return Matrix2D.multiplyByVector(transformation, vector)
|
|
126
206
|
// }
|
|
127
207
|
// /**
|
|
128
208
|
// * Transform vectors based on the current tranformation matrices: translation, rotation and scale
|
|
129
209
|
// * @param vectors The vectors to transform
|
|
130
210
|
// */
|
|
131
|
-
//
|
|
211
|
+
// static transformList(vectors: Vector2D[], transformation: Matrix2D): Vector2D[] {
|
|
132
212
|
// return vectors.map(vector => Matrix2D.multiplyByVector(transformation, vector))
|
|
133
213
|
// }
|
|
134
214
|
/**
|
|
135
|
-
* The distance between
|
|
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.
|
|
136
223
|
*/
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
224
|
+
static distance(vector1, vector2) {
|
|
225
|
+
const ySeparation = vector2.y - vector1.y;
|
|
226
|
+
const xSeparation = vector2.x - vector1.x;
|
|
140
227
|
return Math.sqrt((ySeparation * ySeparation) + (xSeparation * xSeparation));
|
|
141
|
-
}
|
|
228
|
+
}
|
|
142
229
|
/**
|
|
143
|
-
* The distance between
|
|
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.
|
|
144
236
|
*/
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
237
|
+
static distanceSq(vector1, vector2) {
|
|
238
|
+
const ySeparation = vector2.y - vector1.y;
|
|
239
|
+
const xSeparation = vector2.x - vector1.x;
|
|
148
240
|
return (ySeparation * ySeparation) + (xSeparation * xSeparation);
|
|
149
|
-
}
|
|
241
|
+
}
|
|
150
242
|
/**
|
|
151
|
-
*
|
|
243
|
+
* The sign function determines the sign of the cross product between two 2D vectors.
|
|
152
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
|
|
153
250
|
*/
|
|
154
|
-
|
|
251
|
+
static sign(vector1, vector2) {
|
|
155
252
|
if (vector1.y * vector2.x > vector1.x * vector2.y) {
|
|
156
253
|
return -1;
|
|
157
254
|
}
|
|
158
255
|
return 1;
|
|
159
|
-
}
|
|
256
|
+
}
|
|
160
257
|
/**
|
|
161
|
-
*
|
|
162
|
-
* @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
|
|
163
263
|
*/
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
264
|
+
static angle(vector) {
|
|
265
|
+
const origin = new Vector2D(0, -1);
|
|
266
|
+
const radian = Math.acos(Vector2D.dot(vector, origin) / (vector.length * origin.length));
|
|
167
267
|
return Vector2D.sign(vector, origin) === 1 ? ((Math.PI * 2) - radian) : radian;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
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
|
+
*/
|
|
276
|
+
static random(maxX, maxY) {
|
|
277
|
+
const randX = Math.floor(Math.random() * maxX - (maxX / 2));
|
|
278
|
+
const randY = Math.floor(Math.random() * maxY - (maxY / 2));
|
|
172
279
|
return new Vector2D(randX, randY);
|
|
173
|
-
}
|
|
280
|
+
}
|
|
174
281
|
/**
|
|
175
|
-
*
|
|
282
|
+
* The function sets the values of x and y to zero.
|
|
176
283
|
*/
|
|
177
|
-
|
|
284
|
+
zero() {
|
|
178
285
|
this.x = 0;
|
|
179
286
|
this.y = 0;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
}());
|
|
287
|
+
}
|
|
288
|
+
}
|
|
183
289
|
exports.Vector2D = Vector2D;
|
|
184
290
|
exports.default = Vector2D;
|
|
@@ -1,5 +1,15 @@
|
|
|
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
|
+
*/
|
|
1
8
|
import { PriorityQueue } from './priority-queue';
|
|
2
|
-
import type { PriorityQueueOptions } from '
|
|
9
|
+
import type { PriorityQueueOptions } from '../../types';
|
|
3
10
|
export declare class MaxPriorityQueue<T = number> extends PriorityQueue<T> {
|
|
4
|
-
constructor(options?: PriorityQueueOptions<
|
|
11
|
+
constructor(options?: Omit<PriorityQueueOptions<number>, 'comparator'>);
|
|
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>;
|
|
5
15
|
}
|