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