@bitbybit-dev/base 0.19.8 → 0.19.9

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.
Files changed (61) hide show
  1. package/babel.config.cjs +1 -0
  2. package/babel.config.d.cts +5 -0
  3. package/index.d.ts +1 -0
  4. package/{index.ts → index.js} +1 -2
  5. package/lib/api/index.js +1 -0
  6. package/lib/api/inputs/base-inputs.d.ts +35 -0
  7. package/lib/api/inputs/base-inputs.js +1 -0
  8. package/lib/api/inputs/{color-inputs.ts → color-inputs.d.ts} +26 -48
  9. package/lib/api/inputs/color-inputs.js +164 -0
  10. package/lib/api/inputs/index.js +9 -0
  11. package/lib/api/inputs/inputs.js +9 -0
  12. package/lib/api/inputs/{lists-inputs.ts → lists-inputs.d.ts} +91 -190
  13. package/lib/api/inputs/lists-inputs.js +576 -0
  14. package/lib/api/inputs/{logic-inputs.ts → logic-inputs.d.ts} +24 -46
  15. package/lib/api/inputs/logic-inputs.js +111 -0
  16. package/lib/api/inputs/{math-inputs.ts → math-inputs.d.ts} +53 -97
  17. package/lib/api/inputs/math-inputs.js +391 -0
  18. package/lib/api/inputs/{point-inputs.ts → point-inputs.d.ts} +77 -168
  19. package/lib/api/inputs/point-inputs.js +521 -0
  20. package/lib/api/inputs/text-inputs.d.ts +83 -0
  21. package/lib/api/inputs/text-inputs.js +120 -0
  22. package/lib/api/inputs/{transforms-inputs.ts → transforms-inputs.d.ts} +35 -64
  23. package/lib/api/inputs/transforms-inputs.js +200 -0
  24. package/lib/api/inputs/{vector-inputs.ts → vector-inputs.d.ts} +48 -104
  25. package/lib/api/inputs/vector-inputs.js +304 -0
  26. package/lib/api/services/color.d.ts +114 -0
  27. package/lib/api/services/{color.ts → color.js} +15 -34
  28. package/lib/api/services/geometry-helper.d.ts +15 -0
  29. package/lib/api/services/{geometry-helper.ts → geometry-helper.js} +31 -43
  30. package/lib/api/services/{index.ts → index.d.ts} +1 -1
  31. package/lib/api/services/index.js +9 -0
  32. package/lib/api/services/lists.d.ts +287 -0
  33. package/lib/api/services/{lists.ts → lists.js} +59 -83
  34. package/lib/api/services/logic.d.ts +99 -0
  35. package/lib/api/services/{logic.ts → logic.js} +24 -32
  36. package/lib/api/services/math.d.ts +349 -0
  37. package/lib/api/services/{math.ts → math.js} +71 -136
  38. package/lib/api/services/point.d.ts +222 -0
  39. package/lib/api/services/{point.ts → point.js} +32 -67
  40. package/lib/api/services/text.d.ts +69 -0
  41. package/lib/api/services/{text.ts → text.js} +7 -17
  42. package/lib/api/services/transforms.d.ts +122 -0
  43. package/lib/api/services/{transforms.ts → transforms.js} +37 -83
  44. package/lib/api/services/vector.d.ts +320 -0
  45. package/lib/api/services/{vector.ts → vector.js} +42 -80
  46. package/lib/{index.ts → index.d.ts} +0 -1
  47. package/lib/index.js +1 -0
  48. package/package.json +1 -1
  49. package/lib/api/inputs/base-inputs.ts +0 -18
  50. package/lib/api/inputs/text-inputs.ts +0 -108
  51. package/lib/api/services/color.test.ts +0 -86
  52. package/lib/api/services/lists.test.ts +0 -612
  53. package/lib/api/services/logic.test.ts +0 -187
  54. package/lib/api/services/math.test.ts +0 -622
  55. package/lib/api/services/text.test.ts +0 -55
  56. package/lib/api/services/vector.test.ts +0 -360
  57. package/tsconfig.bitbybit.json +0 -26
  58. package/tsconfig.json +0 -24
  59. /package/lib/api/{index.ts → index.d.ts} +0 -0
  60. /package/lib/api/inputs/{index.ts → index.d.ts} +0 -0
  61. /package/lib/api/inputs/{inputs.ts → inputs.d.ts} +0 -0
@@ -1,360 +0,0 @@
1
- import * as Inputs from "../inputs";
2
- import { GeometryHelper } from "./geometry-helper";
3
- import { MathBitByBit } from "./math";
4
- import { Vector } from "./vector";
5
-
6
- describe("Vector unit tests", () => {
7
- let vector: Vector;
8
-
9
- beforeAll(() => {
10
-
11
- vector = new Vector(new MathBitByBit(), new GeometryHelper());
12
- });
13
-
14
- it("should create xyz vector", () => {
15
- const res = vector.vectorXYZ({ x: 1, y: 2, z: 3 });
16
- expect(res).toEqual([1, 2, 3]);
17
- });
18
-
19
- it("should create xy vector", () => {
20
- const res = vector.vectorXY({ x: 1, y: 2 });
21
- expect(res).toEqual([1, 2]);
22
- });
23
-
24
- it("should remove all duplicate vectors", () => {
25
- const res = vector.removeAllDuplicateVectors({ vectors: [[1, 2], [1, 2], [2, 3], [2, 3]], tolerance: 0.1 });
26
- expect(res).toEqual([[1, 2], [2, 3]]);
27
- });
28
-
29
- it("should not remove duplicates vectors when tolerance is 0", () => {
30
- const res = vector.removeAllDuplicateVectors({ vectors: [[1, 2], [1, 2], [2, 3], [2, 3]], tolerance: 0 });
31
- expect(res).toEqual([[1, 2], [1, 2], [2, 3], [2, 3]]);
32
- });
33
-
34
- it("should remove all duplicate vectors with tolerance 0.0001", () => {
35
- const res = vector.removeAllDuplicateVectors({ vectors: [[1, 2], [1.00001, 2], [2, 3], [2, 3]], tolerance: 0.0001 });
36
- expect(res).toEqual([[1, 2], [2, 3]]);
37
- });
38
-
39
- it("should remove all duplicate vectors with tolerance 0.00001", () => {
40
- const res = vector.removeAllDuplicateVectors({ vectors: [[1, 2], [1.0000001, 2], [2, 3], [2, 3]], tolerance: 0.00001 });
41
- expect(res).toEqual([[1, 2], [2, 3]]);
42
- });
43
-
44
- it("should remove all duplicate vectors with tolerance 0.00001 that are not conseqtive", () => {
45
- const res = vector.removeAllDuplicateVectors({ vectors: [[1, 2], [1.0000001, 2], [2, 3], [2, 3], [1, 2.000000001]], tolerance: 0.00001 });
46
- expect(res).toEqual([[1, 2], [2, 3]]);
47
- });
48
-
49
- it("should remove consecutive duplicate vectors and not check first and last", () => {
50
- const res = vector.removeConsecutiveDuplicateVectors({ vectors: [[1, 2], [1, 2], [2, 3], [2, 3], [1, 2]], tolerance: 0.001, checkFirstAndLast: false });
51
- expect(res).toEqual([[1, 2], [2, 3], [1, 2]]);
52
- });
53
-
54
- it("should remove consecutive duplicate vectors and check first and last", () => {
55
- const res = vector.removeConsecutiveDuplicateVectors({ vectors: [[1.000001, 2], [1, 2], [2, 3], [2, 3], [1, 2]], tolerance: 0.001, checkFirstAndLast: true });
56
- expect(res).toEqual([[1, 2], [2, 3]]);
57
- });
58
-
59
- it("should measure angle between vectors", () => {
60
- const res = vector.angleBetween({ first: [1, 0, 0], second: [0, 1, 0] });
61
- expect(res).toBeCloseTo(90);
62
- });
63
-
64
- it("should measure angle between vectors", () => {
65
- const res = vector.angleBetween({ first: [1, 1.231, 0.3], second: [-13, 1, -0.5512] });
66
- expect(res).toBeCloseTo(124.51133246749056);
67
- });
68
-
69
- it("should measure angle between normalized 2d vectors", () => {
70
- const res = vector.angleBetweenNormalized2d({ first: [1, 1.231, 0.3], second: [-13, 1, -0.5512] });
71
- expect(res).toBeCloseTo(125.06491356368089);
72
- });
73
-
74
- it("should measure positive angle between normalized 2d vectors", () => {
75
- const res = vector.positiveAngleBetween({ first: [1, 0, 0], second: [0, 1, 0], reference: [0, 0, 1] });
76
- expect(res).toBeCloseTo(90);
77
- });
78
-
79
- it("should measure positive angle between normalized 2d vectors", () => {
80
- const res = vector.positiveAngleBetween({ first: [1, 0, 0], second: [0, 1, 0], reference: [0.5, -0.5, 1] });
81
- expect(res).toBeCloseTo(90);
82
- });
83
-
84
- it("should measure positive angle between normalized 2d vectors", () => {
85
- const res = vector.positiveAngleBetween({ first: [1, 1, 0], second: [0, 1, 0], reference: [0.5, 1, 1] });
86
- expect(res).toBeCloseTo(45);
87
- });
88
-
89
- it("should create normalized (unit) vector", () => {
90
- const res = vector.normalized({ vector: [1, 1, 0] });
91
- expect(res).toEqual([0.7071067811865475, 0.7071067811865475, 0]);
92
- });
93
-
94
- it("should add all vectors", () => {
95
- const res = vector.addAll({ vectors: [[1, 2, 3], [3, 4, 5], [2, 3, 4]] });
96
- expect(res).toEqual([6, 9, 12]);
97
- });
98
-
99
- it("should add all vectors", () => {
100
- const res = vector.addAll({ vectors: [[1, 2, 3, 4, 5, 3, 4, 5, 6, 7]] });
101
- expect(res).toEqual([1, 2, 3, 4, 5, 3, 4, 5, 6, 7]);
102
- });
103
-
104
- it("should add two vectors", () => {
105
- const res = vector.add({ first: [1, 2, 3], second: [2, 3, 5] });
106
- expect(res).toEqual([3, 5, 8]);
107
- });
108
-
109
- it("should check if all values in the vector are true", () => {
110
- const res = vector.all({ vector: [true, true, true] });
111
- expect(res).toEqual(true);
112
- });
113
-
114
- it("should check if all values in the vector are true", () => {
115
- const res = vector.all({ vector: [true, false, true] });
116
- expect(res).toEqual(false);
117
- });
118
-
119
- it("should cross perpendicular vectors", () => {
120
- const res = vector.cross({ first: [1, 0, 0], second: [0, 1, 0] });
121
- expect(res).toEqual([0, 0, 1]);
122
- });
123
-
124
- it("should cross vectors", () => {
125
- const res = vector.cross({ first: [1, 1.2, 3], second: [-3, 1, -0.5] });
126
- expect(res).toEqual([-3.6, -8.5, 4.6]);
127
- });
128
-
129
- it("should compute dist squared", () => {
130
- const res = vector.distSquared({ first: [1, 2, 3], second: [4, 5, 6] });
131
- expect(res).toEqual(27);
132
- });
133
-
134
- it("should compute dist squared when vectors are the same", () => {
135
- const res = vector.distSquared({ first: [1, 2, 3], second: [1, 2, 3] });
136
- expect(res).toEqual(0);
137
- });
138
-
139
- it("should compute dist", () => {
140
- const res = vector.dist({ first: [1, 2, 3], second: [4, 5, 6] });
141
- expect(res).toEqual(5.196152422706632);
142
- });
143
-
144
- it("should compute dist", () => {
145
- const res = vector.dist({ first: [1, 2, 3], second: [1, 2, 3] });
146
- expect(res).toEqual(0);
147
- });
148
-
149
- it("should compute dist", () => {
150
- const res = vector.dist({ first: [1, -32, 3], second: [1, 23, -30] });
151
- expect(res).toEqual(64.1404708432983);
152
- });
153
-
154
- it("should compute div", () => {
155
- const res = vector.div({ vector: [1, -32, 3], scalar: 3 });
156
- expect(res).toEqual([1 / 3, -32 / 3, 1]);
157
- });
158
-
159
- it("should compute dot", () => {
160
- const res = vector.dot({ first: [1, 2, 3], second: [4, 5, 6] });
161
- expect(res).toEqual(32);
162
- });
163
-
164
- it("should compute domain", () => {
165
- const res = vector.domain({ vector: [1, 2, 3, 5, 6] });
166
- expect(res).toEqual(5);
167
- });
168
-
169
- it("should compute domain", () => {
170
- const res = vector.domain({ vector: [1, 2, -3, 5, 6, -12] });
171
- expect(res).toEqual(-13);
172
- });
173
-
174
- it("should check if there are no infinite values in vector", () => {
175
- const res = vector.finite({ vector: [1, 2, -3, 5, Infinity, -12] });
176
- expect(res).toEqual([true, true, true, true, false, true]);
177
- });
178
-
179
- it("should check if there are no infinite values in vector", () => {
180
- const res = vector.finite({ vector: [1, 2, -3, 5, 3, -12] });
181
- expect(res).toEqual([true, true, true, true, true, true]);
182
- });
183
-
184
- it("should check if vector is zero", () => {
185
- const res = vector.isZero({ vector: [0, 0, 0] });
186
- expect(res).toEqual(true);
187
- });
188
-
189
- it("should check if vector is zero", () => {
190
- const res = vector.isZero({ vector: [0, 0, 0, 0] });
191
- expect(res).toEqual(true);
192
- });
193
-
194
- it("should check if vector is zero", () => {
195
- const res = vector.isZero({ vector: [0, 1, 2] });
196
- expect(res).toEqual(false);
197
- });
198
-
199
- it("should compute lerp", () => {
200
- const res = vector.lerp({ first: [1, 2, 3], second: [4, 5, 6], fraction: 0.5 });
201
- expect(res).toEqual([2.5, 3.5, 4.5]);
202
- });
203
-
204
- it("should compute lerp", () => {
205
- const res = vector.lerp({ first: [1, 2, 3], second: [4, 5, 6], fraction: 0.1 });
206
- expect(res).toEqual([3.7, 4.7, 5.7]);
207
- });
208
-
209
- it("should find min value", () => {
210
- const res = vector.min({ vector: [1, 2, 3, -4, 3, 2] });
211
- expect(res).toEqual(-4);
212
- });
213
-
214
- it("should find max value", () => {
215
- const res = vector.max({ vector: [1, 2, 3, -4, 3, 2] });
216
- expect(res).toEqual(3);
217
- });
218
-
219
- it("should multiply vector", () => {
220
- const res = vector.mul({ vector: [1, 2, 3, -4, 3, 2], scalar: 2 });
221
- expect(res).toEqual([2, 4, 6, -8, 6, 4]);
222
- });
223
-
224
- it("should negate vector", () => {
225
- const res = vector.neg({ vector: [1, 2, 3, -4, 3, 2] });
226
- expect(res).toEqual([-1, -2, -3, 4, -3, -2]);
227
- });
228
-
229
- it("should compute norm squared", () => {
230
- const res = vector.normSquared({ vector: [1, 2, 3] });
231
- expect(res).toEqual(14);
232
- });
233
-
234
- it("should compute norm", () => {
235
- const res = vector.norm({ vector: [1, 2, 3] });
236
- expect(res).toEqual(3.7416573867739413);
237
- });
238
-
239
- it("should normalize vector", () => {
240
- const res = vector.norm({ vector: [1, 2, 3] });
241
- expect(res).toEqual(3.7416573867739413);
242
- });
243
-
244
- it("should find vector on ray", () => {
245
- const res = vector.onRay({ point: [1, 2, 3], vector: [1, 1, 1], distance: 3 });
246
- expect(res).toEqual([4, 5, 6]);
247
- });
248
-
249
- it("should create range", () => {
250
- const res = vector.range({ max: 5 });
251
- expect(res).toEqual([0, 1, 2, 3, 4]);
252
- });
253
-
254
- it("should compute signed angle between vectors", () => {
255
- const res = vector.signedAngleBetween({ first: [1, 0, 0], second: [0, 1, 0], reference: [0, 0, 1] });
256
- expect(res).toEqual(90);
257
- });
258
-
259
- it("should compute signed angle between vectors", () => {
260
- const res = vector.signedAngleBetween({ first: [-1, 0.3, -0.1], second: [0.2, 1.3, -0.5], reference: [-0.3, -0.5, 1] });
261
- expect(res).toEqual(279.35918473906344);
262
- });
263
-
264
- it("should create span", () => {
265
- const res = vector.span({ min: 1, max: 5, step: 0.5 });
266
- expect(res).toEqual([
267
- 1, 1.5, 2, 2.5, 3,
268
- 3.5, 4, 4.5, 5
269
- ]);
270
- });
271
-
272
- it("should create span ease in sine", () => {
273
- const res = vector.spanEaseItems({ min: 1, max: 5, ease: Inputs.Math.easeEnum.easeInSine, nrItems: 10, intervals: false });
274
- expect(res).toEqual([
275
- 1,
276
- 1.060768987951168,
277
- 1.2412295168563663,
278
- 1.5358983848622452,
279
- 1.935822227524088,
280
- 2.4288495612538425,
281
- 2.9999999999999996,
282
- 3.6319194266973245,
283
- 4.305407289332278,
284
- 5
285
- ]);
286
- });
287
-
288
- it("should create span ease in sine with intervals only", () => {
289
- const res = vector.spanEaseItems({ min: 1, max: 5, ease: Inputs.Math.easeEnum.easeInSine, nrItems: 10, intervals: true });
290
- expect(res).toEqual([
291
- 1,
292
- 0.06076898795116792,
293
- 0.18046052890519837,
294
- 0.2946688680058789,
295
- 0.3999238426618428,
296
- 0.4930273337297546,
297
- 0.571150438746157,
298
- 0.6319194266973249,
299
- 0.6734878626349534,
300
- 0.6945927106677221
301
- ]);
302
- });
303
-
304
- it("should create span ease out sine", () => {
305
- const res = vector.spanEaseItems({ min: 1, max: 5, ease: Inputs.Math.easeEnum.easeOutSine, nrItems: 10, intervals: false });
306
- expect(res).toEqual([
307
- 1,
308
- 1.6945927106677212,
309
- 2.3680805733026746,
310
- 3,
311
- 3.571150438746157,
312
- 4.064177772475912,
313
- 4.464101615137754,
314
- 4.758770483143634,
315
- 4.9392310120488325,
316
- 5
317
- ]);
318
- });
319
-
320
- it("should create span with linear items", () => {
321
- const res = vector.spanLinearItems({ nrItems: 10, min: 1, max: 5 });
322
- expect(res).toEqual([
323
- 1,
324
- 1.4444444444444444,
325
- 1.8888888888888888,
326
- 2.333333333333333,
327
- 2.7777777777777777,
328
- 3.2222222222222223,
329
- 3.6666666666666665,
330
- 4.111111111111111,
331
- 4.5555555555555554,
332
- 5
333
- ]);
334
- });
335
-
336
- it("should create span with linear items", () => {
337
- const res = vector.spanLinearItems({ nrItems: 15, min: -1, max: 5 });
338
- expect(res).toEqual([
339
- -1, -0.5714285714285714,
340
- -0.1428571428571429, 0.2857142857142858,
341
- 0.7142857142857142, 1.1428571428571428,
342
- 1.5714285714285716, 2,
343
- 2.4285714285714284, 2.857142857142857,
344
- 3.2857142857142856, 3.7142857142857144,
345
- 4.142857142857143, 4.571428571428571,
346
- 5
347
- ]);
348
- });
349
-
350
- it("should subtract two vectors", () => {
351
- const res = vector.sub({ first: [1, 2, 3], second: [2, 3, 5] });
352
- expect(res).toEqual([-1, -1, -2]);
353
- });
354
-
355
- it("should sum vector values", () => {
356
- const res = vector.sum({ vector: [1, 2, 3] });
357
- expect(res).toEqual(6);
358
- });
359
- });
360
-
@@ -1,26 +0,0 @@
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 DELETED
@@ -1,24 +0,0 @@
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
- }
File without changes
File without changes
File without changes