@bitbybit-dev/base 0.20.13 → 0.20.14
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/lib/api/GlobalCDNProvider.js +1 -1
- package/lib/api/inputs/lists-inputs.d.ts +39 -0
- package/lib/api/inputs/lists-inputs.js +43 -0
- package/lib/api/inputs/math-inputs.d.ts +154 -0
- package/lib/api/inputs/math-inputs.js +217 -0
- package/lib/api/inputs/text-inputs.d.ts +139 -0
- package/lib/api/inputs/text-inputs.js +215 -0
- package/lib/api/inputs/vector-inputs.d.ts +8 -0
- package/lib/api/inputs/vector-inputs.js +8 -0
- package/lib/api/services/color.d.ts +27 -12
- package/lib/api/services/color.js +27 -12
- package/lib/api/services/dates.d.ts +62 -30
- package/lib/api/services/dates.js +62 -30
- package/lib/api/services/geometry-helper.d.ts +50 -0
- package/lib/api/services/geometry-helper.js +50 -2
- package/lib/api/services/helpers/dxf/dxf.d.ts +19 -9
- package/lib/api/services/helpers/dxf/dxf.js +19 -9
- package/lib/api/services/line.d.ts +34 -16
- package/lib/api/services/line.js +34 -16
- package/lib/api/services/lists.d.ts +175 -32
- package/lib/api/services/lists.js +275 -32
- package/lib/api/services/logic.d.ts +24 -13
- package/lib/api/services/logic.js +24 -13
- package/lib/api/services/math.d.ts +180 -35
- package/lib/api/services/math.js +215 -35
- package/lib/api/services/mesh.d.ts +17 -6
- package/lib/api/services/mesh.js +17 -6
- package/lib/api/services/point.d.ts +63 -32
- package/lib/api/services/point.js +63 -32
- package/lib/api/services/polyline.d.ts +27 -11
- package/lib/api/services/polyline.js +27 -11
- package/lib/api/services/text.d.ts +286 -7
- package/lib/api/services/text.js +350 -7
- package/lib/api/services/transforms.d.ts +30 -16
- package/lib/api/services/transforms.js +30 -16
- package/lib/api/services/vector.d.ts +85 -38
- package/lib/api/services/vector.js +87 -38
- package/package.json +1 -1
package/lib/api/services/math.js
CHANGED
|
@@ -4,7 +4,8 @@ import * as Inputs from "../inputs";
|
|
|
4
4
|
*/
|
|
5
5
|
export class MathBitByBit {
|
|
6
6
|
/**
|
|
7
|
-
* Creates a number
|
|
7
|
+
* Creates and returns a number value (pass-through for number input).
|
|
8
|
+
* Example: Input 42 → 42, Input 3.14 → 3.14
|
|
8
9
|
* @param inputs a number to be created
|
|
9
10
|
* @returns number
|
|
10
11
|
* @group create
|
|
@@ -15,7 +16,8 @@ export class MathBitByBit {
|
|
|
15
16
|
return inputs.number;
|
|
16
17
|
}
|
|
17
18
|
/**
|
|
18
|
-
*
|
|
19
|
+
* Performs basic arithmetic operations on two numbers (add, subtract, multiply, divide, power, modulus).
|
|
20
|
+
* Example: 5 + 3 → 8, 10 % 3 → 1, 2 ^ 3 → 8
|
|
19
21
|
* @param inputs two numbers and operator
|
|
20
22
|
* @returns Result of math operation action
|
|
21
23
|
* @group operations
|
|
@@ -49,7 +51,8 @@ export class MathBitByBit {
|
|
|
49
51
|
return result;
|
|
50
52
|
}
|
|
51
53
|
/**
|
|
52
|
-
*
|
|
54
|
+
* Calculates the remainder after division (modulus operation).
|
|
55
|
+
* Example: 10 % 3 → 1, 17 % 5 → 2
|
|
53
56
|
* @param inputs two numbers and operator
|
|
54
57
|
* @returns Result of modulus operation
|
|
55
58
|
* @group operations
|
|
@@ -60,7 +63,8 @@ export class MathBitByBit {
|
|
|
60
63
|
return this.twoNrOperation({ first: inputs.number, second: inputs.modulus, operation: Inputs.Math.mathTwoNrOperatorEnum.modulus });
|
|
61
64
|
}
|
|
62
65
|
/**
|
|
63
|
-
*
|
|
66
|
+
* Rounds a number to specified decimal places.
|
|
67
|
+
* Example: 1.32156 with 3 decimals returns 1.322
|
|
64
68
|
* @param inputs a number and decimal places
|
|
65
69
|
* @returns Result of rounding
|
|
66
70
|
* @group operations
|
|
@@ -71,7 +75,21 @@ export class MathBitByBit {
|
|
|
71
75
|
return Math.round(inputs.number * Math.pow(10, inputs.decimalPlaces)) / Math.pow(10, inputs.decimalPlaces);
|
|
72
76
|
}
|
|
73
77
|
/**
|
|
74
|
-
*
|
|
78
|
+
* Rounds a number to specified decimal places and removes trailing zeros.
|
|
79
|
+
* Example: 1.32156 with 3 decimals returns 1.322, but 1.320000001 returns 1.32, and 1.000 returns 1
|
|
80
|
+
* @param inputs a number and decimal places
|
|
81
|
+
* @returns Result of rounding as a number without trailing zeros
|
|
82
|
+
* @group operations
|
|
83
|
+
* @shortname round trim zeros
|
|
84
|
+
* @drawable false
|
|
85
|
+
*/
|
|
86
|
+
roundAndRemoveTrailingZeros(inputs) {
|
|
87
|
+
const rounded = Math.round(inputs.number * Math.pow(10, inputs.decimalPlaces)) / Math.pow(10, inputs.decimalPlaces);
|
|
88
|
+
return parseFloat(rounded.toFixed(inputs.decimalPlaces));
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Performs mathematical operations on a single number (absolute, negate, sqrt, trig functions, logarithms, etc.).
|
|
92
|
+
* Example: sqrt(5) → 2.236, abs(-3) → 3, sin(π/2) → 1
|
|
75
93
|
* @param inputs one number and operator action
|
|
76
94
|
* @returns Result of math operation
|
|
77
95
|
* @group operations
|
|
@@ -144,7 +162,8 @@ export class MathBitByBit {
|
|
|
144
162
|
return result;
|
|
145
163
|
}
|
|
146
164
|
/**
|
|
147
|
-
*
|
|
165
|
+
* Maps a number from one range to another range proportionally.
|
|
166
|
+
* Example: 5 from [0,10] to [0,100] → 50, 0.5 from [0,1] to [-10,10] → 0
|
|
148
167
|
* @param inputs one number and operator action
|
|
149
168
|
* @returns Result of mapping
|
|
150
169
|
* @group operations
|
|
@@ -155,7 +174,8 @@ export class MathBitByBit {
|
|
|
155
174
|
return (inputs.number - inputs.fromLow) * (inputs.toHigh - inputs.toLow) / (inputs.fromHigh - inputs.fromLow) + inputs.toLow;
|
|
156
175
|
}
|
|
157
176
|
/**
|
|
158
|
-
*
|
|
177
|
+
* Generates a random decimal number between 0 (inclusive) and 1 (exclusive).
|
|
178
|
+
* Example: Outputs like 0.342, 0.891, or any value in [0, 1)
|
|
159
179
|
* @returns A random number between 0 and 1
|
|
160
180
|
* @group generate
|
|
161
181
|
* @shortname random 0 - 1
|
|
@@ -165,7 +185,8 @@ export class MathBitByBit {
|
|
|
165
185
|
return Math.random();
|
|
166
186
|
}
|
|
167
187
|
/**
|
|
168
|
-
*
|
|
188
|
+
* Generates a random number within a specified range (low to high).
|
|
189
|
+
* Example: Range [0, 10] → outputs like 3.7, 8.2, or any value between 0 and 10
|
|
169
190
|
* @param inputs low and high numbers
|
|
170
191
|
* @returns A random number
|
|
171
192
|
* @group generate
|
|
@@ -176,7 +197,8 @@ export class MathBitByBit {
|
|
|
176
197
|
return Math.random() * (inputs.high - inputs.low) + inputs.low;
|
|
177
198
|
}
|
|
178
199
|
/**
|
|
179
|
-
*
|
|
200
|
+
* Generates multiple random numbers within a specified range.
|
|
201
|
+
* Example: Range [0, 10] with 3 items → [2.5, 7.1, 4.8]
|
|
180
202
|
* @param inputs low and high numbers
|
|
181
203
|
* @returns A list of random numbers
|
|
182
204
|
* @group generate
|
|
@@ -191,7 +213,8 @@ export class MathBitByBit {
|
|
|
191
213
|
return result;
|
|
192
214
|
}
|
|
193
215
|
/**
|
|
194
|
-
*
|
|
216
|
+
* Returns the mathematical constant π (pi) ≈ 3.14159.
|
|
217
|
+
* Example: Outputs 3.141592653589793
|
|
195
218
|
* @returns A number PI
|
|
196
219
|
* @group generate
|
|
197
220
|
* @shortname π
|
|
@@ -201,7 +224,8 @@ export class MathBitByBit {
|
|
|
201
224
|
return Math.PI;
|
|
202
225
|
}
|
|
203
226
|
/**
|
|
204
|
-
*
|
|
227
|
+
* Formats a number as a string with a fixed number of decimal places (always shows trailing zeros).
|
|
228
|
+
* Example: 3.14159 with 2 decimals → '3.14', 5 with 3 decimals → '5.000'
|
|
205
229
|
* @param inputs a number to be rounded to decimal places
|
|
206
230
|
* @returns number
|
|
207
231
|
* @group operations
|
|
@@ -212,7 +236,8 @@ export class MathBitByBit {
|
|
|
212
236
|
return inputs.number.toFixed(inputs.decimalPlaces);
|
|
213
237
|
}
|
|
214
238
|
/**
|
|
215
|
-
* Adds two numbers
|
|
239
|
+
* Adds two numbers together.
|
|
240
|
+
* Example: 5 + 3 → 8, -2 + 7 → 5
|
|
216
241
|
* @param inputs two numbers
|
|
217
242
|
* @returns number
|
|
218
243
|
* @group basics
|
|
@@ -223,7 +248,8 @@ export class MathBitByBit {
|
|
|
223
248
|
return inputs.first + inputs.second;
|
|
224
249
|
}
|
|
225
250
|
/**
|
|
226
|
-
* Subtracts
|
|
251
|
+
* Subtracts the second number from the first.
|
|
252
|
+
* Example: 10 - 3 → 7, 5 - 8 → -3
|
|
227
253
|
* @param inputs two numbers
|
|
228
254
|
* @returns number
|
|
229
255
|
* @group basics
|
|
@@ -234,7 +260,8 @@ export class MathBitByBit {
|
|
|
234
260
|
return inputs.first - inputs.second;
|
|
235
261
|
}
|
|
236
262
|
/**
|
|
237
|
-
* Multiplies two numbers
|
|
263
|
+
* Multiplies two numbers together.
|
|
264
|
+
* Example: 5 × 3 → 15, -2 × 4 → -8
|
|
238
265
|
* @param inputs two numbers
|
|
239
266
|
* @returns number
|
|
240
267
|
* @group basics
|
|
@@ -245,7 +272,8 @@ export class MathBitByBit {
|
|
|
245
272
|
return inputs.first * inputs.second;
|
|
246
273
|
}
|
|
247
274
|
/**
|
|
248
|
-
* Divides
|
|
275
|
+
* Divides the first number by the second.
|
|
276
|
+
* Example: 10 ÷ 2 → 5, 7 ÷ 2 → 3.5
|
|
249
277
|
* @param inputs two numbers
|
|
250
278
|
* @returns number
|
|
251
279
|
* @group basics
|
|
@@ -256,7 +284,8 @@ export class MathBitByBit {
|
|
|
256
284
|
return inputs.first / inputs.second;
|
|
257
285
|
}
|
|
258
286
|
/**
|
|
259
|
-
*
|
|
287
|
+
* Raises the first number to the power of the second (exponentiation).
|
|
288
|
+
* Example: 2³ → 8, 5² → 25, 10⁻¹ → 0.1
|
|
260
289
|
* @param inputs two numbers
|
|
261
290
|
* @returns number
|
|
262
291
|
* @group basics
|
|
@@ -267,7 +296,8 @@ export class MathBitByBit {
|
|
|
267
296
|
return Math.pow(inputs.first, inputs.second);
|
|
268
297
|
}
|
|
269
298
|
/**
|
|
270
|
-
*
|
|
299
|
+
* Calculates the square root of a number.
|
|
300
|
+
* Example: √9 → 3, √2 → 1.414, √16 → 4
|
|
271
301
|
* @param inputs a number
|
|
272
302
|
* @returns number
|
|
273
303
|
* @group basics
|
|
@@ -278,7 +308,8 @@ export class MathBitByBit {
|
|
|
278
308
|
return Math.sqrt(inputs.number);
|
|
279
309
|
}
|
|
280
310
|
/**
|
|
281
|
-
*
|
|
311
|
+
* Returns the absolute value (removes negative sign, always positive or zero).
|
|
312
|
+
* Example: |-5| → 5, |3| → 3, |0| → 0
|
|
282
313
|
* @param inputs a number
|
|
283
314
|
* @returns number
|
|
284
315
|
* @group basics
|
|
@@ -289,7 +320,8 @@ export class MathBitByBit {
|
|
|
289
320
|
return Math.abs(inputs.number);
|
|
290
321
|
}
|
|
291
322
|
/**
|
|
292
|
-
* Rounds a number
|
|
323
|
+
* Rounds a number to the nearest integer.
|
|
324
|
+
* Example: 3.7 → 4, 2.3 → 2, 5.5 → 6
|
|
293
325
|
* @param inputs a number
|
|
294
326
|
* @returns number
|
|
295
327
|
* @group basics
|
|
@@ -300,7 +332,8 @@ export class MathBitByBit {
|
|
|
300
332
|
return Math.round(inputs.number);
|
|
301
333
|
}
|
|
302
334
|
/**
|
|
303
|
-
*
|
|
335
|
+
* Rounds a number down to the nearest integer (toward negative infinity).
|
|
336
|
+
* Example: 3.7 → 3, -2.3 → -3, 5 → 5
|
|
304
337
|
* @param inputs a number
|
|
305
338
|
* @returns number
|
|
306
339
|
* @group basics
|
|
@@ -311,7 +344,8 @@ export class MathBitByBit {
|
|
|
311
344
|
return Math.floor(inputs.number);
|
|
312
345
|
}
|
|
313
346
|
/**
|
|
314
|
-
*
|
|
347
|
+
* Rounds a number up to the nearest integer (toward positive infinity).
|
|
348
|
+
* Example: 3.2 → 4, -2.8 → -2, 5 → 5
|
|
315
349
|
* @param inputs a number
|
|
316
350
|
* @returns number
|
|
317
351
|
* @group basics
|
|
@@ -322,7 +356,8 @@ export class MathBitByBit {
|
|
|
322
356
|
return Math.ceil(inputs.number);
|
|
323
357
|
}
|
|
324
358
|
/**
|
|
325
|
-
* Negates a number
|
|
359
|
+
* Negates a number (flips its sign: positive becomes negative, negative becomes positive).
|
|
360
|
+
* Example: 5 → -5, -3 → 3, 0 → 0
|
|
326
361
|
* @param inputs a number
|
|
327
362
|
* @returns number
|
|
328
363
|
* @group basics
|
|
@@ -333,7 +368,8 @@ export class MathBitByBit {
|
|
|
333
368
|
return -inputs.number;
|
|
334
369
|
}
|
|
335
370
|
/**
|
|
336
|
-
*
|
|
371
|
+
* Calculates the natural logarithm (base e) of a number.
|
|
372
|
+
* Example: ln(2.718) → ~1, ln(7.389) → ~2, ln(1) → 0
|
|
337
373
|
* @param inputs a number
|
|
338
374
|
* @returns number
|
|
339
375
|
* @group basics
|
|
@@ -344,7 +380,8 @@ export class MathBitByBit {
|
|
|
344
380
|
return Math.log(inputs.number);
|
|
345
381
|
}
|
|
346
382
|
/**
|
|
347
|
-
*
|
|
383
|
+
* Calculates the base 10 logarithm of a number.
|
|
384
|
+
* Example: log₁₀(100) → 2, log₁₀(1000) → 3, log₁₀(10) → 1
|
|
348
385
|
* @param inputs a number
|
|
349
386
|
* @returns number
|
|
350
387
|
* @group basics
|
|
@@ -355,7 +392,8 @@ export class MathBitByBit {
|
|
|
355
392
|
return Math.log10(inputs.number);
|
|
356
393
|
}
|
|
357
394
|
/**
|
|
358
|
-
* Raises 10 to the power of
|
|
395
|
+
* Raises 10 to the power of the input number.
|
|
396
|
+
* Example: 10² → 100, 10³ → 1000, 10⁻¹ → 0.1
|
|
359
397
|
* @param inputs a number
|
|
360
398
|
* @returns number
|
|
361
399
|
* @group basics
|
|
@@ -366,7 +404,8 @@ export class MathBitByBit {
|
|
|
366
404
|
return Math.pow(10, inputs.number);
|
|
367
405
|
}
|
|
368
406
|
/**
|
|
369
|
-
*
|
|
407
|
+
* Calculates the sine of an angle in radians.
|
|
408
|
+
* Example: sin(0) → 0, sin(π/2) → 1, sin(π) → ~0
|
|
370
409
|
* @param inputs a number
|
|
371
410
|
* @returns number
|
|
372
411
|
* @group basics
|
|
@@ -377,7 +416,8 @@ export class MathBitByBit {
|
|
|
377
416
|
return Math.sin(inputs.number);
|
|
378
417
|
}
|
|
379
418
|
/**
|
|
380
|
-
*
|
|
419
|
+
* Calculates the cosine of an angle in radians.
|
|
420
|
+
* Example: cos(0) → 1, cos(π/2) → ~0, cos(π) → -1
|
|
381
421
|
* @param inputs a number
|
|
382
422
|
* @returns number
|
|
383
423
|
* @group basics
|
|
@@ -388,7 +428,8 @@ export class MathBitByBit {
|
|
|
388
428
|
return Math.cos(inputs.number);
|
|
389
429
|
}
|
|
390
430
|
/**
|
|
391
|
-
*
|
|
431
|
+
* Calculates the tangent of an angle in radians.
|
|
432
|
+
* Example: tan(0) → 0, tan(π/4) → ~1, tan(π/2) → infinity
|
|
392
433
|
* @param inputs a number
|
|
393
434
|
* @returns number
|
|
394
435
|
* @group basics
|
|
@@ -399,7 +440,8 @@ export class MathBitByBit {
|
|
|
399
440
|
return Math.tan(inputs.number);
|
|
400
441
|
}
|
|
401
442
|
/**
|
|
402
|
-
*
|
|
443
|
+
* Calculates the arcsine (inverse sine) in radians, returns angle whose sine is the input.
|
|
444
|
+
* Example: asin(0) → 0, asin(1) → π/2 (~1.57), asin(0.5) → π/6 (~0.524)
|
|
403
445
|
* @param inputs a number
|
|
404
446
|
* @returns number
|
|
405
447
|
* @group basics
|
|
@@ -410,7 +452,8 @@ export class MathBitByBit {
|
|
|
410
452
|
return Math.asin(inputs.number);
|
|
411
453
|
}
|
|
412
454
|
/**
|
|
413
|
-
*
|
|
455
|
+
* Calculates the arccosine (inverse cosine) in radians, returns angle whose cosine is the input.
|
|
456
|
+
* Example: acos(1) → 0, acos(0) → π/2 (~1.57), acos(-1) → π (~3.14)
|
|
414
457
|
* @param inputs a number
|
|
415
458
|
* @returns number
|
|
416
459
|
* @group basics
|
|
@@ -421,7 +464,8 @@ export class MathBitByBit {
|
|
|
421
464
|
return Math.acos(inputs.number);
|
|
422
465
|
}
|
|
423
466
|
/**
|
|
424
|
-
*
|
|
467
|
+
* Calculates the arctangent (inverse tangent) in radians, returns angle whose tangent is the input.
|
|
468
|
+
* Example: atan(0) → 0, atan(1) → π/4 (~0.785), atan(-1) → -π/4
|
|
425
469
|
* @param inputs a number
|
|
426
470
|
* @returns number
|
|
427
471
|
* @group basics
|
|
@@ -432,7 +476,8 @@ export class MathBitByBit {
|
|
|
432
476
|
return Math.atan(inputs.number);
|
|
433
477
|
}
|
|
434
478
|
/**
|
|
435
|
-
*
|
|
479
|
+
* Calculates e raised to the power of the input (exponential function).
|
|
480
|
+
* Example: e⁰ → 1, e¹ → ~2.718, e² → ~7.389
|
|
436
481
|
* @param inputs a number
|
|
437
482
|
* @returns number
|
|
438
483
|
* @group basics
|
|
@@ -443,7 +488,8 @@ export class MathBitByBit {
|
|
|
443
488
|
return Math.exp(inputs.number);
|
|
444
489
|
}
|
|
445
490
|
/**
|
|
446
|
-
* Converts degrees to radians
|
|
491
|
+
* Converts an angle from degrees to radians.
|
|
492
|
+
* Example: 180° → π (~3.14159), 90° → π/2 (~1.5708), 360° → 2π
|
|
447
493
|
* @param inputs a number in degrees
|
|
448
494
|
* @returns number
|
|
449
495
|
* @group basics
|
|
@@ -454,7 +500,8 @@ export class MathBitByBit {
|
|
|
454
500
|
return inputs.number * Math.PI / 180;
|
|
455
501
|
}
|
|
456
502
|
/**
|
|
457
|
-
* Converts radians to degrees
|
|
503
|
+
* Converts an angle from radians to degrees.
|
|
504
|
+
* Example: π → 180°, π/2 → 90°, 2π → 360°
|
|
458
505
|
* @param inputs a number in radians
|
|
459
506
|
* @returns number
|
|
460
507
|
* @group basics
|
|
@@ -465,7 +512,9 @@ export class MathBitByBit {
|
|
|
465
512
|
return inputs.number * 180 / Math.PI;
|
|
466
513
|
}
|
|
467
514
|
/**
|
|
468
|
-
*
|
|
515
|
+
* Applies an easing function to interpolate smoothly between min and max values.
|
|
516
|
+
* Example: x=0.5 from [0,100] with easeInQuad → applies quadratic acceleration curve
|
|
517
|
+
* Useful for smooth animations with various acceleration/deceleration curves.
|
|
469
518
|
* @param inputs a number, min and max values, and ease type
|
|
470
519
|
* @returns number
|
|
471
520
|
* @group operations
|
|
@@ -480,6 +529,137 @@ export class MathBitByBit {
|
|
|
480
529
|
const res = this.remap({ number: y, fromLow: 0, fromHigh: 1, toLow: min, toHigh: max });
|
|
481
530
|
return res;
|
|
482
531
|
}
|
|
532
|
+
/**
|
|
533
|
+
* Constrains a value between a minimum and maximum value.
|
|
534
|
+
* Example: clamp(5, 0, 3) returns 3, clamp(-1, 0, 3) returns 0, clamp(1.5, 0, 3) returns 1.5
|
|
535
|
+
* @param inputs a number, min and max values
|
|
536
|
+
* @returns number clamped between min and max
|
|
537
|
+
* @group operations
|
|
538
|
+
* @shortname clamp
|
|
539
|
+
* @drawable false
|
|
540
|
+
*/
|
|
541
|
+
clamp(inputs) {
|
|
542
|
+
return Math.max(inputs.min, Math.min(inputs.max, inputs.number));
|
|
543
|
+
}
|
|
544
|
+
/**
|
|
545
|
+
* Linear interpolation between two values using parameter t (0 to 1).
|
|
546
|
+
* Example: From 0 to 100 at t=0.5 → 50, From 10 to 20 at t=0.25 → 12.5
|
|
547
|
+
* When t=0 returns start, when t=1 returns end. Useful for smooth transitions.
|
|
548
|
+
* @param inputs start value, end value, and interpolation parameter t
|
|
549
|
+
* @returns interpolated value
|
|
550
|
+
* @group operations
|
|
551
|
+
* @shortname lerp
|
|
552
|
+
* @drawable false
|
|
553
|
+
*/
|
|
554
|
+
lerp(inputs) {
|
|
555
|
+
return inputs.start + (inputs.end - inputs.start) * inputs.t;
|
|
556
|
+
}
|
|
557
|
+
/**
|
|
558
|
+
* Calculates the interpolation parameter t for a value between start and end (reverse of lerp).
|
|
559
|
+
* Example: Value 5 in range [0,10] → t=0.5, Value 2.5 in range [0,10] → t=0.25
|
|
560
|
+
* Returns what t value would produce the given value in a lerp. Useful for finding relative position.
|
|
561
|
+
* @param inputs start value, end value, and the value to find t for
|
|
562
|
+
* @returns interpolation parameter (typically 0-1)
|
|
563
|
+
* @group operations
|
|
564
|
+
* @shortname inverse lerp
|
|
565
|
+
* @drawable false
|
|
566
|
+
*/
|
|
567
|
+
inverseLerp(inputs) {
|
|
568
|
+
if (inputs.start === inputs.end) {
|
|
569
|
+
return 0;
|
|
570
|
+
}
|
|
571
|
+
return (inputs.value - inputs.start) / (inputs.end - inputs.start);
|
|
572
|
+
}
|
|
573
|
+
/**
|
|
574
|
+
* Hermite interpolation with smooth acceleration and deceleration (smoother than linear lerp).
|
|
575
|
+
* Example: x=0 → 0, x=0.5 → 0.5, x=1 → 1 (but with smooth S-curve in between)
|
|
576
|
+
* Input is automatically clamped to [0,1]. Output eases in and out smoothly. Great for animations.
|
|
577
|
+
* @param inputs a number between 0 and 1
|
|
578
|
+
* @returns smoothly interpolated value
|
|
579
|
+
* @group operations
|
|
580
|
+
* @shortname smoothstep
|
|
581
|
+
* @drawable false
|
|
582
|
+
*/
|
|
583
|
+
smoothstep(inputs) {
|
|
584
|
+
const t = Math.max(0, Math.min(1, inputs.number));
|
|
585
|
+
return t * t * (3 - 2 * t);
|
|
586
|
+
}
|
|
587
|
+
/**
|
|
588
|
+
* Returns the sign of a number: -1 for negative, 0 for zero, 1 for positive.
|
|
589
|
+
* Example: -5 → -1, 0 → 0, 3.14 → 1
|
|
590
|
+
* Useful for determining direction or polarity.
|
|
591
|
+
* @param inputs a number
|
|
592
|
+
* @returns -1, 0, or 1
|
|
593
|
+
* @group operations
|
|
594
|
+
* @shortname sign
|
|
595
|
+
* @drawable false
|
|
596
|
+
*/
|
|
597
|
+
sign(inputs) {
|
|
598
|
+
return Math.sign(inputs.number);
|
|
599
|
+
}
|
|
600
|
+
/**
|
|
601
|
+
* Returns the fractional part of a number (removes integer part, keeps decimals).
|
|
602
|
+
* Example: 3.14 → 0.14, 5.9 → 0.9, -2.3 → 0.7
|
|
603
|
+
* Useful for wrapping values and creating repeating patterns.
|
|
604
|
+
* @param inputs a number
|
|
605
|
+
* @returns fractional part (always positive)
|
|
606
|
+
* @group operations
|
|
607
|
+
* @shortname fract
|
|
608
|
+
* @drawable false
|
|
609
|
+
*/
|
|
610
|
+
fract(inputs) {
|
|
611
|
+
return inputs.number - Math.floor(inputs.number);
|
|
612
|
+
}
|
|
613
|
+
/**
|
|
614
|
+
* Wraps a number within a specified range (creates repeating cycle).
|
|
615
|
+
* Example: 1.5 in range [0,1) → 0.5, -0.3 in range [0,1) → 0.7, 370° in range [0,360) → 10°
|
|
616
|
+
* Useful for angles, UVs, or any repeating domain. Like modulo but handles negatives properly.
|
|
617
|
+
* @param inputs a number, min and max values
|
|
618
|
+
* @returns wrapped value within range
|
|
619
|
+
* @group operations
|
|
620
|
+
* @shortname wrap
|
|
621
|
+
* @drawable false
|
|
622
|
+
*/
|
|
623
|
+
wrap(inputs) {
|
|
624
|
+
const range = inputs.max - inputs.min;
|
|
625
|
+
if (range === 0) {
|
|
626
|
+
return inputs.min;
|
|
627
|
+
}
|
|
628
|
+
const normalized = (inputs.number - inputs.min) % range;
|
|
629
|
+
return normalized < 0 ? normalized + inputs.max : normalized + inputs.min;
|
|
630
|
+
}
|
|
631
|
+
/**
|
|
632
|
+
* Creates a ping-pong (back-and-forth) effect that bounces a value between 0 and length.
|
|
633
|
+
* The value goes from 0→length, then back length→0, repeating this cycle.
|
|
634
|
+
* Example: With length=1: t=0→0, t=0.5→0.5, t=1→1 (peak), t=1.5→0.5, t=2→0, t=2.5→0.5 (repeats)
|
|
635
|
+
* Useful for creating bouncing animations like a ball or oscillating motion.
|
|
636
|
+
* @param inputs time value t and length
|
|
637
|
+
* @returns value bouncing between 0 and length
|
|
638
|
+
* @group operations
|
|
639
|
+
* @shortname ping pong
|
|
640
|
+
* @drawable false
|
|
641
|
+
*/
|
|
642
|
+
pingPong(inputs) {
|
|
643
|
+
const t = Math.abs(inputs.t) % (inputs.length * 2);
|
|
644
|
+
return t > inputs.length ? inputs.length * 2 - t : t;
|
|
645
|
+
}
|
|
646
|
+
/**
|
|
647
|
+
* Moves a value toward a target by a maximum delta amount (never overshooting).
|
|
648
|
+
* Example: From 0 toward 10 by max 3 → 3, From 8 toward 10 by max 3 → 10 (reached)
|
|
649
|
+
* Useful for smooth movement with maximum speed limits.
|
|
650
|
+
* @param inputs current value, target value, and maximum delta
|
|
651
|
+
* @returns new value moved toward target
|
|
652
|
+
* @group operations
|
|
653
|
+
* @shortname move towards
|
|
654
|
+
* @drawable false
|
|
655
|
+
*/
|
|
656
|
+
moveTowards(inputs) {
|
|
657
|
+
const delta = inputs.target - inputs.current;
|
|
658
|
+
if (Math.abs(delta) <= inputs.maxDelta) {
|
|
659
|
+
return inputs.target;
|
|
660
|
+
}
|
|
661
|
+
return inputs.current + Math.sign(delta) * inputs.maxDelta;
|
|
662
|
+
}
|
|
483
663
|
easeInSine(x) {
|
|
484
664
|
return 1 - Math.cos((x * Math.PI) / 2);
|
|
485
665
|
}
|
|
@@ -9,7 +9,8 @@ export declare class MeshBitByBit {
|
|
|
9
9
|
private readonly polyline;
|
|
10
10
|
constructor(vector: Vector, polyline: Polyline);
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* Calculates signed distance from a point to a plane (positive=above plane, negative=below).
|
|
13
|
+
* Example: point=[0,5,0], plane={normal:[0,1,0], d:0} → 5 (point is 5 units above XZ plane)
|
|
13
14
|
* @param inputs a point and a plane
|
|
14
15
|
* @returns signed distance
|
|
15
16
|
* @group base
|
|
@@ -18,7 +19,9 @@ export declare class MeshBitByBit {
|
|
|
18
19
|
*/
|
|
19
20
|
signedDistanceToPlane(inputs: Inputs.Mesh.SignedDistanceFromPlaneToPointDto): number;
|
|
20
21
|
/**
|
|
21
|
-
* Calculates
|
|
22
|
+
* Calculates plane equation from triangle vertices (normal vector and distance from origin).
|
|
23
|
+
* Returns undefined if triangle is degenerate (zero area, collinear points).
|
|
24
|
+
* Example: triangle=[[0,0,0], [1,0,0], [0,1,0]] → {normal:[0,0,1], d:0} (XY plane)
|
|
22
25
|
* @param inputs triangle and tolerance
|
|
23
26
|
* @returns triangle plane
|
|
24
27
|
* @group traingle
|
|
@@ -27,7 +30,9 @@ export declare class MeshBitByBit {
|
|
|
27
30
|
*/
|
|
28
31
|
calculateTrianglePlane(inputs: Inputs.Mesh.TriangleToleranceDto): Inputs.Base.TrianglePlane3 | undefined;
|
|
29
32
|
/**
|
|
30
|
-
* Calculates
|
|
33
|
+
* Calculates intersection segment of two triangles (line segment where they cross).
|
|
34
|
+
* Returns undefined if triangles don't intersect, are parallel, or are coplanar.
|
|
35
|
+
* Example: triangle1=[[0,0,0], [2,0,0], [1,2,0]], triangle2=[[1,-1,1], [1,1,1], [1,1,-1]] → [[1,0,0], [1,1,0]]
|
|
31
36
|
* @param inputs first triangle, second triangle, and tolerance
|
|
32
37
|
* @returns intersection segment or undefined if no intersection
|
|
33
38
|
* @group traingle
|
|
@@ -36,7 +41,9 @@ export declare class MeshBitByBit {
|
|
|
36
41
|
*/
|
|
37
42
|
triangleTriangleIntersection(inputs: Inputs.Mesh.TriangleTriangleToleranceDto): Inputs.Base.Segment3 | undefined;
|
|
38
43
|
/**
|
|
39
|
-
*
|
|
44
|
+
* Calculates all intersection segments between two triangle meshes (pairwise triangle tests).
|
|
45
|
+
* Returns array of line segments where mesh surfaces intersect.
|
|
46
|
+
* Example: cube mesh intersecting with sphere mesh → multiple segments forming intersection curve
|
|
40
47
|
* @param inputs first mesh, second mesh, and tolerance
|
|
41
48
|
* @returns array of intersection segments
|
|
42
49
|
* @group mesh
|
|
@@ -45,7 +52,9 @@ export declare class MeshBitByBit {
|
|
|
45
52
|
*/
|
|
46
53
|
meshMeshIntersectionSegments(inputs: Inputs.Mesh.MeshMeshToleranceDto): Inputs.Base.Segment3[];
|
|
47
54
|
/**
|
|
48
|
-
*
|
|
55
|
+
* Calculates intersection polylines between two meshes by sorting segments into connected paths.
|
|
56
|
+
* Segments are joined end-to-end to form continuous or closed curves.
|
|
57
|
+
* Example: cube-sphere intersection → closed polyline loops where surfaces meet
|
|
49
58
|
* @param inputs first mesh, second mesh, and tolerance
|
|
50
59
|
* @returns array of intersection polylines
|
|
51
60
|
* @group mesh
|
|
@@ -54,7 +63,9 @@ export declare class MeshBitByBit {
|
|
|
54
63
|
*/
|
|
55
64
|
meshMeshIntersectionPolylines(inputs: Inputs.Mesh.MeshMeshToleranceDto): Inputs.Base.Polyline3[];
|
|
56
65
|
/**
|
|
57
|
-
*
|
|
66
|
+
* Calculates intersection points between two meshes as point arrays (one array per polyline).
|
|
67
|
+
* Closed polylines have first point duplicated at end.
|
|
68
|
+
* Example: cube-sphere intersection → arrays of points defining intersection curves
|
|
58
69
|
* @param inputs first mesh, second mesh, and tolerance
|
|
59
70
|
* @returns array of intersection points
|
|
60
71
|
* @group mesh
|
package/lib/api/services/mesh.js
CHANGED
|
@@ -7,7 +7,8 @@ export class MeshBitByBit {
|
|
|
7
7
|
this.polyline = polyline;
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
10
|
+
* Calculates signed distance from a point to a plane (positive=above plane, negative=below).
|
|
11
|
+
* Example: point=[0,5,0], plane={normal:[0,1,0], d:0} → 5 (point is 5 units above XZ plane)
|
|
11
12
|
* @param inputs a point and a plane
|
|
12
13
|
* @returns signed distance
|
|
13
14
|
* @group base
|
|
@@ -18,7 +19,9 @@ export class MeshBitByBit {
|
|
|
18
19
|
return this.vector.dot({ first: inputs.plane.normal, second: inputs.point }) - inputs.plane.d;
|
|
19
20
|
}
|
|
20
21
|
/**
|
|
21
|
-
* Calculates
|
|
22
|
+
* Calculates plane equation from triangle vertices (normal vector and distance from origin).
|
|
23
|
+
* Returns undefined if triangle is degenerate (zero area, collinear points).
|
|
24
|
+
* Example: triangle=[[0,0,0], [1,0,0], [0,1,0]] → {normal:[0,0,1], d:0} (XY plane)
|
|
22
25
|
* @param inputs triangle and tolerance
|
|
23
26
|
* @returns triangle plane
|
|
24
27
|
* @group traingle
|
|
@@ -39,7 +42,9 @@ export class MeshBitByBit {
|
|
|
39
42
|
return { normal: normalizedNormal, d: d };
|
|
40
43
|
}
|
|
41
44
|
/**
|
|
42
|
-
* Calculates
|
|
45
|
+
* Calculates intersection segment of two triangles (line segment where they cross).
|
|
46
|
+
* Returns undefined if triangles don't intersect, are parallel, or are coplanar.
|
|
47
|
+
* Example: triangle1=[[0,0,0], [2,0,0], [1,2,0]], triangle2=[[1,-1,1], [1,1,1], [1,1,-1]] → [[1,0,0], [1,1,0]]
|
|
43
48
|
* @param inputs first triangle, second triangle, and tolerance
|
|
44
49
|
* @returns intersection segment or undefined if no intersection
|
|
45
50
|
* @group traingle
|
|
@@ -166,7 +171,9 @@ export class MeshBitByBit {
|
|
|
166
171
|
}
|
|
167
172
|
}
|
|
168
173
|
/**
|
|
169
|
-
*
|
|
174
|
+
* Calculates all intersection segments between two triangle meshes (pairwise triangle tests).
|
|
175
|
+
* Returns array of line segments where mesh surfaces intersect.
|
|
176
|
+
* Example: cube mesh intersecting with sphere mesh → multiple segments forming intersection curve
|
|
170
177
|
* @param inputs first mesh, second mesh, and tolerance
|
|
171
178
|
* @returns array of intersection segments
|
|
172
179
|
* @group mesh
|
|
@@ -190,7 +197,9 @@ export class MeshBitByBit {
|
|
|
190
197
|
return intersectionSegments;
|
|
191
198
|
}
|
|
192
199
|
/**
|
|
193
|
-
*
|
|
200
|
+
* Calculates intersection polylines between two meshes by sorting segments into connected paths.
|
|
201
|
+
* Segments are joined end-to-end to form continuous or closed curves.
|
|
202
|
+
* Example: cube-sphere intersection → closed polyline loops where surfaces meet
|
|
194
203
|
* @param inputs first mesh, second mesh, and tolerance
|
|
195
204
|
* @returns array of intersection polylines
|
|
196
205
|
* @group mesh
|
|
@@ -202,7 +211,9 @@ export class MeshBitByBit {
|
|
|
202
211
|
return this.polyline.sortSegmentsIntoPolylines({ segments, tolerance: inputs.tolerance });
|
|
203
212
|
}
|
|
204
213
|
/**
|
|
205
|
-
*
|
|
214
|
+
* Calculates intersection points between two meshes as point arrays (one array per polyline).
|
|
215
|
+
* Closed polylines have first point duplicated at end.
|
|
216
|
+
* Example: cube-sphere intersection → arrays of points defining intersection curves
|
|
206
217
|
* @param inputs first mesh, second mesh, and tolerance
|
|
207
218
|
* @returns array of intersection points
|
|
208
219
|
* @group mesh
|