@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/random.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"random.js","sourceRoot":"","sources":["../src/random.ts"],"names":[],"mappings":"AAAA,MAAM,sBAAsB,GAAG,CAAC,CAAC,CAAC;AAClC,MAAM,iBAAiB,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,mDAAmD;AAE7F
|
|
1
|
+
{"version":3,"file":"random.js","sourceRoot":"","sources":["../src/random.ts"],"names":[],"mappings":"AAAA,MAAM,sBAAsB,GAAG,CAAC,CAAC,CAAC;AAClC,MAAM,iBAAiB,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,mDAAmD;AAE7F;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,SAAS,CAAC,GAAW,EAAE,GAAW;IACjD,IAAI,GAAG,GAAG,GAAG;QAAE,OAAO,MAAM,CAAC,GA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C/B,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;IACpB,CAAC;IACD,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;IAEzB,MAAM,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,sBAAsB,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;IACzF,OAAO,CAAC,EAAE,GAAG,iBAAiB,CAAC,GAAG,IAAI,CAAC;AACxC,CAAC"}
|
|
@@ -3,70 +3,19 @@
|
|
|
3
3
|
* Provides comprehensive validation functions to ensure vector data integrity
|
|
4
4
|
* and catch errors early in mathematical operations.
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
6
|
+
import { type TVector, type TVector2, type TVector3, type TVector4 } from './types.js';
|
|
7
|
+
import z from 'zod';
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*/
|
|
12
|
-
export type TAssertVectorArgs = IAssertNumberArgs & IAssertArrayArgs;
|
|
13
|
-
/**
|
|
14
|
-
* Extended configuration for validating multiple vectors.
|
|
15
|
-
* Includes all single vector options plus multi-vector constraints.
|
|
16
|
-
*/
|
|
17
|
-
export interface IAssertVectorsArgs extends TAssertVectorArgs {
|
|
18
|
-
/**
|
|
19
|
-
* Minimum vector size allowed.
|
|
20
|
-
* If specified, vectors must have at least this many components.
|
|
21
|
-
*/
|
|
22
|
-
minSize?: number;
|
|
23
|
-
/**
|
|
24
|
-
* Whether all vectors must have the same size.
|
|
25
|
-
* Default: true when using individual arguments, configurable when using array syntax.
|
|
26
|
-
*/
|
|
27
|
-
sameSize?: boolean;
|
|
28
|
-
/**
|
|
29
|
-
* Whether all vector elements must be finite numbers.
|
|
30
|
-
* If true, validates that each element is not Infinity or -Infinity.
|
|
31
|
-
*/
|
|
32
|
-
finite?: boolean;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Extended exception interface for vector-specific error information.
|
|
36
|
-
* Provides additional context about which vector component caused the error.
|
|
37
|
-
*/
|
|
38
|
-
interface IAssertVectorException extends IAssertException {
|
|
39
|
-
/**
|
|
40
|
-
* Index of the vector component that caused the validation failure.
|
|
41
|
-
* Useful for debugging which specific element is invalid.
|
|
42
|
-
*/
|
|
43
|
-
index?: number;
|
|
44
|
-
}
|
|
45
|
-
type TAssertVectorValueArgs = IAssertNumberArgs;
|
|
46
|
-
/**
|
|
47
|
-
* Specialized error class for vector-related operations and validations.
|
|
48
|
-
* Thrown when vector assertions fail or vector operations encounter invalid data.
|
|
9
|
+
* Vector error class for validation failures and vector operations.
|
|
10
|
+
* Extends Error to provide detailed error information with optional cause chain.
|
|
49
11
|
*
|
|
50
12
|
* @example
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
* } catch (error) {
|
|
55
|
-
* if (error instanceof VectorError) {
|
|
56
|
-
* console.log("Vector validation failed:", error.message);
|
|
57
|
-
* }
|
|
58
|
-
* }
|
|
59
|
-
* ```
|
|
13
|
+
* ```typescript
|
|
14
|
+
* throw new VectorError('Invalid vector dimensions', { cause: originalError });
|
|
15
|
+
* ```
|
|
60
16
|
*/
|
|
61
17
|
export declare class VectorError extends Error {
|
|
62
18
|
readonly code: string;
|
|
63
|
-
/**
|
|
64
|
-
* Creates a new VectorError instance.
|
|
65
|
-
*
|
|
66
|
-
* @param message - Error message describing the validation failure
|
|
67
|
-
* @param options - Optional error context
|
|
68
|
-
* @param options.cause - Original error that caused this error
|
|
69
|
-
*/
|
|
70
19
|
constructor(message: string, options?: {
|
|
71
20
|
cause?: unknown;
|
|
72
21
|
});
|
|
@@ -83,18 +32,17 @@ export declare class VectorError extends Error {
|
|
|
83
32
|
* @throws {VectorError} If the value is not a valid vector meeting all constraints
|
|
84
33
|
*
|
|
85
34
|
* @example
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
* ```
|
|
95
|
-
* ```
|
|
35
|
+
* ```typescript
|
|
36
|
+
* // Basic validation — passes silently for a valid vector
|
|
37
|
+
* AssertVector([1, 2, 3]);
|
|
38
|
+
* // Validate with size constraint
|
|
39
|
+
* AssertVector([1, 2], { size: 2 });
|
|
40
|
+
* // Throws VectorError for non-array input
|
|
41
|
+
* AssertVector("not a vector"); // throws VectorError
|
|
42
|
+
* ```
|
|
96
43
|
*/
|
|
97
|
-
export declare function AssertVector(vector: unknown
|
|
44
|
+
export declare function AssertVector(vector: unknown): asserts vector is TVector;
|
|
45
|
+
export declare function ValidateVector(vector: unknown): boolean;
|
|
98
46
|
/**
|
|
99
47
|
* Validates that an unknown value is a valid 2D vector (exactly 2 numeric components).
|
|
100
48
|
*
|
|
@@ -103,15 +51,14 @@ export declare function AssertVector(vector: unknown, args?: TAssertVectorArgs,
|
|
|
103
51
|
* @throws {VectorError} If the value is not a 2-component vector
|
|
104
52
|
*
|
|
105
53
|
* @example
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
* ```
|
|
112
|
-
* ```
|
|
54
|
+
* ```typescript
|
|
55
|
+
* AssertVector2([1, 2]); // passes
|
|
56
|
+
* AssertVector2([1, 2, 3]); // throws — too many components
|
|
57
|
+
* AssertVector2("not a vec"); // throws
|
|
58
|
+
* ```
|
|
113
59
|
*/
|
|
114
|
-
export declare function AssertVector2(vector: unknown
|
|
60
|
+
export declare function AssertVector2(vector: unknown): asserts vector is TVector2;
|
|
61
|
+
export declare function ValidateVector2(vector: unknown): boolean;
|
|
115
62
|
/**
|
|
116
63
|
* Validates that an unknown value is a valid 3D vector (exactly 3 numeric components).
|
|
117
64
|
*
|
|
@@ -120,15 +67,14 @@ export declare function AssertVector2(vector: unknown, exception?: IAssertVector
|
|
|
120
67
|
* @throws {VectorError} If the value is not a 3-component vector
|
|
121
68
|
*
|
|
122
69
|
* @example
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
* ```
|
|
129
|
-
* ```
|
|
70
|
+
* ```typescript
|
|
71
|
+
* AssertVector3([1, 2, 3]); // passes
|
|
72
|
+
* AssertVector3([1, 2]); // throws — too few components
|
|
73
|
+
* AssertVector3(null); // throws
|
|
74
|
+
* ```
|
|
130
75
|
*/
|
|
131
|
-
export declare function AssertVector3(vector: unknown
|
|
76
|
+
export declare function AssertVector3(vector: unknown): asserts vector is TVector3;
|
|
77
|
+
export declare function ValidateVector3(vector: unknown): boolean;
|
|
132
78
|
/**
|
|
133
79
|
* Validates that an unknown value is a valid 4D vector (exactly 4 numeric components).
|
|
134
80
|
*
|
|
@@ -136,151 +82,35 @@ export declare function AssertVector3(vector: unknown, exception?: IAssertVector
|
|
|
136
82
|
* @param exception - Custom exception details if validation fails
|
|
137
83
|
* @throws {VectorError} If the value is not a 4-component vector
|
|
138
84
|
*
|
|
139
|
-
* @example
|
|
140
|
-
* ```typescript
|
|
141
|
-
* ```typescript
|
|
142
|
-
* AssertVector4([1, 2, 3, 4]); // passes
|
|
143
|
-
* AssertVector4([1, 2, 3]); // throws — too few components
|
|
144
|
-
* AssertVector4(undefined); // throws
|
|
145
|
-
* ```
|
|
146
|
-
* ```
|
|
147
|
-
*/
|
|
148
|
-
export declare function AssertVector4(vector: unknown, exception?: IAssertVectorException): asserts vector is TVector4;
|
|
149
|
-
/**
|
|
150
|
-
* Validates that an unknown value is a valid vector element (a finite, non-NaN number).
|
|
151
|
-
*
|
|
152
|
-
* Supports optional numeric constraints such as range bounds, integer enforcement,
|
|
153
|
-
* and finiteness checks. Throws `VectorError` with the component index when available.
|
|
154
|
-
*
|
|
155
|
-
* @param value - The value to validate as a vector element
|
|
156
|
-
* @param args - Numeric constraints (finite, integer, gt, gte, lt, lte, eq)
|
|
157
|
-
* @param exception - Custom exception details, optionally including a component `index`
|
|
158
|
-
* @throws {VectorError} If the value is not a valid number or violates any constraint
|
|
159
|
-
*
|
|
160
|
-
* @example
|
|
161
|
-
* ```typescript
|
|
162
|
-
* ```typescript
|
|
163
|
-
* AssertVectorValue(3.14); // passes
|
|
164
|
-
* AssertVectorValue(3.14, { finite: true }); // passes
|
|
165
|
-
* AssertVectorValue(Infinity, { finite: true }); // throws
|
|
166
|
-
* AssertVectorValue(NaN); // throws
|
|
167
|
-
* AssertVectorValue(5, { gte: 0, lte: 10 }); // passes
|
|
168
|
-
* ```
|
|
169
|
-
* ```
|
|
170
|
-
*/
|
|
171
|
-
export declare function AssertVectorValue(value: unknown, args?: TAssertVectorValueArgs, exception?: IAssertVectorException): asserts value is number;
|
|
172
|
-
/**
|
|
173
|
-
* Validates an array of vectors, ensuring each vector is valid and optionally
|
|
174
|
-
* enforcing that all vectors share the same size.
|
|
175
|
-
*
|
|
176
|
-
* @param vectors - The array of vectors to validate (must be non-empty)
|
|
177
|
-
* @param args - Validation constraints applied to each vector; set `sameSize: true`
|
|
178
|
-
* to require all vectors to have identical lengths
|
|
179
|
-
* @param exception - Custom exception details if validation fails
|
|
180
|
-
* @throws {VectorError} If the array is empty, any vector is invalid, or sizes
|
|
181
|
-
* differ when `sameSize` is `true`
|
|
182
|
-
*
|
|
183
|
-
* @example
|
|
184
|
-
* ```typescript
|
|
185
|
-
* // Validate an array of 3D vectors
|
|
186
|
-
* AssertVectors([[1, 2, 3], [4, 5, 6]]);
|
|
187
|
-
* // Require all vectors to share the same length
|
|
188
|
-
* AssertVectors([[1, 2], [3, 4]], { sameSize: true });
|
|
189
|
-
* // Throws because vectors have different sizes
|
|
190
|
-
* AssertVectors([[1, 2], [1, 2, 3]], { sameSize: true }); // throws
|
|
191
|
-
* ```
|
|
192
|
-
*/
|
|
193
|
-
export declare function AssertVectors(vectors: unknown[], args?: IAssertVectorsArgs, exception?: IAssertVectorException): void;
|
|
194
|
-
/**
|
|
195
|
-
* Validates that an unknown value is a valid vector without throwing an error.
|
|
196
|
-
*
|
|
197
|
-
* This function performs the same validation as AssertVector but returns
|
|
198
|
-
* a boolean instead of throwing an exception, making it suitable for
|
|
199
|
-
* conditional logic where exceptions are not desired.
|
|
200
|
-
*
|
|
201
|
-
* @param vector - The value to validate as a vector
|
|
202
|
-
* @param args - Validation configuration options
|
|
203
|
-
* @returns true if the vector is valid, false otherwise
|
|
204
|
-
*
|
|
205
|
-
* @example
|
|
206
|
-
* ```typescript
|
|
207
|
-
* if (ValidateVector([1, 2, 3])) {
|
|
208
|
-
* // Process the valid vector
|
|
209
|
-
* }
|
|
210
|
-
* ```
|
|
211
|
-
*/
|
|
212
|
-
export declare function ValidateVector(vector: unknown, args?: TAssertVectorArgs): vector is TVector;
|
|
213
|
-
/**
|
|
214
|
-
* Validates that an unknown value is a valid 2D vector without throwing an error.
|
|
215
|
-
*
|
|
216
|
-
* @param vector - The value to validate as a 2D vector
|
|
217
|
-
* @returns true if the vector is valid, false otherwise
|
|
218
|
-
*
|
|
219
|
-
* @example
|
|
220
|
-
* ```typescript
|
|
221
|
-
* if (ValidateVector2([1, 2])) {
|
|
222
|
-
* // Process the valid 2D vector
|
|
223
|
-
* }
|
|
224
|
-
* ```
|
|
225
|
-
*/
|
|
226
|
-
export declare function ValidateVector2(vector: unknown): vector is TVector2;
|
|
227
|
-
/**
|
|
228
|
-
* Validates that an unknown value is a valid 3D vector without throwing an error.
|
|
229
|
-
*
|
|
230
|
-
* @param vector - The value to validate as a 3D vector
|
|
231
|
-
* @returns true if the vector is valid, false otherwise
|
|
232
|
-
*
|
|
233
|
-
* @example
|
|
234
|
-
* ```typescript
|
|
235
|
-
* if (ValidateVector3([1, 2, 3])) {
|
|
236
|
-
* // Process the valid 3D vector
|
|
237
|
-
* }
|
|
238
|
-
* ```
|
|
239
|
-
*/
|
|
240
|
-
export declare function ValidateVector3(vector: unknown): vector is TVector3;
|
|
241
|
-
/**
|
|
242
|
-
* Validates that an unknown value is a valid 4D vector without throwing an error.
|
|
243
|
-
*
|
|
244
|
-
* @param vector - The value to validate as a 4D vector
|
|
245
|
-
* @returns true if the vector is valid, false otherwise
|
|
246
|
-
*
|
|
247
85
|
* @example
|
|
248
86
|
* ```typescript
|
|
249
|
-
*
|
|
250
|
-
*
|
|
251
|
-
*
|
|
87
|
+
* AssertVector4([1, 2, 3, 4]); // passes
|
|
88
|
+
* AssertVector4([1, 2, 3]); // throws — too few components
|
|
89
|
+
* AssertVector4(undefined); // throws
|
|
252
90
|
* ```
|
|
253
91
|
*/
|
|
254
|
-
export declare function
|
|
92
|
+
export declare function AssertVector4(vector: unknown): asserts vector is TVector4;
|
|
93
|
+
export declare function ValidateVector4(vector: unknown): boolean;
|
|
94
|
+
export declare const VECTOR_SAME_SIZE_SCHEMA: z.ZodArray<z.ZodArray<z.ZodNumber>>;
|
|
95
|
+
export type TVectorSameSize = z.infer<typeof VECTOR_SAME_SIZE_SCHEMA>;
|
|
96
|
+
export declare function AssertVectorSameSize(vectors: unknown[]): asserts vectors is TVectorSameSize;
|
|
97
|
+
export declare function ValidateVectorSameSize(vectors: unknown[]): boolean;
|
|
255
98
|
/**
|
|
256
|
-
* Validates that
|
|
99
|
+
* Validates that the given vector is not a zero vector (all components are not zero).
|
|
100
|
+
* Throws a VectorError if the vector is zero.
|
|
257
101
|
*
|
|
258
|
-
* @param
|
|
259
|
-
* @param
|
|
260
|
-
* @
|
|
102
|
+
* @param vector - The vector to validate
|
|
103
|
+
* @param label - The label for the vector used in the error message (default: 'Vector')
|
|
104
|
+
* @throws {VectorError} If the vector is a zero vector
|
|
261
105
|
*
|
|
262
106
|
* @example
|
|
263
107
|
* ```typescript
|
|
264
|
-
*
|
|
265
|
-
*
|
|
266
|
-
* }
|
|
267
|
-
* ```
|
|
268
|
-
*/
|
|
269
|
-
export declare function ValidateVectorValue(value: unknown, args?: TAssertVectorValueArgs): value is number;
|
|
270
|
-
/**
|
|
271
|
-
* Validates that an unknown value is an array of valid vectors without throwing an error.
|
|
272
|
-
*
|
|
273
|
-
* @param vectors - The value to validate as an array of vectors
|
|
274
|
-
* @param args - Validation configuration options
|
|
275
|
-
* @returns true if all vectors are valid, false otherwise
|
|
108
|
+
* const v = [1, 2, 3];
|
|
109
|
+
* AssertVectorNonZero(v); // Valid
|
|
276
110
|
*
|
|
277
|
-
*
|
|
278
|
-
*
|
|
279
|
-
* if (ValidateVectors([v1, v2, v3])) {
|
|
280
|
-
* // Process the valid vector array
|
|
281
|
-
* }
|
|
111
|
+
* const zero = [0, 0, 0];
|
|
112
|
+
* AssertVectorNonZero(zero, 'Direction'); // Throws VectorError: Direction must not be zero
|
|
282
113
|
* ```
|
|
283
114
|
*/
|
|
284
|
-
export declare function
|
|
285
|
-
export {};
|
|
115
|
+
export declare function AssertVectorNonZero(vector: TVector, label?: string): void;
|
|
286
116
|
//# sourceMappingURL=asserts.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asserts.d.ts","sourceRoot":"","sources":["../../src/vectors/asserts.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"asserts.d.ts","sourceRoot":"","sources":["../../src/vectors/asserts.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAiE,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,QAAQ,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtJ,OAAO,CAAC,MAAM,KAAK,CAAC;AAEpB;;;;;;;;GAQG;AACH,qBAAa,WAAY,SAAQ,KAAK;IACrC,SAAgB,IAAI,EAAE,MAAM,CAAkB;gBAElC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE;CAO1D;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,IAAI,OAAO,CASvE;AACD,wBAAgB,cAAc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