@bitbybit-dev/base 0.19.7 → 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.
Files changed (61) hide show
  1. package/babel.config.cjs +0 -1
  2. package/{index.js → index.ts} +2 -1
  3. package/lib/api/inputs/base-inputs.ts +18 -0
  4. package/lib/api/inputs/{color-inputs.d.ts → color-inputs.ts} +48 -26
  5. package/lib/api/inputs/{lists-inputs.d.ts → lists-inputs.ts} +190 -91
  6. package/lib/api/inputs/{logic-inputs.d.ts → logic-inputs.ts} +46 -24
  7. package/lib/api/inputs/{math-inputs.d.ts → math-inputs.ts} +97 -53
  8. package/lib/api/inputs/{point-inputs.d.ts → point-inputs.ts} +168 -77
  9. package/lib/api/inputs/text-inputs.ts +108 -0
  10. package/lib/api/inputs/{transforms-inputs.d.ts → transforms-inputs.ts} +64 -35
  11. package/lib/api/inputs/{vector-inputs.d.ts → vector-inputs.ts} +104 -48
  12. package/lib/api/services/color.test.ts +86 -0
  13. package/lib/api/services/{color.js → color.ts} +34 -15
  14. package/lib/api/services/{geometry-helper.js → geometry-helper.ts} +43 -31
  15. package/lib/api/services/{index.d.ts → index.ts} +1 -1
  16. package/lib/api/services/lists.test.ts +612 -0
  17. package/lib/api/services/{lists.js → lists.ts} +83 -59
  18. package/lib/api/services/logic.test.ts +187 -0
  19. package/lib/api/services/{logic.js → logic.ts} +32 -24
  20. package/lib/api/services/math.test.ts +622 -0
  21. package/lib/api/services/{math.js → math.ts} +136 -71
  22. package/lib/api/services/{point.js → point.ts} +67 -32
  23. package/lib/api/services/text.test.ts +55 -0
  24. package/lib/api/services/{text.js → text.ts} +17 -7
  25. package/lib/api/services/{transforms.js → transforms.ts} +83 -37
  26. package/lib/api/services/vector.test.ts +360 -0
  27. package/lib/api/services/{vector.js → vector.ts} +80 -42
  28. package/lib/{index.d.ts → index.ts} +1 -0
  29. package/package.json +1 -1
  30. package/tsconfig.bitbybit.json +26 -0
  31. package/tsconfig.json +24 -0
  32. package/babel.config.d.cts +0 -5
  33. package/index.d.ts +0 -1
  34. package/lib/api/index.js +0 -1
  35. package/lib/api/inputs/base-inputs.d.ts +0 -35
  36. package/lib/api/inputs/base-inputs.js +0 -1
  37. package/lib/api/inputs/color-inputs.js +0 -164
  38. package/lib/api/inputs/index.js +0 -9
  39. package/lib/api/inputs/inputs.js +0 -9
  40. package/lib/api/inputs/lists-inputs.js +0 -576
  41. package/lib/api/inputs/logic-inputs.js +0 -111
  42. package/lib/api/inputs/math-inputs.js +0 -391
  43. package/lib/api/inputs/point-inputs.js +0 -521
  44. package/lib/api/inputs/text-inputs.d.ts +0 -83
  45. package/lib/api/inputs/text-inputs.js +0 -120
  46. package/lib/api/inputs/transforms-inputs.js +0 -200
  47. package/lib/api/inputs/vector-inputs.js +0 -304
  48. package/lib/api/services/color.d.ts +0 -114
  49. package/lib/api/services/geometry-helper.d.ts +0 -15
  50. package/lib/api/services/index.js +0 -9
  51. package/lib/api/services/lists.d.ts +0 -287
  52. package/lib/api/services/logic.d.ts +0 -99
  53. package/lib/api/services/math.d.ts +0 -349
  54. package/lib/api/services/point.d.ts +0 -222
  55. package/lib/api/services/text.d.ts +0 -69
  56. package/lib/api/services/transforms.d.ts +0 -122
  57. package/lib/api/services/vector.d.ts +0 -320
  58. package/lib/index.js +0 -1
  59. /package/lib/api/{index.d.ts → index.ts} +0 -0
  60. /package/lib/api/inputs/{index.d.ts → index.ts} +0 -0
  61. /package/lib/api/inputs/{inputs.d.ts → inputs.ts} +0 -0
@@ -1,13 +1,18 @@
1
+
2
+ import { Base } from "../inputs/base-inputs";
3
+ import * as Inputs from "../inputs";
4
+ import { MathBitByBit } from "./math";
5
+ import { Vector } from "./vector";
6
+
1
7
  /**
2
8
  * Transformations help to move, scale, rotate objects. You can combine multiple transformations
3
9
  * for object to be placed exactly into position and orientation that you want.
4
10
  * Contains various methods for transformations that represent 4x4 matrixes in flat 16 number arrays.
5
11
  */
6
12
  export class Transforms {
7
- constructor(vector, math) {
8
- this.vector = vector;
9
- this.math = math;
10
- }
13
+
14
+ constructor(private readonly vector: Vector, private readonly math: MathBitByBit) { }
15
+
11
16
  /**
12
17
  * Creates a rotation transformations around the center and an axis
13
18
  * @param inputs Rotation around center with an axis information
@@ -16,13 +21,17 @@ export class Transforms {
16
21
  * @shortname center axis
17
22
  * @drawable false
18
23
  */
19
- rotationCenterAxis(inputs) {
24
+ rotationCenterAxis(inputs: Inputs.Transforms.RotationCenterAxisDto): Base.TransformMatrixes {
20
25
  return [
21
26
  this.translation(-inputs.center[0], -inputs.center[1], -inputs.center[2]),
22
- this.rotationAxis(inputs.axis, this.math.degToRad({ number: inputs.angle })),
27
+ this.rotationAxis(
28
+ inputs.axis,
29
+ this.math.degToRad({ number: inputs.angle })
30
+ ),
23
31
  this.translation(inputs.center[0], inputs.center[1], inputs.center[2]),
24
- ];
32
+ ] as Base.TransformMatrixes;
25
33
  }
34
+
26
35
  /**
27
36
  * Creates a rotation transformations around the center and an X axis
28
37
  * @param inputs Rotation around center with an X axis information
@@ -31,13 +40,14 @@ export class Transforms {
31
40
  * @shortname center x
32
41
  * @drawable false
33
42
  */
34
- rotationCenterX(inputs) {
43
+ rotationCenterX(inputs: Inputs.Transforms.RotationCenterDto): Base.TransformMatrixes {
35
44
  return [
36
45
  this.translation(-inputs.center[0], -inputs.center[1], -inputs.center[2]),
37
46
  this.rotationX(this.math.degToRad({ number: inputs.angle })),
38
47
  this.translation(inputs.center[0], inputs.center[1], inputs.center[2]),
39
- ];
48
+ ] as Base.TransformMatrixes;
40
49
  }
50
+
41
51
  /**
42
52
  * Creates a rotation transformations around the center and an Y axis
43
53
  * @param inputs Rotation around center with an Y axis information
@@ -46,13 +56,14 @@ export class Transforms {
46
56
  * @shortname center y
47
57
  * @drawable false
48
58
  */
49
- rotationCenterY(inputs) {
59
+ rotationCenterY(inputs: Inputs.Transforms.RotationCenterDto): Base.TransformMatrixes {
50
60
  return [
51
61
  this.translation(-inputs.center[0], -inputs.center[1], -inputs.center[2]),
52
62
  this.rotationY(this.math.degToRad({ number: inputs.angle })),
53
63
  this.translation(inputs.center[0], inputs.center[1], inputs.center[2]),
54
- ];
64
+ ] as Base.TransformMatrixes;
55
65
  }
66
+
56
67
  /**
57
68
  * Creates a rotation transformations around the center and an Z axis
58
69
  * @param inputs Rotation around center with an Z axis information
@@ -61,13 +72,14 @@ export class Transforms {
61
72
  * @shortname center z
62
73
  * @drawable false
63
74
  */
64
- rotationCenterZ(inputs) {
75
+ rotationCenterZ(inputs: Inputs.Transforms.RotationCenterDto): Base.TransformMatrixes {
65
76
  return [
66
77
  this.translation(-inputs.center[0], -inputs.center[1], -inputs.center[2]),
67
78
  this.rotationZ(this.math.degToRad({ number: inputs.angle })),
68
79
  this.translation(inputs.center[0], inputs.center[1], inputs.center[2]),
69
- ];
80
+ ] as Base.TransformMatrixes;
70
81
  }
82
+
71
83
  /**
72
84
  * Creates a rotation transformations with yaw pitch and roll
73
85
  * @param inputs Yaw pitch roll rotation information
@@ -76,13 +88,17 @@ export class Transforms {
76
88
  * @shortname yaw pitch roll
77
89
  * @drawable false
78
90
  */
79
- rotationCenterYawPitchRoll(inputs) {
91
+ rotationCenterYawPitchRoll(inputs: Inputs.Transforms.RotationCenterYawPitchRollDto): Base.TransformMatrixes {
80
92
  return [
81
93
  this.translation(-inputs.center[0], -inputs.center[1], -inputs.center[2]),
82
- this.rotationYawPitchRoll(this.math.degToRad({ number: inputs.yaw }), this.math.degToRad({ number: inputs.pitch }), this.math.degToRad({ number: inputs.roll })),
94
+ this.rotationYawPitchRoll(
95
+ this.math.degToRad({ number: inputs.yaw }),
96
+ this.math.degToRad({ number: inputs.pitch }),
97
+ this.math.degToRad({ number: inputs.roll })),
83
98
  this.translation(inputs.center[0], inputs.center[1], inputs.center[2]),
84
- ];
99
+ ] as Base.TransformMatrixes;
85
100
  }
101
+
86
102
  /**
87
103
  * Scale transformation around center and xyz directions
88
104
  * @param inputs Scale center xyz trnansformation
@@ -91,13 +107,14 @@ export class Transforms {
91
107
  * @shortname center xyz
92
108
  * @drawable false
93
109
  */
94
- scaleCenterXYZ(inputs) {
110
+ scaleCenterXYZ(inputs: Inputs.Transforms.ScaleCenterXYZDto): Base.TransformMatrixes {
95
111
  return [
96
112
  this.translation(-inputs.center[0], -inputs.center[1], -inputs.center[2]),
97
113
  this.scaling(inputs.scaleXyz[0], inputs.scaleXyz[1], inputs.scaleXyz[2]),
98
114
  this.translation(inputs.center[0], inputs.center[1], inputs.center[2]),
99
- ];
115
+ ] as Base.TransformMatrixes;
100
116
  }
117
+
101
118
  /**
102
119
  * Creates the scale transformation in x, y and z directions
103
120
  * @param inputs Scale XYZ number array information
@@ -106,9 +123,10 @@ export class Transforms {
106
123
  * @shortname xyz
107
124
  * @drawable false
108
125
  */
109
- scaleXYZ(inputs) {
110
- return [this.scaling(inputs.scaleXyz[0], inputs.scaleXyz[1], inputs.scaleXyz[2])];
126
+ scaleXYZ(inputs: Inputs.Transforms.ScaleXYZDto): Base.TransformMatrixes {
127
+ return [this.scaling(inputs.scaleXyz[0], inputs.scaleXyz[1], inputs.scaleXyz[2])] as Base.TransformMatrixes;
111
128
  }
129
+
112
130
  /**
113
131
  * Creates uniform scale transformation
114
132
  * @param inputs Scale Dto
@@ -117,9 +135,10 @@ export class Transforms {
117
135
  * @shortname uniform
118
136
  * @drawable false
119
137
  */
120
- uniformScale(inputs) {
121
- return [this.scaling(inputs.scale, inputs.scale, inputs.scale)];
138
+ uniformScale(inputs: Inputs.Transforms.UniformScaleDto): Base.TransformMatrixes {
139
+ return [this.scaling(inputs.scale, inputs.scale, inputs.scale)] as Base.TransformMatrixes;
122
140
  }
141
+
123
142
  /**
124
143
  * Creates uniform scale transformation from the center
125
144
  * @param inputs Scale Dto with center point information
@@ -128,13 +147,14 @@ export class Transforms {
128
147
  * @shortname uniform from center
129
148
  * @drawable false
130
149
  */
131
- uniformScaleFromCenter(inputs) {
150
+ uniformScaleFromCenter(inputs: Inputs.Transforms.UniformScaleFromCenterDto): Base.TransformMatrixes {
132
151
  return [
133
152
  this.translation(-inputs.center[0], -inputs.center[1], -inputs.center[2]),
134
153
  this.scaling(inputs.scale, inputs.scale, inputs.scale),
135
154
  this.translation(inputs.center[0], inputs.center[1], inputs.center[2]),
136
- ];
155
+ ] as Base.TransformMatrixes;
137
156
  }
157
+
138
158
  /**
139
159
  * Creates the translation transformation
140
160
  * @param inputs Translation information
@@ -143,9 +163,10 @@ export class Transforms {
143
163
  * @shortname xyz
144
164
  * @drawable false
145
165
  */
146
- translationXYZ(inputs) {
147
- return [this.translation(inputs.translation[0], inputs.translation[1], inputs.translation[2])];
166
+ translationXYZ(inputs: Inputs.Transforms.TranslationXYZDto): Base.TransformMatrixes {
167
+ return [this.translation(inputs.translation[0], inputs.translation[1], inputs.translation[2])] as Base.TransformMatrixes;
148
168
  }
169
+
149
170
  /**
150
171
  * Creates the translation transformation
151
172
  * @param inputs Translation information
@@ -154,77 +175,97 @@ export class Transforms {
154
175
  * @shortname xyz
155
176
  * @drawable false
156
177
  */
157
- translationsXYZ(inputs) {
158
- return inputs.translations.map(translation => [this.translation(translation[0], translation[1], translation[2])]);
178
+ translationsXYZ(inputs: Inputs.Transforms.TranslationsXYZDto): Base.TransformMatrixes[] {
179
+ return inputs.translations.map(translation => [this.translation(translation[0], translation[1], translation[2])]) as Base.TransformMatrixes[];
159
180
  }
160
- translation(x, y, z) {
181
+
182
+ private translation(x: number, y: number, z: number) {
161
183
  return [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, x, y, z, 1.0];
162
184
  }
163
- scaling(x, y, z) {
185
+
186
+ private scaling(x: number, y: number, z: number) {
164
187
  return [x, 0.0, 0.0, 0.0, 0.0, y, 0.0, 0.0, 0.0, 0.0, z, 0.0, 0.0, 0.0, 0.0, 1.0];
165
188
  }
166
- identity() {
189
+
190
+ private identity() {
167
191
  return [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0];
168
192
  }
169
- rotationAxis(axis, angle) {
193
+
194
+ private rotationAxis(axis: Base.Vector3, angle: number) {
170
195
  const s = Math.sin(-angle);
171
196
  const c = Math.cos(-angle);
172
197
  const c1 = 1 - c;
198
+
173
199
  const a = this.vector.normalized({ vector: axis });
200
+
174
201
  const x = a[0];
175
202
  const y = a[1];
176
203
  const z = a[2];
204
+
177
205
  const m = this.identity();
206
+
178
207
  m[0] = x * x * c1 + c;
179
208
  m[1] = x * y * c1 - z * s;
180
209
  m[2] = x * z * c1 + y * s;
181
210
  m[3] = 0.0;
211
+
182
212
  m[4] = y * x * c1 + z * s;
183
213
  m[5] = y * y * c1 + c;
184
214
  m[6] = y * z * c1 - x * s;
185
215
  m[7] = 0.0;
216
+
186
217
  m[8] = z * x * c1 - y * s;
187
218
  m[9] = z * y * c1 + x * s;
188
219
  m[10] = z * z * c1 + c;
189
220
  m[11] = 0.0;
221
+
190
222
  m[12] = 0.0;
191
223
  m[13] = 0.0;
192
224
  m[14] = 0.0;
193
225
  m[15] = 1.0;
226
+
194
227
  return m;
195
228
  }
196
- rotationX(angle) {
229
+
230
+ private rotationX(angle: number) {
197
231
  const s = Math.sin(angle);
198
232
  const c = Math.cos(angle);
199
233
  return [1.0, 0.0, 0.0, 0.0, 0.0, c, s, 0.0, 0.0, -s, c, 0.0, 0.0, 0.0, 0.0, 1.0];
200
234
  }
201
- rotationY(angle) {
235
+
236
+ private rotationY(angle: number) {
202
237
  const s = Math.sin(angle);
203
238
  const c = Math.cos(angle);
204
239
  return [c, 0.0, -s, 0.0, 0.0, 1.0, 0.0, 0.0, s, 0.0, c, 0.0, 0.0, 0.0, 0.0, 1.0];
205
240
  }
206
- rotationZ(angle) {
241
+
242
+ private rotationZ(angle: number) {
207
243
  const s = Math.sin(angle);
208
244
  const c = Math.cos(angle);
209
245
  return [c, s, 0.0, 0.0, -s, c, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0];
210
246
  }
211
- rotationYawPitchRoll(yaw, pitch, roll) {
247
+
248
+ private rotationYawPitchRoll(yaw: number, pitch: number, roll: number) {
212
249
  const halfRoll = roll * 0.5;
213
250
  const halfPitch = pitch * 0.5;
214
251
  const halfYaw = yaw * 0.5;
252
+
215
253
  const sinRoll = Math.sin(halfRoll);
216
254
  const cosRoll = Math.cos(halfRoll);
217
255
  const sinPitch = Math.sin(halfPitch);
218
256
  const cosPitch = Math.cos(halfPitch);
219
257
  const sinYaw = Math.sin(halfYaw);
220
258
  const cosYaw = Math.cos(halfYaw);
259
+
221
260
  const x = cosYaw * sinPitch * cosRoll + sinYaw * cosPitch * sinRoll;
222
261
  const y = sinYaw * cosPitch * cosRoll - cosYaw * sinPitch * sinRoll;
223
262
  const z = cosYaw * cosPitch * sinRoll - sinYaw * sinPitch * cosRoll;
224
263
  const w = cosYaw * cosPitch * cosRoll + sinYaw * sinPitch * sinRoll;
264
+
225
265
  return this.rotationMatrixFromQuat(x, y, z, w);
226
266
  }
227
- rotationMatrixFromQuat(x, y, z, w) {
267
+
268
+ private rotationMatrixFromQuat(x: number, y: number, z: number, w: number) {
228
269
  const xx = x * x;
229
270
  const yy = y * y;
230
271
  const zz = z * z;
@@ -234,19 +275,24 @@ export class Transforms {
234
275
  const yw = y * w;
235
276
  const yz = y * z;
236
277
  const xw = x * w;
278
+
237
279
  const m = this.identity();
280
+
238
281
  m[0] = 1.0 - 2.0 * (yy + zz);
239
282
  m[1] = 2.0 * (xy + zw);
240
283
  m[2] = 2.0 * (zx - yw);
241
284
  m[3] = 0.0;
285
+
242
286
  m[4] = 2.0 * (xy - zw);
243
287
  m[5] = 1.0 - 2.0 * (zz + xx);
244
288
  m[6] = 2.0 * (yz + xw);
245
289
  m[7] = 0.0;
290
+
246
291
  m[8] = 2.0 * (zx + yw);
247
292
  m[9] = 2.0 * (yz - xw);
248
293
  m[10] = 1.0 - 2.0 * (yy + xx);
249
294
  m[11] = 0.0;
295
+
250
296
  m[12] = 0.0;
251
297
  m[13] = 0.0;
252
298
  m[14] = 0.0;
@@ -0,0 +1,360 @@
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
+