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