@bitbybit-dev/base 1.2.0-rc.2 → 1.3.0-rc.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/lib/api/GlobalCDNProvider.js +1 -1
- package/lib/api/inputs/base-inputs.d.ts +13 -12
- package/lib/api/inputs/color-inputs.d.ts +97 -48
- package/lib/api/inputs/color-inputs.js +95 -46
- package/lib/api/inputs/dates-inputs.d.ts +67 -26
- package/lib/api/inputs/dates-inputs.js +57 -16
- package/lib/api/inputs/io-inputs.d.ts +13 -15
- package/lib/api/inputs/io-inputs.js +7 -8
- package/lib/api/inputs/line-inputs.d.ts +88 -33
- package/lib/api/inputs/line-inputs.js +61 -11
- package/lib/api/inputs/lists-inputs.d.ts +207 -96
- package/lib/api/inputs/lists-inputs.js +153 -45
- package/lib/api/inputs/logic-inputs.d.ts +52 -22
- package/lib/api/inputs/logic-inputs.js +41 -12
- package/lib/api/inputs/math-inputs.d.ts +113 -52
- package/lib/api/inputs/math-inputs.js +112 -51
- package/lib/api/inputs/mesh-inputs.d.ts +30 -11
- package/lib/api/inputs/mesh-inputs.js +21 -3
- package/lib/api/inputs/point-inputs.d.ts +240 -107
- package/lib/api/inputs/point-inputs.js +199 -73
- package/lib/api/inputs/polyline-inputs.d.ts +68 -28
- package/lib/api/inputs/polyline-inputs.js +48 -13
- package/lib/api/inputs/text-inputs.d.ts +117 -46
- package/lib/api/inputs/text-inputs.js +111 -41
- package/lib/api/inputs/transforms-inputs.d.ts +65 -23
- package/lib/api/inputs/transforms-inputs.js +64 -22
- package/lib/api/inputs/vector-inputs.d.ts +154 -76
- package/lib/api/inputs/vector-inputs.js +132 -57
- package/lib/api/models/point/hex-grid-data.d.ts +1 -1
- package/lib/api/models/point/hex-grid-data.js +1 -1
- package/lib/api/services/color.d.ts +149 -70
- package/lib/api/services/color.js +149 -70
- package/lib/api/services/dates.d.ts +313 -150
- package/lib/api/services/dates.js +313 -150
- package/lib/api/services/line.d.ts +138 -68
- package/lib/api/services/line.js +138 -68
- package/lib/api/services/lists.d.ts +357 -177
- package/lib/api/services/lists.js +357 -177
- package/lib/api/services/logic.d.ts +98 -45
- package/lib/api/services/logic.js +98 -45
- package/lib/api/services/math.d.ts +363 -211
- package/lib/api/services/math.js +363 -211
- package/lib/api/services/mesh.d.ts +73 -31
- package/lib/api/services/mesh.js +73 -31
- package/lib/api/services/point.d.ts +367 -147
- package/lib/api/services/point.js +367 -147
- package/lib/api/services/polyline.d.ts +146 -71
- package/lib/api/services/polyline.js +146 -71
- package/lib/api/services/text.d.ts +320 -165
- package/lib/api/services/text.js +320 -165
- package/lib/api/services/transforms.d.ts +145 -58
- package/lib/api/services/transforms.js +145 -58
- package/lib/api/services/vector.d.ts +381 -156
- package/lib/api/services/vector.js +381 -156
- package/package.json +1 -1
|
@@ -1,331 +1,436 @@
|
|
|
1
1
|
import * as Inputs from "../inputs";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Arithmetic, rounding, ranges, random numbers and the trigonometric functions on plain numbers.
|
|
4
|
+
* The trigonometric functions take and give angles in radians; `degToRad` and `radToDeg` convert at
|
|
5
|
+
* the boundary, because almost every angle a user types is in degrees. The interpolation helpers
|
|
6
|
+
* (`lerp`, `remap`, `ease`, `smoothstep`, `pingPong`) are the building blocks of animation and
|
|
7
|
+
* parametric variation.
|
|
4
8
|
*/
|
|
5
9
|
export declare class MathBitByBit {
|
|
6
10
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* @
|
|
11
|
+
* Passes a number through unchanged, so a value can be given a name and reused.
|
|
12
|
+
*
|
|
13
|
+
* Example: 42 -> 42
|
|
14
|
+
* @param inputs - The number
|
|
15
|
+
* @returns The same number
|
|
11
16
|
* @group create
|
|
12
17
|
* @shortname number
|
|
13
18
|
* @drawable false
|
|
14
19
|
*/
|
|
15
20
|
number(inputs: Inputs.Math.NumberDto): number;
|
|
16
21
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
22
|
+
* Applies one arithmetic operation to two numbers: add, subtract, multiply, divide, power or
|
|
23
|
+
* modulus.
|
|
24
|
+
*
|
|
25
|
+
* The operation reads `first` then `second`: subtract gives first minus second, power gives
|
|
26
|
+
* first to the power of second.
|
|
27
|
+
* Example: 5 add 3 -> 8, 10 modulus 3 -> 1, 2 power 3 -> 8
|
|
28
|
+
* @param inputs - The two numbers and the operation
|
|
29
|
+
* @returns The result of the operation
|
|
21
30
|
* @group operations
|
|
22
31
|
* @shortname two numbers
|
|
23
32
|
* @drawable false
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* const result = bitbybit.math.twoNrOperation({ first: 2, second: 3, operation: Bit.Inputs.Math.mathTwoNrOperatorEnum.power });
|
|
36
|
+
* ```
|
|
24
37
|
*/
|
|
25
38
|
twoNrOperation(inputs: Inputs.Math.ActionOnTwoNumbersDto): number;
|
|
26
39
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
40
|
+
* Finds the remainder after dividing one number by another.
|
|
41
|
+
*
|
|
42
|
+
* The sign follows the first number, as it does in JavaScript.
|
|
43
|
+
* Example: 10 modulus 3 -> 1, 17 modulus 5 -> 2
|
|
44
|
+
* @param inputs - The number to divide and the number to divide by
|
|
45
|
+
* @returns The remainder
|
|
31
46
|
* @group operations
|
|
32
47
|
* @shortname modulus
|
|
33
48
|
* @drawable false
|
|
49
|
+
* @example
|
|
50
|
+
* ```typescript
|
|
51
|
+
* const remainder = bitbybit.math.modulus({ number: 17, modulus: 5 });
|
|
52
|
+
* ```
|
|
34
53
|
*/
|
|
35
54
|
modulus(inputs: Inputs.Math.ModulusDto): number;
|
|
36
55
|
/**
|
|
37
|
-
* Rounds a number to
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* @
|
|
56
|
+
* Rounds a number to a given number of decimal places.
|
|
57
|
+
*
|
|
58
|
+
* Example: 1.32156 to 3 places -> 1.322
|
|
59
|
+
* @param inputs - The number and how many decimal places to keep
|
|
60
|
+
* @returns The rounded number
|
|
41
61
|
* @group operations
|
|
42
62
|
* @shortname round to decimals
|
|
43
63
|
* @drawable false
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* const rounded = bitbybit.math.roundToDecimals({ number: 1.32156, decimalPlaces: 3 });
|
|
67
|
+
* ```
|
|
44
68
|
*/
|
|
45
69
|
roundToDecimals(inputs: Inputs.Math.RoundToDecimalsDto): number;
|
|
46
70
|
/**
|
|
47
|
-
* Rounds a number to
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
71
|
+
* Rounds a number to a given number of decimal places and drops the zeros at the end.
|
|
72
|
+
*
|
|
73
|
+
* As a number the result cannot carry trailing zeros anyway; the difference from
|
|
74
|
+
* `roundToDecimals` is that floating-point noise such as 1.320000001 is cleaned to 1.32.
|
|
75
|
+
* Example: 1.32156 to 3 places -> 1.322, 1.320000001 -> 1.32, 1.000 -> 1
|
|
76
|
+
* @param inputs - The number and how many decimal places to keep
|
|
77
|
+
* @returns The rounded number
|
|
51
78
|
* @group operations
|
|
52
79
|
* @shortname round trim zeros
|
|
53
80
|
* @drawable false
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* const clean = bitbybit.math.roundAndRemoveTrailingZeros({ number: 1.320000001, decimalPlaces: 3 });
|
|
84
|
+
* ```
|
|
54
85
|
*/
|
|
55
86
|
roundAndRemoveTrailingZeros(inputs: Inputs.Math.RoundToDecimalsDto): number;
|
|
56
87
|
/**
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
88
|
+
* Applies one operation to a single number: absolute, negate, square root, rounding,
|
|
89
|
+
* logarithms, the trigonometric functions and their inverses, exponential, or a conversion
|
|
90
|
+
* between radians and degrees.
|
|
91
|
+
*
|
|
92
|
+
* The trigonometric functions work in radians.
|
|
93
|
+
* Example: sqrt of 5 -> 2.236, absolute of -3 -> 3
|
|
94
|
+
* @param inputs - The number and the operation
|
|
95
|
+
* @returns The result of the operation
|
|
61
96
|
* @group operations
|
|
62
97
|
* @shortname one number
|
|
63
98
|
* @drawable false
|
|
99
|
+
* @example
|
|
100
|
+
* ```typescript
|
|
101
|
+
* const root = bitbybit.math.oneNrOperation({ number: 5, operation: Bit.Inputs.Math.mathOneNrOperatorEnum.sqrt });
|
|
102
|
+
* ```
|
|
64
103
|
*/
|
|
65
104
|
oneNrOperation(inputs: Inputs.Math.ActionOnOneNumberDto): number;
|
|
66
105
|
/**
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
106
|
+
* Maps a number from one range onto another, keeping its relative position.
|
|
107
|
+
*
|
|
108
|
+
* A number outside the source range maps proportionally beyond the target range.
|
|
109
|
+
* Example: 5 from [0,10] to [0,100] -> 50, 0.5 from [0,1] to [-10,10] -> 0
|
|
110
|
+
* @param inputs - The number, the range it is in and the range to map it to
|
|
111
|
+
* @returns The number at the same relative position in the target range
|
|
112
|
+
* @group operations
|
|
113
|
+
* @shortname remap
|
|
114
|
+
* @drawable false
|
|
115
|
+
* @example
|
|
116
|
+
* ```typescript
|
|
117
|
+
* const percent = bitbybit.math.remap({ number: 5, fromLow: 0, fromHigh: 10, toLow: 0, toHigh: 100 });
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
75
120
|
remap(inputs: Inputs.Math.RemapNumberDto): number;
|
|
76
121
|
/**
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
122
|
+
* Gives a random number from 0 up to, but not including, 1.
|
|
123
|
+
*
|
|
124
|
+
* Example: 0.342, 0.891 or any other value in that range
|
|
125
|
+
* @returns A random number between 0 and 1
|
|
126
|
+
* @group generate
|
|
127
|
+
* @shortname random 0 - 1
|
|
128
|
+
* @drawable false
|
|
129
|
+
*/
|
|
84
130
|
random(): number;
|
|
85
131
|
/**
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
132
|
+
* Gives a random number between `low` and `high`.
|
|
133
|
+
*
|
|
134
|
+
* Example: low 0, high 10 -> 3.7, 8.2 or any other value between them
|
|
135
|
+
* @param inputs - The low and high ends of the range
|
|
136
|
+
* @returns A random number in the range
|
|
137
|
+
* @group generate
|
|
138
|
+
* @shortname random number
|
|
139
|
+
* @drawable false
|
|
140
|
+
* @example
|
|
141
|
+
* ```typescript
|
|
142
|
+
* const value = bitbybit.math.randomNumber({ low: 0, high: 10 });
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
94
145
|
randomNumber(inputs: Inputs.Math.RandomNumberDto): number;
|
|
95
146
|
/**
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
147
|
+
* Gives a list of random numbers between `low` and `high`.
|
|
148
|
+
*
|
|
149
|
+
* Example: low 0, high 10, count 3 -> [2.5, 7.1, 4.8]
|
|
150
|
+
* @param inputs - The low and high ends of the range and how many numbers to make
|
|
151
|
+
* @returns The random numbers
|
|
152
|
+
* @group generate
|
|
153
|
+
* @shortname random numbers
|
|
154
|
+
* @drawable false
|
|
155
|
+
* @example
|
|
156
|
+
* ```typescript
|
|
157
|
+
* const values = bitbybit.math.randomNumbers({ low: 0, high: 10, count: 3 });
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
104
160
|
randomNumbers(inputs: Inputs.Math.RandomNumbersDto): number[];
|
|
105
161
|
/**
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
162
|
+
* Gives the constant pi, the ratio of a circle's circumference to its diameter.
|
|
163
|
+
*
|
|
164
|
+
* Example: 3.141592653589793
|
|
165
|
+
* @returns The number pi
|
|
166
|
+
* @group generate
|
|
167
|
+
* @shortname π
|
|
168
|
+
* @drawable false
|
|
169
|
+
*/
|
|
113
170
|
pi(): number;
|
|
114
171
|
/**
|
|
115
|
-
* Formats a number as
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
* @
|
|
172
|
+
* Formats a number as text with a fixed number of decimal places, keeping trailing zeros.
|
|
173
|
+
*
|
|
174
|
+
* Example: 3.14159 with 2 places -> '3.14', 5 with 3 places -> '5.000'
|
|
175
|
+
* @param inputs - The number and how many decimal places to show
|
|
176
|
+
* @returns The formatted text
|
|
119
177
|
* @group operations
|
|
120
178
|
* @shortname to fixed
|
|
121
179
|
* @drawable false
|
|
180
|
+
* @example
|
|
181
|
+
* ```typescript
|
|
182
|
+
* const label = bitbybit.math.toFixed({ number: 3.14159, decimalPlaces: 2 });
|
|
183
|
+
* ```
|
|
122
184
|
*/
|
|
123
185
|
toFixed(inputs: Inputs.Math.ToFixedDto): string;
|
|
124
186
|
/**
|
|
125
|
-
* Adds two numbers
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
* @
|
|
187
|
+
* Adds two numbers.
|
|
188
|
+
*
|
|
189
|
+
* Example: 5 and 3 -> 8, -2 and 7 -> 5
|
|
190
|
+
* @param inputs - The two numbers
|
|
191
|
+
* @returns Their sum
|
|
129
192
|
* @group basics
|
|
130
193
|
* @shortname add
|
|
131
194
|
* @drawable false
|
|
195
|
+
* @example
|
|
196
|
+
* ```typescript
|
|
197
|
+
* const sum = bitbybit.math.add({ first: 5, second: 3 });
|
|
198
|
+
* ```
|
|
132
199
|
*/
|
|
133
200
|
add(inputs: Inputs.Math.TwoNumbersDto): number;
|
|
134
201
|
/**
|
|
135
202
|
* Subtracts the second number from the first.
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
* @
|
|
203
|
+
*
|
|
204
|
+
* Example: 10 and 3 -> 7, 5 and 8 -> -3
|
|
205
|
+
* @param inputs - The number to subtract from and the number to subtract
|
|
206
|
+
* @returns Their difference
|
|
139
207
|
* @group basics
|
|
140
208
|
* @shortname subtract
|
|
141
209
|
* @drawable false
|
|
210
|
+
* @example
|
|
211
|
+
* ```typescript
|
|
212
|
+
* const difference = bitbybit.math.subtract({ first: 10, second: 3 });
|
|
213
|
+
* ```
|
|
142
214
|
*/
|
|
143
215
|
subtract(inputs: Inputs.Math.TwoNumbersDto): number;
|
|
144
216
|
/**
|
|
145
|
-
* Multiplies two numbers
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
* @
|
|
217
|
+
* Multiplies two numbers.
|
|
218
|
+
*
|
|
219
|
+
* Example: 5 and 3 -> 15, -2 and 4 -> -8
|
|
220
|
+
* @param inputs - The two numbers
|
|
221
|
+
* @returns Their product
|
|
149
222
|
* @group basics
|
|
150
223
|
* @shortname multiply
|
|
151
224
|
* @drawable false
|
|
225
|
+
* @example
|
|
226
|
+
* ```typescript
|
|
227
|
+
* const product = bitbybit.math.multiply({ first: 5, second: 3 });
|
|
228
|
+
* ```
|
|
152
229
|
*/
|
|
153
230
|
multiply(inputs: Inputs.Math.TwoNumbersDto): number;
|
|
154
231
|
/**
|
|
155
232
|
* Divides the first number by the second.
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
233
|
+
*
|
|
234
|
+
* Dividing by 0 gives Infinity, as in JavaScript.
|
|
235
|
+
* Example: 10 and 2 -> 5, 7 and 2 -> 3.5
|
|
236
|
+
* @param inputs - The number to divide and the number to divide by
|
|
237
|
+
* @returns Their quotient
|
|
159
238
|
* @group basics
|
|
160
239
|
* @shortname divide
|
|
161
240
|
* @drawable false
|
|
241
|
+
* @example
|
|
242
|
+
* ```typescript
|
|
243
|
+
* const quotient = bitbybit.math.divide({ first: 7, second: 2 });
|
|
244
|
+
* ```
|
|
162
245
|
*/
|
|
163
246
|
divide(inputs: Inputs.Math.TwoNumbersDto): number;
|
|
164
247
|
/**
|
|
165
|
-
* Raises the first number to the power of the second
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
* @
|
|
248
|
+
* Raises the first number to the power of the second.
|
|
249
|
+
*
|
|
250
|
+
* Example: 2 to the 3 -> 8, 5 to the 2 -> 25, 10 to the -1 -> 0.1
|
|
251
|
+
* @param inputs - The base and the exponent
|
|
252
|
+
* @returns The power
|
|
169
253
|
* @group basics
|
|
170
254
|
* @shortname power
|
|
171
255
|
* @drawable false
|
|
256
|
+
* @example
|
|
257
|
+
* ```typescript
|
|
258
|
+
* const cube = bitbybit.math.power({ first: 2, second: 3 });
|
|
259
|
+
* ```
|
|
172
260
|
*/
|
|
173
261
|
power(inputs: Inputs.Math.TwoNumbersDto): number;
|
|
174
262
|
/**
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
*
|
|
263
|
+
* Finds the square root of a number.
|
|
264
|
+
*
|
|
265
|
+
* A negative number gives NaN.
|
|
266
|
+
* Example: 9 -> 3, 2 -> 1.414
|
|
267
|
+
* @param inputs - The number
|
|
268
|
+
* @returns The square root
|
|
179
269
|
* @group basics
|
|
180
270
|
* @shortname sqrt
|
|
181
271
|
* @drawable false
|
|
182
272
|
*/
|
|
183
273
|
sqrt(inputs: Inputs.Math.NumberDto): number;
|
|
184
274
|
/**
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
* @
|
|
275
|
+
* Drops the sign of a number, so the result is never negative.
|
|
276
|
+
*
|
|
277
|
+
* Example: -5 -> 5, 3 -> 3, 0 -> 0
|
|
278
|
+
* @param inputs - The number
|
|
279
|
+
* @returns The absolute value
|
|
189
280
|
* @group basics
|
|
190
281
|
* @shortname abs
|
|
191
282
|
* @drawable false
|
|
192
283
|
*/
|
|
193
284
|
abs(inputs: Inputs.Math.NumberDto): number;
|
|
194
285
|
/**
|
|
195
|
-
* Rounds a number to the nearest
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
* @
|
|
286
|
+
* Rounds a number to the nearest whole number; halves round up.
|
|
287
|
+
*
|
|
288
|
+
* Example: 3.7 -> 4, 2.3 -> 2, 5.5 -> 6
|
|
289
|
+
* @param inputs - The number
|
|
290
|
+
* @returns The nearest whole number
|
|
199
291
|
* @group basics
|
|
200
292
|
* @shortname round
|
|
201
293
|
* @drawable false
|
|
202
294
|
*/
|
|
203
295
|
round(inputs: Inputs.Math.NumberDto): number;
|
|
204
296
|
/**
|
|
205
|
-
* Rounds a number down to the
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
* @
|
|
297
|
+
* Rounds a number down to the whole number below it.
|
|
298
|
+
*
|
|
299
|
+
* Example: 3.7 -> 3, -2.3 -> -3, 5 -> 5
|
|
300
|
+
* @param inputs - The number
|
|
301
|
+
* @returns The whole number below
|
|
209
302
|
* @group basics
|
|
210
303
|
* @shortname floor
|
|
211
304
|
* @drawable false
|
|
212
305
|
*/
|
|
213
306
|
floor(inputs: Inputs.Math.NumberDto): number;
|
|
214
307
|
/**
|
|
215
|
-
* Rounds a number up to the
|
|
216
|
-
*
|
|
217
|
-
*
|
|
218
|
-
* @
|
|
308
|
+
* Rounds a number up to the whole number above it.
|
|
309
|
+
*
|
|
310
|
+
* Example: 3.2 -> 4, -2.8 -> -2, 5 -> 5
|
|
311
|
+
* @param inputs - The number
|
|
312
|
+
* @returns The whole number above
|
|
219
313
|
* @group basics
|
|
220
314
|
* @shortname ceil
|
|
221
315
|
* @drawable false
|
|
222
316
|
*/
|
|
223
317
|
ceil(inputs: Inputs.Math.NumberDto): number;
|
|
224
318
|
/**
|
|
225
|
-
*
|
|
226
|
-
*
|
|
227
|
-
*
|
|
228
|
-
* @
|
|
319
|
+
* Flips the sign of a number.
|
|
320
|
+
*
|
|
321
|
+
* Example: 5 -> -5, -3 -> 3, 0 -> 0
|
|
322
|
+
* @param inputs - The number
|
|
323
|
+
* @returns The number with the opposite sign
|
|
229
324
|
* @group basics
|
|
230
325
|
* @shortname negate
|
|
231
326
|
* @drawable false
|
|
232
327
|
*/
|
|
233
328
|
negate(inputs: Inputs.Math.NumberDto): number;
|
|
234
329
|
/**
|
|
235
|
-
*
|
|
236
|
-
*
|
|
237
|
-
*
|
|
238
|
-
* @
|
|
330
|
+
* Finds the natural logarithm of a number: the power e must be raised to for that number.
|
|
331
|
+
*
|
|
332
|
+
* Example: 2.718 -> about 1, 1 -> 0
|
|
333
|
+
* @param inputs - The number, greater than 0
|
|
334
|
+
* @returns The natural logarithm
|
|
239
335
|
* @group basics
|
|
240
336
|
* @shortname ln
|
|
241
337
|
* @drawable false
|
|
242
338
|
*/
|
|
243
339
|
ln(inputs: Inputs.Math.NumberDto): number;
|
|
244
340
|
/**
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
* @
|
|
341
|
+
* Finds the base-10 logarithm of a number: the power 10 must be raised to for that number.
|
|
342
|
+
*
|
|
343
|
+
* Example: 100 -> 2, 1000 -> 3, 10 -> 1
|
|
344
|
+
* @param inputs - The number, greater than 0
|
|
345
|
+
* @returns The base-10 logarithm
|
|
249
346
|
* @group basics
|
|
250
347
|
* @shortname log10
|
|
251
348
|
* @drawable false
|
|
252
349
|
*/
|
|
253
350
|
log10(inputs: Inputs.Math.NumberDto): number;
|
|
254
351
|
/**
|
|
255
|
-
* Raises 10 to the power of
|
|
256
|
-
*
|
|
257
|
-
*
|
|
258
|
-
* @
|
|
352
|
+
* Raises 10 to the power of a number.
|
|
353
|
+
*
|
|
354
|
+
* Example: 2 -> 100, 3 -> 1000, -1 -> 0.1
|
|
355
|
+
* @param inputs - The exponent
|
|
356
|
+
* @returns 10 to that power
|
|
259
357
|
* @group basics
|
|
260
358
|
* @shortname ten pow
|
|
261
359
|
* @drawable false
|
|
262
360
|
*/
|
|
263
361
|
tenPow(inputs: Inputs.Math.NumberDto): number;
|
|
264
362
|
/**
|
|
265
|
-
*
|
|
266
|
-
*
|
|
267
|
-
*
|
|
268
|
-
* @
|
|
363
|
+
* Finds the sine of an angle given in radians.
|
|
364
|
+
*
|
|
365
|
+
* Example: 0 -> 0, pi/2 -> 1
|
|
366
|
+
* @param inputs - The angle in radians
|
|
367
|
+
* @returns The sine, between -1 and 1
|
|
269
368
|
* @group basics
|
|
270
369
|
* @shortname sin
|
|
271
370
|
* @drawable false
|
|
272
371
|
*/
|
|
273
372
|
sin(inputs: Inputs.Math.NumberDto): number;
|
|
274
373
|
/**
|
|
275
|
-
*
|
|
276
|
-
*
|
|
277
|
-
*
|
|
278
|
-
* @
|
|
374
|
+
* Finds the cosine of an angle given in radians.
|
|
375
|
+
*
|
|
376
|
+
* Example: 0 -> 1, pi -> -1
|
|
377
|
+
* @param inputs - The angle in radians
|
|
378
|
+
* @returns The cosine, between -1 and 1
|
|
279
379
|
* @group basics
|
|
280
380
|
* @shortname cos
|
|
281
381
|
* @drawable false
|
|
282
382
|
*/
|
|
283
383
|
cos(inputs: Inputs.Math.NumberDto): number;
|
|
284
384
|
/**
|
|
285
|
-
*
|
|
286
|
-
*
|
|
287
|
-
*
|
|
288
|
-
* @
|
|
385
|
+
* Finds the tangent of an angle given in radians.
|
|
386
|
+
*
|
|
387
|
+
* Example: 0 -> 0, pi/4 -> about 1
|
|
388
|
+
* @param inputs - The angle in radians
|
|
389
|
+
* @returns The tangent
|
|
289
390
|
* @group basics
|
|
290
391
|
* @shortname tan
|
|
291
392
|
* @drawable false
|
|
292
393
|
*/
|
|
293
394
|
tan(inputs: Inputs.Math.NumberDto): number;
|
|
294
395
|
/**
|
|
295
|
-
*
|
|
296
|
-
*
|
|
297
|
-
*
|
|
298
|
-
* @
|
|
396
|
+
* Finds the angle, in radians, whose sine is the given number.
|
|
397
|
+
*
|
|
398
|
+
* Example: 0 -> 0, 1 -> pi/2 (about 1.57)
|
|
399
|
+
* @param inputs - A number between -1 and 1
|
|
400
|
+
* @returns The angle in radians
|
|
299
401
|
* @group basics
|
|
300
402
|
* @shortname asin
|
|
301
403
|
* @drawable false
|
|
302
404
|
*/
|
|
303
405
|
asin(inputs: Inputs.Math.NumberDto): number;
|
|
304
406
|
/**
|
|
305
|
-
*
|
|
306
|
-
*
|
|
307
|
-
*
|
|
308
|
-
* @
|
|
407
|
+
* Finds the angle, in radians, whose cosine is the given number.
|
|
408
|
+
*
|
|
409
|
+
* Example: 1 -> 0, -1 -> pi (about 3.14)
|
|
410
|
+
* @param inputs - A number between -1 and 1
|
|
411
|
+
* @returns The angle in radians
|
|
309
412
|
* @group basics
|
|
310
413
|
* @shortname acos
|
|
311
414
|
* @drawable false
|
|
312
415
|
*/
|
|
313
416
|
acos(inputs: Inputs.Math.NumberDto): number;
|
|
314
417
|
/**
|
|
315
|
-
*
|
|
316
|
-
*
|
|
317
|
-
*
|
|
318
|
-
* @
|
|
418
|
+
* Finds the angle, in radians, whose tangent is the given number.
|
|
419
|
+
*
|
|
420
|
+
* Example: 0 -> 0, 1 -> pi/4 (about 0.785)
|
|
421
|
+
* @param inputs - The number
|
|
422
|
+
* @returns The angle in radians, between -pi/2 and pi/2
|
|
319
423
|
* @group basics
|
|
320
424
|
* @shortname atan
|
|
321
425
|
* @drawable false
|
|
322
426
|
*/
|
|
323
427
|
atan(inputs: Inputs.Math.NumberDto): number;
|
|
324
428
|
/**
|
|
325
|
-
*
|
|
326
|
-
*
|
|
327
|
-
*
|
|
328
|
-
* @
|
|
429
|
+
* Raises e, the base of the natural logarithm, to the power of a number.
|
|
430
|
+
*
|
|
431
|
+
* Example: 0 -> 1, 1 -> about 2.718, 2 -> about 7.389
|
|
432
|
+
* @param inputs - The exponent
|
|
433
|
+
* @returns e to that power
|
|
329
434
|
* @group basics
|
|
330
435
|
* @shortname exp
|
|
331
436
|
* @drawable false
|
|
@@ -333,9 +438,10 @@ export declare class MathBitByBit {
|
|
|
333
438
|
exp(inputs: Inputs.Math.NumberDto): number;
|
|
334
439
|
/**
|
|
335
440
|
* Converts an angle from degrees to radians.
|
|
336
|
-
*
|
|
337
|
-
*
|
|
338
|
-
* @
|
|
441
|
+
*
|
|
442
|
+
* Example: 180 -> pi (about 3.14159), 90 -> pi/2
|
|
443
|
+
* @param inputs - The angle in degrees
|
|
444
|
+
* @returns The angle in radians
|
|
339
445
|
* @group basics
|
|
340
446
|
* @shortname deg to rad
|
|
341
447
|
* @drawable false
|
|
@@ -343,134 +449,180 @@ export declare class MathBitByBit {
|
|
|
343
449
|
degToRad(inputs: Inputs.Math.NumberDto): number;
|
|
344
450
|
/**
|
|
345
451
|
* Converts an angle from radians to degrees.
|
|
346
|
-
*
|
|
347
|
-
*
|
|
348
|
-
* @
|
|
452
|
+
*
|
|
453
|
+
* Example: pi -> 180, pi/2 -> 90
|
|
454
|
+
* @param inputs - The angle in radians
|
|
455
|
+
* @returns The angle in degrees
|
|
349
456
|
* @group basics
|
|
350
457
|
* @shortname rad to deg
|
|
351
458
|
* @drawable false
|
|
352
459
|
*/
|
|
353
460
|
radToDeg(inputs: Inputs.Math.NumberDto): number;
|
|
354
461
|
/**
|
|
355
|
-
*
|
|
356
|
-
*
|
|
357
|
-
*
|
|
358
|
-
*
|
|
359
|
-
*
|
|
462
|
+
* Maps a value from 0 to 1 onto the range `min` to `max` along an easing curve, so the result
|
|
463
|
+
* speeds up or slows down instead of changing evenly.
|
|
464
|
+
*
|
|
465
|
+
* An `easeIn` curve starts slowly, an `easeOut` curve ends slowly, an `easeInOut` curve does
|
|
466
|
+
* both.
|
|
467
|
+
* Example: 0.5 from [0,100] with easeInQuad -> 25
|
|
468
|
+
* @param inputs - The value between 0 and 1, the target range and the easing curve
|
|
469
|
+
* @returns The eased value in the target range
|
|
360
470
|
* @group operations
|
|
361
471
|
* @shortname ease
|
|
362
472
|
* @drawable false
|
|
473
|
+
* @example
|
|
474
|
+
* ```typescript
|
|
475
|
+
* const eased = bitbybit.math.ease({ x: 0.5, min: 0, max: 100, ease: Bit.Inputs.Math.easeEnum.easeInQuad });
|
|
476
|
+
* ```
|
|
363
477
|
*/
|
|
364
478
|
ease(inputs: Inputs.Math.EaseDto): number;
|
|
365
479
|
/**
|
|
366
|
-
*
|
|
367
|
-
*
|
|
368
|
-
*
|
|
369
|
-
* @
|
|
480
|
+
* Keeps a number within a range: below `min` becomes `min`, above `max` becomes `max`.
|
|
481
|
+
*
|
|
482
|
+
* Example: 5 in [0,3] -> 3, -1 in [0,3] -> 0, 1.5 in [0,3] -> 1.5
|
|
483
|
+
* @param inputs - The number and the range to keep it in
|
|
484
|
+
* @returns The number, limited to the range
|
|
370
485
|
* @group operations
|
|
371
486
|
* @shortname clamp
|
|
372
487
|
* @drawable false
|
|
488
|
+
* @example
|
|
489
|
+
* ```typescript
|
|
490
|
+
* const limited = bitbybit.math.clamp({ number: 5, min: 0, max: 3 });
|
|
491
|
+
* ```
|
|
373
492
|
*/
|
|
374
493
|
clamp(inputs: Inputs.Math.ClampDto): number;
|
|
375
494
|
/**
|
|
376
|
-
*
|
|
377
|
-
*
|
|
378
|
-
*
|
|
379
|
-
*
|
|
380
|
-
*
|
|
495
|
+
* Blends from a start value to an end value by a fraction `t`: 0 gives the start, 1 the end,
|
|
496
|
+
* 0.5 the midpoint.
|
|
497
|
+
*
|
|
498
|
+
* A `t` outside 0 to 1 extrapolates past the ends.
|
|
499
|
+
* Example: 0 to 100 at 0.5 -> 50, 10 to 20 at 0.25 -> 12.5
|
|
500
|
+
* @param inputs - The start value, the end value and the fraction
|
|
501
|
+
* @returns The blended value
|
|
381
502
|
* @group operations
|
|
382
503
|
* @shortname lerp
|
|
383
504
|
* @drawable false
|
|
505
|
+
* @example
|
|
506
|
+
* ```typescript
|
|
507
|
+
* const mid = bitbybit.math.lerp({ start: 10, end: 20, t: 0.25 });
|
|
508
|
+
* ```
|
|
384
509
|
*/
|
|
385
510
|
lerp(inputs: Inputs.Math.LerpDto): number;
|
|
386
511
|
/**
|
|
387
|
-
*
|
|
388
|
-
*
|
|
389
|
-
*
|
|
390
|
-
*
|
|
391
|
-
* @
|
|
512
|
+
* Finds where a value sits between a start and an end, as a fraction: the `t` that `lerp` would
|
|
513
|
+
* need to produce it.
|
|
514
|
+
*
|
|
515
|
+
* Example: 5 in [0,10] -> 0.5, 2.5 in [0,10] -> 0.25
|
|
516
|
+
* @param inputs - The start value, the end value and the value to locate
|
|
517
|
+
* @returns The fraction from start to end
|
|
392
518
|
* @group operations
|
|
393
519
|
* @shortname inverse lerp
|
|
394
520
|
* @drawable false
|
|
521
|
+
* @example
|
|
522
|
+
* ```typescript
|
|
523
|
+
* const fraction = bitbybit.math.inverseLerp({ start: 0, end: 10, value: 2.5 });
|
|
524
|
+
* ```
|
|
395
525
|
*/
|
|
396
526
|
inverseLerp(inputs: Inputs.Math.InverseLerpDto): number;
|
|
397
527
|
/**
|
|
398
|
-
*
|
|
399
|
-
*
|
|
400
|
-
*
|
|
401
|
-
*
|
|
402
|
-
* @
|
|
528
|
+
* Turns a value from 0 to 1 into a smooth S-curve that starts and ends gently; the value is
|
|
529
|
+
* clamped to that range first.
|
|
530
|
+
*
|
|
531
|
+
* Example: 0 -> 0, 0.5 -> 0.5, 0.25 -> 0.156
|
|
532
|
+
* @param inputs - The value between 0 and 1
|
|
533
|
+
* @returns The smoothed value between 0 and 1
|
|
403
534
|
* @group operations
|
|
404
535
|
* @shortname smoothstep
|
|
405
536
|
* @drawable false
|
|
406
537
|
*/
|
|
407
538
|
smoothstep(inputs: Inputs.Math.NumberDto): number;
|
|
408
539
|
/**
|
|
409
|
-
*
|
|
410
|
-
*
|
|
411
|
-
*
|
|
412
|
-
* @param inputs
|
|
413
|
-
* @returns -1, 0
|
|
540
|
+
* Tells the sign of a number: -1 when negative, 0 when zero, 1 when positive.
|
|
541
|
+
*
|
|
542
|
+
* Example: -5 -> -1, 0 -> 0, 3.14 -> 1
|
|
543
|
+
* @param inputs - The number
|
|
544
|
+
* @returns -1, 0 or 1
|
|
414
545
|
* @group operations
|
|
415
546
|
* @shortname sign
|
|
416
547
|
* @drawable false
|
|
417
548
|
*/
|
|
418
549
|
sign(inputs: Inputs.Math.NumberDto): number;
|
|
419
550
|
/**
|
|
420
|
-
*
|
|
421
|
-
*
|
|
422
|
-
*
|
|
423
|
-
*
|
|
424
|
-
* @
|
|
551
|
+
* Keeps the part of a number after the decimal point, measured up from the whole number below
|
|
552
|
+
* it, so the result is always from 0 up to 1.
|
|
553
|
+
*
|
|
554
|
+
* Example: 3.14 -> 0.14, -2.3 -> 0.7
|
|
555
|
+
* @param inputs - The number
|
|
556
|
+
* @returns The fractional part, from 0 up to 1
|
|
425
557
|
* @group operations
|
|
426
558
|
* @shortname fract
|
|
427
559
|
* @drawable false
|
|
428
560
|
*/
|
|
429
561
|
fract(inputs: Inputs.Math.NumberDto): number;
|
|
430
562
|
/**
|
|
431
|
-
* Wraps a number
|
|
432
|
-
*
|
|
433
|
-
*
|
|
434
|
-
*
|
|
435
|
-
*
|
|
563
|
+
* Wraps a number into a range so it cycles round: past `max` it comes back in at `min`, and
|
|
564
|
+
* below `min` it comes back in at `max`.
|
|
565
|
+
*
|
|
566
|
+
* Useful for angles and repeating patterns; unlike a plain modulus it handles negative numbers.
|
|
567
|
+
* Example: 1.5 in [0,1) -> 0.5, -0.3 in [0,1) -> 0.7, 370 in [0,360) -> 10
|
|
568
|
+
* @param inputs - The number and the range to wrap it into
|
|
569
|
+
* @returns The wrapped number, from min up to max
|
|
436
570
|
* @group operations
|
|
437
571
|
* @shortname wrap
|
|
438
572
|
* @drawable false
|
|
573
|
+
* @example
|
|
574
|
+
* ```typescript
|
|
575
|
+
* const angle = bitbybit.math.wrap({ number: 370, min: 0, max: 360 });
|
|
576
|
+
* ```
|
|
439
577
|
*/
|
|
440
578
|
wrap(inputs: Inputs.Math.WrapDto): number;
|
|
441
579
|
/**
|
|
442
|
-
*
|
|
443
|
-
*
|
|
444
|
-
*
|
|
445
|
-
*
|
|
446
|
-
* @param inputs
|
|
447
|
-
* @returns value
|
|
580
|
+
* Bounces a value back and forth between 0 and `length` as `t` grows: up to `length`, back down
|
|
581
|
+
* to 0, and again.
|
|
582
|
+
*
|
|
583
|
+
* Example: length 1 at t 0.5 -> 0.5, t 1 -> 1, t 1.5 -> 0.5, t 2 -> 0
|
|
584
|
+
* @param inputs - The running value and the length to bounce within
|
|
585
|
+
* @returns The bounced value between 0 and length
|
|
448
586
|
* @group operations
|
|
449
587
|
* @shortname ping pong
|
|
450
588
|
* @drawable false
|
|
589
|
+
* @example
|
|
590
|
+
* ```typescript
|
|
591
|
+
* const bounce = bitbybit.math.pingPong({ t: 1.5, length: 1 });
|
|
592
|
+
* ```
|
|
451
593
|
*/
|
|
452
594
|
pingPong(inputs: Inputs.Math.PingPongDto): number;
|
|
453
595
|
/**
|
|
454
|
-
* Moves a value toward a target by
|
|
455
|
-
*
|
|
456
|
-
*
|
|
457
|
-
* @param inputs current value, target
|
|
458
|
-
* @returns
|
|
596
|
+
* Moves a value toward a target by at most `maxDelta`, without overshooting it.
|
|
597
|
+
*
|
|
598
|
+
* Example: 0 toward 10 by 3 -> 3, 8 toward 10 by 3 -> 10
|
|
599
|
+
* @param inputs - The current value, the target and the largest step allowed
|
|
600
|
+
* @returns The value after one step
|
|
459
601
|
* @group operations
|
|
460
602
|
* @shortname move towards
|
|
461
603
|
* @drawable false
|
|
604
|
+
* @example
|
|
605
|
+
* ```typescript
|
|
606
|
+
* const next = bitbybit.math.moveTowards({ current: 8, target: 10, maxDelta: 3 });
|
|
607
|
+
* ```
|
|
462
608
|
*/
|
|
463
609
|
moveTowards(inputs: Inputs.Math.MoveTowardsDto): number;
|
|
464
610
|
/**
|
|
465
|
-
*
|
|
466
|
-
*
|
|
467
|
-
*
|
|
468
|
-
*
|
|
469
|
-
*
|
|
470
|
-
*
|
|
611
|
+
* Works out a simple arithmetic expression written as text: numbers, +, -, the multiplication
|
|
612
|
+
* sign, /, parentheses and spaces.
|
|
613
|
+
*
|
|
614
|
+
* The expression is parsed and computed by the library itself, never handed to the JavaScript
|
|
615
|
+
* engine to run, so it is safe with text a user typed.
|
|
616
|
+
* Example: '(3+2) times 4' written with the sign -> 20, '10/3' -> 3.3333
|
|
617
|
+
* @param inputs - The expression text
|
|
618
|
+
* @returns The computed value
|
|
471
619
|
* @group operations
|
|
472
620
|
* @shortname eval arithmetic
|
|
473
621
|
* @drawable false
|
|
622
|
+
* @example
|
|
623
|
+
* ```typescript
|
|
624
|
+
* const value = bitbybit.math.evalArithmetic({ expression: "(3 + 2) * 4" });
|
|
625
|
+
* ```
|
|
474
626
|
*/
|
|
475
627
|
evalArithmetic(inputs: Inputs.Math.EvalArithmeticDto): number;
|
|
476
628
|
private easeInSine;
|