@pawells/math-extended 2.0.0 → 3.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/README.md +15 -21
- package/build/clamp.d.ts +5 -5
- package/build/clamp.js +5 -5
- package/build/core.d.ts +23 -0
- package/build/core.d.ts.map +1 -0
- package/build/core.js +25 -0
- package/build/core.js.map +1 -0
- package/build/index.d.ts +1 -4
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1 -6
- package/build/index.js.map +1 -1
- package/build/interpolation.d.ts +158 -171
- package/build/interpolation.d.ts.map +1 -1
- package/build/interpolation.js +162 -181
- package/build/interpolation.js.map +1 -1
- package/build/matrices/arithmetic.d.ts +132 -132
- package/build/matrices/arithmetic.d.ts.map +1 -1
- package/build/matrices/arithmetic.js +194 -226
- package/build/matrices/arithmetic.js.map +1 -1
- package/build/matrices/asserts.d.ts +30 -408
- package/build/matrices/asserts.d.ts.map +1 -1
- package/build/matrices/asserts.js +98 -542
- package/build/matrices/asserts.js.map +1 -1
- package/build/matrices/core.d.ts +117 -46
- package/build/matrices/core.d.ts.map +1 -1
- package/build/matrices/core.js +127 -103
- package/build/matrices/core.js.map +1 -1
- package/build/matrices/decompositions.d.ts +95 -96
- package/build/matrices/decompositions.d.ts.map +1 -1
- package/build/matrices/decompositions.js +119 -160
- package/build/matrices/decompositions.js.map +1 -1
- package/build/matrices/index.d.ts +0 -1
- package/build/matrices/index.d.ts.map +1 -1
- package/build/matrices/index.js +0 -3
- package/build/matrices/index.js.map +1 -1
- package/build/matrices/linear-algebra.d.ts +45 -8
- package/build/matrices/linear-algebra.d.ts.map +1 -1
- package/build/matrices/linear-algebra.js +76 -32
- package/build/matrices/linear-algebra.js.map +1 -1
- package/build/matrices/normalization.d.ts +29 -8
- package/build/matrices/normalization.d.ts.map +1 -1
- package/build/matrices/normalization.js +32 -23
- package/build/matrices/normalization.js.map +1 -1
- package/build/matrices/transformations.d.ts +116 -148
- package/build/matrices/transformations.d.ts.map +1 -1
- package/build/matrices/transformations.js +69 -91
- package/build/matrices/transformations.js.map +1 -1
- package/build/matrices/types.d.ts +32 -60
- package/build/matrices/types.d.ts.map +1 -1
- package/build/matrices/types.js +63 -1
- package/build/matrices/types.js.map +1 -1
- package/build/quaternions/asserts.d.ts +29 -38
- package/build/quaternions/asserts.d.ts.map +1 -1
- package/build/quaternions/asserts.js +61 -77
- package/build/quaternions/asserts.js.map +1 -1
- package/build/quaternions/conversions.d.ts +26 -26
- package/build/quaternions/conversions.d.ts.map +1 -1
- package/build/quaternions/conversions.js +24 -24
- package/build/quaternions/core.d.ts +70 -69
- package/build/quaternions/core.d.ts.map +1 -1
- package/build/quaternions/core.js +71 -71
- package/build/quaternions/core.js.map +1 -1
- package/build/quaternions/index.d.ts +0 -1
- package/build/quaternions/index.d.ts.map +1 -1
- package/build/quaternions/index.js +0 -2
- package/build/quaternions/index.js.map +1 -1
- package/build/quaternions/interpolation.d.ts +16 -16
- package/build/quaternions/interpolation.d.ts.map +1 -1
- package/build/quaternions/interpolation.js +21 -21
- package/build/quaternions/interpolation.js.map +1 -1
- package/build/quaternions/predefined.d.ts +10 -10
- package/build/quaternions/predefined.d.ts.map +1 -1
- package/build/quaternions/predefined.js +9 -9
- package/build/quaternions/types.d.ts +23 -12
- package/build/quaternions/types.d.ts.map +1 -1
- package/build/quaternions/types.js +51 -1
- package/build/quaternions/types.js.map +1 -1
- package/build/random.d.ts +66 -20
- package/build/random.d.ts.map +1 -1
- package/build/random.js +73 -20
- package/build/random.js.map +1 -1
- package/build/vectors/asserts.d.ts +50 -220
- package/build/vectors/asserts.d.ts.map +1 -1
- package/build/vectors/asserts.js +141 -327
- package/build/vectors/asserts.js.map +1 -1
- package/build/vectors/core.d.ts +182 -229
- package/build/vectors/core.d.ts.map +1 -1
- package/build/vectors/core.js +234 -288
- package/build/vectors/core.js.map +1 -1
- package/build/vectors/index.d.ts +0 -1
- package/build/vectors/index.d.ts.map +1 -1
- package/build/vectors/index.js +0 -2
- package/build/vectors/index.js.map +1 -1
- package/build/vectors/interpolation.d.ts +40 -40
- package/build/vectors/interpolation.d.ts.map +1 -1
- package/build/vectors/interpolation.js +75 -86
- package/build/vectors/interpolation.js.map +1 -1
- package/build/vectors/predefined.d.ts +31 -7
- package/build/vectors/predefined.d.ts.map +1 -1
- package/build/vectors/predefined.js +30 -6
- package/build/vectors/predefined.js.map +1 -1
- package/build/vectors/types.d.ts +26 -4
- package/build/vectors/types.d.ts.map +1 -1
- package/build/vectors/types.js +50 -1
- package/build/vectors/types.js.map +1 -1
- package/package.json +3 -2
- package/build/matrices/_exports.d.ts +0 -13
- package/build/matrices/_exports.d.ts.map +0 -1
- package/build/matrices/_exports.js +0 -13
- package/build/matrices/_exports.js.map +0 -1
- package/build/quaternions/_exports.d.ts +0 -11
- package/build/quaternions/_exports.d.ts.map +0 -1
- package/build/quaternions/_exports.js +0 -11
- package/build/quaternions/_exports.js.map +0 -1
- package/build/vectors/_exports.d.ts +0 -10
- package/build/vectors/_exports.d.ts.map +0 -1
- package/build/vectors/_exports.js +0 -10
- package/build/vectors/_exports.js.map +0 -1
package/build/vectors/core.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Core vector mathematics operations for linear algebra and geometric calculations.
|
|
3
3
|
* Provides a comprehensive set of vector operations with type safety and error checking.
|
|
4
4
|
*/
|
|
5
|
-
import { TAnyVector, TVectorResult, TVector, TVector2, TVector3 } from './types.js';
|
|
5
|
+
import type { TAnyVector, TVectorResult, TVector, TVector2, TVector3 } from './types.js';
|
|
6
6
|
/**
|
|
7
7
|
* Creates a deep copy of a vector.
|
|
8
8
|
* Essential for avoiding mutations when performing operations that should preserve the original vector.
|
|
@@ -12,11 +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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const original = [1, 2, 3];
|
|
17
|
+
* const copy = VectorClone(original);
|
|
18
|
+
* copy[0] = 10; // original remains unchanged
|
|
19
|
+
* ```
|
|
20
20
|
*/
|
|
21
21
|
export declare function VectorClone<T extends TAnyVector>(vector: T): TVectorResult<T>;
|
|
22
22
|
/**
|
|
@@ -30,12 +30,12 @@ export declare function VectorClone<T extends TAnyVector>(vector: T): TVectorRes
|
|
|
30
30
|
* @returns True if vectors are equal within tolerance, false otherwise
|
|
31
31
|
*
|
|
32
32
|
* @example
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
+
* ```
|
|
39
39
|
*/
|
|
40
40
|
export declare function VectorEquals<T extends TAnyVector>(a: T, b: T, tolerance?: number): boolean;
|
|
41
41
|
/**
|
|
@@ -47,11 +47,11 @@ export declare function VectorEquals<T extends TAnyVector>(a: T, b: T, tolerance
|
|
|
47
47
|
* @returns String representation of the vector
|
|
48
48
|
*
|
|
49
49
|
* @example
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
+
* ```
|
|
55
55
|
*/
|
|
56
56
|
export declare function VectorToString(vector: TVector, style?: 'parens' | 'brackets'): string;
|
|
57
57
|
/**
|
|
@@ -64,11 +64,11 @@ export declare function VectorToString(vector: TVector, style?: 'parens' | 'brac
|
|
|
64
64
|
* @returns New vector where each component is the sum of corresponding components
|
|
65
65
|
*
|
|
66
66
|
* @example
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
+
* ```
|
|
72
72
|
*/
|
|
73
73
|
export declare function VectorAdd<T extends TAnyVector>(a: T, b: T): TVectorResult<T>;
|
|
74
74
|
/**
|
|
@@ -81,11 +81,11 @@ export declare function VectorAdd<T extends TAnyVector>(a: T, b: T): TVectorResu
|
|
|
81
81
|
* @returns New vector where each component is the difference of corresponding components
|
|
82
82
|
*
|
|
83
83
|
* @example
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
84
|
+
* ```typescript
|
|
85
|
+
* const target = [100, 50, 0];
|
|
86
|
+
* const current = [80, 30, 0];
|
|
87
|
+
* const direction = VectorSubtract(target, current); // [20, 20, 0]
|
|
88
|
+
* ```
|
|
89
89
|
*/
|
|
90
90
|
export declare function VectorSubtract<T extends TAnyVector>(a: T, b: T): TVectorResult<T>;
|
|
91
91
|
/**
|
|
@@ -98,12 +98,12 @@ export declare function VectorSubtract<T extends TAnyVector>(a: T, b: T): TVecto
|
|
|
98
98
|
* @returns New vector with multiplied components
|
|
99
99
|
*
|
|
100
100
|
* @example
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
+
* ```
|
|
107
107
|
*/
|
|
108
108
|
export declare function VectorMultiply<T extends TAnyVector>(a: T, b: T | number): TVectorResult<T>;
|
|
109
109
|
/**
|
|
@@ -115,11 +115,11 @@ export declare function VectorMultiply<T extends TAnyVector>(a: T, b: T | number
|
|
|
115
115
|
* @returns The straight-line distance between the two points represented by the vectors
|
|
116
116
|
*
|
|
117
117
|
* @example
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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
|
+
* ```
|
|
123
123
|
*/
|
|
124
124
|
export declare function VectorDistance(a: TVector, b: TVector): number;
|
|
125
125
|
/**
|
|
@@ -132,11 +132,11 @@ export declare function VectorDistance(a: TVector, b: TVector): number;
|
|
|
132
132
|
* @returns The squared distance between vectors
|
|
133
133
|
*
|
|
134
134
|
* @example
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
135
|
+
* ```typescript
|
|
136
|
+
* const pointA = [1, 1];
|
|
137
|
+
* const pointB = [4, 5];
|
|
138
|
+
* const distSq = VectorDistanceSquared(pointA, pointB); // 25 (faster than distance comparison)
|
|
139
|
+
* ```
|
|
140
140
|
*/
|
|
141
141
|
export declare function VectorDistanceSquared(a: TVector, b: TVector): number;
|
|
142
142
|
/**
|
|
@@ -149,13 +149,13 @@ export declare function VectorDistanceSquared(a: TVector, b: TVector): number;
|
|
|
149
149
|
* @returns The dot product (scalar value)
|
|
150
150
|
*
|
|
151
151
|
* @example
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
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
|
+
* ```
|
|
159
159
|
*/
|
|
160
160
|
export declare function VectorDot(a: TVector, b: TVector): number;
|
|
161
161
|
/**
|
|
@@ -169,12 +169,12 @@ export declare function VectorDot(a: TVector, b: TVector): number;
|
|
|
169
169
|
* @throws {VectorError} If the vector is zero or has infinite magnitude
|
|
170
170
|
*
|
|
171
171
|
* @example
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
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
|
+
* ```
|
|
178
178
|
*/
|
|
179
179
|
export declare function VectorNormalize<T extends TAnyVector>(a: T): TVectorResult<T>;
|
|
180
180
|
/**
|
|
@@ -185,12 +185,12 @@ export declare function VectorNormalize<T extends TAnyVector>(a: T): TVectorResu
|
|
|
185
185
|
* @returns The magnitude (length) of the vector
|
|
186
186
|
*
|
|
187
187
|
* @example
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
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
|
+
* ```
|
|
194
194
|
*/
|
|
195
195
|
export declare function VectorMagnitude(a: TVector): number;
|
|
196
196
|
/**
|
|
@@ -202,12 +202,12 @@ export declare function VectorMagnitude(a: TVector): number;
|
|
|
202
202
|
* @returns New vector with absolute values of all components
|
|
203
203
|
*
|
|
204
204
|
* @example
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
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
|
+
* ```
|
|
211
211
|
*/
|
|
212
212
|
export declare function VectorAbs<T extends TAnyVector>(a: T): TVectorResult<T>;
|
|
213
213
|
/**
|
|
@@ -218,12 +218,12 @@ export declare function VectorAbs<T extends TAnyVector>(a: T): TVectorResult<T>;
|
|
|
218
218
|
* @returns True if all components are zero, false otherwise
|
|
219
219
|
*
|
|
220
220
|
* @example
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
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
|
+
* ```
|
|
227
227
|
*/
|
|
228
228
|
export declare function VectorIsZero(vector: TVector): boolean;
|
|
229
229
|
/**
|
|
@@ -237,16 +237,33 @@ export declare function VectorIsZero(vector: TVector): boolean;
|
|
|
237
237
|
* @throws {VectorError} If either vector is zero
|
|
238
238
|
*
|
|
239
239
|
* @example
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
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
|
+
* ```
|
|
248
248
|
*/
|
|
249
249
|
export declare function VectorAngle(a: TVector, b: TVector): number;
|
|
250
|
+
/**
|
|
251
|
+
* Limits (clamps) the magnitude of a vector to a maximum value.
|
|
252
|
+
* If the vector's magnitude exceeds the maximum, scales it down proportionally while preserving direction.
|
|
253
|
+
* If the magnitude is below the maximum, the vector is returned unchanged.
|
|
254
|
+
*
|
|
255
|
+
* @param vector - The input vector to limit
|
|
256
|
+
* @param maxMagnitude - The maximum allowed magnitude (must be >= 0)
|
|
257
|
+
* @returns A new vector with magnitude limited to maxMagnitude
|
|
258
|
+
* @throws {VectorError} If vector is invalid or maxMagnitude is invalid
|
|
259
|
+
*
|
|
260
|
+
* @example
|
|
261
|
+
* ```typescript
|
|
262
|
+
* const v = [3, 4]; // magnitude 5
|
|
263
|
+
* VectorLimit(v, 3); // [1.8, 2.4] — magnitude now 3
|
|
264
|
+
* ```
|
|
265
|
+
*/
|
|
266
|
+
export declare function VectorLimit<T extends TAnyVector>(vector: T, maxMagnitude: number): TVectorResult<T>;
|
|
250
267
|
/**
|
|
251
268
|
* Rotates a 2D vector by the specified angle in radians.
|
|
252
269
|
* Essential for 2D transformations, sprite rotations, and directional calculations.
|
|
@@ -256,11 +273,11 @@ export declare function VectorAngle(a: TVector, b: TVector): number;
|
|
|
256
273
|
* @returns New rotated 2D vector
|
|
257
274
|
*
|
|
258
275
|
* @example
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
276
|
+
* ```typescript
|
|
277
|
+
* const right = [1, 0];
|
|
278
|
+
* const rotated90 = Vector2Rotate(right, Math.PI / 2); // [0, 1] (up)
|
|
279
|
+
* const rotated180 = Vector2Rotate(right, Math.PI); // [-1, 0] (left)
|
|
280
|
+
* ```
|
|
264
281
|
*/
|
|
265
282
|
export declare function Vector2Rotate(vector: TVector2, radians: number): TVector2;
|
|
266
283
|
/**
|
|
@@ -271,11 +288,11 @@ export declare function Vector2Rotate(vector: TVector2, radians: number): TVecto
|
|
|
271
288
|
* @returns Unit vector pointing in the specified direction
|
|
272
289
|
*
|
|
273
290
|
* @example
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
291
|
+
* ```typescript
|
|
292
|
+
* const right = Vector2FromAngle(0); // [1, 0]
|
|
293
|
+
* const up = Vector2FromAngle(Math.PI / 2); // [0, 1]
|
|
294
|
+
* const diagonal = Vector2FromAngle(Math.PI / 4); // [0.707, 0.707]
|
|
295
|
+
* ```
|
|
279
296
|
*/
|
|
280
297
|
export declare function Vector2FromAngle(radians: number): TVector2;
|
|
281
298
|
/**
|
|
@@ -288,12 +305,12 @@ export declare function Vector2FromAngle(radians: number): TVector2;
|
|
|
288
305
|
* @returns Scalar cross product (positive = counterclockwise, negative = clockwise)
|
|
289
306
|
*
|
|
290
307
|
* @example
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
308
|
+
* ```typescript
|
|
309
|
+
* const right = [1, 0];
|
|
310
|
+
* const up = [0, 1];
|
|
311
|
+
* const cross = Vector2Cross(right, up); // 1 (counterclockwise)
|
|
312
|
+
* const crossReverse = Vector2Cross(up, right); // -1 (clockwise)
|
|
313
|
+
* ```
|
|
297
314
|
*/
|
|
298
315
|
export declare function Vector2Cross(a: TVector2, b: TVector2): number;
|
|
299
316
|
/**
|
|
@@ -307,11 +324,11 @@ export declare function Vector2Cross(a: TVector2, b: TVector2): number;
|
|
|
307
324
|
* @throws {VectorError} If vector b is zero
|
|
308
325
|
*
|
|
309
326
|
* @example
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
327
|
+
* ```typescript
|
|
328
|
+
* const force = [5, 3, 0];
|
|
329
|
+
* const surface = [1, 0, 0];
|
|
330
|
+
* const perpendicular = Vector3Reject(force, surface); // [0, 3, 0]
|
|
331
|
+
* ```
|
|
315
332
|
*/
|
|
316
333
|
export declare function Vector3Reject(a: TVector3, b: TVector3): TVector3;
|
|
317
334
|
/**
|
|
@@ -326,11 +343,11 @@ export declare function Vector3Reject(a: TVector3, b: TVector3): TVector3;
|
|
|
326
343
|
* @throws {VectorError} If vector b is zero
|
|
327
344
|
*
|
|
328
345
|
* @example
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
346
|
+
* ```typescript
|
|
347
|
+
* const force = [5, 3, 0];
|
|
348
|
+
* const surface = [1, 0, 0];
|
|
349
|
+
* const parallel = VectorProject(force, surface); // [5, 0, 0]
|
|
350
|
+
* ```
|
|
334
351
|
*/
|
|
335
352
|
export declare function VectorProject<T extends TAnyVector>(a: T, b: T): TVectorResult<T>;
|
|
336
353
|
/**
|
|
@@ -344,11 +361,11 @@ export declare function VectorProject<T extends TAnyVector>(a: T, b: T): TVector
|
|
|
344
361
|
* @throws {VectorError} If the normal is a zero vector
|
|
345
362
|
*
|
|
346
363
|
* @example
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
364
|
+
* ```typescript
|
|
365
|
+
* const incoming = [1, -1, 0];
|
|
366
|
+
* const normal = [0, 1, 0]; // surface normal (upward)
|
|
367
|
+
* const reflected = Vector3Reflect(incoming, normal); // [1, 1, 0]
|
|
368
|
+
* ```
|
|
352
369
|
*/
|
|
353
370
|
export declare function Vector3Reflect(incident: TVector3, normal: TVector3): TVector3;
|
|
354
371
|
/**
|
|
@@ -361,12 +378,12 @@ export declare function Vector3Reflect(incident: TVector3, normal: TVector3): TV
|
|
|
361
378
|
* @returns Vector perpendicular to both a and b (following right-hand rule)
|
|
362
379
|
*
|
|
363
380
|
* @example
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
381
|
+
* ```typescript
|
|
382
|
+
* const right = [1, 0, 0];
|
|
383
|
+
* const forward = [0, 0, 1];
|
|
384
|
+
* const up = Vector3Cross(right, forward); // [0, 1, 0]
|
|
385
|
+
* const normal = Vector3Cross([1, 0, 0], [0, 1, 0]); // [0, 0, 1]
|
|
386
|
+
* ```
|
|
370
387
|
*/
|
|
371
388
|
export declare function Vector3Cross(a: TVector3, b: TVector3): TVector3;
|
|
372
389
|
/**
|
|
@@ -379,11 +396,11 @@ export declare function Vector3Cross(a: TVector3, b: TVector3): TVector3;
|
|
|
379
396
|
* @returns Magnitude of the cross product
|
|
380
397
|
*
|
|
381
398
|
* @example
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
399
|
+
* ```typescript
|
|
400
|
+
* const side1 = [3, 0, 0];
|
|
401
|
+
* const side2 = [0, 4, 0];
|
|
402
|
+
* const area = VectorCrossMagnitude(side1, side2); // 12 (area of rectangle)
|
|
403
|
+
* ```
|
|
387
404
|
*/
|
|
388
405
|
export declare function VectorCrossMagnitude(a: TVector3, b: TVector3): number;
|
|
389
406
|
/**
|
|
@@ -397,12 +414,12 @@ export declare function VectorCrossMagnitude(a: TVector3, b: TVector3): number;
|
|
|
397
414
|
* @returns Signed volume (positive = right-handed orientation)
|
|
398
415
|
*
|
|
399
416
|
* @example
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
417
|
+
* ```typescript
|
|
418
|
+
* const x = [1, 0, 0];
|
|
419
|
+
* const y = [0, 1, 0];
|
|
420
|
+
* const z = [0, 0, 1];
|
|
421
|
+
* const volume = Vector3ScalarTripleProduct(x, y, z); // 1 (unit cube)
|
|
422
|
+
* ```
|
|
406
423
|
*/
|
|
407
424
|
export declare function Vector3ScalarTripleProduct(a: TVector3, b: TVector3, c: TVector3): number;
|
|
408
425
|
/**
|
|
@@ -416,12 +433,12 @@ export declare function Vector3ScalarTripleProduct(a: TVector3, b: TVector3, c:
|
|
|
416
433
|
* @returns Vector result of a × (b × c)
|
|
417
434
|
*
|
|
418
435
|
* @example
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
436
|
+
* ```typescript
|
|
437
|
+
* const a = [1, 0, 0];
|
|
438
|
+
* const b = [0, 1, 0];
|
|
439
|
+
* const c = [0, 0, 1];
|
|
440
|
+
* const result = Vector3TripleProduct(a, b, c); // [0, 0, 0]
|
|
441
|
+
* ```
|
|
425
442
|
*/
|
|
426
443
|
export declare function Vector3TripleProduct(a: TVector3, b: TVector3, c: TVector3): TVector3;
|
|
427
444
|
/**
|
|
@@ -435,11 +452,11 @@ export declare function Vector3TripleProduct(a: TVector3, b: TVector3, c: TVecto
|
|
|
435
452
|
* @returns The reflected vector
|
|
436
453
|
*
|
|
437
454
|
* @example
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
455
|
+
* ```typescript
|
|
456
|
+
* const incoming = [1, -1, 0];
|
|
457
|
+
* const wall = [0, 1, 0]; // vertical wall normal
|
|
458
|
+
* const bounced = VectorReflect(incoming, wall); // [1, 1, 0]
|
|
459
|
+
* ```
|
|
443
460
|
*/
|
|
444
461
|
export declare function VectorReflect<T extends TAnyVector>(incident: T, normal: T): TVectorResult<T>;
|
|
445
462
|
/**
|
|
@@ -452,12 +469,12 @@ export declare function VectorReflect<T extends TAnyVector>(incident: T, normal:
|
|
|
452
469
|
* @returns Vector with all components negated
|
|
453
470
|
*
|
|
454
471
|
* @example
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
472
|
+
* ```typescript
|
|
473
|
+
* const forward = [0, 0, 1];
|
|
474
|
+
* const backward = VectorNegate(forward); // [0, 0, -1]
|
|
475
|
+
* const velocity = [5, -3, 2];
|
|
476
|
+
* const opposite = VectorNegate(velocity); // [-5, 3, -2]
|
|
477
|
+
* ```
|
|
461
478
|
*/
|
|
462
479
|
export declare function VectorNegate<T extends TAnyVector>(a: T): TVectorResult<T>;
|
|
463
480
|
/**
|
|
@@ -471,12 +488,12 @@ export declare function VectorNegate<T extends TAnyVector>(a: T): TVectorResult<
|
|
|
471
488
|
* @throws {VectorError} If any divisor component is zero
|
|
472
489
|
*
|
|
473
490
|
* @example
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
491
|
+
* ```typescript
|
|
492
|
+
* const velocity = [20, 10, 0];
|
|
493
|
+
* const halved = VectorDivide(velocity, 2); // [10, 5, 0] - scalar division
|
|
494
|
+
* const factors = [2, 5, 1];
|
|
495
|
+
* const componentWise = VectorDivide(velocity, factors); // [10, 2, 0] - component-wise
|
|
496
|
+
* ```
|
|
480
497
|
*/
|
|
481
498
|
export declare function VectorDivide<T extends TAnyVector>(a: T, b: T | number): TVectorResult<T>;
|
|
482
499
|
/**
|
|
@@ -491,79 +508,15 @@ export declare function VectorDivide<T extends TAnyVector>(a: T, b: T | number):
|
|
|
491
508
|
* @returns New vector with each component clamped between min and max
|
|
492
509
|
*
|
|
493
510
|
* @example
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
511
|
+
* ```typescript
|
|
512
|
+
* const v = [5, -3, 12, 0];
|
|
513
|
+
* VectorClamp(v, 0, 10); // [5, 0, 10, 0] - scalar bounds
|
|
514
|
+
* const mins = [0, -5, 0, -1];
|
|
515
|
+
* const maxs = [10, 5, 8, 1];
|
|
516
|
+
* VectorClamp(v, mins, maxs); // [5, -3, 8, 0] - per-component bounds
|
|
517
|
+
* ```
|
|
501
518
|
*/
|
|
502
519
|
export declare function VectorClamp<T extends TAnyVector>(a: T, min: T | number, max: T | number): TVectorResult<T>;
|
|
503
|
-
/**
|
|
504
|
-
* Limits the magnitude of a vector to a maximum value.
|
|
505
|
-
* If the vector's magnitude exceeds the limit, scales it down proportionally.
|
|
506
|
-
* Preserves direction while constraining magnitude.
|
|
507
|
-
*
|
|
508
|
-
* @template T - The vector type extending TVector
|
|
509
|
-
* @param a - Vector to limit
|
|
510
|
-
* @param max - Maximum allowed magnitude
|
|
511
|
-
* @returns Vector with magnitude limited to max
|
|
512
|
-
* @throws {VectorError} If max is negative
|
|
513
|
-
*
|
|
514
|
-
* @example
|
|
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
|
-
|
|
567
520
|
/**
|
|
568
521
|
* Performs Gram-Schmidt orthogonalization on a set of vectors.
|
|
569
522
|
* Converts a set of linearly independent vectors into an orthogonal (or orthonormal) set.
|
|
@@ -576,11 +529,11 @@ export function VectorGramSchmidt<T extends TAnyVector>(vectors: T[], normalize:
|
|
|
576
529
|
* @throws {VectorError} If vectors are linearly dependent or invalid
|
|
577
530
|
*
|
|
578
531
|
* @example
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
532
|
+
* ```typescript
|
|
533
|
+
* const vectors = [[1, 1, 0], [1, 0, 1], [0, 1, 1]];
|
|
534
|
+
* const orthogonal = VectorGramSchmidt(vectors); // Orthogonal set
|
|
535
|
+
* const orthonormal = VectorGramSchmidt(vectors, true); // Orthonormal set
|
|
536
|
+
* ```
|
|
584
537
|
*/
|
|
585
538
|
export declare function VectorGramSchmidt<T extends TAnyVector>(vectors: T[], normalize?: boolean): TVectorResult<T>[];
|
|
586
539
|
//# 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;
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../src/vectors/core.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEzF;;;;;;;;;;;;;;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,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,SAAS,GAAE,MAAU,GAAG,OAAO,CAe7F;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,GAAE,QAAQ,GAAG,UAAqB,GAAG,MAAM,CAM/F;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,UAAU,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAc5E;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,cAAc,CAAC,CAAC,SAAS,UAAU,EAAE,CAAC,EAAE,CAAC,E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