@bitbybit-dev/base 1.2.0 → 1.3.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/lib/api/GlobalCDNProvider.js +1 -1
- package/lib/api/inputs/base-inputs.d.ts +13 -12
- package/lib/api/inputs/color-inputs.d.ts +97 -48
- package/lib/api/inputs/color-inputs.js +95 -46
- package/lib/api/inputs/dates-inputs.d.ts +67 -26
- package/lib/api/inputs/dates-inputs.js +57 -16
- package/lib/api/inputs/io-inputs.d.ts +13 -15
- package/lib/api/inputs/io-inputs.js +7 -8
- package/lib/api/inputs/line-inputs.d.ts +88 -33
- package/lib/api/inputs/line-inputs.js +61 -11
- package/lib/api/inputs/lists-inputs.d.ts +207 -96
- package/lib/api/inputs/lists-inputs.js +153 -45
- package/lib/api/inputs/logic-inputs.d.ts +52 -22
- package/lib/api/inputs/logic-inputs.js +41 -12
- package/lib/api/inputs/math-inputs.d.ts +113 -52
- package/lib/api/inputs/math-inputs.js +112 -51
- package/lib/api/inputs/mesh-inputs.d.ts +30 -11
- package/lib/api/inputs/mesh-inputs.js +21 -3
- package/lib/api/inputs/point-inputs.d.ts +240 -107
- package/lib/api/inputs/point-inputs.js +199 -73
- package/lib/api/inputs/polyline-inputs.d.ts +68 -28
- package/lib/api/inputs/polyline-inputs.js +48 -13
- package/lib/api/inputs/text-inputs.d.ts +117 -46
- package/lib/api/inputs/text-inputs.js +111 -41
- package/lib/api/inputs/transforms-inputs.d.ts +65 -23
- package/lib/api/inputs/transforms-inputs.js +64 -22
- package/lib/api/inputs/vector-inputs.d.ts +154 -76
- package/lib/api/inputs/vector-inputs.js +132 -57
- package/lib/api/models/point/hex-grid-data.d.ts +1 -1
- package/lib/api/models/point/hex-grid-data.js +1 -1
- package/lib/api/services/color.d.ts +149 -70
- package/lib/api/services/color.js +149 -70
- package/lib/api/services/dates.d.ts +313 -150
- package/lib/api/services/dates.js +313 -150
- package/lib/api/services/line.d.ts +138 -68
- package/lib/api/services/line.js +138 -68
- package/lib/api/services/lists.d.ts +357 -177
- package/lib/api/services/lists.js +357 -177
- package/lib/api/services/logic.d.ts +98 -45
- package/lib/api/services/logic.js +98 -45
- package/lib/api/services/math.d.ts +363 -211
- package/lib/api/services/math.js +363 -211
- package/lib/api/services/mesh.d.ts +73 -31
- package/lib/api/services/mesh.js +73 -31
- package/lib/api/services/point.d.ts +367 -147
- package/lib/api/services/point.js +367 -147
- package/lib/api/services/polyline.d.ts +146 -71
- package/lib/api/services/polyline.js +146 -71
- package/lib/api/services/text.d.ts +320 -165
- package/lib/api/services/text.js +320 -165
- package/lib/api/services/transforms.d.ts +145 -58
- package/lib/api/services/transforms.js +145 -58
- package/lib/api/services/vector.d.ts +381 -156
- package/lib/api/services/vector.js +381 -156
- package/package.json +1 -1
|
@@ -2,393 +2,618 @@ import * as Inputs from "../inputs";
|
|
|
2
2
|
import { GeometryHelper } from "./geometry-helper";
|
|
3
3
|
import { MathBitByBit } from "./math";
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* Vector maths on plain number arrays. A vector is an array of numbers; in 3D it is `[x, y, z]`
|
|
6
|
+
* with Y pointing up, the same shape as a point, so the two can be passed to each other's methods.
|
|
7
|
+
* Every method returns a new array or a number and never changes its inputs. Angles are in degrees.
|
|
8
8
|
*/
|
|
9
9
|
export declare class Vector {
|
|
10
10
|
private readonly math;
|
|
11
11
|
private readonly geometryHelper;
|
|
12
12
|
constructor(math: MathBitByBit, geometryHelper: GeometryHelper);
|
|
13
13
|
/**
|
|
14
|
-
* Removes
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
14
|
+
* Removes every repeated vector from a list, keeping the first occurrence of each.
|
|
15
|
+
*
|
|
16
|
+
* Two vectors count as the same when every entry differs by less than `tolerance`.
|
|
17
|
+
* Example: [[1,2,3], [4,5,6], [1,2,3], [7,8,9]] -> [[1,2,3], [4,5,6], [7,8,9]]
|
|
18
|
+
* @param inputs - Vectors to filter and the tolerance
|
|
19
|
+
* @returns The vectors without repeats, in their original order
|
|
18
20
|
* @group remove
|
|
19
21
|
* @shortname remove all duplicates
|
|
20
22
|
* @drawable false
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* const unique = bitbybit.vector.removeAllDuplicateVectors({
|
|
26
|
+
* vectors: [[1, 2, 3], [4, 5, 6], [1, 2, 3]],
|
|
27
|
+
* tolerance: 1e-7,
|
|
28
|
+
* });
|
|
29
|
+
* ```
|
|
21
30
|
*/
|
|
22
31
|
removeAllDuplicateVectors(inputs: Inputs.Vector.RemoveAllDuplicateVectorsDto): number[][];
|
|
23
32
|
/**
|
|
24
|
-
* Removes
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
33
|
+
* Removes a vector when it repeats the one right before it; the same vector further away is
|
|
34
|
+
* kept.
|
|
35
|
+
*
|
|
36
|
+
* With `checkFirstAndLast` on, a last vector that repeats the first is dropped too, which
|
|
37
|
+
* closes a loop of points cleanly. Entries within `tolerance` of each other count as equal.
|
|
38
|
+
* Example: [[1,2], [1,2], [3,4], [1,2]] -> [[1,2], [3,4], [1,2]]
|
|
39
|
+
* @param inputs - Vectors to filter, whether to compare the first and last, and the tolerance
|
|
40
|
+
* @returns The vectors without consecutive repeats
|
|
28
41
|
* @group remove
|
|
29
42
|
* @shortname remove consecutive duplicates
|
|
30
43
|
* @drawable false
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* const cleaned = bitbybit.vector.removeConsecutiveDuplicateVectors({
|
|
47
|
+
* vectors: [[0, 0], [0, 0], [1, 1], [0, 0]],
|
|
48
|
+
* checkFirstAndLast: true,
|
|
49
|
+
* tolerance: 1e-7,
|
|
50
|
+
* });
|
|
51
|
+
* ```
|
|
31
52
|
*/
|
|
32
53
|
removeConsecutiveDuplicateVectors(inputs: Inputs.Vector.RemoveConsecutiveDuplicateVectorsDto): number[][];
|
|
33
54
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
55
|
+
* Tells whether two vectors are the same within a tolerance, entry by entry.
|
|
56
|
+
*
|
|
57
|
+
* Vectors of different length are never the same.
|
|
58
|
+
* Example: [1,2,3] and [1.0001,2.0001,3.0001] with tolerance 0.001 -> true
|
|
59
|
+
* @param inputs - The two vectors and the tolerance
|
|
60
|
+
* @returns True when every entry differs by less than the tolerance
|
|
38
61
|
* @group validate
|
|
39
62
|
* @shortname vectors the same
|
|
40
63
|
* @drawable false
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* const same = bitbybit.vector.vectorsTheSame({ vec1: [1, 2, 3], vec2: [1, 2, 3.0000001], tolerance: 1e-6 });
|
|
67
|
+
* ```
|
|
41
68
|
*/
|
|
42
69
|
vectorsTheSame(inputs: Inputs.Vector.VectorsTheSameDto): boolean;
|
|
43
70
|
/**
|
|
44
|
-
* Measures the angle between two vectors in degrees
|
|
45
|
-
*
|
|
46
|
-
*
|
|
71
|
+
* Measures the angle between two vectors in degrees, always between 0 and 180.
|
|
72
|
+
*
|
|
73
|
+
* The direction of turning is not considered; use `signedAngleBetween` for that.
|
|
74
|
+
* Example: [1,0,0] and [0,1,0] -> 90
|
|
75
|
+
* @param inputs - The two vectors
|
|
76
|
+
* @returns Angle in degrees
|
|
47
77
|
* @group angles
|
|
48
78
|
* @shortname angle
|
|
49
|
-
* @returns Number in degrees
|
|
50
79
|
* @drawable false
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* const angle = bitbybit.vector.angleBetween({ first: [1, 0, 0], second: [0, 1, 0] });
|
|
83
|
+
* ```
|
|
51
84
|
*/
|
|
52
85
|
angleBetween(inputs: Inputs.Vector.TwoVectorsDto): number;
|
|
53
86
|
/**
|
|
54
|
-
* Measures the
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
87
|
+
* Measures the signed angle from the first 2D vector to the second, in degrees from -180 to
|
|
88
|
+
* 180.
|
|
89
|
+
*
|
|
90
|
+
* Only the first two entries of each vector are used; a positive angle turns counter-clockwise.
|
|
91
|
+
* Example: [1,0] to [0,1] -> 90, [0,1] to [1,0] -> -90
|
|
92
|
+
* @param inputs - The two 2D vectors
|
|
93
|
+
* @returns Signed angle in degrees
|
|
58
94
|
* @group angles
|
|
59
95
|
* @shortname angle normalized 2d
|
|
60
96
|
* @drawable false
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* const angle = bitbybit.vector.angleBetweenNormalized2d({ first: [1, 0], second: [0, 1] });
|
|
100
|
+
* ```
|
|
61
101
|
*/
|
|
62
102
|
angleBetweenNormalized2d(inputs: Inputs.Vector.TwoVectorsDto): number;
|
|
63
103
|
/**
|
|
64
|
-
* Measures
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
104
|
+
* Measures the angle from the first vector to the second, turning around a reference direction,
|
|
105
|
+
* in degrees from 0 to 360.
|
|
106
|
+
*
|
|
107
|
+
* The turn is counter-clockwise when the reference vector points toward you.
|
|
108
|
+
* Example: [1,0,0] to [0,0,-1] around [0,1,0] -> 90
|
|
109
|
+
* @param inputs - The two vectors and the reference direction to turn around
|
|
110
|
+
* @returns Angle in degrees from 0 to 360
|
|
68
111
|
* @group angles
|
|
69
112
|
* @shortname positive angle
|
|
70
113
|
* @drawable false
|
|
114
|
+
* @example
|
|
115
|
+
* ```typescript
|
|
116
|
+
* const angle = bitbybit.vector.positiveAngleBetween({ first: [1, 0, 0], second: [0, 0, -1], reference: [0, 1, 0] });
|
|
117
|
+
* ```
|
|
71
118
|
*/
|
|
72
119
|
positiveAngleBetween(inputs: Inputs.Vector.TwoVectorsReferenceDto): number;
|
|
73
120
|
/**
|
|
74
|
-
* Adds
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
121
|
+
* Adds a list of vectors together entry by entry into one vector.
|
|
122
|
+
*
|
|
123
|
+
* The result has as many entries as the first vector.
|
|
124
|
+
* Example: [[1,2,3], [4,5,6], [7,8,9]] -> [12,15,18]
|
|
125
|
+
* @param inputs - Vectors to add
|
|
126
|
+
* @returns The vector of sums
|
|
78
127
|
* @group sum
|
|
79
128
|
* @shortname add all
|
|
80
129
|
* @drawable false
|
|
130
|
+
* @example
|
|
131
|
+
* ```typescript
|
|
132
|
+
* const total = bitbybit.vector.addAll({ vectors: [[1, 2, 3], [4, 5, 6], [7, 8, 9]] });
|
|
133
|
+
* ```
|
|
81
134
|
*/
|
|
82
135
|
addAll(inputs: Inputs.Vector.VectorsDto): number[];
|
|
83
136
|
/**
|
|
84
|
-
* Adds two vectors
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
* @
|
|
137
|
+
* Adds two vectors entry by entry.
|
|
138
|
+
*
|
|
139
|
+
* Example: [1,2,3] + [4,5,6] -> [5,7,9]
|
|
140
|
+
* @param inputs - The two vectors to add
|
|
141
|
+
* @returns The vector of sums
|
|
88
142
|
* @group sum
|
|
89
143
|
* @shortname add
|
|
90
144
|
* @drawable false
|
|
145
|
+
* @example
|
|
146
|
+
* ```typescript
|
|
147
|
+
* const sum = bitbybit.vector.add({ first: [1, 2, 3], second: [4, 5, 6] });
|
|
148
|
+
* ```
|
|
91
149
|
*/
|
|
92
150
|
add(inputs: Inputs.Vector.TwoVectorsDto): number[];
|
|
93
151
|
/**
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
* @
|
|
152
|
+
* Tells whether every value in a list of booleans is true.
|
|
153
|
+
*
|
|
154
|
+
* Example: [true, true, true] -> true, [true, false, true] -> false
|
|
155
|
+
* @param inputs - The booleans to check
|
|
156
|
+
* @returns True when no entry is false
|
|
98
157
|
* @group sum
|
|
99
158
|
* @shortname all
|
|
100
159
|
* @drawable false
|
|
160
|
+
* @example
|
|
161
|
+
* ```typescript
|
|
162
|
+
* const allTrue = bitbybit.vector.all({ vector: [true, true, false] });
|
|
163
|
+
* ```
|
|
101
164
|
*/
|
|
102
165
|
all(inputs: Inputs.Vector.VectorBoolDto): boolean;
|
|
103
166
|
/**
|
|
104
|
-
* Computes the cross product of two 3D vectors
|
|
105
|
-
*
|
|
106
|
-
*
|
|
167
|
+
* Computes the cross product of two 3D vectors: a vector at right angles to both.
|
|
168
|
+
*
|
|
169
|
+
* Its direction follows the right-hand rule and its length is the area of the parallelogram the
|
|
170
|
+
* two vectors span.
|
|
171
|
+
* Example: [1,0,0] x [0,1,0] -> [0,0,1]
|
|
172
|
+
* @param inputs - The two 3D vectors
|
|
173
|
+
* @returns The vector perpendicular to both
|
|
107
174
|
* @group base
|
|
108
175
|
* @shortname cross
|
|
109
|
-
* @returns Crossed vector
|
|
110
176
|
* @drawable false
|
|
177
|
+
* @example
|
|
178
|
+
* ```typescript
|
|
179
|
+
* const normal = bitbybit.vector.cross({ first: [1, 0, 0], second: [0, 1, 0] });
|
|
180
|
+
* ```
|
|
111
181
|
*/
|
|
112
182
|
cross(inputs: Inputs.Vector.TwoVectorsDto): number[];
|
|
113
183
|
/**
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
184
|
+
* Computes the squared distance between two vectors, which avoids the square root when only
|
|
185
|
+
* comparing distances.
|
|
186
|
+
*
|
|
187
|
+
* Example: [0,0,0] to [3,4,0] -> 25
|
|
188
|
+
* @param inputs - The two vectors
|
|
189
|
+
* @returns The squared distance
|
|
118
190
|
* @group distance
|
|
119
191
|
* @shortname dist squared
|
|
120
192
|
* @drawable false
|
|
193
|
+
* @example
|
|
194
|
+
* ```typescript
|
|
195
|
+
* const d2 = bitbybit.vector.distSquared({ first: [0, 0, 0], second: [3, 4, 0] });
|
|
196
|
+
* ```
|
|
121
197
|
*/
|
|
122
198
|
distSquared(inputs: Inputs.Vector.TwoVectorsDto): number;
|
|
123
199
|
/**
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
* @
|
|
200
|
+
* Computes the straight-line distance between two vectors.
|
|
201
|
+
*
|
|
202
|
+
* Example: [0,0,0] to [3,4,0] -> 5
|
|
203
|
+
* @param inputs - The two vectors
|
|
204
|
+
* @returns The distance in model units
|
|
128
205
|
* @group distance
|
|
129
206
|
* @shortname dist
|
|
130
207
|
* @drawable false
|
|
208
|
+
* @example
|
|
209
|
+
* ```typescript
|
|
210
|
+
* const distance = bitbybit.vector.dist({ first: [0, 0, 0], second: [3, 4, 0] });
|
|
211
|
+
* ```
|
|
131
212
|
*/
|
|
132
213
|
dist(inputs: Inputs.Vector.TwoVectorsDto): number;
|
|
133
214
|
/**
|
|
134
|
-
* Divides
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
* @
|
|
215
|
+
* Divides every entry of a vector by one number.
|
|
216
|
+
*
|
|
217
|
+
* Example: [10,20,30] / 2 -> [5,10,15]
|
|
218
|
+
* @param inputs - The vector and the number to divide by
|
|
219
|
+
* @returns The divided vector
|
|
138
220
|
* @group base
|
|
139
221
|
* @shortname div
|
|
140
222
|
* @drawable false
|
|
223
|
+
* @example
|
|
224
|
+
* ```typescript
|
|
225
|
+
* const half = bitbybit.vector.div({ vector: [10, 20, 30], scalar: 2 });
|
|
226
|
+
* ```
|
|
141
227
|
*/
|
|
142
228
|
div(inputs: Inputs.Vector.VectorScalarDto): number[];
|
|
143
229
|
/**
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
* @
|
|
230
|
+
* Subtracts the first value of a vector from its last, which for a sorted list is its range.
|
|
231
|
+
*
|
|
232
|
+
* Example: [1,3,5,9] -> 8
|
|
233
|
+
* @param inputs - The vector
|
|
234
|
+
* @returns Last value minus first value
|
|
148
235
|
* @group base
|
|
149
236
|
* @shortname domain
|
|
150
237
|
* @drawable false
|
|
238
|
+
* @example
|
|
239
|
+
* ```typescript
|
|
240
|
+
* const span = bitbybit.vector.domain({ vector: [1, 3, 5, 9] });
|
|
241
|
+
* ```
|
|
151
242
|
*/
|
|
152
243
|
domain(inputs: Inputs.Vector.VectorDto): number;
|
|
153
244
|
/**
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
245
|
+
* Computes the dot product of two vectors: the sum of the products of matching entries.
|
|
246
|
+
*
|
|
247
|
+
* It is 0 for vectors at right angles and, for unit vectors, the cosine of the angle between
|
|
248
|
+
* them.
|
|
249
|
+
* Example: [1,2,3] and [4,5,6] -> 32
|
|
250
|
+
* @param inputs - The two vectors
|
|
251
|
+
* @returns The dot product
|
|
158
252
|
* @group base
|
|
159
253
|
* @shortname dot
|
|
160
254
|
* @drawable false
|
|
255
|
+
* @example
|
|
256
|
+
* ```typescript
|
|
257
|
+
* const projection = bitbybit.vector.dot({ first: [1, 2, 3], second: [4, 5, 6] });
|
|
258
|
+
* ```
|
|
161
259
|
*/
|
|
162
260
|
dot(inputs: Inputs.Vector.TwoVectorsDto): number;
|
|
163
261
|
/**
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
* @
|
|
168
|
-
*
|
|
262
|
+
* Marks which entries of a vector are finite numbers.
|
|
263
|
+
*
|
|
264
|
+
* Example: [1, 2, Infinity, 3] -> [true, true, false, true]
|
|
265
|
+
* @param inputs - The vector to check
|
|
266
|
+
* @returns One boolean per entry, true when it is finite
|
|
169
267
|
* @group validate
|
|
170
268
|
* @shortname finite
|
|
171
269
|
* @drawable false
|
|
270
|
+
* @example
|
|
271
|
+
* ```typescript
|
|
272
|
+
* const flags = bitbybit.vector.finite({ vector: [1, Infinity, 3] });
|
|
273
|
+
* ```
|
|
172
274
|
*/
|
|
173
275
|
finite(inputs: Inputs.Vector.VectorDto): boolean[];
|
|
174
276
|
/**
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
* @
|
|
277
|
+
* Tells whether a vector has no length, that is, every entry is exactly 0.
|
|
278
|
+
*
|
|
279
|
+
* Example: [0,0,0] -> true, [0,0,0.001] -> false
|
|
280
|
+
* @param inputs - The vector to check
|
|
281
|
+
* @returns True when the length is 0
|
|
179
282
|
* @group validate
|
|
180
283
|
* @shortname isZero
|
|
181
284
|
* @drawable false
|
|
285
|
+
* @example
|
|
286
|
+
* ```typescript
|
|
287
|
+
* const zero = bitbybit.vector.isZero({ vector: [0, 0, 0] });
|
|
288
|
+
* ```
|
|
182
289
|
*/
|
|
183
290
|
isZero(inputs: Inputs.Vector.VectorDto): boolean;
|
|
184
291
|
/**
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
292
|
+
* Blends two vectors linearly by a fraction.
|
|
293
|
+
*
|
|
294
|
+
* `fraction` is the share of `first`: 1 gives `first`, 0 gives `second`, 0.5 the midpoint.
|
|
295
|
+
* Example: [0,0,0] and [10,10,10] at 0.5 -> [5,5,5]
|
|
296
|
+
* @param inputs - The two vectors and the fraction of the first
|
|
297
|
+
* @returns The blended vector
|
|
189
298
|
* @group distance
|
|
190
299
|
* @shortname lerp
|
|
191
300
|
* @drawable false
|
|
301
|
+
* @example
|
|
302
|
+
* ```typescript
|
|
303
|
+
* const mid = bitbybit.vector.lerp({ first: [0, 0, 0], second: [10, 10, 10], fraction: 0.5 });
|
|
304
|
+
* ```
|
|
192
305
|
*/
|
|
193
306
|
lerp(inputs: Inputs.Vector.FractionTwoVectorsDto): number[];
|
|
194
307
|
/**
|
|
195
|
-
* Finds the
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
* @
|
|
308
|
+
* Finds the largest value in a vector.
|
|
309
|
+
*
|
|
310
|
+
* Example: [3, 7, 2, 9, 1] -> 9
|
|
311
|
+
* @param inputs - The vector
|
|
312
|
+
* @returns The largest entry
|
|
199
313
|
* @group extract
|
|
200
314
|
* @shortname max
|
|
201
315
|
* @drawable false
|
|
316
|
+
* @example
|
|
317
|
+
* ```typescript
|
|
318
|
+
* const largest = bitbybit.vector.max({ vector: [3, 7, 2, 9, 1] });
|
|
319
|
+
* ```
|
|
202
320
|
*/
|
|
203
321
|
max(inputs: Inputs.Vector.VectorDto): number;
|
|
204
322
|
/**
|
|
205
|
-
* Finds the
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
* @
|
|
323
|
+
* Finds the smallest value in a vector.
|
|
324
|
+
*
|
|
325
|
+
* Example: [3, 7, 2, 9, 1] -> 1
|
|
326
|
+
* @param inputs - The vector
|
|
327
|
+
* @returns The smallest entry
|
|
209
328
|
* @group extract
|
|
210
329
|
* @shortname min
|
|
211
330
|
* @drawable false
|
|
331
|
+
* @example
|
|
332
|
+
* ```typescript
|
|
333
|
+
* const smallest = bitbybit.vector.min({ vector: [3, 7, 2, 9, 1] });
|
|
334
|
+
* ```
|
|
212
335
|
*/
|
|
213
336
|
min(inputs: Inputs.Vector.VectorDto): number;
|
|
214
337
|
/**
|
|
215
|
-
* Multiplies
|
|
216
|
-
*
|
|
217
|
-
*
|
|
218
|
-
* @
|
|
338
|
+
* Multiplies every entry of a vector by one number.
|
|
339
|
+
*
|
|
340
|
+
* Example: [2,3,4] x 5 -> [10,15,20]
|
|
341
|
+
* @param inputs - The vector and the number to multiply by
|
|
342
|
+
* @returns The scaled vector
|
|
219
343
|
* @group base
|
|
220
344
|
* @shortname mul
|
|
221
345
|
* @drawable false
|
|
346
|
+
* @example
|
|
347
|
+
* ```typescript
|
|
348
|
+
* const scaled = bitbybit.vector.mul({ vector: [2, 3, 4], scalar: 5 });
|
|
349
|
+
* ```
|
|
222
350
|
*/
|
|
223
351
|
mul(inputs: Inputs.Vector.VectorScalarDto): number[];
|
|
224
352
|
/**
|
|
225
|
-
*
|
|
226
|
-
*
|
|
227
|
-
*
|
|
228
|
-
* @
|
|
353
|
+
* Flips the sign of every entry, so the vector points the opposite way.
|
|
354
|
+
*
|
|
355
|
+
* Example: [5,-3,2] -> [-5,3,-2]
|
|
356
|
+
* @param inputs - The vector to flip
|
|
357
|
+
* @returns The negated vector
|
|
229
358
|
* @group base
|
|
230
359
|
* @shortname neg
|
|
231
360
|
* @drawable false
|
|
361
|
+
* @example
|
|
362
|
+
* ```typescript
|
|
363
|
+
* const opposite = bitbybit.vector.neg({ vector: [5, -3, 2] });
|
|
364
|
+
* ```
|
|
232
365
|
*/
|
|
233
366
|
neg(inputs: Inputs.Vector.VectorDto): number[];
|
|
234
367
|
/**
|
|
235
|
-
* Computes the squared
|
|
236
|
-
*
|
|
237
|
-
*
|
|
238
|
-
*
|
|
368
|
+
* Computes the squared length of a vector, which avoids the square root when only comparing
|
|
369
|
+
* lengths.
|
|
370
|
+
*
|
|
371
|
+
* Example: [3,4,0] -> 25
|
|
372
|
+
* @param inputs - The vector
|
|
373
|
+
* @returns The squared length
|
|
239
374
|
* @group base
|
|
240
375
|
* @shortname norm squared
|
|
241
376
|
* @drawable false
|
|
377
|
+
* @example
|
|
378
|
+
* ```typescript
|
|
379
|
+
* const n2 = bitbybit.vector.normSquared({ vector: [3, 4, 0] });
|
|
380
|
+
* ```
|
|
242
381
|
*/
|
|
243
382
|
normSquared(inputs: Inputs.Vector.VectorDto): number;
|
|
244
383
|
/**
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
* @
|
|
384
|
+
* Computes the length of a vector.
|
|
385
|
+
*
|
|
386
|
+
* Example: [3,4,0] -> 5, [1,0,0] -> 1
|
|
387
|
+
* @param inputs - The vector
|
|
388
|
+
* @returns The length in model units
|
|
249
389
|
* @group base
|
|
250
390
|
* @shortname norm
|
|
251
391
|
* @drawable false
|
|
392
|
+
* @example
|
|
393
|
+
* ```typescript
|
|
394
|
+
* const len = bitbybit.vector.norm({ vector: [3, 4, 0] });
|
|
395
|
+
* ```
|
|
252
396
|
*/
|
|
253
397
|
norm(inputs: Inputs.Vector.VectorDto): number;
|
|
254
398
|
/**
|
|
255
|
-
*
|
|
256
|
-
*
|
|
257
|
-
*
|
|
258
|
-
*
|
|
399
|
+
* Scales a 3D vector to length 1 while keeping its direction.
|
|
400
|
+
*
|
|
401
|
+
* A vector shorter than 1e-8 has no direction to keep, so the result is undefined.
|
|
402
|
+
* Example: [3,4,0] -> [0.6,0.8,0]
|
|
403
|
+
* @param inputs - The 3D vector to normalize
|
|
404
|
+
* @returns The unit vector, or undefined for a zero-length input
|
|
259
405
|
* @group base
|
|
260
406
|
* @shortname normalized
|
|
261
407
|
* @drawable false
|
|
408
|
+
* @example
|
|
409
|
+
* ```typescript
|
|
410
|
+
* const direction = bitbybit.vector.normalized({ vector: [3, 4, 0] });
|
|
411
|
+
* ```
|
|
262
412
|
*/
|
|
263
413
|
normalized(inputs: Inputs.Vector.VectorDto): number[] | undefined;
|
|
264
414
|
/**
|
|
265
|
-
* Finds
|
|
266
|
-
*
|
|
267
|
-
*
|
|
268
|
-
*
|
|
415
|
+
* Finds the point at a given distance from a start point along a direction.
|
|
416
|
+
*
|
|
417
|
+
* The direction is used as given, so a direction of length 2 travels twice the distance.
|
|
418
|
+
* Example: start [0,0,0], direction [1,0,0], distance 5 -> [5,0,0]
|
|
419
|
+
* @param inputs - The start point, the direction and the distance
|
|
420
|
+
* @returns The point on the ray
|
|
269
421
|
* @group base
|
|
270
422
|
* @shortname on ray
|
|
271
423
|
* @drawable false
|
|
424
|
+
* @example
|
|
425
|
+
* ```typescript
|
|
426
|
+
* const ahead = bitbybit.vector.onRay({ point: [0, 0, 0], vector: [1, 0, 0], distance: 5 });
|
|
427
|
+
* ```
|
|
272
428
|
*/
|
|
273
429
|
onRay(inputs: Inputs.Vector.RayPointDto): number[];
|
|
274
430
|
/**
|
|
275
|
-
*
|
|
276
|
-
*
|
|
277
|
-
*
|
|
278
|
-
* @
|
|
431
|
+
* Builds a 3D vector from its x, y and z values.
|
|
432
|
+
*
|
|
433
|
+
* Example: x=1, y=2, z=3 -> [1,2,3]
|
|
434
|
+
* @param inputs - The three values
|
|
435
|
+
* @returns The vector `[x, y, z]`
|
|
279
436
|
* @group create
|
|
280
437
|
* @shortname vector XYZ
|
|
281
438
|
* @drawable true
|
|
439
|
+
* @example
|
|
440
|
+
* ```typescript
|
|
441
|
+
* const up = bitbybit.vector.vectorXYZ({ x: 0, y: 1, z: 0 });
|
|
442
|
+
* ```
|
|
282
443
|
*/
|
|
283
444
|
vectorXYZ(inputs: Inputs.Vector.VectorXYZDto): Inputs.Base.Vector3;
|
|
284
445
|
/**
|
|
285
|
-
*
|
|
286
|
-
*
|
|
287
|
-
*
|
|
288
|
-
* @
|
|
446
|
+
* Builds a 2D vector from its x and y values.
|
|
447
|
+
*
|
|
448
|
+
* Example: x=3, y=4 -> [3,4]
|
|
449
|
+
* @param inputs - The two values
|
|
450
|
+
* @returns The vector `[x, y]`
|
|
289
451
|
* @group create
|
|
290
452
|
* @shortname vector XY
|
|
291
453
|
* @drawable true
|
|
454
|
+
* @example
|
|
455
|
+
* ```typescript
|
|
456
|
+
* const right = bitbybit.vector.vectorXY({ x: 1, y: 0 });
|
|
457
|
+
* ```
|
|
292
458
|
*/
|
|
293
459
|
vectorXY(inputs: Inputs.Vector.VectorXYDto): Inputs.Base.Vector2;
|
|
294
460
|
/**
|
|
295
|
-
*
|
|
296
|
-
*
|
|
297
|
-
*
|
|
298
|
-
* @
|
|
461
|
+
* Lists the whole numbers from 0 up to, but not including, `max`.
|
|
462
|
+
*
|
|
463
|
+
* Example: max=5 -> [0,1,2,3,4]
|
|
464
|
+
* @param inputs - The end of the range, which is left out
|
|
465
|
+
* @returns The numbers from 0 to max - 1
|
|
299
466
|
* @group create
|
|
300
467
|
* @shortname range
|
|
301
468
|
* @drawable false
|
|
469
|
+
* @example
|
|
470
|
+
* ```typescript
|
|
471
|
+
* const indices = bitbybit.vector.range({ max: 5 });
|
|
472
|
+
* ```
|
|
302
473
|
*/
|
|
303
474
|
range(inputs: Inputs.Vector.RangeMaxDto): number[];
|
|
304
475
|
/**
|
|
305
|
-
*
|
|
306
|
-
*
|
|
307
|
-
*
|
|
308
|
-
*
|
|
476
|
+
* Measures the angle from the first vector to the second, turning around a reference direction,
|
|
477
|
+
* in degrees from 0 to 360.
|
|
478
|
+
*
|
|
479
|
+
* The turn is counter-clockwise when the reference vector points toward you: a clockwise turn
|
|
480
|
+
* of 30 degrees reads as 330.
|
|
481
|
+
* Example: [1,0,0] to [0,0,-1] around [0,1,0] -> 90
|
|
482
|
+
* @param inputs - The two vectors and the reference direction to turn around
|
|
483
|
+
* @returns Angle in degrees from 0 to 360
|
|
309
484
|
* @group angles
|
|
310
485
|
* @shortname signed angle
|
|
311
486
|
* @drawable false
|
|
487
|
+
* @example
|
|
488
|
+
* ```typescript
|
|
489
|
+
* const angle = bitbybit.vector.signedAngleBetween({ first: [1, 0, 0], second: [0, 0, -1], reference: [0, 1, 0] });
|
|
490
|
+
* ```
|
|
312
491
|
*/
|
|
313
492
|
signedAngleBetween(inputs: Inputs.Vector.TwoVectorsReferenceDto): number;
|
|
314
493
|
/**
|
|
315
|
-
*
|
|
316
|
-
*
|
|
317
|
-
*
|
|
318
|
-
*
|
|
494
|
+
* Lists the numbers from `min` to `max`, stepping by `step`; `max` is included when a step
|
|
495
|
+
* lands on it.
|
|
496
|
+
*
|
|
497
|
+
* Example: min=0, max=10, step=2 -> [0,2,4,6,8,10]
|
|
498
|
+
* @param inputs - The start, the end and the step
|
|
499
|
+
* @returns The numbers in the span
|
|
319
500
|
* @group create
|
|
320
501
|
* @shortname span
|
|
321
502
|
* @drawable false
|
|
503
|
+
* @example
|
|
504
|
+
* ```typescript
|
|
505
|
+
* const values = bitbybit.vector.span({ min: 0, max: 10, step: 2.5 });
|
|
506
|
+
* ```
|
|
322
507
|
*/
|
|
323
508
|
span(inputs: Inputs.Vector.SpanDto): number[];
|
|
324
509
|
/**
|
|
325
|
-
*
|
|
326
|
-
*
|
|
327
|
-
*
|
|
328
|
-
*
|
|
510
|
+
* Lists `nrItems` numbers from `min` to `max` spaced by an easing curve, so they bunch up at
|
|
511
|
+
* one end or both.
|
|
512
|
+
*
|
|
513
|
+
* With `intervals` on, the result holds the gaps between neighbors instead of the values
|
|
514
|
+
* themselves.
|
|
515
|
+
* Example: min=0, max=100, nrItems=5, ease='easeInQuad' -> [0, 6.25, 25, 56.25, 100]
|
|
516
|
+
* @param inputs - The start, the end, the number of items, the easing and whether to return the gaps
|
|
517
|
+
* @returns The eased numbers, or the gaps between them
|
|
329
518
|
* @group create
|
|
330
519
|
* @shortname span ease items
|
|
331
520
|
* @drawable false
|
|
521
|
+
* @example
|
|
522
|
+
* ```typescript
|
|
523
|
+
* const eased = bitbybit.vector.spanEaseItems({ min: 0, max: 100, nrItems: 5, ease: Bit.Inputs.Math.easeEnum.easeInQuad, intervals: false });
|
|
524
|
+
* ```
|
|
332
525
|
*/
|
|
333
526
|
spanEaseItems(inputs: Inputs.Vector.SpanEaseItemsDto): number[];
|
|
334
527
|
/**
|
|
335
|
-
*
|
|
336
|
-
*
|
|
337
|
-
*
|
|
338
|
-
* @
|
|
528
|
+
* Lists `nrItems` evenly spaced numbers from `min` to `max`, both included.
|
|
529
|
+
*
|
|
530
|
+
* Example: min=0, max=10, nrItems=5 -> [0, 2.5, 5, 7.5, 10]
|
|
531
|
+
* @param inputs - The start, the end and the number of items
|
|
532
|
+
* @returns The evenly spaced numbers
|
|
339
533
|
* @group create
|
|
340
534
|
* @shortname span linear items
|
|
341
535
|
* @drawable false
|
|
536
|
+
* @example
|
|
537
|
+
* ```typescript
|
|
538
|
+
* const values = bitbybit.vector.spanLinearItems({ min: 0, max: 10, nrItems: 5 });
|
|
539
|
+
* ```
|
|
342
540
|
*/
|
|
343
541
|
spanLinearItems(inputs: Inputs.Vector.SpanLinearItemsDto): number[];
|
|
344
542
|
/**
|
|
345
|
-
* Subtracts the second vector from the first
|
|
346
|
-
*
|
|
347
|
-
*
|
|
348
|
-
* @
|
|
543
|
+
* Subtracts the second vector from the first, entry by entry.
|
|
544
|
+
*
|
|
545
|
+
* Example: [10,20,30] - [1,2,3] -> [9,18,27]
|
|
546
|
+
* @param inputs - The vector to subtract from and the vector to subtract
|
|
547
|
+
* @returns The vector of differences
|
|
349
548
|
* @group base
|
|
350
549
|
* @shortname sub
|
|
351
550
|
* @drawable false
|
|
551
|
+
* @example
|
|
552
|
+
* ```typescript
|
|
553
|
+
* const diff = bitbybit.vector.sub({ first: [10, 20, 30], second: [1, 2, 3] });
|
|
554
|
+
* ```
|
|
352
555
|
*/
|
|
353
556
|
sub(inputs: Inputs.Vector.TwoVectorsDto): number[];
|
|
354
557
|
/**
|
|
355
|
-
*
|
|
356
|
-
*
|
|
357
|
-
*
|
|
358
|
-
* @
|
|
558
|
+
* Adds up all values of a vector into one number.
|
|
559
|
+
*
|
|
560
|
+
* Example: [1,2,3,4] -> 10
|
|
561
|
+
* @param inputs - The vector to add up
|
|
562
|
+
* @returns The total
|
|
359
563
|
* @group base
|
|
360
564
|
* @shortname sum
|
|
361
565
|
* @drawable false
|
|
566
|
+
* @example
|
|
567
|
+
* ```typescript
|
|
568
|
+
* const total = bitbybit.vector.sum({ vector: [1, 2, 3, 4] });
|
|
569
|
+
* ```
|
|
362
570
|
*/
|
|
363
571
|
sum(inputs: Inputs.Vector.VectorDto): number;
|
|
364
572
|
/**
|
|
365
|
-
* Computes the squared length
|
|
366
|
-
*
|
|
367
|
-
*
|
|
368
|
-
*
|
|
573
|
+
* Computes the squared length of a 3D vector, which avoids the square root when only comparing
|
|
574
|
+
* lengths.
|
|
575
|
+
*
|
|
576
|
+
* Example: [3,4,0] -> 25
|
|
577
|
+
* @param inputs - The 3D vector
|
|
578
|
+
* @returns The squared length
|
|
369
579
|
* @group base
|
|
370
580
|
* @shortname length squared
|
|
371
581
|
* @drawable false
|
|
582
|
+
* @example
|
|
583
|
+
* ```typescript
|
|
584
|
+
* const l2 = bitbybit.vector.lengthSq({ vector: [3, 4, 0] });
|
|
585
|
+
* ```
|
|
372
586
|
*/
|
|
373
587
|
lengthSq(inputs: Inputs.Vector.Vector3Dto): number;
|
|
374
588
|
/**
|
|
375
|
-
* Computes the length
|
|
376
|
-
*
|
|
377
|
-
*
|
|
378
|
-
* @
|
|
589
|
+
* Computes the length of a 3D vector.
|
|
590
|
+
*
|
|
591
|
+
* Example: [3,4,0] -> 5
|
|
592
|
+
* @param inputs - The 3D vector
|
|
593
|
+
* @returns The length in model units
|
|
379
594
|
* @group base
|
|
380
595
|
* @shortname length
|
|
381
596
|
* @drawable false
|
|
597
|
+
* @example
|
|
598
|
+
* ```typescript
|
|
599
|
+
* const len = bitbybit.vector.length({ vector: [3, 4, 0] });
|
|
600
|
+
* ```
|
|
382
601
|
*/
|
|
383
602
|
length(inputs: Inputs.Vector.Vector3Dto): number;
|
|
384
603
|
/**
|
|
385
|
-
*
|
|
386
|
-
*
|
|
387
|
-
*
|
|
388
|
-
*
|
|
604
|
+
* Turns a list of number strings into numbers.
|
|
605
|
+
*
|
|
606
|
+
* A string that is not a number becomes NaN.
|
|
607
|
+
* Example: ['1', '2.5', '3'] -> [1, 2.5, 3]
|
|
608
|
+
* @param inputs - The strings to parse
|
|
609
|
+
* @returns The numbers
|
|
389
610
|
* @group create
|
|
390
611
|
* @shortname parse numbers
|
|
391
612
|
* @drawable false
|
|
613
|
+
* @example
|
|
614
|
+
* ```typescript
|
|
615
|
+
* const numbers = bitbybit.vector.parseNumbers({ vector: ["1", "2.5", "-3"] });
|
|
616
|
+
* ```
|
|
392
617
|
*/
|
|
393
618
|
parseNumbers(inputs: Inputs.Vector.VectorStringDto): number[];
|
|
394
619
|
}
|