@bitbybit-dev/base 0.19.8 → 0.20.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/babel.config.cjs +1 -0
- package/babel.config.d.cts +5 -0
- package/index.d.ts +1 -0
- package/{index.ts → index.js} +1 -2
- package/lib/api/index.js +1 -0
- package/lib/api/inputs/base-inputs.d.ts +35 -0
- package/lib/api/inputs/base-inputs.js +1 -0
- package/lib/api/inputs/{color-inputs.ts → color-inputs.d.ts} +26 -48
- package/lib/api/inputs/color-inputs.js +164 -0
- package/lib/api/inputs/dates-inputs.d.ts +216 -0
- package/lib/api/inputs/dates-inputs.js +271 -0
- package/lib/api/inputs/{index.ts → index.d.ts} +1 -0
- package/lib/api/inputs/index.js +10 -0
- package/lib/api/inputs/{inputs.ts → inputs.d.ts} +1 -0
- package/lib/api/inputs/inputs.js +10 -0
- package/lib/api/inputs/{lists-inputs.ts → lists-inputs.d.ts} +91 -190
- package/lib/api/inputs/lists-inputs.js +576 -0
- package/lib/api/inputs/{logic-inputs.ts → logic-inputs.d.ts} +24 -46
- package/lib/api/inputs/logic-inputs.js +111 -0
- package/lib/api/inputs/{math-inputs.ts → math-inputs.d.ts} +53 -97
- package/lib/api/inputs/math-inputs.js +391 -0
- package/lib/api/inputs/{point-inputs.ts → point-inputs.d.ts} +77 -168
- package/lib/api/inputs/point-inputs.js +521 -0
- package/lib/api/inputs/text-inputs.d.ts +83 -0
- package/lib/api/inputs/text-inputs.js +120 -0
- package/lib/api/inputs/{transforms-inputs.ts → transforms-inputs.d.ts} +35 -64
- package/lib/api/inputs/transforms-inputs.js +200 -0
- package/lib/api/inputs/{vector-inputs.ts → vector-inputs.d.ts} +48 -104
- package/lib/api/inputs/vector-inputs.js +304 -0
- package/lib/api/services/color.d.ts +114 -0
- package/lib/api/services/{color.ts → color.js} +15 -34
- package/lib/api/services/dates.d.ts +367 -0
- package/lib/api/services/dates.js +450 -0
- package/lib/api/services/geometry-helper.d.ts +15 -0
- package/lib/api/services/{geometry-helper.ts → geometry-helper.js} +31 -43
- package/lib/api/services/{index.ts → index.d.ts} +2 -1
- package/lib/api/services/index.js +10 -0
- package/lib/api/services/lists.d.ts +287 -0
- package/lib/api/services/{lists.ts → lists.js} +59 -83
- package/lib/api/services/logic.d.ts +99 -0
- package/lib/api/services/{logic.ts → logic.js} +24 -32
- package/lib/api/services/math.d.ts +349 -0
- package/lib/api/services/{math.ts → math.js} +71 -136
- package/lib/api/services/point.d.ts +222 -0
- package/lib/api/services/{point.ts → point.js} +32 -67
- package/lib/api/services/text.d.ts +69 -0
- package/lib/api/services/{text.ts → text.js} +7 -17
- package/lib/api/services/transforms.d.ts +122 -0
- package/lib/api/services/{transforms.ts → transforms.js} +37 -83
- package/lib/api/services/vector.d.ts +320 -0
- package/lib/api/services/{vector.ts → vector.js} +42 -80
- package/lib/{index.ts → index.d.ts} +0 -1
- package/lib/index.js +1 -0
- package/package.json +1 -1
- package/lib/api/inputs/base-inputs.ts +0 -18
- package/lib/api/inputs/text-inputs.ts +0 -108
- package/lib/api/services/color.test.ts +0 -86
- package/lib/api/services/lists.test.ts +0 -612
- package/lib/api/services/logic.test.ts +0 -187
- package/lib/api/services/math.test.ts +0 -622
- package/lib/api/services/text.test.ts +0 -55
- package/lib/api/services/vector.test.ts +0 -360
- package/tsconfig.bitbybit.json +0 -26
- package/tsconfig.json +0 -24
- /package/lib/api/{index.ts → index.d.ts} +0 -0
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
import * as Inputs from "../inputs";
|
|
3
|
-
import { GeometryHelper } from "./geometry-helper";
|
|
4
|
-
import { MathBitByBit } from "./math";
|
|
5
|
-
|
|
6
1
|
/**
|
|
7
2
|
* Contains various methods for vector mathematics. Vector in bitbybit is simply an array, usually containing numbers.
|
|
8
3
|
* In 3D [x, y, z] form describes space, where y is the up vector.
|
|
9
4
|
* Because of this form Vector can be interchanged with Point, which also is an array in [x, y, z] form.
|
|
10
5
|
*/
|
|
11
6
|
export class Vector {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
constructor(math, geometryHelper) {
|
|
8
|
+
this.math = math;
|
|
9
|
+
this.geometryHelper = geometryHelper;
|
|
10
|
+
}
|
|
15
11
|
/**
|
|
16
12
|
* Removes all duplicate vectors from the input array
|
|
17
13
|
* @param inputs Contains vectors and a tolerance value
|
|
@@ -20,10 +16,9 @@ export class Vector {
|
|
|
20
16
|
* @shortname remove all duplicates
|
|
21
17
|
* @drawable false
|
|
22
18
|
*/
|
|
23
|
-
removeAllDuplicateVectors(inputs
|
|
19
|
+
removeAllDuplicateVectors(inputs) {
|
|
24
20
|
return this.geometryHelper.removeAllDuplicateVectors(inputs.vectors, inputs.tolerance);
|
|
25
21
|
}
|
|
26
|
-
|
|
27
22
|
/**
|
|
28
23
|
* Removes consecutive duplicate vectors from the input array
|
|
29
24
|
* @param inputs Contains vectors and a tolerance value
|
|
@@ -32,7 +27,7 @@ export class Vector {
|
|
|
32
27
|
* @shortname remove consecutive duplicates
|
|
33
28
|
* @drawable false
|
|
34
29
|
*/
|
|
35
|
-
removeConsecutiveDuplicateVectors(inputs
|
|
30
|
+
removeConsecutiveDuplicateVectors(inputs) {
|
|
36
31
|
return this.geometryHelper.removeConsecutiveVectorDuplicates(inputs.vectors, inputs.checkFirstAndLast, inputs.tolerance);
|
|
37
32
|
}
|
|
38
33
|
/**
|
|
@@ -43,12 +38,11 @@ export class Vector {
|
|
|
43
38
|
* @returns Number in degrees
|
|
44
39
|
* @drawable false
|
|
45
40
|
*/
|
|
46
|
-
angleBetween(inputs
|
|
41
|
+
angleBetween(inputs) {
|
|
47
42
|
return this.math.radToDeg({
|
|
48
43
|
number: Math.acos(this.dot({ first: inputs.first, second: inputs.second }) / (this.norm({ vector: inputs.first }) * this.norm({ vector: inputs.second })))
|
|
49
44
|
});
|
|
50
45
|
}
|
|
51
|
-
|
|
52
46
|
/**
|
|
53
47
|
* Measures the normalized 2d angle between two vectors in degrees
|
|
54
48
|
* @param inputs Contains two vectors represented as number arrays
|
|
@@ -57,13 +51,12 @@ export class Vector {
|
|
|
57
51
|
* @shortname angle normalized 2d
|
|
58
52
|
* @drawable false
|
|
59
53
|
*/
|
|
60
|
-
angleBetweenNormalized2d(inputs
|
|
54
|
+
angleBetweenNormalized2d(inputs) {
|
|
61
55
|
const perpDot = inputs.first[0] * inputs.second[1] - inputs.first[1] * inputs.second[0];
|
|
62
56
|
return this.math.radToDeg({
|
|
63
57
|
number: Math.atan2(perpDot, this.dot({ first: inputs.first, second: inputs.second }))
|
|
64
58
|
});
|
|
65
59
|
}
|
|
66
|
-
|
|
67
60
|
/**
|
|
68
61
|
* Measures a positive angle between two vectors given the reference vector in degrees
|
|
69
62
|
* @param inputs Contains information of two vectors and a reference vector
|
|
@@ -72,11 +65,10 @@ export class Vector {
|
|
|
72
65
|
* @shortname positive angle
|
|
73
66
|
* @drawable false
|
|
74
67
|
*/
|
|
75
|
-
positiveAngleBetween(inputs
|
|
68
|
+
positiveAngleBetween(inputs) {
|
|
76
69
|
const angle = this.signedAngleBetween(inputs);
|
|
77
70
|
return angle < 0 ? 360 + angle : angle;
|
|
78
71
|
}
|
|
79
|
-
|
|
80
72
|
/**
|
|
81
73
|
* Adds all vector xyz values together and create a new vector
|
|
82
74
|
* @param inputs Vectors to be added
|
|
@@ -85,7 +77,7 @@ export class Vector {
|
|
|
85
77
|
* @shortname add all
|
|
86
78
|
* @drawable false
|
|
87
79
|
*/
|
|
88
|
-
addAll(inputs
|
|
80
|
+
addAll(inputs) {
|
|
89
81
|
const res = [];
|
|
90
82
|
for (let i = 0; i < inputs.vectors[0].length; i++) {
|
|
91
83
|
let sum = 0;
|
|
@@ -96,7 +88,6 @@ export class Vector {
|
|
|
96
88
|
}
|
|
97
89
|
return res;
|
|
98
90
|
}
|
|
99
|
-
|
|
100
91
|
/**
|
|
101
92
|
* Adds two vectors together
|
|
102
93
|
* @param inputs Two vectors to be added
|
|
@@ -105,14 +96,13 @@ export class Vector {
|
|
|
105
96
|
* @shortname add
|
|
106
97
|
* @drawable false
|
|
107
98
|
*/
|
|
108
|
-
add(inputs
|
|
99
|
+
add(inputs) {
|
|
109
100
|
const res = [];
|
|
110
101
|
for (let i = 0; i < inputs.first.length; i++) {
|
|
111
102
|
res.push(inputs.first[i] + inputs.second[i]);
|
|
112
103
|
}
|
|
113
104
|
return res;
|
|
114
105
|
}
|
|
115
|
-
|
|
116
106
|
/**
|
|
117
107
|
* Checks if the boolean array contains only true values, if there's a single false it will return false.
|
|
118
108
|
* @param inputs Vectors to be checked
|
|
@@ -121,10 +111,9 @@ export class Vector {
|
|
|
121
111
|
* @shortname all
|
|
122
112
|
* @drawable false
|
|
123
113
|
*/
|
|
124
|
-
all(inputs
|
|
114
|
+
all(inputs) {
|
|
125
115
|
return inputs.vector.every(v => v);
|
|
126
116
|
}
|
|
127
|
-
|
|
128
117
|
/**
|
|
129
118
|
* Cross two vectors
|
|
130
119
|
* @param inputs Two vectors to be crossed
|
|
@@ -133,14 +122,13 @@ export class Vector {
|
|
|
133
122
|
* @returns Crossed vector
|
|
134
123
|
* @drawable false
|
|
135
124
|
*/
|
|
136
|
-
cross(inputs
|
|
125
|
+
cross(inputs) {
|
|
137
126
|
const res = [];
|
|
138
127
|
res.push(inputs.first[1] * inputs.second[2] - inputs.first[2] * inputs.second[1]);
|
|
139
128
|
res.push(inputs.first[2] * inputs.second[0] - inputs.first[0] * inputs.second[2]);
|
|
140
129
|
res.push(inputs.first[0] * inputs.second[1] - inputs.first[1] * inputs.second[0]);
|
|
141
130
|
return res;
|
|
142
131
|
}
|
|
143
|
-
|
|
144
132
|
/**
|
|
145
133
|
* Squared distance between two vectors
|
|
146
134
|
* @param inputs Two vectors
|
|
@@ -149,14 +137,13 @@ export class Vector {
|
|
|
149
137
|
* @shortname dist squared
|
|
150
138
|
* @drawable false
|
|
151
139
|
*/
|
|
152
|
-
distSquared(inputs
|
|
140
|
+
distSquared(inputs) {
|
|
153
141
|
let res = 0;
|
|
154
142
|
for (let i = 0; i < inputs.first.length; i++) {
|
|
155
143
|
res += Math.pow(inputs.first[i] - inputs.second[i], 2);
|
|
156
144
|
}
|
|
157
145
|
return res;
|
|
158
146
|
}
|
|
159
|
-
|
|
160
147
|
/**
|
|
161
148
|
* Distance between two vectors
|
|
162
149
|
* @param inputs Two vectors
|
|
@@ -165,10 +152,9 @@ export class Vector {
|
|
|
165
152
|
* @shortname dist
|
|
166
153
|
* @drawable false
|
|
167
154
|
*/
|
|
168
|
-
dist(inputs
|
|
155
|
+
dist(inputs) {
|
|
169
156
|
return Math.sqrt(this.distSquared(inputs));
|
|
170
157
|
}
|
|
171
|
-
|
|
172
158
|
/**
|
|
173
159
|
* Divide the vector by a scalar value
|
|
174
160
|
* @param inputs Contains vector and a scalar
|
|
@@ -177,14 +163,13 @@ export class Vector {
|
|
|
177
163
|
* @shortname div
|
|
178
164
|
* @drawable false
|
|
179
165
|
*/
|
|
180
|
-
div(inputs
|
|
166
|
+
div(inputs) {
|
|
181
167
|
const res = [];
|
|
182
168
|
for (let i = 0; i < inputs.vector.length; i++) {
|
|
183
169
|
res.push(inputs.vector[i] / inputs.scalar);
|
|
184
170
|
}
|
|
185
171
|
return res;
|
|
186
172
|
}
|
|
187
|
-
|
|
188
173
|
/**
|
|
189
174
|
* Computes the domain between minimum and maximum values of the vector
|
|
190
175
|
* @param inputs Vector information
|
|
@@ -193,10 +178,9 @@ export class Vector {
|
|
|
193
178
|
* @shortname domain
|
|
194
179
|
* @drawable false
|
|
195
180
|
*/
|
|
196
|
-
domain(inputs
|
|
181
|
+
domain(inputs) {
|
|
197
182
|
return inputs.vector[inputs.vector.length - 1] - inputs.vector[0];
|
|
198
183
|
}
|
|
199
|
-
|
|
200
184
|
/**
|
|
201
185
|
* Dot product between two vectors
|
|
202
186
|
* @param inputs Two vectors
|
|
@@ -205,14 +189,13 @@ export class Vector {
|
|
|
205
189
|
* @shortname dot
|
|
206
190
|
* @drawable false
|
|
207
191
|
*/
|
|
208
|
-
dot(inputs
|
|
192
|
+
dot(inputs) {
|
|
209
193
|
let res = 0;
|
|
210
194
|
for (let i = 0; i < inputs.first.length; i++) {
|
|
211
195
|
res += inputs.first[i] * inputs.second[i];
|
|
212
196
|
}
|
|
213
197
|
return res;
|
|
214
198
|
}
|
|
215
|
-
|
|
216
199
|
/**
|
|
217
200
|
* Checks if vector is finite for each number and returns a boolean array
|
|
218
201
|
* @param inputs Vector with possibly infinite values
|
|
@@ -222,10 +205,9 @@ export class Vector {
|
|
|
222
205
|
* @shortname finite
|
|
223
206
|
* @drawable false
|
|
224
207
|
*/
|
|
225
|
-
finite(inputs
|
|
208
|
+
finite(inputs) {
|
|
226
209
|
return inputs.vector.map(v => isFinite(v));
|
|
227
210
|
}
|
|
228
|
-
|
|
229
211
|
/**
|
|
230
212
|
* Checks if the vector is zero length
|
|
231
213
|
* @param inputs Vector to be checked
|
|
@@ -234,10 +216,9 @@ export class Vector {
|
|
|
234
216
|
* @shortname isZero
|
|
235
217
|
* @drawable false
|
|
236
218
|
*/
|
|
237
|
-
isZero(inputs
|
|
219
|
+
isZero(inputs) {
|
|
238
220
|
return this.norm({ vector: inputs.vector }) === 0;
|
|
239
221
|
}
|
|
240
|
-
|
|
241
222
|
/**
|
|
242
223
|
* Finds in between vector between two vectors by providing a fracture
|
|
243
224
|
* @param inputs Information for finding vector between two vectors using a fraction
|
|
@@ -246,15 +227,12 @@ export class Vector {
|
|
|
246
227
|
* @shortname lerp
|
|
247
228
|
* @drawable false
|
|
248
229
|
*/
|
|
249
|
-
lerp(inputs
|
|
250
|
-
return this.add(
|
|
251
|
-
{
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
}
|
|
255
|
-
);
|
|
230
|
+
lerp(inputs) {
|
|
231
|
+
return this.add({
|
|
232
|
+
first: this.mul({ vector: inputs.first, scalar: inputs.fraction }),
|
|
233
|
+
second: this.mul({ vector: inputs.second, scalar: 1.0 - inputs.fraction })
|
|
234
|
+
});
|
|
256
235
|
}
|
|
257
|
-
|
|
258
236
|
/**
|
|
259
237
|
* Finds the maximum value in the vector
|
|
260
238
|
* @param inputs Vector to be checked
|
|
@@ -263,10 +241,9 @@ export class Vector {
|
|
|
263
241
|
* @shortname max
|
|
264
242
|
* @drawable false
|
|
265
243
|
*/
|
|
266
|
-
max(inputs
|
|
244
|
+
max(inputs) {
|
|
267
245
|
return Math.max(...inputs.vector);
|
|
268
246
|
}
|
|
269
|
-
|
|
270
247
|
/**
|
|
271
248
|
* Finds the minimum value in the vector
|
|
272
249
|
* @param inputs Vector to be checked
|
|
@@ -275,10 +252,9 @@ export class Vector {
|
|
|
275
252
|
* @shortname min
|
|
276
253
|
* @drawable false
|
|
277
254
|
*/
|
|
278
|
-
min(inputs
|
|
255
|
+
min(inputs) {
|
|
279
256
|
return Math.min(...inputs.vector);
|
|
280
257
|
}
|
|
281
|
-
|
|
282
258
|
/**
|
|
283
259
|
* Multiple vector with the scalar
|
|
284
260
|
* @param inputs Vector with a scalar
|
|
@@ -287,14 +263,13 @@ export class Vector {
|
|
|
287
263
|
* @shortname mul
|
|
288
264
|
* @drawable false
|
|
289
265
|
*/
|
|
290
|
-
mul(inputs
|
|
266
|
+
mul(inputs) {
|
|
291
267
|
const res = [];
|
|
292
268
|
for (let i = 0; i < inputs.vector.length; i++) {
|
|
293
269
|
res.push(inputs.vector[i] * inputs.scalar);
|
|
294
270
|
}
|
|
295
271
|
return res;
|
|
296
272
|
}
|
|
297
|
-
|
|
298
273
|
/**
|
|
299
274
|
* Negates the vector
|
|
300
275
|
* @param inputs Vector to negate
|
|
@@ -303,14 +278,13 @@ export class Vector {
|
|
|
303
278
|
* @shortname neg
|
|
304
279
|
* @drawable false
|
|
305
280
|
*/
|
|
306
|
-
neg(inputs
|
|
281
|
+
neg(inputs) {
|
|
307
282
|
const res = [];
|
|
308
283
|
for (let i = 0; i < inputs.vector.length; i++) {
|
|
309
284
|
res.push(-inputs.vector[i]);
|
|
310
285
|
}
|
|
311
286
|
return res;
|
|
312
287
|
}
|
|
313
|
-
|
|
314
288
|
/**
|
|
315
289
|
* Compute squared norm
|
|
316
290
|
* @param inputs Vector for squared norm
|
|
@@ -319,10 +293,9 @@ export class Vector {
|
|
|
319
293
|
* @shortname norm squared
|
|
320
294
|
* @drawable false
|
|
321
295
|
*/
|
|
322
|
-
normSquared(inputs
|
|
296
|
+
normSquared(inputs) {
|
|
323
297
|
return this.dot({ first: inputs.vector, second: inputs.vector });
|
|
324
298
|
}
|
|
325
|
-
|
|
326
299
|
/**
|
|
327
300
|
* Norm of the vector
|
|
328
301
|
* @param inputs Vector to compute the norm
|
|
@@ -331,11 +304,10 @@ export class Vector {
|
|
|
331
304
|
* @shortname norm
|
|
332
305
|
* @drawable false
|
|
333
306
|
*/
|
|
334
|
-
norm(inputs
|
|
307
|
+
norm(inputs) {
|
|
335
308
|
const norm2 = this.normSquared(inputs);
|
|
336
309
|
return norm2 !== 0.0 ? Math.sqrt(norm2) : norm2;
|
|
337
310
|
}
|
|
338
|
-
|
|
339
311
|
/**
|
|
340
312
|
* Normalize the vector into a unit vector, that has a length of 1
|
|
341
313
|
* @param inputs Vector to normalize
|
|
@@ -344,10 +316,9 @@ export class Vector {
|
|
|
344
316
|
* @shortname normalized
|
|
345
317
|
* @drawable false
|
|
346
318
|
*/
|
|
347
|
-
normalized(inputs
|
|
319
|
+
normalized(inputs) {
|
|
348
320
|
return this.div({ scalar: this.norm(inputs), vector: inputs.vector });
|
|
349
321
|
}
|
|
350
|
-
|
|
351
322
|
/**
|
|
352
323
|
* Finds a point coordinates on the given distance ray that spans between the point along the direction vector
|
|
353
324
|
* @param inputs Provide a point, vector and a distance for finding a point
|
|
@@ -356,10 +327,9 @@ export class Vector {
|
|
|
356
327
|
* @shortname on ray
|
|
357
328
|
* @drawable false
|
|
358
329
|
*/
|
|
359
|
-
onRay(inputs
|
|
330
|
+
onRay(inputs) {
|
|
360
331
|
return this.add({ first: inputs.point, second: this.mul({ vector: inputs.vector, scalar: inputs.distance }) });
|
|
361
332
|
}
|
|
362
|
-
|
|
363
333
|
/**
|
|
364
334
|
* Create a xyz vector
|
|
365
335
|
* @param inputs Vector coordinates
|
|
@@ -368,10 +338,9 @@ export class Vector {
|
|
|
368
338
|
* @shortname vector XYZ
|
|
369
339
|
* @drawable true
|
|
370
340
|
*/
|
|
371
|
-
vectorXYZ(inputs
|
|
341
|
+
vectorXYZ(inputs) {
|
|
372
342
|
return [inputs.x, inputs.y, inputs.z];
|
|
373
343
|
}
|
|
374
|
-
|
|
375
344
|
/**
|
|
376
345
|
* Create 2d xy vector
|
|
377
346
|
* @param inputs Vector coordinates
|
|
@@ -380,10 +349,9 @@ export class Vector {
|
|
|
380
349
|
* @shortname vector XY
|
|
381
350
|
* @drawable true
|
|
382
351
|
*/
|
|
383
|
-
vectorXY(inputs
|
|
352
|
+
vectorXY(inputs) {
|
|
384
353
|
return [inputs.x, inputs.y];
|
|
385
354
|
}
|
|
386
|
-
|
|
387
355
|
/**
|
|
388
356
|
* Creates a vector of integers between 0 and maximum ceiling integer
|
|
389
357
|
* @param inputs Max value for the range
|
|
@@ -392,14 +360,13 @@ export class Vector {
|
|
|
392
360
|
* @shortname range
|
|
393
361
|
* @drawable false
|
|
394
362
|
*/
|
|
395
|
-
range(inputs
|
|
363
|
+
range(inputs) {
|
|
396
364
|
const res = [];
|
|
397
365
|
for (let i = 0; i < inputs.max; i++) {
|
|
398
366
|
res.push(i);
|
|
399
367
|
}
|
|
400
368
|
return res;
|
|
401
369
|
}
|
|
402
|
-
|
|
403
370
|
/**
|
|
404
371
|
* Computes signed angle between two vectors and a reference. This will always return a smaller angle between two possible angles.
|
|
405
372
|
* @param inputs Contains information of two vectors and a reference vector
|
|
@@ -408,7 +375,7 @@ export class Vector {
|
|
|
408
375
|
* @shortname signed angle
|
|
409
376
|
* @drawable false
|
|
410
377
|
*/
|
|
411
|
-
signedAngleBetween(inputs
|
|
378
|
+
signedAngleBetween(inputs) {
|
|
412
379
|
const nab = this.cross({ first: inputs.first, second: inputs.second });
|
|
413
380
|
const al = this.norm({ vector: inputs.first });
|
|
414
381
|
const bl = this.norm({ vector: inputs.second });
|
|
@@ -421,7 +388,6 @@ export class Vector {
|
|
|
421
388
|
const res = s > 0.0 ? w : 2 * Math.PI - w;
|
|
422
389
|
return this.math.radToDeg({ number: res });
|
|
423
390
|
}
|
|
424
|
-
|
|
425
391
|
/**
|
|
426
392
|
* Creates a vector that contains numbers spanning between minimum and maximum values at a given step
|
|
427
393
|
* @param inputs Span information containing min, max and step values
|
|
@@ -430,14 +396,13 @@ export class Vector {
|
|
|
430
396
|
* @shortname span
|
|
431
397
|
* @drawable false
|
|
432
398
|
*/
|
|
433
|
-
span(inputs
|
|
399
|
+
span(inputs) {
|
|
434
400
|
const res = [];
|
|
435
401
|
for (let i = inputs.min; i <= inputs.max; i += inputs.step) {
|
|
436
402
|
res.push(i);
|
|
437
403
|
}
|
|
438
404
|
return res;
|
|
439
405
|
}
|
|
440
|
-
|
|
441
406
|
/**
|
|
442
407
|
* Creates a vector that contains numbers spanning between minimum and maximum values at a given ease function
|
|
443
408
|
* @param inputs Span information containing min, max and ease function
|
|
@@ -446,7 +411,7 @@ export class Vector {
|
|
|
446
411
|
* @shortname span ease items
|
|
447
412
|
* @drawable false
|
|
448
413
|
*/
|
|
449
|
-
spanEaseItems(inputs
|
|
414
|
+
spanEaseItems(inputs) {
|
|
450
415
|
const res = [];
|
|
451
416
|
for (let i = 0; i < inputs.nrItems; i++) {
|
|
452
417
|
const x = i * 1 / (inputs.nrItems - 1);
|
|
@@ -457,7 +422,6 @@ export class Vector {
|
|
|
457
422
|
}
|
|
458
423
|
return res;
|
|
459
424
|
}
|
|
460
|
-
|
|
461
425
|
/**
|
|
462
426
|
* Creates a vector that contains numbers spanning between minimum and maximum values by giving nr of items
|
|
463
427
|
* @param inputs Span information containing min, max and step values
|
|
@@ -466,7 +430,7 @@ export class Vector {
|
|
|
466
430
|
* @shortname span linear items
|
|
467
431
|
* @drawable false
|
|
468
432
|
*/
|
|
469
|
-
spanLinearItems(inputs
|
|
433
|
+
spanLinearItems(inputs) {
|
|
470
434
|
const res = [];
|
|
471
435
|
const dist = (inputs.max - inputs.min);
|
|
472
436
|
for (let i = 0; i < inputs.nrItems; i++) {
|
|
@@ -475,7 +439,6 @@ export class Vector {
|
|
|
475
439
|
}
|
|
476
440
|
return res;
|
|
477
441
|
}
|
|
478
|
-
|
|
479
442
|
/**
|
|
480
443
|
* Subtract two vectors
|
|
481
444
|
* @param inputs Two vectors
|
|
@@ -484,14 +447,13 @@ export class Vector {
|
|
|
484
447
|
* @shortname sub
|
|
485
448
|
* @drawable false
|
|
486
449
|
*/
|
|
487
|
-
sub(inputs
|
|
450
|
+
sub(inputs) {
|
|
488
451
|
const res = [];
|
|
489
452
|
for (let i = 0; i < inputs.first.length; i++) {
|
|
490
453
|
res.push(inputs.first[i] - inputs.second[i]);
|
|
491
454
|
}
|
|
492
455
|
return res;
|
|
493
456
|
}
|
|
494
|
-
|
|
495
457
|
/**
|
|
496
458
|
* Sums the values of the vector
|
|
497
459
|
* @param inputs Vector to sum
|
|
@@ -500,7 +462,7 @@ export class Vector {
|
|
|
500
462
|
* @shortname sum
|
|
501
463
|
* @drawable false
|
|
502
464
|
*/
|
|
503
|
-
sum(inputs
|
|
465
|
+
sum(inputs) {
|
|
504
466
|
return inputs.vector.reduce((a, b) => a + b, 0);
|
|
505
467
|
}
|
|
506
468
|
}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./api";
|
package/package.json
CHANGED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-namespace */
|
|
2
|
-
export namespace Base {
|
|
3
|
-
export type Color = string;
|
|
4
|
-
export type ColorRGB = { r: number, g: number, b: number };
|
|
5
|
-
export type Material = any;
|
|
6
|
-
export type Point2 = [number, number];
|
|
7
|
-
export type Vector2 = [number, number];
|
|
8
|
-
export type Point3 = [number, number, number];
|
|
9
|
-
export type Vector3 = [number, number, number];
|
|
10
|
-
export type Line2 = { start: Base.Point2, end: Base.Point2 };
|
|
11
|
-
export type Line3 = { start: Base.Point3, end: Base.Point3 };
|
|
12
|
-
export type Polyline3 = { points: Base.Point3[], isClosed?: boolean, color?: number[] };
|
|
13
|
-
export type Polyline2 = { points: Base.Point2[], isClosed?: boolean, color?: number[] };
|
|
14
|
-
export type TransformMatrix3x3 = [number, number, number, number, number, number, number, number, number];
|
|
15
|
-
export type TransformMatrixes3x3 = TransformMatrix3x3[];
|
|
16
|
-
export type TransformMatrix = [number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number];
|
|
17
|
-
export type TransformMatrixes = TransformMatrix[];
|
|
18
|
-
}
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-namespace */
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export namespace Text {
|
|
5
|
-
|
|
6
|
-
export class TextDto {
|
|
7
|
-
constructor(text?: string) {
|
|
8
|
-
if (text !== undefined) { this.text = text; }
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* The text
|
|
12
|
-
* @default Hello World
|
|
13
|
-
*/
|
|
14
|
-
text = "Hello World";
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export class TextSplitDto {
|
|
18
|
-
constructor(text?: string, separator?: string) {
|
|
19
|
-
if (text !== undefined) { this.text = text; }
|
|
20
|
-
if (separator !== undefined) { this.separator = separator; }
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Text to split
|
|
24
|
-
* @default a,b,c
|
|
25
|
-
*/
|
|
26
|
-
text = "a,b,c";
|
|
27
|
-
/**
|
|
28
|
-
* Text to split by
|
|
29
|
-
* @default ,
|
|
30
|
-
*/
|
|
31
|
-
separator = ",";
|
|
32
|
-
}
|
|
33
|
-
export class TextReplaceDto {
|
|
34
|
-
constructor(text?: string, search?: string, replaceWith?: string) {
|
|
35
|
-
if (text !== undefined) { this.text = text; }
|
|
36
|
-
if (search !== undefined) { this.search = search; }
|
|
37
|
-
if (replaceWith !== undefined) { this.replaceWith = replaceWith; }
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Text to replace
|
|
41
|
-
* @default a-c
|
|
42
|
-
*/
|
|
43
|
-
text = "a-c";
|
|
44
|
-
/**
|
|
45
|
-
* Text to search for
|
|
46
|
-
* @default -
|
|
47
|
-
*/
|
|
48
|
-
search = "-";
|
|
49
|
-
/**
|
|
50
|
-
* Text to replace found occurences
|
|
51
|
-
* @default b
|
|
52
|
-
*/
|
|
53
|
-
replaceWith = "b";
|
|
54
|
-
}
|
|
55
|
-
export class TextJoinDto {
|
|
56
|
-
constructor(list?: string[], separator?: string) {
|
|
57
|
-
if (list !== undefined) { this.list = list; }
|
|
58
|
-
if (separator !== undefined) { this.separator = separator; }
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Text to join
|
|
62
|
-
* @default undefined
|
|
63
|
-
*/
|
|
64
|
-
list: string[];
|
|
65
|
-
/**
|
|
66
|
-
* Text to join by
|
|
67
|
-
* @default ,
|
|
68
|
-
*/
|
|
69
|
-
separator = ",";
|
|
70
|
-
}
|
|
71
|
-
export class ToStringDto<T> {
|
|
72
|
-
constructor(item?: T) {
|
|
73
|
-
if (item !== undefined) { this.item = item; }
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Item to stringify
|
|
77
|
-
* @default undefined
|
|
78
|
-
*/
|
|
79
|
-
item: T;
|
|
80
|
-
}
|
|
81
|
-
export class ToStringEachDto<T> {
|
|
82
|
-
constructor(list?: T[]) {
|
|
83
|
-
if (list !== undefined) { this.list = list; }
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Item to stringify
|
|
87
|
-
* @default undefined
|
|
88
|
-
*/
|
|
89
|
-
list: T[];
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export class TextFormatDto {
|
|
93
|
-
constructor(text?: string, values?: string[]) {
|
|
94
|
-
if (text !== undefined) { this.text = text; }
|
|
95
|
-
if (values !== undefined) { this.values = values; }
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Text to format
|
|
99
|
-
* @default Hello {0}
|
|
100
|
-
*/
|
|
101
|
-
text = "Hello {0}";
|
|
102
|
-
/**
|
|
103
|
-
* Values to format
|
|
104
|
-
* @default ["World"]
|
|
105
|
-
*/
|
|
106
|
-
values = ["World"];
|
|
107
|
-
}
|
|
108
|
-
}
|