@bitbybit-dev/base 1.3.2 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/lib/api/GlobalCDNProvider.js +1 -1
- package/lib/api/index.d.ts +2 -0
- package/lib/api/index.js +2 -0
- package/lib/api/inputs/base-inputs.d.ts +10 -4
- package/lib/api/inputs/color-inputs.d.ts +24 -23
- package/lib/api/inputs/color-inputs.js +1 -0
- package/lib/api/inputs/dates-inputs.d.ts +16 -16
- package/lib/api/inputs/frame-inputs.d.ts +515 -0
- package/lib/api/inputs/frame-inputs.js +617 -0
- package/lib/api/inputs/index.d.ts +1 -0
- package/lib/api/inputs/index.js +1 -0
- package/lib/api/inputs/io-inputs.d.ts +3 -3
- package/lib/api/inputs/io-inputs.js +1 -1
- package/lib/api/inputs/lists-inputs.d.ts +23 -23
- package/lib/api/inputs/logic-inputs.d.ts +11 -11
- package/lib/api/inputs/math-inputs.d.ts +49 -49
- package/lib/api/inputs/math-inputs.js +4 -4
- package/lib/api/inputs/mesh-inputs.d.ts +3 -3
- package/lib/api/inputs/mesh-inputs.js +3 -3
- package/lib/api/inputs/point-inputs.d.ts +39 -38
- package/lib/api/inputs/point-inputs.js +6 -5
- package/lib/api/inputs/polyline-inputs.d.ts +5 -4
- package/lib/api/inputs/polyline-inputs.js +3 -3
- package/lib/api/inputs/text-inputs.d.ts +34 -33
- package/lib/api/inputs/text-inputs.js +15 -12
- package/lib/api/inputs/transforms-inputs.d.ts +16 -16
- package/lib/api/inputs/vector-inputs.d.ts +26 -25
- package/lib/api/inputs/vector-inputs.js +2 -1
- package/lib/api/kernel-calls/call-by-path.d.ts +12 -0
- package/lib/api/kernel-calls/call-by-path.js +36 -0
- package/lib/api/kernel-calls/constraints.d.ts +53 -0
- package/lib/api/kernel-calls/constraints.js +21 -0
- package/lib/api/kernel-calls/describe-failure.d.ts +32 -0
- package/lib/api/kernel-calls/describe-failure.js +164 -0
- package/lib/api/kernel-calls/errors.d.ts +55 -0
- package/lib/api/kernel-calls/errors.js +42 -0
- package/lib/api/kernel-calls/failure-message.d.ts +18 -0
- package/lib/api/kernel-calls/failure-message.js +36 -0
- package/lib/api/kernel-calls/index.d.ts +10 -0
- package/lib/api/kernel-calls/index.js +10 -0
- package/lib/api/kernel-calls/input-rules.d.ts +67 -0
- package/lib/api/kernel-calls/input-rules.js +135 -0
- package/lib/api/kernel-calls/input-validation.d.ts +130 -0
- package/lib/api/kernel-calls/input-validation.js +221 -0
- package/lib/api/kernel-calls/rehydrate.d.ts +16 -0
- package/lib/api/kernel-calls/rehydrate.js +38 -0
- package/lib/api/kernel-calls/resolve-dto.d.ts +59 -0
- package/lib/api/kernel-calls/resolve-dto.js +61 -0
- package/lib/api/kernel-calls/with-defaults.d.ts +16 -0
- package/lib/api/kernel-calls/with-defaults.js +53 -0
- package/lib/api/resolved-inputs/index.d.ts +304 -0
- package/lib/api/resolved-inputs/index.js +1 -0
- package/lib/api/services/color.js +43 -26
- package/lib/api/services/dates.js +53 -33
- package/lib/api/services/frame.d.ts +670 -0
- package/lib/api/services/frame.js +1040 -0
- package/lib/api/services/helpers/dxf/dxf-generator.d.ts +2 -3
- package/lib/api/services/helpers/dxf/dxf-generator.js +27 -37
- package/lib/api/services/helpers/dxf/dxf.js +10 -4
- package/lib/api/services/helpers/frame-axes.d.ts +36 -0
- package/lib/api/services/helpers/frame-axes.js +57 -0
- package/lib/api/services/helpers/matrices.d.ts +17 -0
- package/lib/api/services/helpers/matrices.js +51 -0
- package/lib/api/services/index.d.ts +1 -0
- package/lib/api/services/index.js +1 -0
- package/lib/api/services/line.js +15 -12
- package/lib/api/services/lists.js +174 -136
- package/lib/api/services/logic.js +44 -34
- package/lib/api/services/math.js +127 -82
- package/lib/api/services/mesh.js +20 -13
- package/lib/api/services/point.js +62 -46
- package/lib/api/services/polyline.js +22 -18
- package/lib/api/services/text.js +81 -46
- package/lib/api/services/transforms.js +38 -25
- package/lib/api/services/vector.js +37 -22
- package/package.json +1 -1
package/lib/api/services/math.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as Inputs from "../inputs";
|
|
2
|
+
import { resolveDto } from "../kernel-calls";
|
|
2
3
|
/**
|
|
3
4
|
* Arithmetic, rounding, ranges, random numbers and the trigonometric functions on plain numbers.
|
|
4
5
|
* The trigonometric functions take and give angles in radians; `degToRad` and `radToDeg` convert at
|
|
@@ -18,7 +19,8 @@ export class MathBitByBit {
|
|
|
18
19
|
* @drawable false
|
|
19
20
|
*/
|
|
20
21
|
number(inputs) {
|
|
21
|
-
|
|
22
|
+
const resolved = resolveDto(Inputs.Math.NumberDto, inputs);
|
|
23
|
+
return resolved.number;
|
|
22
24
|
}
|
|
23
25
|
/**
|
|
24
26
|
* Applies one arithmetic operation to two numbers: add, subtract, multiply, divide, power or
|
|
@@ -38,25 +40,26 @@ export class MathBitByBit {
|
|
|
38
40
|
* ```
|
|
39
41
|
*/
|
|
40
42
|
twoNrOperation(inputs) {
|
|
43
|
+
const resolved = resolveDto(Inputs.Math.ActionOnTwoNumbersDto, inputs);
|
|
41
44
|
let result;
|
|
42
|
-
switch (
|
|
45
|
+
switch (resolved.operation) {
|
|
43
46
|
case Inputs.Math.mathTwoNrOperatorEnum.add:
|
|
44
|
-
result =
|
|
47
|
+
result = resolved.first + resolved.second;
|
|
45
48
|
break;
|
|
46
49
|
case Inputs.Math.mathTwoNrOperatorEnum.subtract:
|
|
47
|
-
result =
|
|
50
|
+
result = resolved.first - resolved.second;
|
|
48
51
|
break;
|
|
49
52
|
case Inputs.Math.mathTwoNrOperatorEnum.multiply:
|
|
50
|
-
result =
|
|
53
|
+
result = resolved.first * resolved.second;
|
|
51
54
|
break;
|
|
52
55
|
case Inputs.Math.mathTwoNrOperatorEnum.divide:
|
|
53
|
-
result =
|
|
56
|
+
result = resolved.first / resolved.second;
|
|
54
57
|
break;
|
|
55
58
|
case Inputs.Math.mathTwoNrOperatorEnum.power:
|
|
56
|
-
result = Math.pow(
|
|
59
|
+
result = Math.pow(resolved.first, resolved.second);
|
|
57
60
|
break;
|
|
58
61
|
case Inputs.Math.mathTwoNrOperatorEnum.modulus:
|
|
59
|
-
result =
|
|
62
|
+
result = resolved.first % resolved.second;
|
|
60
63
|
break;
|
|
61
64
|
default:
|
|
62
65
|
break;
|
|
@@ -79,7 +82,8 @@ export class MathBitByBit {
|
|
|
79
82
|
* ```
|
|
80
83
|
*/
|
|
81
84
|
modulus(inputs) {
|
|
82
|
-
|
|
85
|
+
const resolved = resolveDto(Inputs.Math.ModulusDto, inputs);
|
|
86
|
+
return this.twoNrOperation({ first: resolved.number, second: resolved.modulus, operation: Inputs.Math.mathTwoNrOperatorEnum.modulus });
|
|
83
87
|
}
|
|
84
88
|
/**
|
|
85
89
|
* Rounds a number to a given number of decimal places.
|
|
@@ -96,7 +100,8 @@ export class MathBitByBit {
|
|
|
96
100
|
* ```
|
|
97
101
|
*/
|
|
98
102
|
roundToDecimals(inputs) {
|
|
99
|
-
|
|
103
|
+
const resolved = resolveDto(Inputs.Math.RoundToDecimalsDto, inputs);
|
|
104
|
+
return Math.round(resolved.number * Math.pow(10, resolved.decimalPlaces)) / Math.pow(10, resolved.decimalPlaces);
|
|
100
105
|
}
|
|
101
106
|
/**
|
|
102
107
|
* Rounds a number to a given number of decimal places and drops the zeros at the end.
|
|
@@ -115,8 +120,9 @@ export class MathBitByBit {
|
|
|
115
120
|
* ```
|
|
116
121
|
*/
|
|
117
122
|
roundAndRemoveTrailingZeros(inputs) {
|
|
118
|
-
const
|
|
119
|
-
|
|
123
|
+
const resolved = resolveDto(Inputs.Math.RoundToDecimalsDto, inputs);
|
|
124
|
+
const rounded = Math.round(resolved.number * Math.pow(10, resolved.decimalPlaces)) / Math.pow(10, resolved.decimalPlaces);
|
|
125
|
+
return parseFloat(rounded.toFixed(resolved.decimalPlaces));
|
|
120
126
|
}
|
|
121
127
|
/**
|
|
122
128
|
* Applies one operation to a single number: absolute, negate, square root, rounding,
|
|
@@ -136,64 +142,65 @@ export class MathBitByBit {
|
|
|
136
142
|
* ```
|
|
137
143
|
*/
|
|
138
144
|
oneNrOperation(inputs) {
|
|
145
|
+
const resolved = resolveDto(Inputs.Math.ActionOnOneNumberDto, inputs);
|
|
139
146
|
let result;
|
|
140
|
-
switch (
|
|
147
|
+
switch (resolved.operation) {
|
|
141
148
|
case Inputs.Math.mathOneNrOperatorEnum.absolute:
|
|
142
|
-
result = Math.abs(
|
|
149
|
+
result = Math.abs(resolved.number);
|
|
143
150
|
break;
|
|
144
151
|
case Inputs.Math.mathOneNrOperatorEnum.negate:
|
|
145
|
-
result = -
|
|
152
|
+
result = -resolved.number;
|
|
146
153
|
break;
|
|
147
154
|
case Inputs.Math.mathOneNrOperatorEnum.ln:
|
|
148
|
-
result = Math.log(
|
|
155
|
+
result = Math.log(resolved.number);
|
|
149
156
|
break;
|
|
150
157
|
case Inputs.Math.mathOneNrOperatorEnum.log10:
|
|
151
|
-
result = Math.log10(
|
|
158
|
+
result = Math.log10(resolved.number);
|
|
152
159
|
break;
|
|
153
160
|
case Inputs.Math.mathOneNrOperatorEnum.tenPow:
|
|
154
|
-
result = Math.pow(10,
|
|
161
|
+
result = Math.pow(10, resolved.number);
|
|
155
162
|
break;
|
|
156
163
|
case Inputs.Math.mathOneNrOperatorEnum.round:
|
|
157
|
-
result = Math.round(
|
|
164
|
+
result = Math.round(resolved.number);
|
|
158
165
|
break;
|
|
159
166
|
case Inputs.Math.mathOneNrOperatorEnum.floor:
|
|
160
|
-
result = Math.floor(
|
|
167
|
+
result = Math.floor(resolved.number);
|
|
161
168
|
break;
|
|
162
169
|
case Inputs.Math.mathOneNrOperatorEnum.ceil:
|
|
163
|
-
result = Math.ceil(
|
|
170
|
+
result = Math.ceil(resolved.number);
|
|
164
171
|
break;
|
|
165
172
|
case Inputs.Math.mathOneNrOperatorEnum.sqrt:
|
|
166
|
-
result = Math.sqrt(
|
|
173
|
+
result = Math.sqrt(resolved.number);
|
|
167
174
|
break;
|
|
168
175
|
case Inputs.Math.mathOneNrOperatorEnum.sin:
|
|
169
|
-
result = Math.sin(
|
|
176
|
+
result = Math.sin(resolved.number);
|
|
170
177
|
break;
|
|
171
178
|
case Inputs.Math.mathOneNrOperatorEnum.cos:
|
|
172
|
-
result = Math.cos(
|
|
179
|
+
result = Math.cos(resolved.number);
|
|
173
180
|
break;
|
|
174
181
|
case Inputs.Math.mathOneNrOperatorEnum.tan:
|
|
175
|
-
result = Math.tan(
|
|
182
|
+
result = Math.tan(resolved.number);
|
|
176
183
|
break;
|
|
177
184
|
case Inputs.Math.mathOneNrOperatorEnum.asin:
|
|
178
|
-
result = Math.asin(
|
|
185
|
+
result = Math.asin(resolved.number);
|
|
179
186
|
break;
|
|
180
187
|
case Inputs.Math.mathOneNrOperatorEnum.acos:
|
|
181
|
-
result = Math.acos(
|
|
188
|
+
result = Math.acos(resolved.number);
|
|
182
189
|
break;
|
|
183
190
|
case Inputs.Math.mathOneNrOperatorEnum.atan:
|
|
184
|
-
result = Math.atan(
|
|
191
|
+
result = Math.atan(resolved.number);
|
|
185
192
|
break;
|
|
186
193
|
case Inputs.Math.mathOneNrOperatorEnum.log:
|
|
187
|
-
result = Math.log(
|
|
194
|
+
result = Math.log(resolved.number);
|
|
188
195
|
break;
|
|
189
196
|
case Inputs.Math.mathOneNrOperatorEnum.exp:
|
|
190
|
-
result = Math.exp(
|
|
197
|
+
result = Math.exp(resolved.number);
|
|
191
198
|
break;
|
|
192
199
|
case Inputs.Math.mathOneNrOperatorEnum.degToRad:
|
|
193
|
-
result =
|
|
200
|
+
result = resolved.number * Math.PI / 180;
|
|
194
201
|
break;
|
|
195
202
|
case Inputs.Math.mathOneNrOperatorEnum.radToDeg:
|
|
196
|
-
result =
|
|
203
|
+
result = resolved.number * 180 / Math.PI;
|
|
197
204
|
break;
|
|
198
205
|
default:
|
|
199
206
|
break;
|
|
@@ -216,7 +223,8 @@ export class MathBitByBit {
|
|
|
216
223
|
* ```
|
|
217
224
|
*/
|
|
218
225
|
remap(inputs) {
|
|
219
|
-
|
|
226
|
+
const resolved = resolveDto(Inputs.Math.RemapNumberDto, inputs);
|
|
227
|
+
return (resolved.number - resolved.fromLow) * (resolved.toHigh - resolved.toLow) / (resolved.fromHigh - resolved.fromLow) + resolved.toLow;
|
|
220
228
|
}
|
|
221
229
|
/**
|
|
222
230
|
* Gives a random number from 0 up to, but not including, 1.
|
|
@@ -245,7 +253,8 @@ export class MathBitByBit {
|
|
|
245
253
|
* ```
|
|
246
254
|
*/
|
|
247
255
|
randomNumber(inputs) {
|
|
248
|
-
|
|
256
|
+
const resolved = resolveDto(Inputs.Math.RandomNumberDto, inputs);
|
|
257
|
+
return Math.random() * (resolved.high - resolved.low) + resolved.low;
|
|
249
258
|
}
|
|
250
259
|
/**
|
|
251
260
|
* Gives a list of random numbers between `low` and `high`.
|
|
@@ -262,9 +271,10 @@ export class MathBitByBit {
|
|
|
262
271
|
* ```
|
|
263
272
|
*/
|
|
264
273
|
randomNumbers(inputs) {
|
|
274
|
+
const resolved = resolveDto(Inputs.Math.RandomNumbersDto, inputs);
|
|
265
275
|
const result = [];
|
|
266
|
-
for (let i = 0; i <
|
|
267
|
-
result.push(this.randomNumber(
|
|
276
|
+
for (let i = 0; i < resolved.count; i++) {
|
|
277
|
+
result.push(this.randomNumber(resolved));
|
|
268
278
|
}
|
|
269
279
|
return result;
|
|
270
280
|
}
|
|
@@ -295,7 +305,8 @@ export class MathBitByBit {
|
|
|
295
305
|
* ```
|
|
296
306
|
*/
|
|
297
307
|
toFixed(inputs) {
|
|
298
|
-
|
|
308
|
+
const resolved = resolveDto(Inputs.Math.ToFixedDto, inputs);
|
|
309
|
+
return resolved.number.toFixed(resolved.decimalPlaces);
|
|
299
310
|
}
|
|
300
311
|
/**
|
|
301
312
|
* Adds two numbers.
|
|
@@ -312,7 +323,8 @@ export class MathBitByBit {
|
|
|
312
323
|
* ```
|
|
313
324
|
*/
|
|
314
325
|
add(inputs) {
|
|
315
|
-
|
|
326
|
+
const resolved = resolveDto(Inputs.Math.TwoNumbersDto, inputs);
|
|
327
|
+
return resolved.first + resolved.second;
|
|
316
328
|
}
|
|
317
329
|
/**
|
|
318
330
|
* Subtracts the second number from the first.
|
|
@@ -329,7 +341,8 @@ export class MathBitByBit {
|
|
|
329
341
|
* ```
|
|
330
342
|
*/
|
|
331
343
|
subtract(inputs) {
|
|
332
|
-
|
|
344
|
+
const resolved = resolveDto(Inputs.Math.TwoNumbersDto, inputs);
|
|
345
|
+
return resolved.first - resolved.second;
|
|
333
346
|
}
|
|
334
347
|
/**
|
|
335
348
|
* Multiplies two numbers.
|
|
@@ -346,7 +359,8 @@ export class MathBitByBit {
|
|
|
346
359
|
* ```
|
|
347
360
|
*/
|
|
348
361
|
multiply(inputs) {
|
|
349
|
-
|
|
362
|
+
const resolved = resolveDto(Inputs.Math.TwoNumbersDto, inputs);
|
|
363
|
+
return resolved.first * resolved.second;
|
|
350
364
|
}
|
|
351
365
|
/**
|
|
352
366
|
* Divides the first number by the second.
|
|
@@ -364,7 +378,8 @@ export class MathBitByBit {
|
|
|
364
378
|
* ```
|
|
365
379
|
*/
|
|
366
380
|
divide(inputs) {
|
|
367
|
-
|
|
381
|
+
const resolved = resolveDto(Inputs.Math.TwoNumbersDto, inputs);
|
|
382
|
+
return resolved.first / resolved.second;
|
|
368
383
|
}
|
|
369
384
|
/**
|
|
370
385
|
* Raises the first number to the power of the second.
|
|
@@ -381,7 +396,8 @@ export class MathBitByBit {
|
|
|
381
396
|
* ```
|
|
382
397
|
*/
|
|
383
398
|
power(inputs) {
|
|
384
|
-
|
|
399
|
+
const resolved = resolveDto(Inputs.Math.TwoNumbersDto, inputs);
|
|
400
|
+
return Math.pow(resolved.first, resolved.second);
|
|
385
401
|
}
|
|
386
402
|
/**
|
|
387
403
|
* Finds the square root of a number.
|
|
@@ -395,7 +411,8 @@ export class MathBitByBit {
|
|
|
395
411
|
* @drawable false
|
|
396
412
|
*/
|
|
397
413
|
sqrt(inputs) {
|
|
398
|
-
|
|
414
|
+
const resolved = resolveDto(Inputs.Math.NumberDto, inputs);
|
|
415
|
+
return Math.sqrt(resolved.number);
|
|
399
416
|
}
|
|
400
417
|
/**
|
|
401
418
|
* Drops the sign of a number, so the result is never negative.
|
|
@@ -408,7 +425,8 @@ export class MathBitByBit {
|
|
|
408
425
|
* @drawable false
|
|
409
426
|
*/
|
|
410
427
|
abs(inputs) {
|
|
411
|
-
|
|
428
|
+
const resolved = resolveDto(Inputs.Math.NumberDto, inputs);
|
|
429
|
+
return Math.abs(resolved.number);
|
|
412
430
|
}
|
|
413
431
|
/**
|
|
414
432
|
* Rounds a number to the nearest whole number; halves round up.
|
|
@@ -421,7 +439,8 @@ export class MathBitByBit {
|
|
|
421
439
|
* @drawable false
|
|
422
440
|
*/
|
|
423
441
|
round(inputs) {
|
|
424
|
-
|
|
442
|
+
const resolved = resolveDto(Inputs.Math.NumberDto, inputs);
|
|
443
|
+
return Math.round(resolved.number);
|
|
425
444
|
}
|
|
426
445
|
/**
|
|
427
446
|
* Rounds a number down to the whole number below it.
|
|
@@ -434,7 +453,8 @@ export class MathBitByBit {
|
|
|
434
453
|
* @drawable false
|
|
435
454
|
*/
|
|
436
455
|
floor(inputs) {
|
|
437
|
-
|
|
456
|
+
const resolved = resolveDto(Inputs.Math.NumberDto, inputs);
|
|
457
|
+
return Math.floor(resolved.number);
|
|
438
458
|
}
|
|
439
459
|
/**
|
|
440
460
|
* Rounds a number up to the whole number above it.
|
|
@@ -447,7 +467,8 @@ export class MathBitByBit {
|
|
|
447
467
|
* @drawable false
|
|
448
468
|
*/
|
|
449
469
|
ceil(inputs) {
|
|
450
|
-
|
|
470
|
+
const resolved = resolveDto(Inputs.Math.NumberDto, inputs);
|
|
471
|
+
return Math.ceil(resolved.number);
|
|
451
472
|
}
|
|
452
473
|
/**
|
|
453
474
|
* Flips the sign of a number.
|
|
@@ -460,7 +481,8 @@ export class MathBitByBit {
|
|
|
460
481
|
* @drawable false
|
|
461
482
|
*/
|
|
462
483
|
negate(inputs) {
|
|
463
|
-
|
|
484
|
+
const resolved = resolveDto(Inputs.Math.NumberDto, inputs);
|
|
485
|
+
return -resolved.number;
|
|
464
486
|
}
|
|
465
487
|
/**
|
|
466
488
|
* Finds the natural logarithm of a number: the power e must be raised to for that number.
|
|
@@ -473,7 +495,8 @@ export class MathBitByBit {
|
|
|
473
495
|
* @drawable false
|
|
474
496
|
*/
|
|
475
497
|
ln(inputs) {
|
|
476
|
-
|
|
498
|
+
const resolved = resolveDto(Inputs.Math.NumberDto, inputs);
|
|
499
|
+
return Math.log(resolved.number);
|
|
477
500
|
}
|
|
478
501
|
/**
|
|
479
502
|
* Finds the base-10 logarithm of a number: the power 10 must be raised to for that number.
|
|
@@ -486,7 +509,8 @@ export class MathBitByBit {
|
|
|
486
509
|
* @drawable false
|
|
487
510
|
*/
|
|
488
511
|
log10(inputs) {
|
|
489
|
-
|
|
512
|
+
const resolved = resolveDto(Inputs.Math.NumberDto, inputs);
|
|
513
|
+
return Math.log10(resolved.number);
|
|
490
514
|
}
|
|
491
515
|
/**
|
|
492
516
|
* Raises 10 to the power of a number.
|
|
@@ -499,7 +523,8 @@ export class MathBitByBit {
|
|
|
499
523
|
* @drawable false
|
|
500
524
|
*/
|
|
501
525
|
tenPow(inputs) {
|
|
502
|
-
|
|
526
|
+
const resolved = resolveDto(Inputs.Math.NumberDto, inputs);
|
|
527
|
+
return Math.pow(10, resolved.number);
|
|
503
528
|
}
|
|
504
529
|
/**
|
|
505
530
|
* Finds the sine of an angle given in radians.
|
|
@@ -512,7 +537,8 @@ export class MathBitByBit {
|
|
|
512
537
|
* @drawable false
|
|
513
538
|
*/
|
|
514
539
|
sin(inputs) {
|
|
515
|
-
|
|
540
|
+
const resolved = resolveDto(Inputs.Math.NumberDto, inputs);
|
|
541
|
+
return Math.sin(resolved.number);
|
|
516
542
|
}
|
|
517
543
|
/**
|
|
518
544
|
* Finds the cosine of an angle given in radians.
|
|
@@ -525,7 +551,8 @@ export class MathBitByBit {
|
|
|
525
551
|
* @drawable false
|
|
526
552
|
*/
|
|
527
553
|
cos(inputs) {
|
|
528
|
-
|
|
554
|
+
const resolved = resolveDto(Inputs.Math.NumberDto, inputs);
|
|
555
|
+
return Math.cos(resolved.number);
|
|
529
556
|
}
|
|
530
557
|
/**
|
|
531
558
|
* Finds the tangent of an angle given in radians.
|
|
@@ -538,7 +565,8 @@ export class MathBitByBit {
|
|
|
538
565
|
* @drawable false
|
|
539
566
|
*/
|
|
540
567
|
tan(inputs) {
|
|
541
|
-
|
|
568
|
+
const resolved = resolveDto(Inputs.Math.NumberDto, inputs);
|
|
569
|
+
return Math.tan(resolved.number);
|
|
542
570
|
}
|
|
543
571
|
/**
|
|
544
572
|
* Finds the angle, in radians, whose sine is the given number.
|
|
@@ -551,7 +579,8 @@ export class MathBitByBit {
|
|
|
551
579
|
* @drawable false
|
|
552
580
|
*/
|
|
553
581
|
asin(inputs) {
|
|
554
|
-
|
|
582
|
+
const resolved = resolveDto(Inputs.Math.NumberDto, inputs);
|
|
583
|
+
return Math.asin(resolved.number);
|
|
555
584
|
}
|
|
556
585
|
/**
|
|
557
586
|
* Finds the angle, in radians, whose cosine is the given number.
|
|
@@ -564,7 +593,8 @@ export class MathBitByBit {
|
|
|
564
593
|
* @drawable false
|
|
565
594
|
*/
|
|
566
595
|
acos(inputs) {
|
|
567
|
-
|
|
596
|
+
const resolved = resolveDto(Inputs.Math.NumberDto, inputs);
|
|
597
|
+
return Math.acos(resolved.number);
|
|
568
598
|
}
|
|
569
599
|
/**
|
|
570
600
|
* Finds the angle, in radians, whose tangent is the given number.
|
|
@@ -577,7 +607,8 @@ export class MathBitByBit {
|
|
|
577
607
|
* @drawable false
|
|
578
608
|
*/
|
|
579
609
|
atan(inputs) {
|
|
580
|
-
|
|
610
|
+
const resolved = resolveDto(Inputs.Math.NumberDto, inputs);
|
|
611
|
+
return Math.atan(resolved.number);
|
|
581
612
|
}
|
|
582
613
|
/**
|
|
583
614
|
* Raises e, the base of the natural logarithm, to the power of a number.
|
|
@@ -590,7 +621,8 @@ export class MathBitByBit {
|
|
|
590
621
|
* @drawable false
|
|
591
622
|
*/
|
|
592
623
|
exp(inputs) {
|
|
593
|
-
|
|
624
|
+
const resolved = resolveDto(Inputs.Math.NumberDto, inputs);
|
|
625
|
+
return Math.exp(resolved.number);
|
|
594
626
|
}
|
|
595
627
|
/**
|
|
596
628
|
* Converts an angle from degrees to radians.
|
|
@@ -603,7 +635,8 @@ export class MathBitByBit {
|
|
|
603
635
|
* @drawable false
|
|
604
636
|
*/
|
|
605
637
|
degToRad(inputs) {
|
|
606
|
-
|
|
638
|
+
const resolved = resolveDto(Inputs.Math.NumberDto, inputs);
|
|
639
|
+
return resolved.number * Math.PI / 180;
|
|
607
640
|
}
|
|
608
641
|
/**
|
|
609
642
|
* Converts an angle from radians to degrees.
|
|
@@ -616,7 +649,8 @@ export class MathBitByBit {
|
|
|
616
649
|
* @drawable false
|
|
617
650
|
*/
|
|
618
651
|
radToDeg(inputs) {
|
|
619
|
-
|
|
652
|
+
const resolved = resolveDto(Inputs.Math.NumberDto, inputs);
|
|
653
|
+
return resolved.number * 180 / Math.PI;
|
|
620
654
|
}
|
|
621
655
|
/**
|
|
622
656
|
* Maps a value from 0 to 1 onto the range `min` to `max` along an easing curve, so the result
|
|
@@ -636,10 +670,11 @@ export class MathBitByBit {
|
|
|
636
670
|
* ```
|
|
637
671
|
*/
|
|
638
672
|
ease(inputs) {
|
|
639
|
-
const
|
|
640
|
-
const
|
|
641
|
-
const
|
|
642
|
-
const
|
|
673
|
+
const resolved = resolveDto(Inputs.Math.EaseDto, inputs);
|
|
674
|
+
const x = resolved.x;
|
|
675
|
+
const min = resolved.min;
|
|
676
|
+
const max = resolved.max;
|
|
677
|
+
const y = this[resolved.ease](x);
|
|
643
678
|
const res = this.remap({ number: y, fromLow: 0, fromHigh: 1, toLow: min, toHigh: max });
|
|
644
679
|
return res;
|
|
645
680
|
}
|
|
@@ -658,7 +693,8 @@ export class MathBitByBit {
|
|
|
658
693
|
* ```
|
|
659
694
|
*/
|
|
660
695
|
clamp(inputs) {
|
|
661
|
-
|
|
696
|
+
const resolved = resolveDto(Inputs.Math.ClampDto, inputs);
|
|
697
|
+
return Math.max(resolved.min, Math.min(resolved.max, resolved.number));
|
|
662
698
|
}
|
|
663
699
|
/**
|
|
664
700
|
* Blends from a start value to an end value by a fraction `t`: 0 gives the start, 1 the end,
|
|
@@ -677,7 +713,8 @@ export class MathBitByBit {
|
|
|
677
713
|
* ```
|
|
678
714
|
*/
|
|
679
715
|
lerp(inputs) {
|
|
680
|
-
|
|
716
|
+
const resolved = resolveDto(Inputs.Math.LerpDto, inputs);
|
|
717
|
+
return resolved.start + (resolved.end - resolved.start) * resolved.t;
|
|
681
718
|
}
|
|
682
719
|
/**
|
|
683
720
|
* Finds where a value sits between a start and an end, as a fraction: the `t` that `lerp` would
|
|
@@ -695,10 +732,11 @@ export class MathBitByBit {
|
|
|
695
732
|
* ```
|
|
696
733
|
*/
|
|
697
734
|
inverseLerp(inputs) {
|
|
698
|
-
|
|
735
|
+
const resolved = resolveDto(Inputs.Math.InverseLerpDto, inputs);
|
|
736
|
+
if (resolved.start === resolved.end) {
|
|
699
737
|
return 0;
|
|
700
738
|
}
|
|
701
|
-
return (
|
|
739
|
+
return (resolved.value - resolved.start) / (resolved.end - resolved.start);
|
|
702
740
|
}
|
|
703
741
|
/**
|
|
704
742
|
* Turns a value from 0 to 1 into a smooth S-curve that starts and ends gently; the value is
|
|
@@ -712,7 +750,8 @@ export class MathBitByBit {
|
|
|
712
750
|
* @drawable false
|
|
713
751
|
*/
|
|
714
752
|
smoothstep(inputs) {
|
|
715
|
-
const
|
|
753
|
+
const resolved = resolveDto(Inputs.Math.NumberDto, inputs);
|
|
754
|
+
const t = Math.max(0, Math.min(1, resolved.number));
|
|
716
755
|
return t * t * (3 - 2 * t);
|
|
717
756
|
}
|
|
718
757
|
/**
|
|
@@ -726,7 +765,8 @@ export class MathBitByBit {
|
|
|
726
765
|
* @drawable false
|
|
727
766
|
*/
|
|
728
767
|
sign(inputs) {
|
|
729
|
-
|
|
768
|
+
const resolved = resolveDto(Inputs.Math.NumberDto, inputs);
|
|
769
|
+
return Math.sign(resolved.number);
|
|
730
770
|
}
|
|
731
771
|
/**
|
|
732
772
|
* Keeps the part of a number after the decimal point, measured up from the whole number below
|
|
@@ -740,7 +780,8 @@ export class MathBitByBit {
|
|
|
740
780
|
* @drawable false
|
|
741
781
|
*/
|
|
742
782
|
fract(inputs) {
|
|
743
|
-
|
|
783
|
+
const resolved = resolveDto(Inputs.Math.NumberDto, inputs);
|
|
784
|
+
return resolved.number - Math.floor(resolved.number);
|
|
744
785
|
}
|
|
745
786
|
/**
|
|
746
787
|
* Wraps a number into a range so it cycles round: past `max` it comes back in at `min`, and
|
|
@@ -759,12 +800,13 @@ export class MathBitByBit {
|
|
|
759
800
|
* ```
|
|
760
801
|
*/
|
|
761
802
|
wrap(inputs) {
|
|
762
|
-
const
|
|
803
|
+
const resolved = resolveDto(Inputs.Math.WrapDto, inputs);
|
|
804
|
+
const range = resolved.max - resolved.min;
|
|
763
805
|
if (range === 0) {
|
|
764
|
-
return
|
|
806
|
+
return resolved.min;
|
|
765
807
|
}
|
|
766
|
-
const normalized = (
|
|
767
|
-
return normalized < 0 ? normalized +
|
|
808
|
+
const normalized = (resolved.number - resolved.min) % range;
|
|
809
|
+
return normalized < 0 ? normalized + resolved.max : normalized + resolved.min;
|
|
768
810
|
}
|
|
769
811
|
/**
|
|
770
812
|
* Bounces a value back and forth between 0 and `length` as `t` grows: up to `length`, back down
|
|
@@ -782,8 +824,9 @@ export class MathBitByBit {
|
|
|
782
824
|
* ```
|
|
783
825
|
*/
|
|
784
826
|
pingPong(inputs) {
|
|
785
|
-
const
|
|
786
|
-
|
|
827
|
+
const resolved = resolveDto(Inputs.Math.PingPongDto, inputs);
|
|
828
|
+
const t = Math.abs(resolved.t) % (resolved.length * 2);
|
|
829
|
+
return t > resolved.length ? resolved.length * 2 - t : t;
|
|
787
830
|
}
|
|
788
831
|
/**
|
|
789
832
|
* Moves a value toward a target by at most `maxDelta`, without overshooting it.
|
|
@@ -800,11 +843,12 @@ export class MathBitByBit {
|
|
|
800
843
|
* ```
|
|
801
844
|
*/
|
|
802
845
|
moveTowards(inputs) {
|
|
803
|
-
const
|
|
804
|
-
|
|
805
|
-
|
|
846
|
+
const resolved = resolveDto(Inputs.Math.MoveTowardsDto, inputs);
|
|
847
|
+
const delta = resolved.target - resolved.current;
|
|
848
|
+
if (Math.abs(delta) <= resolved.maxDelta) {
|
|
849
|
+
return resolved.target;
|
|
806
850
|
}
|
|
807
|
-
return
|
|
851
|
+
return resolved.current + Math.sign(delta) * resolved.maxDelta;
|
|
808
852
|
}
|
|
809
853
|
/**
|
|
810
854
|
* Works out a simple arithmetic expression written as text: numbers, +, -, the multiplication
|
|
@@ -825,7 +869,8 @@ export class MathBitByBit {
|
|
|
825
869
|
*/
|
|
826
870
|
evalArithmetic(inputs) {
|
|
827
871
|
var _a;
|
|
828
|
-
const
|
|
872
|
+
const resolved = resolveDto(Inputs.Math.EvalArithmeticDto, inputs);
|
|
873
|
+
const expr = resolved.expression;
|
|
829
874
|
const tokens = [];
|
|
830
875
|
let i = 0;
|
|
831
876
|
while (i < expr.length) {
|
package/lib/api/services/mesh.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import * as Inputs from "../inputs";
|
|
2
|
+
import { resolveDto } from "../kernel-calls";
|
|
1
3
|
/**
|
|
2
4
|
* Geometry on plain triangle meshes: a mesh is a list of triangles, each three points. The methods
|
|
3
5
|
* here work out the plane of a triangle, the distance from a point to a plane, and where two meshes
|
|
@@ -45,15 +47,16 @@ export class MeshBitByBit {
|
|
|
45
47
|
* ```
|
|
46
48
|
*/
|
|
47
49
|
calculateTrianglePlane(inputs) {
|
|
48
|
-
const
|
|
49
|
-
const
|
|
50
|
-
const
|
|
50
|
+
const resolved = resolveDto(Inputs.Mesh.TriangleToleranceDto, inputs);
|
|
51
|
+
const EPSILON_SQ = Math.pow((resolved.tolerance || 1e-7), 2);
|
|
52
|
+
const edge1 = this.vector.sub({ first: resolved.triangle[1], second: resolved.triangle[0] });
|
|
53
|
+
const edge2 = this.vector.sub({ first: resolved.triangle[2], second: resolved.triangle[0] });
|
|
51
54
|
const normal = this.vector.cross({ first: edge1, second: edge2 });
|
|
52
55
|
if (this.vector.lengthSq({ vector: normal }) < EPSILON_SQ) {
|
|
53
56
|
return undefined;
|
|
54
57
|
}
|
|
55
58
|
const normalizedNormal = this.vector.normalized({ vector: normal });
|
|
56
|
-
const d = this.vector.dot({ first: normalizedNormal, second:
|
|
59
|
+
const d = this.vector.dot({ first: normalizedNormal, second: resolved.triangle[0] });
|
|
57
60
|
return { normal: normalizedNormal, d: d };
|
|
58
61
|
}
|
|
59
62
|
/**
|
|
@@ -77,9 +80,10 @@ export class MeshBitByBit {
|
|
|
77
80
|
* ```
|
|
78
81
|
*/
|
|
79
82
|
triangleTriangleIntersection(inputs) {
|
|
80
|
-
const
|
|
81
|
-
const
|
|
82
|
-
const
|
|
83
|
+
const resolved = resolveDto(Inputs.Mesh.TriangleTriangleToleranceDto, inputs);
|
|
84
|
+
const t1 = resolved.triangle1;
|
|
85
|
+
const t2 = resolved.triangle2;
|
|
86
|
+
const EPSILON = resolved.tolerance || 1e-7;
|
|
83
87
|
const p1 = t1[0], p2 = t1[1], p3 = t1[2];
|
|
84
88
|
const q1 = t2[0], q2 = t2[1], q3 = t2[2];
|
|
85
89
|
const plane1 = this.calculateTrianglePlane({ triangle: t1, tolerance: EPSILON });
|
|
@@ -194,14 +198,15 @@ export class MeshBitByBit {
|
|
|
194
198
|
* ```
|
|
195
199
|
*/
|
|
196
200
|
meshMeshIntersectionSegments(inputs) {
|
|
197
|
-
const
|
|
198
|
-
const
|
|
201
|
+
const resolved = resolveDto(Inputs.Mesh.MeshMeshToleranceDto, inputs);
|
|
202
|
+
const mesh1 = resolved.mesh1;
|
|
203
|
+
const mesh2 = resolved.mesh2;
|
|
199
204
|
const intersectionSegments = [];
|
|
200
205
|
for (let i = 0; i < mesh1.length; ++i) {
|
|
201
206
|
for (let j = 0; j < mesh2.length; ++j) {
|
|
202
207
|
const triangle1 = mesh1[i];
|
|
203
208
|
const triangle2 = mesh2[j];
|
|
204
|
-
const segment = this.triangleTriangleIntersection({ triangle1, triangle2, tolerance:
|
|
209
|
+
const segment = this.triangleTriangleIntersection({ triangle1, triangle2, tolerance: resolved.tolerance });
|
|
205
210
|
if (segment) {
|
|
206
211
|
intersectionSegments.push(segment);
|
|
207
212
|
}
|
|
@@ -225,8 +230,9 @@ export class MeshBitByBit {
|
|
|
225
230
|
* ```
|
|
226
231
|
*/
|
|
227
232
|
meshMeshIntersectionPolylines(inputs) {
|
|
228
|
-
const
|
|
229
|
-
|
|
233
|
+
const resolved = resolveDto(Inputs.Mesh.MeshMeshToleranceDto, inputs);
|
|
234
|
+
const segments = this.meshMeshIntersectionSegments(resolved);
|
|
235
|
+
return this.polyline.sortSegmentsIntoPolylines({ segments, tolerance: resolved.tolerance });
|
|
230
236
|
}
|
|
231
237
|
/**
|
|
232
238
|
* Finds where the surfaces of two meshes cut through each other, as one list of points per
|
|
@@ -245,7 +251,8 @@ export class MeshBitByBit {
|
|
|
245
251
|
* ```
|
|
246
252
|
*/
|
|
247
253
|
meshMeshIntersectionPoints(inputs) {
|
|
248
|
-
const
|
|
254
|
+
const resolved = resolveDto(Inputs.Mesh.MeshMeshToleranceDto, inputs);
|
|
255
|
+
const polylines = this.meshMeshIntersectionPolylines(resolved);
|
|
249
256
|
return polylines.map(polyline => {
|
|
250
257
|
if (polyline.isClosed) {
|
|
251
258
|
return [...polyline.points, polyline.points[0]];
|