@equinor/videx-linear-algebra 1.0.6 → 1.0.9
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 -21
- package/README.md +1 -40
- package/dist/index.d.ts +91 -43
- package/dist/index.esm.js +1 -1
- package/dist/index.js +1 -1
- package/dist/index.umd.js +1 -1
- package/package.json +14 -13
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2019 Equinor
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Equinor
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
[](https://scm-compliance-api.radix.equinor.com/repos/equinor/videx-linear-algebra/badge)
|
|
1
2
|
# Videx linear algebra
|
|
2
3
|
|
|
3
4
|
A library with linear algebra used by Videx. Functions are designed with performance in mind, where a target vector can be used to avoid creating new objects.
|
|
@@ -22,44 +23,4 @@ const add = someVar.add;
|
|
|
22
23
|
```
|
|
23
24
|
Where X.X.X is desired version number.
|
|
24
25
|
|
|
25
|
-
## Available functions
|
|
26
|
-
|
|
27
|
-
<table style="width:auto;">
|
|
28
|
-
<tr>
|
|
29
|
-
<td><a href="https://equinor.github.io/videx-linear-algebra/modules/_index_.html#add">add</a></td>
|
|
30
|
-
<td><a href="https://equinor.github.io/videx-linear-algebra/modules/_index_.html#addall">addAll</a></td>
|
|
31
|
-
<td><a href="https://equinor.github.io/videx-linear-algebra/modules/_index_.html#clamp">clamp</a></td>
|
|
32
|
-
<td><a href="https://equinor.github.io/videx-linear-algebra/modules/_index_.html#copy">copy</a></td>
|
|
33
|
-
</tr>
|
|
34
|
-
<tr>
|
|
35
|
-
<td><a href="https://equinor.github.io/videx-linear-algebra/modules/_index_.html#cross">cross</a></td>
|
|
36
|
-
<td><a href="https://equinor.github.io/videx-linear-algebra/modules/_index_.html#dir">dir</a></td>
|
|
37
|
-
<td><a href="https://equinor.github.io/videx-linear-algebra/modules/_index_.html#dist">dist</a></td>
|
|
38
|
-
<td><a href="https://equinor.github.io/videx-linear-algebra/modules/_index_.html#dot">dot</a></td>
|
|
39
|
-
</tr>
|
|
40
|
-
<tr>
|
|
41
|
-
<td><a href="https://equinor.github.io/videx-linear-algebra/modules/_index_.html#flatten">flatten</a></td>
|
|
42
|
-
<td><a href="https://equinor.github.io/videx-linear-algebra/modules/_index_.html#iszerovector">isZeroVector</a></td>
|
|
43
|
-
<td><a href="https://equinor.github.io/videx-linear-algebra/modules/_index_.html#magnitude">magnitude</a></td>
|
|
44
|
-
<td><a href="https://equinor.github.io/videx-linear-algebra/modules/_index_.html#mix">mix</a></td>
|
|
45
|
-
</tr>
|
|
46
|
-
<tr>
|
|
47
|
-
<td><a href="https://equinor.github.io/videx-linear-algebra/modules/_index_.html#normalize">normalize</a></td>
|
|
48
|
-
<td><a href="https://equinor.github.io/videx-linear-algebra/modules/_index_.html#reshape">reshape</a></td>
|
|
49
|
-
<td><a href="https://equinor.github.io/videx-linear-algebra/modules/_index_.html#round">round</a></td>
|
|
50
|
-
<td><a href="https://equinor.github.io/videx-linear-algebra/modules/_index_.html#scale">scale</a></td>
|
|
51
|
-
</tr>
|
|
52
|
-
<tr>
|
|
53
|
-
<td><a href="https://equinor.github.io/videx-linear-algebra/modules/_index_.html#step">step</a></td>
|
|
54
|
-
<td><a href="https://equinor.github.io/videx-linear-algebra/modules/_index_.html#sub">sub</a></td>
|
|
55
|
-
<td><a href="https://equinor.github.io/videx-linear-algebra/modules/_index_.html#suball">subAll</a></td>
|
|
56
|
-
<td><a href="https://equinor.github.io/videx-linear-algebra/modules/_index_.html#sumsqr">sumsqr</a></td>
|
|
57
|
-
</tr>
|
|
58
|
-
<tr>
|
|
59
|
-
<td><a href="https://equinor.github.io/videx-linear-algebra/modules/_index_.html#triple">triple</a></td>
|
|
60
|
-
</tr>
|
|
61
|
-
</table>
|
|
62
|
-
|
|
63
|
-
<br/>
|
|
64
|
-
|
|
65
26
|

|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
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
|
+
}
|
|
1
14
|
/**
|
|
2
15
|
* Copy the values of one vector to another without creating a new object.
|
|
3
16
|
* @param source Source vector
|
|
@@ -5,9 +18,9 @@
|
|
|
5
18
|
* @returns Target vector as a copy of source
|
|
6
19
|
*
|
|
7
20
|
* @example
|
|
8
|
-
* copy([3, 4], [2, 2]); // Returns [3, 4]
|
|
21
|
+
* copy([3, 4], [2, 2]); // Returns: [3, 4]
|
|
9
22
|
*/
|
|
10
|
-
export declare function copy(source:
|
|
23
|
+
export declare function copy<T extends VectorLike>(source: VectorLike, target: T): T;
|
|
11
24
|
/**
|
|
12
25
|
* a + b
|
|
13
26
|
*
|
|
@@ -19,9 +32,9 @@ export declare function copy(source: any, target: any): any;
|
|
|
19
32
|
* @return Resulting vector
|
|
20
33
|
*
|
|
21
34
|
* @example
|
|
22
|
-
* add([1, 2], [3, 4], new Array(2)); // Returns [4, 6]
|
|
35
|
+
* add([1, 2], [3, 4], new Array(2)); // Returns: [4, 6]
|
|
23
36
|
*/
|
|
24
|
-
export declare function add(a:
|
|
37
|
+
export declare function add<T extends VectorLike>(a: T, b: VectorLike, target?: T): T;
|
|
25
38
|
/**
|
|
26
39
|
* v1 + ... + vM
|
|
27
40
|
*
|
|
@@ -32,9 +45,9 @@ export declare function add(a: any, b: any, target?: any): any;
|
|
|
32
45
|
* @return Resulting vector
|
|
33
46
|
*
|
|
34
47
|
* @example
|
|
35
|
-
* addAll([ [1, 2], [3, 4], [5, 6] ], new Array(2)); // Returns [9, 12]
|
|
48
|
+
* addAll([ [1, 2], [3, 4], [5, 6] ], new Array(2)); // Returns: [9, 12]
|
|
36
49
|
*/
|
|
37
|
-
export declare function addAll(vectors:
|
|
50
|
+
export declare function addAll<T extends VectorLike>(vectors: T[], target?: T): T;
|
|
38
51
|
/**
|
|
39
52
|
* a - b
|
|
40
53
|
*
|
|
@@ -46,9 +59,9 @@ export declare function addAll(vectors: any[], target?: any): any;
|
|
|
46
59
|
* @return Resulting vector
|
|
47
60
|
*
|
|
48
61
|
* @example
|
|
49
|
-
* sub([4, 3], [2, 1], new Array(2)); // Returns [2, 2]
|
|
62
|
+
* sub([4, 3], [2, 1], new Array(2)); // Returns: [2, 2]
|
|
50
63
|
*/
|
|
51
|
-
export declare function sub(a:
|
|
64
|
+
export declare function sub<T extends VectorLike>(a: T, b: VectorLike, target?: T): T;
|
|
52
65
|
/**
|
|
53
66
|
* v1 - ... - vM
|
|
54
67
|
*
|
|
@@ -60,9 +73,9 @@ export declare function sub(a: any, b: any, target?: any): any;
|
|
|
60
73
|
* @return Resulting vector
|
|
61
74
|
*
|
|
62
75
|
* @example
|
|
63
|
-
* subAll([9, 9], [ [2, 3], [0, 2] ], new Array(2)); // Returns [7, 4]
|
|
76
|
+
* subAll([9, 9], [ [2, 3], [0, 2] ], new Array(2)); // Returns: [7, 4]
|
|
64
77
|
*/
|
|
65
|
-
export declare function subAll(a:
|
|
78
|
+
export declare function subAll<T extends VectorLike>(a: T, vectors: VectorLike[], target?: T): T;
|
|
66
79
|
/**
|
|
67
80
|
* Component-wise scaling of vector.
|
|
68
81
|
* @param a Vector to scale
|
|
@@ -71,27 +84,27 @@ export declare function subAll(a: any, vectors: any[], target?: any): any;
|
|
|
71
84
|
* @return Resulting vector
|
|
72
85
|
*
|
|
73
86
|
* @example
|
|
74
|
-
* scale([1, 2, 3], 2, new Array(3)); // Returns [2, 4, 6]
|
|
87
|
+
* scale([1, 2, 3], 2, new Array(3)); // Returns: [2, 4, 6]
|
|
75
88
|
*/
|
|
76
|
-
export declare function scale(a:
|
|
89
|
+
export declare function scale<T extends VectorLike>(a: T, factor: number, target?: T): T;
|
|
77
90
|
/**
|
|
78
91
|
* Computes the sum of squares
|
|
79
92
|
* @param a Target vector
|
|
80
93
|
* @return Sum of squares
|
|
81
94
|
*
|
|
82
95
|
* @example
|
|
83
|
-
* sumsqr([1, 2, 3]); // Returns 14
|
|
96
|
+
* sumsqr([1, 2, 3]); // Returns: 14
|
|
84
97
|
*/
|
|
85
|
-
export declare function sumsqr(a:
|
|
98
|
+
export declare function sumsqr(a: VectorLike): number;
|
|
86
99
|
/**
|
|
87
100
|
* Computes the magnitude of a vector.
|
|
88
101
|
* @param a Target vector
|
|
89
102
|
* @return Magnitude of vector
|
|
90
103
|
*
|
|
91
104
|
* @example
|
|
92
|
-
* magnitude([3, 4]); // Returns 5
|
|
105
|
+
* magnitude([3, 4]); // Returns: 5
|
|
93
106
|
*/
|
|
94
|
-
export declare function magnitude(a:
|
|
107
|
+
export declare function magnitude(a: VectorLike): number;
|
|
95
108
|
/**
|
|
96
109
|
* Normalizes a vector
|
|
97
110
|
* @param a Vector to normalize
|
|
@@ -99,9 +112,19 @@ export declare function magnitude(a: any): number;
|
|
|
99
112
|
* @return Normalized vector
|
|
100
113
|
*
|
|
101
114
|
* @example
|
|
102
|
-
* magnitude([0, 10, 0], new Array(3)); // Returns [0, 1, 0]
|
|
115
|
+
* magnitude([0, 10, 0], new Array(3)); // Returns: [0, 1, 0]
|
|
103
116
|
*/
|
|
104
|
-
export declare function normalize(a:
|
|
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;
|
|
105
128
|
/**
|
|
106
129
|
* Get the vector going from b to a.
|
|
107
130
|
* @param a Start coordinates
|
|
@@ -110,9 +133,9 @@ export declare function normalize(a: any, target?: any): any;
|
|
|
110
133
|
* @return Vector going from a to b
|
|
111
134
|
*
|
|
112
135
|
* @example
|
|
113
|
-
* dir([2, 1], [3, 0], new Array(2)); // Returns [1, -1]
|
|
136
|
+
* dir([2, 1], [3, 0], new Array(2)); // Returns: [1, -1]
|
|
114
137
|
*/
|
|
115
|
-
export declare function dir(a:
|
|
138
|
+
export declare function dir<T extends VectorLike>(a: T, b: VectorLike, target?: T): T;
|
|
116
139
|
/**
|
|
117
140
|
* Calculate the distance between two coordinates.
|
|
118
141
|
* @param a Start coordinates
|
|
@@ -120,9 +143,9 @@ export declare function dir(a: any, b: any, target?: any): any;
|
|
|
120
143
|
* @return Distance between coordinates
|
|
121
144
|
*
|
|
122
145
|
* @example
|
|
123
|
-
* dist([1, 2], [4, 6]); // Returns 5
|
|
146
|
+
* dist([1, 2], [4, 6]); // Returns: 5
|
|
124
147
|
*/
|
|
125
|
-
export declare function dist(a:
|
|
148
|
+
export declare function dist(a: VectorLike, b: VectorLike): number;
|
|
126
149
|
/**
|
|
127
150
|
* Calculate the dot product between two vectors.
|
|
128
151
|
* @param a Left operand
|
|
@@ -130,9 +153,9 @@ export declare function dist(a: any, b: any): number;
|
|
|
130
153
|
* @return Dot product
|
|
131
154
|
*
|
|
132
155
|
* @example
|
|
133
|
-
* dist([1, 2], [3, 4]); // Returns 11
|
|
156
|
+
* dist([1, 2], [3, 4]); // Returns: 11
|
|
134
157
|
*/
|
|
135
|
-
export declare function dot(a:
|
|
158
|
+
export declare function dot(a: VectorLike, b: VectorLike): number;
|
|
136
159
|
/**
|
|
137
160
|
* a × b
|
|
138
161
|
*
|
|
@@ -143,9 +166,9 @@ export declare function dot(a: any, b: any): number;
|
|
|
143
166
|
* @return Cross product of vectors
|
|
144
167
|
*
|
|
145
168
|
* @example
|
|
146
|
-
* cross([1, 0, 0], [0, 1, 0]); // Returns [0, 0, 1]
|
|
169
|
+
* cross([1, 0, 0], [0, 1, 0]); // Returns: [0, 0, 1]
|
|
147
170
|
*/
|
|
148
|
-
export declare function cross(a:
|
|
171
|
+
export declare function cross<T extends VectorLike>(a: T, b: VectorLike, target?: T): T;
|
|
149
172
|
/**
|
|
150
173
|
* a ∙ b × c
|
|
151
174
|
*
|
|
@@ -156,9 +179,9 @@ export declare function cross(a: any, b: any, target?: any): any;
|
|
|
156
179
|
* @return Triple product of vectors
|
|
157
180
|
*
|
|
158
181
|
* @example
|
|
159
|
-
* triple([1, 0, 0], [0, 1, 0], [0, 0, 1]); // Returns 1
|
|
182
|
+
* triple([1, 0, 0], [0, 1, 0], [0, 0, 1]); // Returns: 1
|
|
160
183
|
*/
|
|
161
|
-
export declare function triple(a:
|
|
184
|
+
export declare function triple(a: VectorLike, b: VectorLike, c: VectorLike): number;
|
|
162
185
|
/**
|
|
163
186
|
* Clamp all values of a vector
|
|
164
187
|
* @param a Values to clamp
|
|
@@ -168,9 +191,9 @@ export declare function triple(a: any, b: any, c: any): number;
|
|
|
168
191
|
* @return Vector with clamped values
|
|
169
192
|
*
|
|
170
193
|
* @example
|
|
171
|
-
* clamp([0, 1, 2, 3], 1, 2, new Array(4)); // Returns [1, 1, 2, 2]
|
|
194
|
+
* clamp([0, 1, 2, 3], 1, 2, new Array(4)); // Returns: [1, 1, 2, 2]
|
|
172
195
|
*/
|
|
173
|
-
export declare function clamp(a:
|
|
196
|
+
export declare function clamp<T extends VectorLike>(a: T, min?: number, max?: number, target?: T): T;
|
|
174
197
|
/**
|
|
175
198
|
* GLSL step for all values of a vector
|
|
176
199
|
* @param edges Edges of the step function
|
|
@@ -179,9 +202,9 @@ export declare function clamp(a: any, min?: number, max?: number, target?: any):
|
|
|
179
202
|
* @return results for each value in edges
|
|
180
203
|
*
|
|
181
204
|
* @example
|
|
182
|
-
* step([0, 1, 2, 3], 1.5, new Array(4)); // Returns [1, 1, 0, 0]
|
|
205
|
+
* step([0, 1, 2, 3], 1.5, new Array(4)); // Returns: [1, 1, 0, 0]
|
|
183
206
|
*/
|
|
184
|
-
export declare function step(edges:
|
|
207
|
+
export declare function step<T extends VectorLike>(edges: T, x: number, target?: T): T;
|
|
185
208
|
/**
|
|
186
209
|
* Mix (interpolate) vectors (similar to glsl implementation).
|
|
187
210
|
* @param a Vector to interpolate from
|
|
@@ -191,20 +214,20 @@ export declare function step(edges: any, x: number, target?: any): any;
|
|
|
191
214
|
* @return The interpolated vector
|
|
192
215
|
*
|
|
193
216
|
* @example
|
|
194
|
-
* mix([1, 3], [3, 5], 0.5, new Array(2)); // Returns [2, 4]
|
|
217
|
+
* mix([1, 3], [3, 5], 0.5, new Array(2)); // Returns: [2, 4]
|
|
195
218
|
*/
|
|
196
|
-
export declare function mix(a:
|
|
219
|
+
export declare function mix<T extends VectorLike>(a: T, b: VectorLike, t: number, target?: T): T;
|
|
197
220
|
/**
|
|
198
|
-
*
|
|
199
|
-
* @param a Vector to
|
|
200
|
-
* @param
|
|
221
|
+
* Modify each component of a vector with given function.
|
|
222
|
+
* @param a Vector to modify
|
|
223
|
+
* @param modifier Function used to modify component
|
|
201
224
|
* @param target Target for storing the results (Default: a)
|
|
202
|
-
* @return Vector with
|
|
225
|
+
* @return Vector with modified values
|
|
203
226
|
*
|
|
204
227
|
* @example
|
|
205
|
-
*
|
|
228
|
+
* modify([1.12, 1.55], Math.round, new Array(2)); // Returns: [1, 2]
|
|
206
229
|
*/
|
|
207
|
-
export declare function
|
|
230
|
+
export declare function modify<T extends VectorLike>(a: T, modifier: ((val: number, index: number) => number), target?: T): T;
|
|
208
231
|
/**
|
|
209
232
|
* Returns true if all elements of a vector is zero, otherwise returns false.
|
|
210
233
|
* @param a Target vector
|
|
@@ -212,9 +235,18 @@ export declare function round(a: any, digits?: number, target?: any): number;
|
|
|
212
235
|
* @returns Is target zero vector?
|
|
213
236
|
*
|
|
214
237
|
* @example
|
|
215
|
-
* isZeroVector([0, 0.000023, 0], 0.001); // Returns true
|
|
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]
|
|
216
248
|
*/
|
|
217
|
-
export declare function
|
|
249
|
+
export declare function reverse<T extends VectorLike>(vector: T): T;
|
|
218
250
|
/**
|
|
219
251
|
* Flatten a collection of vectors to a single array.
|
|
220
252
|
* @param vectors Array of vectors
|
|
@@ -223,7 +255,7 @@ export declare function isZeroVector(a: any, epsilon?: number): boolean;
|
|
|
223
255
|
* @example
|
|
224
256
|
* flatten([ [1, 2], [3, 4], [5, 6] ]); // Returns [1, 2, 3, 4, 5, 6]
|
|
225
257
|
*/
|
|
226
|
-
export declare function flatten(vectors:
|
|
258
|
+
export declare function flatten(vectors: VectorLike[]): number[];
|
|
227
259
|
/**
|
|
228
260
|
* Reshapes an array of values to a collection of vectors with given dimensions.
|
|
229
261
|
* @param array Single array with all values
|
|
@@ -234,3 +266,19 @@ export declare function flatten(vectors: number[][]): number[];
|
|
|
234
266
|
* reshape([1, 2, 3, 4, 5, 6], 3); // Returns [ [1, 2, 3], [4, 5, 6] ]
|
|
235
267
|
*/
|
|
236
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} tolerance - Precision tolerance for handling points near edges (default: 0.0001).
|
|
277
|
+
* @returns {boolean} True if the point is strictly inside the triangle; otherwise, false.
|
|
278
|
+
*/
|
|
279
|
+
export declare function isPointInTriangle(p: VectorLike, a: VectorLike, b: VectorLike, c: VectorLike, tolerance?: number): boolean;
|
|
280
|
+
/**
|
|
281
|
+
* Wrapper function for isPointInTriangle which allows an array of vectors.
|
|
282
|
+
* @returns {boolean} True if the point is strictly inside the triangle; otherwise, false.
|
|
283
|
+
*/
|
|
284
|
+
export declare function isPointInTriangleArray(p: VectorLike, triangle: [VectorLike, VectorLike, VectorLike], tolerance?: number): boolean;
|
package/dist/index.esm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{clamp as clamp$1,step as step$1}from"@equinor/videx-math";function copy(source,target){for(var i=0;i<source.length;i++)target[i]=source[i];return target}function add(a,b,target){void 0===target&&(target=a);for(var i=0;i<a.length;i++)target[i]=a[i]+b[i];return target}function addAll(vectors,target){void 0===target&&(target=vectors[0]),copy(vectors[0],target);for(var m=1;m<vectors.length;m++)for(var n=0;n<target.length;n++)target[n]+=vectors[m][n];return target}function sub(a,b,target){void 0===target&&(target=a);for(var i=0;i<a.length;i++)target[i]=a[i]-b[i];return target}function subAll(a,vectors,target){void 0===target&&(target=a),copy(a,target);for(var m=0;m<vectors.length;m++)for(var n=0;n<target.length;n++)target[n]-=vectors[m][n];return target}function scale(a,factor,target){void 0===target&&(target=a);for(var i=0;i<a.length;i++)target[i]=a[i]*factor;return target}function sumsqr(a){for(var sum=0,i=0;i<a.length;i++)sum+=Math.pow(a[i],2);return sum}function magnitude(a){var sq=sumsqr(a);return 0===sq?sq:Math.sqrt(sq)}function normalize(a,target){void 0===target&&(target=a);var len=magnitude(a);return
|
|
1
|
+
import{clamp as clamp$1,step as step$1}from"@equinor/videx-math";function copy(source,target){for(var i=0;i<source.length;i++)target[i]=source[i];return target}function add(a,b,target){void 0===target&&(target=a);for(var i=0;i<a.length;i++)target[i]=a[i]+b[i];return target}function addAll(vectors,target){void 0===target&&(target=vectors[0]),copy(vectors[0],target);for(var m=1;m<vectors.length;m++)for(var n=0;n<target.length;n++)target[n]+=vectors[m][n];return target}function sub(a,b,target){void 0===target&&(target=a);for(var i=0;i<a.length;i++)target[i]=a[i]-b[i];return target}function subAll(a,vectors,target){void 0===target&&(target=a),copy(a,target);for(var m=0;m<vectors.length;m++)for(var n=0;n<target.length;n++)target[n]-=vectors[m][n];return target}function scale(a,factor,target){void 0===target&&(target=a);for(var i=0;i<a.length;i++)target[i]=a[i]*factor;return target}function sumsqr(a){for(var sum=0,i=0;i<a.length;i++)sum+=Math.pow(a[i],2);return sum}function magnitude(a){var sq=sumsqr(a);return 0===sq?sq:Math.sqrt(sq)}function normalize(a,target){void 0===target&&(target=a);var len=magnitude(a);return 0===len?fill(0,target):scale(a,1/len,target)}function fill(value,target){for(var i=0;i<target.length;i++)target[i]=value;return target}function dir(a,b,target){void 0===target&&(target=a);for(var i=0;i<a.length;i++)target[i]=b[i]-a[i];return target}function dist(a,b){for(var sq=0,i=0;i<a.length;i++)sq+=Math.pow(b[i]-a[i],2);return 0===sq?sq:Math.sqrt(sq)}function dot(a,b){for(var sum=0,i=0;i<a.length;i++)sum+=a[i]*b[i];return sum}function cross(a,b,target){void 0===target&&(target=a);var y=a[2]*b[0]-a[0]*b[2],z=a[0]*b[1]-a[1]*b[0];return target[0]=a[1]*b[2]-a[2]*b[1],target[1]=y,target[2]=z,target}function triple(a,b,c){return dot(a,cross(b,c))}function clamp(a,min,max,target){void 0===min&&(min=0),void 0===max&&(max=1),void 0===target&&(target=a);for(var i=0;i<a.length;i++)target[i]=clamp$1(a[i],min,max);return target}function step(edges,x,target){void 0===target&&(target=edges);for(var i=0;i<edges.length;i++)target[i]=step$1(edges[i],x);return target}function mix(a,b,t,target){void 0===target&&(target=a);for(var n=clamp$1(t,0,1),m=1-n,i=0;i<a.length;i++)target[i]=a[i]*m+b[i]*n;return target}function modify(a,modifier,target){void 0===target&&(target=a);for(var i=0;i<a.length;i++)target[i]=modifier(a[i],i);return target}function isZeroVector(a,epsilon){void 0===epsilon&&(epsilon=0),void 0===epsilon&&(epsilon=0);for(var i=0;i<a.length;i++)if(Math.abs(a[i])>epsilon)return!1;return!0}function reverse(vector){for(var temp,tempIdx,end=vector.length-1,i=0;i<Math.ceil(end/2);i++)temp=vector[tempIdx=end-i],vector[tempIdx]=vector[i],vector[i]=temp;return vector}function flatten(vectors){for(var output=[],m=0;m<vectors.length;m++)for(var n=0;n<vectors[m].length;n++)output.push(vectors[m][n]);return output}function reshape(array,dimensions){for(var output=[],i=0;i<array.length;i+=dimensions){for(var vector=new Array(dimensions),n=0;n<dimensions;n++)vector[n]=array[i+n];output.push(vector)}return output}function isPointInTriangle(p,a,b,c,tolerance){void 0===tolerance&&(tolerance=1e-4);var APx=p[0]-a[0],APy=p[1]-a[1],crossAB=(b[0]-a[0])*APy-(b[1]-a[1])*APx,signAB_AC=crossAB*((c[0]-a[0])*APy-(c[1]-a[1])*APx);if(Math.abs(signAB_AC)<tolerance||signAB_AC>0)return!1;var signAB_BC=crossAB*((c[0]-b[0])*(p[1]-b[1])-(c[1]-b[1])*(p[0]-b[0]));return!(Math.abs(signAB_BC)<tolerance||signAB_BC<0)}function isPointInTriangleArray(p,triangle,tolerance){return void 0===tolerance&&(tolerance=1e-4),isPointInTriangle(p,triangle[0],triangle[1],triangle[2],tolerance)}export{add,addAll,clamp,copy,cross,dir,dist,dot,fill,flatten,isPointInTriangle,isPointInTriangleArray,isZeroVector,magnitude,mix,modify,normalize,reshape,reverse,scale,step,sub,subAll,sumsqr,triple};
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var videxMath=require("@equinor/videx-math");function copy(source,target){for(var i=0;i<source.length;i++)target[i]=source[i];return target}function
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var videxMath=require("@equinor/videx-math");function copy(source,target){for(var i=0;i<source.length;i++)target[i]=source[i];return target}function scale(a,factor,target){void 0===target&&(target=a);for(var i=0;i<a.length;i++)target[i]=a[i]*factor;return target}function sumsqr(a){for(var sum=0,i=0;i<a.length;i++)sum+=Math.pow(a[i],2);return sum}function magnitude(a){var sq=sumsqr(a);return 0===sq?sq:Math.sqrt(sq)}function fill(value,target){for(var i=0;i<target.length;i++)target[i]=value;return target}function dot(a,b){for(var sum=0,i=0;i<a.length;i++)sum+=a[i]*b[i];return sum}function cross(a,b,target){void 0===target&&(target=a);var y=a[2]*b[0]-a[0]*b[2],z=a[0]*b[1]-a[1]*b[0];return target[0]=a[1]*b[2]-a[2]*b[1],target[1]=y,target[2]=z,target}function isPointInTriangle(p,a,b,c,tolerance){void 0===tolerance&&(tolerance=1e-4);var APx=p[0]-a[0],APy=p[1]-a[1],crossAB=(b[0]-a[0])*APy-(b[1]-a[1])*APx,signAB_AC=crossAB*((c[0]-a[0])*APy-(c[1]-a[1])*APx);if(Math.abs(signAB_AC)<tolerance||signAB_AC>0)return!1;var signAB_BC=crossAB*((c[0]-b[0])*(p[1]-b[1])-(c[1]-b[1])*(p[0]-b[0]));return!(Math.abs(signAB_BC)<tolerance||signAB_BC<0)}exports.add=function(a,b,target){void 0===target&&(target=a);for(var i=0;i<a.length;i++)target[i]=a[i]+b[i];return target},exports.addAll=function(vectors,target){void 0===target&&(target=vectors[0]),copy(vectors[0],target);for(var m=1;m<vectors.length;m++)for(var n=0;n<target.length;n++)target[n]+=vectors[m][n];return target},exports.clamp=function(a,min,max,target){void 0===min&&(min=0),void 0===max&&(max=1),void 0===target&&(target=a);for(var i=0;i<a.length;i++)target[i]=videxMath.clamp(a[i],min,max);return target},exports.copy=copy,exports.cross=cross,exports.dir=function(a,b,target){void 0===target&&(target=a);for(var i=0;i<a.length;i++)target[i]=b[i]-a[i];return target},exports.dist=function(a,b){for(var sq=0,i=0;i<a.length;i++)sq+=Math.pow(b[i]-a[i],2);return 0===sq?sq:Math.sqrt(sq)},exports.dot=dot,exports.fill=fill,exports.flatten=function(vectors){for(var output=[],m=0;m<vectors.length;m++)for(var n=0;n<vectors[m].length;n++)output.push(vectors[m][n]);return output},exports.isPointInTriangle=isPointInTriangle,exports.isPointInTriangleArray=function(p,triangle,tolerance){return void 0===tolerance&&(tolerance=1e-4),isPointInTriangle(p,triangle[0],triangle[1],triangle[2],tolerance)},exports.isZeroVector=function(a,epsilon){void 0===epsilon&&(epsilon=0),void 0===epsilon&&(epsilon=0);for(var i=0;i<a.length;i++)if(Math.abs(a[i])>epsilon)return!1;return!0},exports.magnitude=magnitude,exports.mix=function(a,b,t,target){void 0===target&&(target=a);for(var n=videxMath.clamp(t,0,1),m=1-n,i=0;i<a.length;i++)target[i]=a[i]*m+b[i]*n;return target},exports.modify=function(a,modifier,target){void 0===target&&(target=a);for(var i=0;i<a.length;i++)target[i]=modifier(a[i],i);return target},exports.normalize=function(a,target){void 0===target&&(target=a);var len=magnitude(a);return 0===len?fill(0,target):scale(a,1/len,target)},exports.reshape=function(array,dimensions){for(var output=[],i=0;i<array.length;i+=dimensions){for(var vector=new Array(dimensions),n=0;n<dimensions;n++)vector[n]=array[i+n];output.push(vector)}return output},exports.reverse=function(vector){for(var temp,tempIdx,end=vector.length-1,i=0;i<Math.ceil(end/2);i++)temp=vector[tempIdx=end-i],vector[tempIdx]=vector[i],vector[i]=temp;return vector},exports.scale=scale,exports.step=function(edges,x,target){void 0===target&&(target=edges);for(var i=0;i<edges.length;i++)target[i]=videxMath.step(edges[i],x);return target},exports.sub=function(a,b,target){void 0===target&&(target=a);for(var i=0;i<a.length;i++)target[i]=a[i]-b[i];return target},exports.subAll=function(a,vectors,target){void 0===target&&(target=a),copy(a,target);for(var m=0;m<vectors.length;m++)for(var n=0;n<target.length;n++)target[n]-=vectors[m][n];return target},exports.sumsqr=sumsqr,exports.triple=function(a,b,c){return dot(a,cross(b,c))};
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(global,factory){"object"==typeof exports&&"undefined"!=typeof module?factory(exports):"function"==typeof define&&define.amd?define(["exports"],factory):factory((global=global||self).Vector2={})}(this,(function(exports){"use strict";function clamp(value,min
|
|
1
|
+
!function(global,factory){"object"==typeof exports&&"undefined"!=typeof module?factory(exports):"function"==typeof define&&define.amd?define(["exports"],factory):factory((global=global||self).Vector2={})}(this,(function(exports){"use strict";function clamp(value,min=0,max=1){return value<min?min:value>max?max:value}function step(edge,x){return x>=edge?1:0}function copy(source,target){for(var i=0;i<source.length;i++)target[i]=source[i];return target}function scale(a,factor,target){void 0===target&&(target=a);for(var i=0;i<a.length;i++)target[i]=a[i]*factor;return target}function sumsqr(a){for(var sum=0,i=0;i<a.length;i++)sum+=Math.pow(a[i],2);return sum}function magnitude(a){var sq=sumsqr(a);return 0===sq?sq:Math.sqrt(sq)}function fill(value,target){for(var i=0;i<target.length;i++)target[i]=value;return target}function dot(a,b){for(var sum=0,i=0;i<a.length;i++)sum+=a[i]*b[i];return sum}function cross(a,b,target){void 0===target&&(target=a);var y=a[2]*b[0]-a[0]*b[2],z=a[0]*b[1]-a[1]*b[0];return target[0]=a[1]*b[2]-a[2]*b[1],target[1]=y,target[2]=z,target}function isPointInTriangle(p,a,b,c,tolerance){void 0===tolerance&&(tolerance=1e-4);var APx=p[0]-a[0],APy=p[1]-a[1],crossAB=(b[0]-a[0])*APy-(b[1]-a[1])*APx,signAB_AC=crossAB*((c[0]-a[0])*APy-(c[1]-a[1])*APx);if(Math.abs(signAB_AC)<tolerance||signAB_AC>0)return!1;var signAB_BC=crossAB*((c[0]-b[0])*(p[1]-b[1])-(c[1]-b[1])*(p[0]-b[0]));return!(Math.abs(signAB_BC)<tolerance||signAB_BC<0)}exports.add=function(a,b,target){void 0===target&&(target=a);for(var i=0;i<a.length;i++)target[i]=a[i]+b[i];return target},exports.addAll=function(vectors,target){void 0===target&&(target=vectors[0]),copy(vectors[0],target);for(var m=1;m<vectors.length;m++)for(var n=0;n<target.length;n++)target[n]+=vectors[m][n];return target},exports.clamp=function(a,min,max,target){void 0===min&&(min=0),void 0===max&&(max=1),void 0===target&&(target=a);for(var i=0;i<a.length;i++)target[i]=clamp(a[i],min,max);return target},exports.copy=copy,exports.cross=cross,exports.dir=function(a,b,target){void 0===target&&(target=a);for(var i=0;i<a.length;i++)target[i]=b[i]-a[i];return target},exports.dist=function(a,b){for(var sq=0,i=0;i<a.length;i++)sq+=Math.pow(b[i]-a[i],2);return 0===sq?sq:Math.sqrt(sq)},exports.dot=dot,exports.fill=fill,exports.flatten=function(vectors){for(var output=[],m=0;m<vectors.length;m++)for(var n=0;n<vectors[m].length;n++)output.push(vectors[m][n]);return output},exports.isPointInTriangle=isPointInTriangle,exports.isPointInTriangleArray=function(p,triangle,tolerance){return void 0===tolerance&&(tolerance=1e-4),isPointInTriangle(p,triangle[0],triangle[1],triangle[2],tolerance)},exports.isZeroVector=function(a,epsilon){void 0===epsilon&&(epsilon=0),void 0===epsilon&&(epsilon=0);for(var i=0;i<a.length;i++)if(Math.abs(a[i])>epsilon)return!1;return!0},exports.magnitude=magnitude,exports.mix=function(a,b,t,target){void 0===target&&(target=a);for(var n=clamp(t,0,1),m=1-n,i=0;i<a.length;i++)target[i]=a[i]*m+b[i]*n;return target},exports.modify=function(a,modifier,target){void 0===target&&(target=a);for(var i=0;i<a.length;i++)target[i]=modifier(a[i],i);return target},exports.normalize=function(a,target){void 0===target&&(target=a);var len=magnitude(a);return 0===len?fill(0,target):scale(a,1/len,target)},exports.reshape=function(array,dimensions){for(var output=[],i=0;i<array.length;i+=dimensions){for(var vector=new Array(dimensions),n=0;n<dimensions;n++)vector[n]=array[i+n];output.push(vector)}return output},exports.reverse=function(vector){for(var temp,tempIdx,end=vector.length-1,i=0;i<Math.ceil(end/2);i++)temp=vector[tempIdx=end-i],vector[tempIdx]=vector[i],vector[i]=temp;return vector},exports.scale=scale,exports.step=function(edges,x,target){void 0===target&&(target=edges);for(var i=0;i<edges.length;i++)target[i]=step(edges[i],x);return target},exports.sub=function(a,b,target){void 0===target&&(target=a);for(var i=0;i<a.length;i++)target[i]=a[i]-b[i];return target},exports.subAll=function(a,vectors,target){void 0===target&&(target=a),copy(a,target);for(var m=0;m<vectors.length;m++)for(var n=0;n<target.length;n++)target[n]-=vectors[m][n];return target},exports.sumsqr=sumsqr,exports.triple=function(a,b,c){return dot(a,cross(b,c))},Object.defineProperty(exports,"__esModule",{value:!0})}));
|
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.9",
|
|
4
4
|
"description": "A library with linear algebra used by Videx.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.esm.js",
|
|
@@ -39,20 +39,21 @@
|
|
|
39
39
|
},
|
|
40
40
|
"homepage": "https://github.com/equinor/videx-linear-algebra#readme",
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@
|
|
43
|
-
"
|
|
44
|
-
"
|
|
42
|
+
"@equinor/videx-vector2": "^1.0.40",
|
|
43
|
+
"@types/jest": "^25.1.1",
|
|
44
|
+
"copyfiles": "^2.2.0",
|
|
45
|
+
"eslint": "^6.8.0",
|
|
45
46
|
"eslint-config-airbnb-base": "^14.0.0",
|
|
46
|
-
"eslint-plugin-import": "^2.
|
|
47
|
-
"jest": "^
|
|
48
|
-
"rimraf": "^3.0.
|
|
49
|
-
"rollup": "^1.
|
|
47
|
+
"eslint-plugin-import": "^2.20.1",
|
|
48
|
+
"jest": "^29.5.0",
|
|
49
|
+
"rimraf": "^3.0.1",
|
|
50
|
+
"rollup": "^1.31.0",
|
|
50
51
|
"rollup-plugin-node-resolve": "^5.2.0",
|
|
51
|
-
"rollup-plugin-terser": "^5.
|
|
52
|
-
"rollup-plugin-typescript2": "^0.
|
|
53
|
-
"ts-jest": "^
|
|
54
|
-
"typedoc": "^0.
|
|
55
|
-
"typescript": "^
|
|
52
|
+
"rollup-plugin-terser": "^5.2.0",
|
|
53
|
+
"rollup-plugin-typescript2": "^0.34.1",
|
|
54
|
+
"ts-jest": "^29.1.0",
|
|
55
|
+
"typedoc": "^0.24.8",
|
|
56
|
+
"typescript": "^4.7.4"
|
|
56
57
|
},
|
|
57
58
|
"dependencies": {
|
|
58
59
|
"@equinor/videx-math": "^1.0.12"
|