@equinor/videx-linear-algebra 1.0.10 → 1.0.12
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/dist/index.d.ts +287 -287
- package/package.json +7 -7
package/dist/index.d.ts
CHANGED
|
@@ -1,287 +1,287 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Interface for arrays and vector-like class structures.
|
|
3
|
-
*/
|
|
4
|
-
export interface VectorLike {
|
|
5
|
-
/**
|
|
6
|
-
* Length of vector-like object.
|
|
7
|
-
*/
|
|
8
|
-
length: number;
|
|
9
|
-
/**
|
|
10
|
-
* Numeric indices.
|
|
11
|
-
*/
|
|
12
|
-
[index: number]: number;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Copy the values of one vector to another without creating a new object.
|
|
16
|
-
* @param source Source vector
|
|
17
|
-
* @param target Target vector
|
|
18
|
-
* @returns Target vector as a copy of source
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* copy([3, 4], [2, 2]); // Returns: [3, 4]
|
|
22
|
-
*/
|
|
23
|
-
export declare function copy<T extends VectorLike>(source: VectorLike, target: T): T;
|
|
24
|
-
/**
|
|
25
|
-
* a + b
|
|
26
|
-
*
|
|
27
|
-
* Component-wise addition of two n-dimensional vectors.
|
|
28
|
-
* Target is used to store the results.
|
|
29
|
-
* @param a Left operand
|
|
30
|
-
* @param b Right operand
|
|
31
|
-
* @param target Target for storing the results (Default: a)
|
|
32
|
-
* @return Resulting vector
|
|
33
|
-
*
|
|
34
|
-
* @example
|
|
35
|
-
* add([1, 2], [3, 4], new Array(2)); // Returns: [4, 6]
|
|
36
|
-
*/
|
|
37
|
-
export declare function add<T extends VectorLike>(a: T, b: VectorLike, target?: T): T;
|
|
38
|
-
/**
|
|
39
|
-
* v1 + ... + vM
|
|
40
|
-
*
|
|
41
|
-
* Component-wise addition of M n-dimensional vectors. Target is
|
|
42
|
-
* used to store the results.
|
|
43
|
-
* @param vectors Array of vectors with length n.
|
|
44
|
-
* @param target Target for storing the results (Default: vectors[0])
|
|
45
|
-
* @return Resulting vector
|
|
46
|
-
*
|
|
47
|
-
* @example
|
|
48
|
-
* addAll([ [1, 2], [3, 4], [5, 6] ], new Array(2)); // Returns: [9, 12]
|
|
49
|
-
*/
|
|
50
|
-
export declare function addAll<T extends VectorLike>(vectors: T[], target?: T): T;
|
|
51
|
-
/**
|
|
52
|
-
* a - b
|
|
53
|
-
*
|
|
54
|
-
* Component-wise subtraction of two n-dimensional vectors.
|
|
55
|
-
* Target is used to store the results.
|
|
56
|
-
* @param a Left operand
|
|
57
|
-
* @param b Right operand
|
|
58
|
-
* @param target Target for storing the results (Default: a)
|
|
59
|
-
* @return Resulting vector
|
|
60
|
-
*
|
|
61
|
-
* @example
|
|
62
|
-
* sub([4, 3], [2, 1], new Array(2)); // Returns: [2, 2]
|
|
63
|
-
*/
|
|
64
|
-
export declare function sub<T extends VectorLike>(a: T, b: VectorLike, target?: T): T;
|
|
65
|
-
/**
|
|
66
|
-
* v1 - ... - vM
|
|
67
|
-
*
|
|
68
|
-
* Component-wise subtraction of M n-dimensional vectors from a. Target is
|
|
69
|
-
* used to store the results.
|
|
70
|
-
* @param a Vector with length n.
|
|
71
|
-
* @param vectors Array of vectors with length n.
|
|
72
|
-
* @param target Target for storing the results (Default: a)
|
|
73
|
-
* @return Resulting vector
|
|
74
|
-
*
|
|
75
|
-
* @example
|
|
76
|
-
* subAll([9, 9], [ [2, 3], [0, 2] ], new Array(2)); // Returns: [7, 4]
|
|
77
|
-
*/
|
|
78
|
-
export declare function subAll<T extends VectorLike>(a: T, vectors: VectorLike[], target?: T): T;
|
|
79
|
-
/**
|
|
80
|
-
* Component-wise scaling of vector.
|
|
81
|
-
* @param a Vector to scale
|
|
82
|
-
* @param factor Scaling factor
|
|
83
|
-
* @param target Target for storing the results (Default: a)
|
|
84
|
-
* @return Resulting vector
|
|
85
|
-
*
|
|
86
|
-
* @example
|
|
87
|
-
* scale([1, 2, 3], 2, new Array(3)); // Returns: [2, 4, 6]
|
|
88
|
-
*/
|
|
89
|
-
export declare function scale<T extends VectorLike>(a: T, factor: number, target?: T): T;
|
|
90
|
-
/**
|
|
91
|
-
* Computes the sum of squares
|
|
92
|
-
* @param a Target vector
|
|
93
|
-
* @return Sum of squares
|
|
94
|
-
*
|
|
95
|
-
* @example
|
|
96
|
-
* sumsqr([1, 2, 3]); // Returns: 14
|
|
97
|
-
*/
|
|
98
|
-
export declare function sumsqr(a: VectorLike): number;
|
|
99
|
-
/**
|
|
100
|
-
* Computes the magnitude of a vector.
|
|
101
|
-
* @param a Target vector
|
|
102
|
-
* @return Magnitude of vector
|
|
103
|
-
*
|
|
104
|
-
* @example
|
|
105
|
-
* magnitude([3, 4]); // Returns: 5
|
|
106
|
-
*/
|
|
107
|
-
export declare function magnitude(a: VectorLike): number;
|
|
108
|
-
/**
|
|
109
|
-
* Normalizes a vector
|
|
110
|
-
* @param a Vector to normalize
|
|
111
|
-
* @param target Target for storing the results (Default: a)
|
|
112
|
-
* @return Normalized vector
|
|
113
|
-
*
|
|
114
|
-
* @example
|
|
115
|
-
* magnitude([0, 10, 0], new Array(3)); // Returns: [0, 1, 0]
|
|
116
|
-
*/
|
|
117
|
-
export declare function normalize<T extends VectorLike>(a: T, target?: T): T;
|
|
118
|
-
/**
|
|
119
|
-
* Fill an array/vector with given value.
|
|
120
|
-
* @param value Value to fill
|
|
121
|
-
* @param target Target for storing the results
|
|
122
|
-
* @returns Filled vector
|
|
123
|
-
*
|
|
124
|
-
* @example
|
|
125
|
-
* fill(1, new Array(3)); // Returns: [1, 1, 1]
|
|
126
|
-
*/
|
|
127
|
-
export declare function fill<T extends VectorLike>(value: number, target: T): T;
|
|
128
|
-
/**
|
|
129
|
-
* Get the vector going from b to a.
|
|
130
|
-
* @param a Start coordinates
|
|
131
|
-
* @param b End coordinates
|
|
132
|
-
* @param target Target for storing the results (Default: a)
|
|
133
|
-
* @return Vector going from a to b
|
|
134
|
-
*
|
|
135
|
-
* @example
|
|
136
|
-
* dir([2, 1], [3, 0], new Array(2)); // Returns: [1, -1]
|
|
137
|
-
*/
|
|
138
|
-
export declare function dir<T extends VectorLike>(a: T, b: VectorLike, target?: T): T;
|
|
139
|
-
/**
|
|
140
|
-
* Calculate the distance between two coordinates.
|
|
141
|
-
* @param a Start coordinates
|
|
142
|
-
* @param b End coordinates
|
|
143
|
-
* @return Distance between coordinates
|
|
144
|
-
*
|
|
145
|
-
* @example
|
|
146
|
-
* dist([1, 2], [4, 6]); // Returns: 5
|
|
147
|
-
*/
|
|
148
|
-
export declare function dist(a: VectorLike, b: VectorLike): number;
|
|
149
|
-
/**
|
|
150
|
-
* Calculate the dot product between two vectors.
|
|
151
|
-
* @param a Left operand
|
|
152
|
-
* @param b Right operand
|
|
153
|
-
* @return Dot product
|
|
154
|
-
*
|
|
155
|
-
* @example
|
|
156
|
-
* dist([1, 2], [3, 4]); // Returns: 11
|
|
157
|
-
*/
|
|
158
|
-
export declare function dot(a: VectorLike, b: VectorLike): number;
|
|
159
|
-
/**
|
|
160
|
-
* a × b
|
|
161
|
-
*
|
|
162
|
-
* Find cross product of vectors. Only defined for 3d vectors.
|
|
163
|
-
* @param a Left operand (3d vector)
|
|
164
|
-
* @param b Right operand (3d vector)
|
|
165
|
-
* @param target Target for storing the results (Default: a)
|
|
166
|
-
* @return Cross product of vectors
|
|
167
|
-
*
|
|
168
|
-
* @example
|
|
169
|
-
* cross([1, 0, 0], [0, 1, 0]); // Returns: [0, 0, 1]
|
|
170
|
-
*/
|
|
171
|
-
export declare function cross<T extends VectorLike>(a: T, b: VectorLike, target?: T): T;
|
|
172
|
-
/**
|
|
173
|
-
* a ∙ b × c
|
|
174
|
-
*
|
|
175
|
-
* Find triple product between three vectors. Only defined for 3d vectors.
|
|
176
|
-
* @param a Left operand for dot product (3d vector)
|
|
177
|
-
* @param b Left operand for cross product (3d vector)
|
|
178
|
-
* @param c Right operand for cross product (3d vector)
|
|
179
|
-
* @return Triple product of vectors
|
|
180
|
-
*
|
|
181
|
-
* @example
|
|
182
|
-
* triple([1, 0, 0], [0, 1, 0], [0, 0, 1]); // Returns: 1
|
|
183
|
-
*/
|
|
184
|
-
export declare function triple(a: VectorLike, b: VectorLike, c: VectorLike): number;
|
|
185
|
-
/**
|
|
186
|
-
* Clamp all values of a vector
|
|
187
|
-
* @param a Values to clamp
|
|
188
|
-
* @param min Minimum value (Default: 0)
|
|
189
|
-
* @param max Maximum value (Default: 1)
|
|
190
|
-
* @param target Target for storing the results (Default: a)
|
|
191
|
-
* @return Vector with clamped values
|
|
192
|
-
*
|
|
193
|
-
* @example
|
|
194
|
-
* clamp([0, 1, 2, 3], 1, 2, new Array(4)); // Returns: [1, 1, 2, 2]
|
|
195
|
-
*/
|
|
196
|
-
export declare function clamp<T extends VectorLike>(a: T, min?: number, max?: number, target?: T): T;
|
|
197
|
-
/**
|
|
198
|
-
* GLSL step for all values of a vector
|
|
199
|
-
* @param edges Edges of the step function
|
|
200
|
-
* @param x Value used to generate the step function
|
|
201
|
-
* @param target Target for storing the results (Default: edges)
|
|
202
|
-
* @return results for each value in edges
|
|
203
|
-
*
|
|
204
|
-
* @example
|
|
205
|
-
* step([0, 1, 2, 3], 1.5, new Array(4)); // Returns: [1, 1, 0, 0]
|
|
206
|
-
*/
|
|
207
|
-
export declare function step<T extends VectorLike>(edges: T, x: number, target?: T): T;
|
|
208
|
-
/**
|
|
209
|
-
* Mix (interpolate) vectors (similar to glsl implementation).
|
|
210
|
-
* @param a Vector to interpolate from
|
|
211
|
-
* @param b Vector to interpolate to
|
|
212
|
-
* @param t Interpolation parameter, 0 = a and 1 = b
|
|
213
|
-
* @param target Target for storing the results (Default: a)
|
|
214
|
-
* @return The interpolated vector
|
|
215
|
-
*
|
|
216
|
-
* @example
|
|
217
|
-
* mix([1, 3], [3, 5], 0.5, new Array(2)); // Returns: [2, 4]
|
|
218
|
-
*/
|
|
219
|
-
export declare function mix<T extends VectorLike>(a: T, b: VectorLike, t: number, target?: T): T;
|
|
220
|
-
/**
|
|
221
|
-
* Modify each component of a vector with given function.
|
|
222
|
-
* @param a Vector to modify
|
|
223
|
-
* @param modifier Function used to modify component
|
|
224
|
-
* @param target Target for storing the results (Default: a)
|
|
225
|
-
* @return Vector with modified values
|
|
226
|
-
*
|
|
227
|
-
* @example
|
|
228
|
-
* modify([1.12, 1.55], Math.round, new Array(2)); // Returns: [1, 2]
|
|
229
|
-
*/
|
|
230
|
-
export declare function modify<T extends VectorLike>(a: T, modifier: (_arg0: number, _arg1: number) => number, target?: T): T;
|
|
231
|
-
/**
|
|
232
|
-
* Returns true if all elements of a vector is zero, otherwise returns false.
|
|
233
|
-
* @param a Target vector
|
|
234
|
-
* @param epsilon Accepted deviation from 0.00 (Default: 0)
|
|
235
|
-
* @returns Is target zero vector?
|
|
236
|
-
*
|
|
237
|
-
* @example
|
|
238
|
-
* isZeroVector([0, 0.000023, 0], 0.001); // Returns: true
|
|
239
|
-
*/
|
|
240
|
-
export declare function isZeroVector(a: VectorLike, epsilon?: number): boolean;
|
|
241
|
-
/**
|
|
242
|
-
* Reverses the components of a vector with an performance of O(n/2).
|
|
243
|
-
* @param vector The vector to reverse
|
|
244
|
-
* @returns Reversed vector
|
|
245
|
-
*
|
|
246
|
-
* @example
|
|
247
|
-
* reverse([1, 2, 3]); // Returns: [3, 2, 1]
|
|
248
|
-
*/
|
|
249
|
-
export declare function reverse<T extends VectorLike>(vector: T): T;
|
|
250
|
-
/**
|
|
251
|
-
* Flatten a collection of vectors to a single array.
|
|
252
|
-
* @param vectors Array of vectors
|
|
253
|
-
* @return Single array with all values
|
|
254
|
-
*
|
|
255
|
-
* @example
|
|
256
|
-
* flatten([ [1, 2], [3, 4], [5, 6] ]); // Returns [1, 2, 3, 4, 5, 6]
|
|
257
|
-
*/
|
|
258
|
-
export declare function flatten(vectors: VectorLike[]): number[];
|
|
259
|
-
/**
|
|
260
|
-
* Reshapes an array of values to a collection of vectors with given dimensions.
|
|
261
|
-
* @param array Single array with all values
|
|
262
|
-
* @param dimensions Dimensions per vector
|
|
263
|
-
* @return Array of vectors with given dimensions
|
|
264
|
-
*
|
|
265
|
-
* @example
|
|
266
|
-
* reshape([1, 2, 3, 4, 5, 6], 3); // Returns [ [1, 2, 3], [4, 5, 6] ]
|
|
267
|
-
*/
|
|
268
|
-
export declare function reshape(array: number[], dimensions: number): number[][];
|
|
269
|
-
/**
|
|
270
|
-
* Determines if a point lies within a triangle in 2D space.
|
|
271
|
-
* Inspired by: https://stackoverflow.com/a/9755252/5946596
|
|
272
|
-
* @param {VectorLike} p - The point to check [x, y].
|
|
273
|
-
* @param {VectorLike} a - Vertex A of the triangle [x, y].
|
|
274
|
-
* @param {VectorLike} b - Vertex B of the triangle [x, y].
|
|
275
|
-
* @param {VectorLike} c - Vertex C of the triangle [x, y].
|
|
276
|
-
* @param {number} inwardAdjustment - Scales inward adjustment relative to distance for edge handling (default: 1e-6).
|
|
277
|
-
* @returns {boolean} True if the point is strictly inside the triangle; otherwise, false.
|
|
278
|
-
*
|
|
279
|
-
* @example
|
|
280
|
-
* isPointInTriangle([0.25, 0.25], [0, 0], [1, 0], [0, 1]); // Returns true
|
|
281
|
-
*/
|
|
282
|
-
export declare function isPointInTriangle(p: VectorLike, a: VectorLike, b: VectorLike, c: VectorLike, inwardAdjustment?: number): boolean;
|
|
283
|
-
/**
|
|
284
|
-
* Wrapper function for isPointInTriangle which allows an array of vectors.
|
|
285
|
-
* @returns {boolean} True if the point is strictly inside the triangle; otherwise, false.
|
|
286
|
-
*/
|
|
287
|
-
export declare function isPointInTriangleArray(p: VectorLike, triangle: [VectorLike, VectorLike, VectorLike], tolerance?: number): boolean;
|
|
1
|
+
/**
|
|
2
|
+
* Interface for arrays and vector-like class structures.
|
|
3
|
+
*/
|
|
4
|
+
export interface VectorLike {
|
|
5
|
+
/**
|
|
6
|
+
* Length of vector-like object.
|
|
7
|
+
*/
|
|
8
|
+
length: number;
|
|
9
|
+
/**
|
|
10
|
+
* Numeric indices.
|
|
11
|
+
*/
|
|
12
|
+
[index: number]: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Copy the values of one vector to another without creating a new object.
|
|
16
|
+
* @param source Source vector
|
|
17
|
+
* @param target Target vector
|
|
18
|
+
* @returns Target vector as a copy of source
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* copy([3, 4], [2, 2]); // Returns: [3, 4]
|
|
22
|
+
*/
|
|
23
|
+
export declare function copy<T extends VectorLike>(source: VectorLike, target: T): T;
|
|
24
|
+
/**
|
|
25
|
+
* a + b
|
|
26
|
+
*
|
|
27
|
+
* Component-wise addition of two n-dimensional vectors.
|
|
28
|
+
* Target is used to store the results.
|
|
29
|
+
* @param a Left operand
|
|
30
|
+
* @param b Right operand
|
|
31
|
+
* @param target Target for storing the results (Default: a)
|
|
32
|
+
* @return Resulting vector
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* add([1, 2], [3, 4], new Array(2)); // Returns: [4, 6]
|
|
36
|
+
*/
|
|
37
|
+
export declare function add<T extends VectorLike>(a: T, b: VectorLike, target?: T): T;
|
|
38
|
+
/**
|
|
39
|
+
* v1 + ... + vM
|
|
40
|
+
*
|
|
41
|
+
* Component-wise addition of M n-dimensional vectors. Target is
|
|
42
|
+
* used to store the results.
|
|
43
|
+
* @param vectors Array of vectors with length n.
|
|
44
|
+
* @param target Target for storing the results (Default: vectors[0])
|
|
45
|
+
* @return Resulting vector
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* addAll([ [1, 2], [3, 4], [5, 6] ], new Array(2)); // Returns: [9, 12]
|
|
49
|
+
*/
|
|
50
|
+
export declare function addAll<T extends VectorLike>(vectors: T[], target?: T): T;
|
|
51
|
+
/**
|
|
52
|
+
* a - b
|
|
53
|
+
*
|
|
54
|
+
* Component-wise subtraction of two n-dimensional vectors.
|
|
55
|
+
* Target is used to store the results.
|
|
56
|
+
* @param a Left operand
|
|
57
|
+
* @param b Right operand
|
|
58
|
+
* @param target Target for storing the results (Default: a)
|
|
59
|
+
* @return Resulting vector
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* sub([4, 3], [2, 1], new Array(2)); // Returns: [2, 2]
|
|
63
|
+
*/
|
|
64
|
+
export declare function sub<T extends VectorLike>(a: T, b: VectorLike, target?: T): T;
|
|
65
|
+
/**
|
|
66
|
+
* v1 - ... - vM
|
|
67
|
+
*
|
|
68
|
+
* Component-wise subtraction of M n-dimensional vectors from a. Target is
|
|
69
|
+
* used to store the results.
|
|
70
|
+
* @param a Vector with length n.
|
|
71
|
+
* @param vectors Array of vectors with length n.
|
|
72
|
+
* @param target Target for storing the results (Default: a)
|
|
73
|
+
* @return Resulting vector
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* subAll([9, 9], [ [2, 3], [0, 2] ], new Array(2)); // Returns: [7, 4]
|
|
77
|
+
*/
|
|
78
|
+
export declare function subAll<T extends VectorLike>(a: T, vectors: VectorLike[], target?: T): T;
|
|
79
|
+
/**
|
|
80
|
+
* Component-wise scaling of vector.
|
|
81
|
+
* @param a Vector to scale
|
|
82
|
+
* @param factor Scaling factor
|
|
83
|
+
* @param target Target for storing the results (Default: a)
|
|
84
|
+
* @return Resulting vector
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* scale([1, 2, 3], 2, new Array(3)); // Returns: [2, 4, 6]
|
|
88
|
+
*/
|
|
89
|
+
export declare function scale<T extends VectorLike>(a: T, factor: number, target?: T): T;
|
|
90
|
+
/**
|
|
91
|
+
* Computes the sum of squares
|
|
92
|
+
* @param a Target vector
|
|
93
|
+
* @return Sum of squares
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* sumsqr([1, 2, 3]); // Returns: 14
|
|
97
|
+
*/
|
|
98
|
+
export declare function sumsqr(a: VectorLike): number;
|
|
99
|
+
/**
|
|
100
|
+
* Computes the magnitude of a vector.
|
|
101
|
+
* @param a Target vector
|
|
102
|
+
* @return Magnitude of vector
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* magnitude([3, 4]); // Returns: 5
|
|
106
|
+
*/
|
|
107
|
+
export declare function magnitude(a: VectorLike): number;
|
|
108
|
+
/**
|
|
109
|
+
* Normalizes a vector
|
|
110
|
+
* @param a Vector to normalize
|
|
111
|
+
* @param target Target for storing the results (Default: a)
|
|
112
|
+
* @return Normalized vector
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* magnitude([0, 10, 0], new Array(3)); // Returns: [0, 1, 0]
|
|
116
|
+
*/
|
|
117
|
+
export declare function normalize<T extends VectorLike>(a: T, target?: T): T;
|
|
118
|
+
/**
|
|
119
|
+
* Fill an array/vector with given value.
|
|
120
|
+
* @param value Value to fill
|
|
121
|
+
* @param target Target for storing the results
|
|
122
|
+
* @returns Filled vector
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* fill(1, new Array(3)); // Returns: [1, 1, 1]
|
|
126
|
+
*/
|
|
127
|
+
export declare function fill<T extends VectorLike>(value: number, target: T): T;
|
|
128
|
+
/**
|
|
129
|
+
* Get the vector going from b to a.
|
|
130
|
+
* @param a Start coordinates
|
|
131
|
+
* @param b End coordinates
|
|
132
|
+
* @param target Target for storing the results (Default: a)
|
|
133
|
+
* @return Vector going from a to b
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* dir([2, 1], [3, 0], new Array(2)); // Returns: [1, -1]
|
|
137
|
+
*/
|
|
138
|
+
export declare function dir<T extends VectorLike>(a: T, b: VectorLike, target?: T): T;
|
|
139
|
+
/**
|
|
140
|
+
* Calculate the distance between two coordinates.
|
|
141
|
+
* @param a Start coordinates
|
|
142
|
+
* @param b End coordinates
|
|
143
|
+
* @return Distance between coordinates
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* dist([1, 2], [4, 6]); // Returns: 5
|
|
147
|
+
*/
|
|
148
|
+
export declare function dist(a: VectorLike, b: VectorLike): number;
|
|
149
|
+
/**
|
|
150
|
+
* Calculate the dot product between two vectors.
|
|
151
|
+
* @param a Left operand
|
|
152
|
+
* @param b Right operand
|
|
153
|
+
* @return Dot product
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* dist([1, 2], [3, 4]); // Returns: 11
|
|
157
|
+
*/
|
|
158
|
+
export declare function dot(a: VectorLike, b: VectorLike): number;
|
|
159
|
+
/**
|
|
160
|
+
* a × b
|
|
161
|
+
*
|
|
162
|
+
* Find cross product of vectors. Only defined for 3d vectors.
|
|
163
|
+
* @param a Left operand (3d vector)
|
|
164
|
+
* @param b Right operand (3d vector)
|
|
165
|
+
* @param target Target for storing the results (Default: a)
|
|
166
|
+
* @return Cross product of vectors
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* cross([1, 0, 0], [0, 1, 0]); // Returns: [0, 0, 1]
|
|
170
|
+
*/
|
|
171
|
+
export declare function cross<T extends VectorLike>(a: T, b: VectorLike, target?: T): T;
|
|
172
|
+
/**
|
|
173
|
+
* a ∙ b × c
|
|
174
|
+
*
|
|
175
|
+
* Find triple product between three vectors. Only defined for 3d vectors.
|
|
176
|
+
* @param a Left operand for dot product (3d vector)
|
|
177
|
+
* @param b Left operand for cross product (3d vector)
|
|
178
|
+
* @param c Right operand for cross product (3d vector)
|
|
179
|
+
* @return Triple product of vectors
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* triple([1, 0, 0], [0, 1, 0], [0, 0, 1]); // Returns: 1
|
|
183
|
+
*/
|
|
184
|
+
export declare function triple(a: VectorLike, b: VectorLike, c: VectorLike): number;
|
|
185
|
+
/**
|
|
186
|
+
* Clamp all values of a vector
|
|
187
|
+
* @param a Values to clamp
|
|
188
|
+
* @param min Minimum value (Default: 0)
|
|
189
|
+
* @param max Maximum value (Default: 1)
|
|
190
|
+
* @param target Target for storing the results (Default: a)
|
|
191
|
+
* @return Vector with clamped values
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* clamp([0, 1, 2, 3], 1, 2, new Array(4)); // Returns: [1, 1, 2, 2]
|
|
195
|
+
*/
|
|
196
|
+
export declare function clamp<T extends VectorLike>(a: T, min?: number, max?: number, target?: T): T;
|
|
197
|
+
/**
|
|
198
|
+
* GLSL step for all values of a vector
|
|
199
|
+
* @param edges Edges of the step function
|
|
200
|
+
* @param x Value used to generate the step function
|
|
201
|
+
* @param target Target for storing the results (Default: edges)
|
|
202
|
+
* @return results for each value in edges
|
|
203
|
+
*
|
|
204
|
+
* @example
|
|
205
|
+
* step([0, 1, 2, 3], 1.5, new Array(4)); // Returns: [1, 1, 0, 0]
|
|
206
|
+
*/
|
|
207
|
+
export declare function step<T extends VectorLike>(edges: T, x: number, target?: T): T;
|
|
208
|
+
/**
|
|
209
|
+
* Mix (interpolate) vectors (similar to glsl implementation).
|
|
210
|
+
* @param a Vector to interpolate from
|
|
211
|
+
* @param b Vector to interpolate to
|
|
212
|
+
* @param t Interpolation parameter, 0 = a and 1 = b
|
|
213
|
+
* @param target Target for storing the results (Default: a)
|
|
214
|
+
* @return The interpolated vector
|
|
215
|
+
*
|
|
216
|
+
* @example
|
|
217
|
+
* mix([1, 3], [3, 5], 0.5, new Array(2)); // Returns: [2, 4]
|
|
218
|
+
*/
|
|
219
|
+
export declare function mix<T extends VectorLike>(a: T, b: VectorLike, t: number, target?: T): T;
|
|
220
|
+
/**
|
|
221
|
+
* Modify each component of a vector with given function.
|
|
222
|
+
* @param a Vector to modify
|
|
223
|
+
* @param modifier Function used to modify component
|
|
224
|
+
* @param target Target for storing the results (Default: a)
|
|
225
|
+
* @return Vector with modified values
|
|
226
|
+
*
|
|
227
|
+
* @example
|
|
228
|
+
* modify([1.12, 1.55], Math.round, new Array(2)); // Returns: [1, 2]
|
|
229
|
+
*/
|
|
230
|
+
export declare function modify<T extends VectorLike>(a: T, modifier: (_arg0: number, _arg1: number) => number, target?: T): T;
|
|
231
|
+
/**
|
|
232
|
+
* Returns true if all elements of a vector is zero, otherwise returns false.
|
|
233
|
+
* @param a Target vector
|
|
234
|
+
* @param epsilon Accepted deviation from 0.00 (Default: 0)
|
|
235
|
+
* @returns Is target zero vector?
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* isZeroVector([0, 0.000023, 0], 0.001); // Returns: true
|
|
239
|
+
*/
|
|
240
|
+
export declare function isZeroVector(a: VectorLike, epsilon?: number): boolean;
|
|
241
|
+
/**
|
|
242
|
+
* Reverses the components of a vector with an performance of O(n/2).
|
|
243
|
+
* @param vector The vector to reverse
|
|
244
|
+
* @returns Reversed vector
|
|
245
|
+
*
|
|
246
|
+
* @example
|
|
247
|
+
* reverse([1, 2, 3]); // Returns: [3, 2, 1]
|
|
248
|
+
*/
|
|
249
|
+
export declare function reverse<T extends VectorLike>(vector: T): T;
|
|
250
|
+
/**
|
|
251
|
+
* Flatten a collection of vectors to a single array.
|
|
252
|
+
* @param vectors Array of vectors
|
|
253
|
+
* @return Single array with all values
|
|
254
|
+
*
|
|
255
|
+
* @example
|
|
256
|
+
* flatten([ [1, 2], [3, 4], [5, 6] ]); // Returns [1, 2, 3, 4, 5, 6]
|
|
257
|
+
*/
|
|
258
|
+
export declare function flatten(vectors: VectorLike[]): number[];
|
|
259
|
+
/**
|
|
260
|
+
* Reshapes an array of values to a collection of vectors with given dimensions.
|
|
261
|
+
* @param array Single array with all values
|
|
262
|
+
* @param dimensions Dimensions per vector
|
|
263
|
+
* @return Array of vectors with given dimensions
|
|
264
|
+
*
|
|
265
|
+
* @example
|
|
266
|
+
* reshape([1, 2, 3, 4, 5, 6], 3); // Returns [ [1, 2, 3], [4, 5, 6] ]
|
|
267
|
+
*/
|
|
268
|
+
export declare function reshape(array: number[], dimensions: number): number[][];
|
|
269
|
+
/**
|
|
270
|
+
* Determines if a point lies within a triangle in 2D space.
|
|
271
|
+
* Inspired by: https://stackoverflow.com/a/9755252/5946596
|
|
272
|
+
* @param {VectorLike} p - The point to check [x, y].
|
|
273
|
+
* @param {VectorLike} a - Vertex A of the triangle [x, y].
|
|
274
|
+
* @param {VectorLike} b - Vertex B of the triangle [x, y].
|
|
275
|
+
* @param {VectorLike} c - Vertex C of the triangle [x, y].
|
|
276
|
+
* @param {number} inwardAdjustment - Scales inward adjustment relative to distance for edge handling (default: 1e-6).
|
|
277
|
+
* @returns {boolean} True if the point is strictly inside the triangle; otherwise, false.
|
|
278
|
+
*
|
|
279
|
+
* @example
|
|
280
|
+
* isPointInTriangle([0.25, 0.25], [0, 0], [1, 0], [0, 1]); // Returns true
|
|
281
|
+
*/
|
|
282
|
+
export declare function isPointInTriangle(p: VectorLike, a: VectorLike, b: VectorLike, c: VectorLike, inwardAdjustment?: number): boolean;
|
|
283
|
+
/**
|
|
284
|
+
* Wrapper function for isPointInTriangle which allows an array of vectors.
|
|
285
|
+
* @returns {boolean} True if the point is strictly inside the triangle; otherwise, false.
|
|
286
|
+
*/
|
|
287
|
+
export declare function isPointInTriangleArray(p: VectorLike, triangle: [VectorLike, VectorLike, VectorLike], tolerance?: number): boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@equinor/videx-linear-algebra",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.12",
|
|
4
4
|
"description": "A library with linear algebra used by Videx.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.esm.js",
|
|
@@ -40,19 +40,19 @@
|
|
|
40
40
|
},
|
|
41
41
|
"homepage": "https://github.com/equinor/videx-linear-algebra#readme",
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@equinor/videx-vector2": "^1.0.
|
|
44
|
-
"@types/jest": "^29.5.14",
|
|
45
|
-
"copyfiles": "^2.2.0",
|
|
43
|
+
"@equinor/videx-vector2": "^1.0.46",
|
|
46
44
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
47
45
|
"@rollup/plugin-terser": "^0.4.4",
|
|
48
46
|
"@rollup/plugin-typescript": "^11.1.6",
|
|
49
|
-
"
|
|
50
|
-
"eslint": "^9.14.0",
|
|
51
|
-
"eslint-plugin-import": "^2.31.0",
|
|
47
|
+
"@types/jest": "^29.5.14",
|
|
52
48
|
"@typescript-eslint/eslint-plugin": "^8.13.0",
|
|
53
49
|
"@typescript-eslint/parser": "^8.13.0",
|
|
50
|
+
"copyfiles": "^2.2.0",
|
|
51
|
+
"eslint": "^9.32.0",
|
|
52
|
+
"eslint-plugin-import": "^2.31.0",
|
|
54
53
|
"jest": "^29.7.0",
|
|
55
54
|
"rimraf": "^3.0.1",
|
|
55
|
+
"rollup": "^3.29.5",
|
|
56
56
|
"ts-jest": "^29.1.0",
|
|
57
57
|
"typedoc": "^0.24.8",
|
|
58
58
|
"typescript": "^4.7.4"
|