@pawells/math-extended 1.1.1 → 2.0.0
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/build/angles.d.ts +28 -18
- package/build/angles.d.ts.map +1 -1
- package/build/angles.js +28 -18
- package/build/angles.js.map +1 -1
- package/build/clamp.d.ts +5 -3
- package/build/clamp.d.ts.map +1 -1
- package/build/clamp.js +5 -3
- package/build/clamp.js.map +1 -1
- package/build/interpolation.d.ts +158 -96
- package/build/interpolation.d.ts.map +1 -1
- package/build/interpolation.js +158 -96
- package/build/interpolation.js.map +1 -1
- package/build/matrices/_exports.d.ts +13 -0
- package/build/matrices/_exports.d.ts.map +1 -0
- package/build/matrices/_exports.js +13 -0
- package/build/matrices/_exports.js.map +1 -0
- package/build/matrices/arithmetic.d.ts +170 -181
- package/build/matrices/arithmetic.d.ts.map +1 -1
- package/build/matrices/arithmetic.js +192 -202
- package/build/matrices/arithmetic.js.map +1 -1
- package/build/matrices/asserts.d.ts +240 -109
- package/build/matrices/asserts.d.ts.map +1 -1
- package/build/matrices/asserts.js +287 -87
- package/build/matrices/asserts.js.map +1 -1
- package/build/matrices/core.d.ts +29 -29
- package/build/matrices/core.js +1 -1
- package/build/matrices/decompositions.d.ts +102 -104
- package/build/matrices/decompositions.d.ts.map +1 -1
- package/build/matrices/decompositions.js +87 -89
- package/build/matrices/decompositions.js.map +1 -1
- package/build/matrices/index.d.ts +3 -2
- package/build/matrices/index.d.ts.map +1 -1
- package/build/matrices/index.js +5 -2
- package/build/matrices/index.js.map +1 -1
- package/build/matrices/linear-algebra.d.ts +12 -12
- package/build/matrices/linear-algebra.js +4 -4
- package/build/matrices/normalization.d.ts +8 -8
- package/build/matrices/transformations.d.ts +184 -165
- package/build/matrices/transformations.d.ts.map +1 -1
- package/build/matrices/transformations.js +99 -80
- package/build/matrices/transformations.js.map +1 -1
- package/build/matrices/types.d.ts +12 -12
- package/build/matrices/types.d.ts.map +1 -1
- package/build/quaternions/_exports.d.ts +11 -0
- package/build/quaternions/_exports.d.ts.map +1 -0
- package/build/quaternions/_exports.js +11 -0
- package/build/quaternions/_exports.js.map +1 -0
- package/build/quaternions/asserts.d.ts +115 -7
- package/build/quaternions/asserts.d.ts.map +1 -1
- package/build/quaternions/asserts.js +162 -8
- package/build/quaternions/asserts.js.map +1 -1
- package/build/quaternions/conversions.d.ts +31 -21
- package/build/quaternions/conversions.d.ts.map +1 -1
- package/build/quaternions/conversions.js +28 -18
- package/build/quaternions/conversions.js.map +1 -1
- package/build/quaternions/core.d.ts +67 -39
- package/build/quaternions/core.d.ts.map +1 -1
- package/build/quaternions/core.js +67 -39
- package/build/quaternions/core.js.map +1 -1
- package/build/quaternions/index.d.ts +3 -2
- package/build/quaternions/index.d.ts.map +1 -1
- package/build/quaternions/index.js +5 -2
- package/build/quaternions/index.js.map +1 -1
- package/build/quaternions/interpolation.d.ts +15 -9
- package/build/quaternions/interpolation.d.ts.map +1 -1
- package/build/quaternions/interpolation.js +15 -9
- package/build/quaternions/interpolation.js.map +1 -1
- package/build/quaternions/predefined.d.ts +9 -3
- package/build/quaternions/predefined.d.ts.map +1 -1
- package/build/quaternions/predefined.js +9 -3
- package/build/quaternions/predefined.js.map +1 -1
- package/build/quaternions/types.d.ts +3 -3
- package/build/vectors/_exports.d.ts +10 -0
- package/build/vectors/_exports.d.ts.map +1 -0
- package/build/vectors/_exports.js +10 -0
- package/build/vectors/_exports.js.map +1 -0
- package/build/vectors/asserts.d.ts +153 -49
- package/build/vectors/asserts.d.ts.map +1 -1
- package/build/vectors/asserts.js +202 -52
- package/build/vectors/asserts.js.map +1 -1
- package/build/vectors/core.d.ts +216 -137
- package/build/vectors/core.d.ts.map +1 -1
- package/build/vectors/core.js +212 -149
- package/build/vectors/core.js.map +1 -1
- package/build/vectors/index.d.ts +1 -0
- package/build/vectors/index.d.ts.map +1 -1
- package/build/vectors/index.js +3 -0
- package/build/vectors/index.js.map +1 -1
- package/build/vectors/interpolation.d.ts +39 -27
- package/build/vectors/interpolation.d.ts.map +1 -1
- package/build/vectors/interpolation.js +39 -27
- package/build/vectors/interpolation.js.map +1 -1
- package/build/vectors/predefined.d.ts +48 -24
- package/build/vectors/predefined.d.ts.map +1 -1
- package/build/vectors/predefined.js +38 -18
- package/build/vectors/predefined.js.map +1 -1
- package/package.json +3 -3
package/build/vectors/core.d.ts
CHANGED
|
@@ -12,9 +12,11 @@ import { TAnyVector, TVectorResult, TVector, TVector2, TVector3 } from './types.
|
|
|
12
12
|
* @returns A new vector with identical components
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const original = [1, 2, 3];
|
|
17
|
+
* const copy = VectorClone(original);
|
|
18
|
+
* copy[0] = 10; // original remains unchanged
|
|
19
|
+
* ```
|
|
18
20
|
*/
|
|
19
21
|
export declare function VectorClone<T extends TAnyVector>(vector: T): TVectorResult<T>;
|
|
20
22
|
/**
|
|
@@ -28,10 +30,12 @@ export declare function VectorClone<T extends TAnyVector>(vector: T): TVectorRes
|
|
|
28
30
|
* @returns True if vectors are equal within tolerance, false otherwise
|
|
29
31
|
*
|
|
30
32
|
* @example
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
* ```typescript
|
|
34
|
+
* const a = [1.0001, 2.0001];
|
|
35
|
+
* const b = [1.0002, 2.0002];
|
|
36
|
+
* const exactlyEqual = VectorEquals(a, b); // false
|
|
37
|
+
* const approximatelyEqual = VectorEquals(a, b, 0.001); // true
|
|
38
|
+
* ```
|
|
35
39
|
*/
|
|
36
40
|
export declare function VectorEquals<T extends TAnyVector>(a: T, b: T, tolerance?: number): boolean;
|
|
37
41
|
/**
|
|
@@ -43,9 +47,11 @@ export declare function VectorEquals<T extends TAnyVector>(a: T, b: T, tolerance
|
|
|
43
47
|
* @returns String representation of the vector
|
|
44
48
|
*
|
|
45
49
|
* @example
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
50
|
+
* ```typescript
|
|
51
|
+
* const vec = [1, 2, 3];
|
|
52
|
+
* const parens = VectorToString(vec, 'parens'); // "(1, 2, 3)"
|
|
53
|
+
* const brackets = VectorToString(vec, 'brackets'); // "[1, 2, 3]"
|
|
54
|
+
* ```
|
|
49
55
|
*/
|
|
50
56
|
export declare function VectorToString(vector: TVector, style?: 'parens' | 'brackets'): string;
|
|
51
57
|
/**
|
|
@@ -58,9 +64,11 @@ export declare function VectorToString(vector: TVector, style?: 'parens' | 'brac
|
|
|
58
64
|
* @returns New vector where each component is the sum of corresponding components
|
|
59
65
|
*
|
|
60
66
|
* @example
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
67
|
+
* ```typescript
|
|
68
|
+
* const position = [10, 20, 30];
|
|
69
|
+
* const velocity = [1, -2, 0.5];
|
|
70
|
+
* const newPosition = VectorAdd(position, velocity); // [11, 18, 30.5]
|
|
71
|
+
* ```
|
|
64
72
|
*/
|
|
65
73
|
export declare function VectorAdd<T extends TAnyVector>(a: T, b: T): TVectorResult<T>;
|
|
66
74
|
/**
|
|
@@ -73,9 +81,11 @@ export declare function VectorAdd<T extends TAnyVector>(a: T, b: T): TVectorResu
|
|
|
73
81
|
* @returns New vector where each component is the difference of corresponding components
|
|
74
82
|
*
|
|
75
83
|
* @example
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
84
|
+
* ```typescript
|
|
85
|
+
* const target = [100, 50, 0];
|
|
86
|
+
* const current = [80, 30, 0];
|
|
87
|
+
* const direction = VectorSubtract(target, current); // [20, 20, 0]
|
|
88
|
+
* ```
|
|
79
89
|
*/
|
|
80
90
|
export declare function VectorSubtract<T extends TAnyVector>(a: T, b: T): TVectorResult<T>;
|
|
81
91
|
/**
|
|
@@ -88,10 +98,12 @@ export declare function VectorSubtract<T extends TAnyVector>(a: T, b: T): TVecto
|
|
|
88
98
|
* @returns New vector with multiplied components
|
|
89
99
|
*
|
|
90
100
|
* @example
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
101
|
+
* ```typescript
|
|
102
|
+
* const velocity = [10, 5, 0];
|
|
103
|
+
* const scaled = VectorMultiply(velocity, 2); // [20, 10, 0] - scalar multiplication
|
|
104
|
+
* const factors = [1, -1, 0.5];
|
|
105
|
+
* const componentWise = VectorMultiply(velocity, factors); // [10, -5, 0] - component-wise
|
|
106
|
+
* ```
|
|
95
107
|
*/
|
|
96
108
|
export declare function VectorMultiply<T extends TAnyVector>(a: T, b: T | number): TVectorResult<T>;
|
|
97
109
|
/**
|
|
@@ -103,9 +115,11 @@ export declare function VectorMultiply<T extends TAnyVector>(a: T, b: T | number
|
|
|
103
115
|
* @returns The straight-line distance between the two points represented by the vectors
|
|
104
116
|
*
|
|
105
117
|
* @example
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
118
|
+
* ```typescript
|
|
119
|
+
* const pointA = [0, 0, 0];
|
|
120
|
+
* const pointB = [3, 4, 0];
|
|
121
|
+
* const distance = VectorDistance(pointA, pointB); // 5.0 (3-4-5 triangle)
|
|
122
|
+
* ```
|
|
109
123
|
*/
|
|
110
124
|
export declare function VectorDistance(a: TVector, b: TVector): number;
|
|
111
125
|
/**
|
|
@@ -118,9 +132,11 @@ export declare function VectorDistance(a: TVector, b: TVector): number;
|
|
|
118
132
|
* @returns The squared distance between vectors
|
|
119
133
|
*
|
|
120
134
|
* @example
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
135
|
+
* ```typescript
|
|
136
|
+
* const pointA = [1, 1];
|
|
137
|
+
* const pointB = [4, 5];
|
|
138
|
+
* const distSq = VectorDistanceSquared(pointA, pointB); // 25 (faster than distance comparison)
|
|
139
|
+
* ```
|
|
124
140
|
*/
|
|
125
141
|
export declare function VectorDistanceSquared(a: TVector, b: TVector): number;
|
|
126
142
|
/**
|
|
@@ -133,12 +149,13 @@ export declare function VectorDistanceSquared(a: TVector, b: TVector): number;
|
|
|
133
149
|
* @returns The dot product (scalar value)
|
|
134
150
|
*
|
|
135
151
|
* @example
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
152
|
+
* ```typescript
|
|
153
|
+
* const forward = [0, 0, 1];
|
|
154
|
+
* const direction = [0, 0, 2];
|
|
155
|
+
* const dot = VectorDot(forward, direction); // 2 (same direction)
|
|
156
|
+
* const perpendicular = [1, 0, 0];
|
|
157
|
+
* const dotPerp = VectorDot(forward, perpendicular); // 0 (perpendicular)
|
|
158
|
+
* ```
|
|
142
159
|
*/
|
|
143
160
|
export declare function VectorDot(a: TVector, b: TVector): number;
|
|
144
161
|
/**
|
|
@@ -152,11 +169,12 @@ export declare function VectorDot(a: TVector, b: TVector): number;
|
|
|
152
169
|
* @throws {VectorError} If the vector is zero or has infinite magnitude
|
|
153
170
|
*
|
|
154
171
|
* @example
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
172
|
+
* ```typescript
|
|
173
|
+
* const vector = [3, 4, 0];
|
|
174
|
+
* const normalized = VectorNormalize(vector); // [0.6, 0.8, 0] (magnitude = 1)
|
|
175
|
+
* const direction = [10, 0, 0];
|
|
176
|
+
* const unitDirection = VectorNormalize(direction); // [1, 0, 0]
|
|
177
|
+
* ```
|
|
160
178
|
*/
|
|
161
179
|
export declare function VectorNormalize<T extends TAnyVector>(a: T): TVectorResult<T>;
|
|
162
180
|
/**
|
|
@@ -167,11 +185,12 @@ export declare function VectorNormalize<T extends TAnyVector>(a: T): TVectorResu
|
|
|
167
185
|
* @returns The magnitude (length) of the vector
|
|
168
186
|
*
|
|
169
187
|
* @example
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
188
|
+
* ```typescript
|
|
189
|
+
* const velocity = [3, 4, 0];
|
|
190
|
+
* const speed = VectorMagnitude(velocity); // 5.0
|
|
191
|
+
* const unitVector = [1, 0, 0];
|
|
192
|
+
* const unitLength = VectorMagnitude(unitVector); // 1.0
|
|
193
|
+
* ```
|
|
175
194
|
*/
|
|
176
195
|
export declare function VectorMagnitude(a: TVector): number;
|
|
177
196
|
/**
|
|
@@ -183,11 +202,12 @@ export declare function VectorMagnitude(a: TVector): number;
|
|
|
183
202
|
* @returns New vector with absolute values of all components
|
|
184
203
|
*
|
|
185
204
|
* @example
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
205
|
+
* ```typescript
|
|
206
|
+
* const vector = [-3, 4, -2];
|
|
207
|
+
* const absolute = VectorAbs(vector); // [3, 4, 2]
|
|
208
|
+
* const mixed = [1.5, -2.7, 0];
|
|
209
|
+
* const absValues = VectorAbs(mixed); // [1.5, 2.7, 0]
|
|
210
|
+
* ```
|
|
191
211
|
*/
|
|
192
212
|
export declare function VectorAbs<T extends TAnyVector>(a: T): TVectorResult<T>;
|
|
193
213
|
/**
|
|
@@ -198,11 +218,12 @@ export declare function VectorAbs<T extends TAnyVector>(a: T): TVectorResult<T>;
|
|
|
198
218
|
* @returns True if all components are zero, false otherwise
|
|
199
219
|
*
|
|
200
220
|
* @example
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
221
|
+
* ```typescript
|
|
222
|
+
* const zero = [0, 0, 0];
|
|
223
|
+
* const isZero = VectorIsZero(zero); // true
|
|
224
|
+
* const notZero = [0, 0.001, 0];
|
|
225
|
+
* const isNotZero = VectorIsZero(notZero); // false
|
|
226
|
+
* ```
|
|
206
227
|
*/
|
|
207
228
|
export declare function VectorIsZero(vector: TVector): boolean;
|
|
208
229
|
/**
|
|
@@ -216,13 +237,14 @@ export declare function VectorIsZero(vector: TVector): boolean;
|
|
|
216
237
|
* @throws {VectorError} If either vector is zero
|
|
217
238
|
*
|
|
218
239
|
* @example
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
240
|
+
* ```typescript
|
|
241
|
+
* const right = [1, 0, 0];
|
|
242
|
+
* const up = [0, 1, 0];
|
|
243
|
+
* const angle = VectorAngle(right, up); // π/2 (90 degrees)
|
|
244
|
+
* const forward = [0, 0, 1];
|
|
245
|
+
* const backward = [0, 0, -1];
|
|
246
|
+
* const oppositeAngle = VectorAngle(forward, backward); // π (180 degrees)
|
|
247
|
+
* ```
|
|
226
248
|
*/
|
|
227
249
|
export declare function VectorAngle(a: TVector, b: TVector): number;
|
|
228
250
|
/**
|
|
@@ -234,9 +256,11 @@ export declare function VectorAngle(a: TVector, b: TVector): number;
|
|
|
234
256
|
* @returns New rotated 2D vector
|
|
235
257
|
*
|
|
236
258
|
* @example
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
259
|
+
* ```typescript
|
|
260
|
+
* const right = [1, 0];
|
|
261
|
+
* const rotated90 = Vector2Rotate(right, Math.PI / 2); // [0, 1] (up)
|
|
262
|
+
* const rotated180 = Vector2Rotate(right, Math.PI); // [-1, 0] (left)
|
|
263
|
+
* ```
|
|
240
264
|
*/
|
|
241
265
|
export declare function Vector2Rotate(vector: TVector2, radians: number): TVector2;
|
|
242
266
|
/**
|
|
@@ -247,9 +271,11 @@ export declare function Vector2Rotate(vector: TVector2, radians: number): TVecto
|
|
|
247
271
|
* @returns Unit vector pointing in the specified direction
|
|
248
272
|
*
|
|
249
273
|
* @example
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
274
|
+
* ```typescript
|
|
275
|
+
* const right = Vector2FromAngle(0); // [1, 0]
|
|
276
|
+
* const up = Vector2FromAngle(Math.PI / 2); // [0, 1]
|
|
277
|
+
* const diagonal = Vector2FromAngle(Math.PI / 4); // [0.707, 0.707]
|
|
278
|
+
* ```
|
|
253
279
|
*/
|
|
254
280
|
export declare function Vector2FromAngle(radians: number): TVector2;
|
|
255
281
|
/**
|
|
@@ -262,10 +288,12 @@ export declare function Vector2FromAngle(radians: number): TVector2;
|
|
|
262
288
|
* @returns Scalar cross product (positive = counterclockwise, negative = clockwise)
|
|
263
289
|
*
|
|
264
290
|
* @example
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
291
|
+
* ```typescript
|
|
292
|
+
* const right = [1, 0];
|
|
293
|
+
* const up = [0, 1];
|
|
294
|
+
* const cross = Vector2Cross(right, up); // 1 (counterclockwise)
|
|
295
|
+
* const crossReverse = Vector2Cross(up, right); // -1 (clockwise)
|
|
296
|
+
* ```
|
|
269
297
|
*/
|
|
270
298
|
export declare function Vector2Cross(a: TVector2, b: TVector2): number;
|
|
271
299
|
/**
|
|
@@ -279,9 +307,11 @@ export declare function Vector2Cross(a: TVector2, b: TVector2): number;
|
|
|
279
307
|
* @throws {VectorError} If vector b is zero
|
|
280
308
|
*
|
|
281
309
|
* @example
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
310
|
+
* ```typescript
|
|
311
|
+
* const force = [5, 3, 0];
|
|
312
|
+
* const surface = [1, 0, 0];
|
|
313
|
+
* const perpendicular = Vector3Reject(force, surface); // [0, 3, 0]
|
|
314
|
+
* ```
|
|
285
315
|
*/
|
|
286
316
|
export declare function Vector3Reject(a: TVector3, b: TVector3): TVector3;
|
|
287
317
|
/**
|
|
@@ -296,9 +326,11 @@ export declare function Vector3Reject(a: TVector3, b: TVector3): TVector3;
|
|
|
296
326
|
* @throws {VectorError} If vector b is zero
|
|
297
327
|
*
|
|
298
328
|
* @example
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
329
|
+
* ```typescript
|
|
330
|
+
* const force = [5, 3, 0];
|
|
331
|
+
* const surface = [1, 0, 0];
|
|
332
|
+
* const parallel = VectorProject(force, surface); // [5, 0, 0]
|
|
333
|
+
* ```
|
|
302
334
|
*/
|
|
303
335
|
export declare function VectorProject<T extends TAnyVector>(a: T, b: T): TVectorResult<T>;
|
|
304
336
|
/**
|
|
@@ -312,9 +344,11 @@ export declare function VectorProject<T extends TAnyVector>(a: T, b: T): TVector
|
|
|
312
344
|
* @throws {VectorError} If the normal is a zero vector
|
|
313
345
|
*
|
|
314
346
|
* @example
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
347
|
+
* ```typescript
|
|
348
|
+
* const incoming = [1, -1, 0];
|
|
349
|
+
* const normal = [0, 1, 0]; // surface normal (upward)
|
|
350
|
+
* const reflected = Vector3Reflect(incoming, normal); // [1, 1, 0]
|
|
351
|
+
* ```
|
|
318
352
|
*/
|
|
319
353
|
export declare function Vector3Reflect(incident: TVector3, normal: TVector3): TVector3;
|
|
320
354
|
/**
|
|
@@ -327,11 +361,12 @@ export declare function Vector3Reflect(incident: TVector3, normal: TVector3): TV
|
|
|
327
361
|
* @returns Vector perpendicular to both a and b (following right-hand rule)
|
|
328
362
|
*
|
|
329
363
|
* @example
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
364
|
+
* ```typescript
|
|
365
|
+
* const right = [1, 0, 0];
|
|
366
|
+
* const forward = [0, 0, 1];
|
|
367
|
+
* const up = Vector3Cross(right, forward); // [0, 1, 0]
|
|
368
|
+
* const normal = Vector3Cross([1, 0, 0], [0, 1, 0]); // [0, 0, 1]
|
|
369
|
+
* ```
|
|
335
370
|
*/
|
|
336
371
|
export declare function Vector3Cross(a: TVector3, b: TVector3): TVector3;
|
|
337
372
|
/**
|
|
@@ -344,9 +379,11 @@ export declare function Vector3Cross(a: TVector3, b: TVector3): TVector3;
|
|
|
344
379
|
* @returns Magnitude of the cross product
|
|
345
380
|
*
|
|
346
381
|
* @example
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
382
|
+
* ```typescript
|
|
383
|
+
* const side1 = [3, 0, 0];
|
|
384
|
+
* const side2 = [0, 4, 0];
|
|
385
|
+
* const area = VectorCrossMagnitude(side1, side2); // 12 (area of rectangle)
|
|
386
|
+
* ```
|
|
350
387
|
*/
|
|
351
388
|
export declare function VectorCrossMagnitude(a: TVector3, b: TVector3): number;
|
|
352
389
|
/**
|
|
@@ -360,10 +397,12 @@ export declare function VectorCrossMagnitude(a: TVector3, b: TVector3): number;
|
|
|
360
397
|
* @returns Signed volume (positive = right-handed orientation)
|
|
361
398
|
*
|
|
362
399
|
* @example
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
400
|
+
* ```typescript
|
|
401
|
+
* const x = [1, 0, 0];
|
|
402
|
+
* const y = [0, 1, 0];
|
|
403
|
+
* const z = [0, 0, 1];
|
|
404
|
+
* const volume = Vector3ScalarTripleProduct(x, y, z); // 1 (unit cube)
|
|
405
|
+
* ```
|
|
367
406
|
*/
|
|
368
407
|
export declare function Vector3ScalarTripleProduct(a: TVector3, b: TVector3, c: TVector3): number;
|
|
369
408
|
/**
|
|
@@ -377,10 +416,12 @@ export declare function Vector3ScalarTripleProduct(a: TVector3, b: TVector3, c:
|
|
|
377
416
|
* @returns Vector result of a × (b × c)
|
|
378
417
|
*
|
|
379
418
|
* @example
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
419
|
+
* ```typescript
|
|
420
|
+
* const a = [1, 0, 0];
|
|
421
|
+
* const b = [0, 1, 0];
|
|
422
|
+
* const c = [0, 0, 1];
|
|
423
|
+
* const result = Vector3TripleProduct(a, b, c); // [0, 0, 0]
|
|
424
|
+
* ```
|
|
384
425
|
*/
|
|
385
426
|
export declare function Vector3TripleProduct(a: TVector3, b: TVector3, c: TVector3): TVector3;
|
|
386
427
|
/**
|
|
@@ -394,9 +435,11 @@ export declare function Vector3TripleProduct(a: TVector3, b: TVector3, c: TVecto
|
|
|
394
435
|
* @returns The reflected vector
|
|
395
436
|
*
|
|
396
437
|
* @example
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
438
|
+
* ```typescript
|
|
439
|
+
* const incoming = [1, -1, 0];
|
|
440
|
+
* const wall = [0, 1, 0]; // vertical wall normal
|
|
441
|
+
* const bounced = VectorReflect(incoming, wall); // [1, 1, 0]
|
|
442
|
+
* ```
|
|
400
443
|
*/
|
|
401
444
|
export declare function VectorReflect<T extends TAnyVector>(incident: T, normal: T): TVectorResult<T>;
|
|
402
445
|
/**
|
|
@@ -409,11 +452,12 @@ export declare function VectorReflect<T extends TAnyVector>(incident: T, normal:
|
|
|
409
452
|
* @returns Vector with all components negated
|
|
410
453
|
*
|
|
411
454
|
* @example
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
455
|
+
* ```typescript
|
|
456
|
+
* const forward = [0, 0, 1];
|
|
457
|
+
* const backward = VectorNegate(forward); // [0, 0, -1]
|
|
458
|
+
* const velocity = [5, -3, 2];
|
|
459
|
+
* const opposite = VectorNegate(velocity); // [-5, 3, -2]
|
|
460
|
+
* ```
|
|
417
461
|
*/
|
|
418
462
|
export declare function VectorNegate<T extends TAnyVector>(a: T): TVectorResult<T>;
|
|
419
463
|
/**
|
|
@@ -427,10 +471,12 @@ export declare function VectorNegate<T extends TAnyVector>(a: T): TVectorResult<
|
|
|
427
471
|
* @throws {VectorError} If any divisor component is zero
|
|
428
472
|
*
|
|
429
473
|
* @example
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
474
|
+
* ```typescript
|
|
475
|
+
* const velocity = [20, 10, 0];
|
|
476
|
+
* const halved = VectorDivide(velocity, 2); // [10, 5, 0] - scalar division
|
|
477
|
+
* const factors = [2, 5, 1];
|
|
478
|
+
* const componentWise = VectorDivide(velocity, factors); // [10, 2, 0] - component-wise
|
|
479
|
+
* ```
|
|
434
480
|
*/
|
|
435
481
|
export declare function VectorDivide<T extends TAnyVector>(a: T, b: T | number): TVectorResult<T>;
|
|
436
482
|
/**
|
|
@@ -445,12 +491,13 @@ export declare function VectorDivide<T extends TAnyVector>(a: T, b: T | number):
|
|
|
445
491
|
* @returns New vector with each component clamped between min and max
|
|
446
492
|
*
|
|
447
493
|
* @example
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
494
|
+
* ```typescript
|
|
495
|
+
* const v = [5, -3, 12, 0];
|
|
496
|
+
* VectorClamp(v, 0, 10); // [5, 0, 10, 0] - scalar bounds
|
|
497
|
+
* const mins = [0, -5, 0, -1];
|
|
498
|
+
* const maxs = [10, 5, 8, 1];
|
|
499
|
+
* VectorClamp(v, mins, maxs); // [5, -3, 8, 0] - per-component bounds
|
|
500
|
+
* ```
|
|
454
501
|
*/
|
|
455
502
|
export declare function VectorClamp<T extends TAnyVector>(a: T, min: T | number, max: T | number): TVectorResult<T>;
|
|
456
503
|
/**
|
|
@@ -465,28 +512,58 @@ export declare function VectorClamp<T extends TAnyVector>(a: T, min: T | number,
|
|
|
465
512
|
* @throws {VectorError} If max is negative
|
|
466
513
|
*
|
|
467
514
|
* @example
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
export
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
515
|
+
* ```typescript
|
|
516
|
+
* const velocity = [15, 20, 0]; // magnitude ≈ 25
|
|
517
|
+
* const limited = VectorLimit(velocity, 10); // magnitude = 10, same direction
|
|
518
|
+
* const small = [1, 1, 0]; // magnitude ≈ 1.414
|
|
519
|
+
* const unchanged = VectorLimit(small, 5); // unchanged since already under limit
|
|
520
|
+
* ```
|
|
521
|
+
export function VectorGramSchmidt<T extends TAnyVector>(vectors: T[], normalize: boolean = false): TVectorResult<T>[] {
|
|
522
|
+
if (vectors.length === 0) throw new VectorError('GramSchmidt: Empty Vector Set');
|
|
523
|
+
const [firstVector] = vectors;
|
|
524
|
+
if (!firstVector) throw new VectorError('GramSchmidt: Undefined First Vector');
|
|
525
|
+
const dimension = firstVector.length;
|
|
526
|
+
for (const [i, vector] of vectors.entries()) {
|
|
527
|
+
AssertVector(vector);
|
|
528
|
+
if (vector.length !== dimension) throw new VectorError(`GramSchmidt: Vector at index ${i} has different dimension than first vector. Expected ${dimension}, got ${vector.length}`);
|
|
529
|
+
if (VectorIsZero(vector)) throw new VectorError(`GramSchmidt: Vector at index ${i} is a zero vector. Cannot orthogonalize zero vectors.`);
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
const result: TVectorResult<T>[] = [];
|
|
533
|
+
|
|
534
|
+
for (const [i, currentVector] of vectors.entries()) {
|
|
535
|
+
AssertVector(currentVector);
|
|
536
|
+
|
|
537
|
+
// Start with a clone of the current vector
|
|
538
|
+
let orthogonalVector = VectorClone(currentVector);
|
|
539
|
+
|
|
540
|
+
// Subtract projections of all previous vectors
|
|
541
|
+
for (let j = 0; j < i; j++) {
|
|
542
|
+
const previousVector = result[j];
|
|
543
|
+
AssertVector(previousVector);
|
|
544
|
+
|
|
545
|
+
// Both vectors have the same dimension, projection result is compatible
|
|
546
|
+
const vectorT = currentVector as unknown as T;
|
|
547
|
+
const prevT = previousVector as unknown as T;
|
|
548
|
+
const projection = VectorProject(vectorT, prevT);
|
|
549
|
+
orthogonalVector = VectorSubtract(orthogonalVector as unknown as T, projection as unknown as T);
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
if (VectorIsZero(orthogonalVector as unknown as T)) {
|
|
553
|
+
throw new VectorError(`GramSchmidt: Vector at index ${i} is linearly dependent on previous vectors. Cannot orthogonalize linearly dependent vectors.`);
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
if (normalize) {
|
|
557
|
+
orthogonalVector = VectorNormalize(orthogonalVector as unknown as T);
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
result.push(orthogonalVector as TVectorResult<T>);
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
return result;
|
|
564
|
+
}}
|
|
565
|
+
}
|
|
566
|
+
|
|
490
567
|
/**
|
|
491
568
|
* Performs Gram-Schmidt orthogonalization on a set of vectors.
|
|
492
569
|
* Converts a set of linearly independent vectors into an orthogonal (or orthonormal) set.
|
|
@@ -499,9 +576,11 @@ export declare function VectorIsValid(vector: unknown): boolean;
|
|
|
499
576
|
* @throws {VectorError} If vectors are linearly dependent or invalid
|
|
500
577
|
*
|
|
501
578
|
* @example
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
579
|
+
* ```typescript
|
|
580
|
+
* const vectors = [[1, 1, 0], [1, 0, 1], [0, 1, 1]];
|
|
581
|
+
* const orthogonal = VectorGramSchmidt(vectors); // Orthogonal set
|
|
582
|
+
* const orthonormal = VectorGramSchmidt(vectors, true); // Orthonormal set
|
|
583
|
+
* ```
|
|
505
584
|
*/
|
|
506
585
|
export declare function VectorGramSchmidt<T extends TAnyVector>(vectors: T[], normalize?: boolean): TVectorResult<T>[];
|
|
507
586
|
//# sourceMappingURL=core.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../src/vectors/core.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEpF
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../src/vectors/core.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEpF;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,UAAU,EAAE,MAAM,EAAE,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAG7E;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,UAAU,EAAE,CAAC,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