@oazmi/superbuild 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/esm/_dnt.shims.d.ts +2 -0
  2. package/esm/_dnt.shims.d.ts.map +1 -0
  3. package/esm/_dnt.shims.js +57 -0
  4. package/esm/deps/jsr.io/@oazmi/esbuild-types/0.28.0/src/mod.d.ts +598 -0
  5. package/esm/deps/jsr.io/@oazmi/esbuild-types/0.28.0/src/mod.d.ts.map +1 -0
  6. package/esm/deps/jsr.io/@oazmi/esbuild-types/0.28.0/src/mod.js +1 -0
  7. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/alias.d.ts +617 -0
  8. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/alias.d.ts.map +1 -0
  9. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/alias.js +671 -0
  10. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/array1d.d.ts +487 -0
  11. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/array1d.d.ts.map +1 -0
  12. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/array1d.js +536 -0
  13. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/array2d.d.ts +266 -0
  14. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/array2d.d.ts.map +1 -0
  15. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/array2d.js +318 -0
  16. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/binder.d.ts +368 -0
  17. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/binder.d.ts.map +1 -0
  18. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/binder.js +380 -0
  19. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/crossenv.d.ts +711 -0
  20. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/crossenv.d.ts.map +1 -0
  21. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/crossenv.js +1173 -0
  22. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/cryptoman.d.ts +171 -0
  23. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/cryptoman.d.ts.map +1 -0
  24. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/cryptoman.js +308 -0
  25. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/deps.d.ts +10 -0
  26. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/deps.d.ts.map +1 -0
  27. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/deps.js +10 -0
  28. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/eightpack.d.ts +168 -0
  29. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/eightpack.d.ts.map +1 -0
  30. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/eightpack.js +236 -0
  31. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/eightpack_varint.d.ts +90 -0
  32. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/eightpack_varint.d.ts.map +1 -0
  33. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/eightpack_varint.js +237 -0
  34. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/numericarray.d.ts +213 -0
  35. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/numericarray.d.ts.map +1 -0
  36. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/numericarray.js +363 -0
  37. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/numericmethods.d.ts +233 -0
  38. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/numericmethods.d.ts.map +1 -0
  39. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/numericmethods.js +256 -0
  40. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/pathman.d.ts +1436 -0
  41. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/pathman.d.ts.map +1 -0
  42. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/pathman.js +1730 -0
  43. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/promiseman.d.ts +647 -0
  44. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/promiseman.d.ts.map +1 -0
  45. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/promiseman.js +762 -0
  46. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/stringman.d.ts +538 -0
  47. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/stringman.d.ts.map +1 -0
  48. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/stringman.js +626 -0
  49. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/struct.d.ts +734 -0
  50. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/struct.d.ts.map +1 -0
  51. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/struct.js +764 -0
  52. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/typedbuffer.d.ts +137 -0
  53. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/typedbuffer.d.ts.map +1 -0
  54. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/typedbuffer.js +234 -0
  55. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/typedefs.d.ts +391 -0
  56. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/typedefs.d.ts.map +1 -0
  57. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/typedefs.js +8 -0
  58. package/esm/deps.d.ts +56 -0
  59. package/esm/deps.d.ts.map +1 -0
  60. package/esm/deps.js +37 -0
  61. package/esm/esbuild/metafile.d.ts +90 -0
  62. package/esm/esbuild/metafile.d.ts.map +1 -0
  63. package/esm/esbuild/metafile.js +275 -0
  64. package/esm/esbuild/native.d.ts +95 -0
  65. package/esm/esbuild/native.d.ts.map +1 -0
  66. package/esm/esbuild/native.js +127 -0
  67. package/esm/esbuild/outputfile.d.ts +86 -0
  68. package/esm/esbuild/outputfile.d.ts.map +1 -0
  69. package/esm/esbuild/outputfile.js +221 -0
  70. package/esm/esbuild/strongtypes.d.ts +90 -0
  71. package/esm/esbuild/strongtypes.d.ts.map +1 -0
  72. package/esm/esbuild/strongtypes.js +8 -0
  73. package/esm/esbuild/typedefs.d.ts +121 -0
  74. package/esm/esbuild/typedefs.d.ts.map +1 -0
  75. package/esm/esbuild/typedefs.js +55 -0
  76. package/esm/esbuild/weaktypes.d.ts +46 -0
  77. package/esm/esbuild/weaktypes.d.ts.map +1 -0
  78. package/esm/esbuild/weaktypes.js +8 -0
  79. package/esm/funcdefs.d.ts +89 -0
  80. package/esm/funcdefs.d.ts.map +1 -0
  81. package/esm/funcdefs.js +145 -0
  82. package/esm/mod.d.ts +4 -0
  83. package/esm/mod.d.ts.map +1 -0
  84. package/esm/mod.js +2 -0
  85. package/esm/package.json +3 -0
  86. package/esm/plugins/emissions_driver.d.ts +33 -0
  87. package/esm/plugins/emissions_driver.d.ts.map +1 -0
  88. package/esm/plugins/emissions_driver.js +260 -0
  89. package/esm/plugins/long_build.d.ts +138 -0
  90. package/esm/plugins/long_build.d.ts.map +1 -0
  91. package/esm/plugins/long_build.js +288 -0
  92. package/esm/plugins/native_replica.d.ts +48 -0
  93. package/esm/plugins/native_replica.d.ts.map +1 -0
  94. package/esm/plugins/native_replica.js +122 -0
  95. package/esm/super/build.d.ts +53 -0
  96. package/esm/super/build.d.ts.map +1 -0
  97. package/esm/super/build.js +39 -0
  98. package/esm/super/build_context.d.ts +83 -0
  99. package/esm/super/build_context.d.ts.map +1 -0
  100. package/esm/super/build_context.js +124 -0
  101. package/esm/super/mod.d.ts +12 -0
  102. package/esm/super/mod.d.ts.map +1 -0
  103. package/esm/super/mod.js +9 -0
  104. package/esm/super/plugin.d.ts +23 -0
  105. package/esm/super/plugin.d.ts.map +1 -0
  106. package/esm/super/plugin.js +31 -0
  107. package/esm/super/plugin_build.d.ts +38 -0
  108. package/esm/super/plugin_build.d.ts.map +1 -0
  109. package/esm/super/plugin_build.js +198 -0
  110. package/esm/super/typedefs.d.ts +323 -0
  111. package/esm/super/typedefs.d.ts.map +1 -0
  112. package/esm/super/typedefs.js +10 -0
  113. package/esm/typedefs.d.ts +21 -0
  114. package/esm/typedefs.d.ts.map +1 -0
  115. package/esm/typedefs.js +5 -0
  116. package/license.md +37 -0
  117. package/package.json +88 -0
  118. package/readme.md +181 -0
@@ -0,0 +1,363 @@
1
+ /** utility functions for numeric array manipulation and array math functions.
2
+ *
3
+ * @module
4
+ */
5
+ import { resolveRange } from "./array1d.js";
6
+ import { constructorOf } from "./struct.js";
7
+ /** transpose a 2d array (matrix).
8
+ *
9
+ * if you're wondering what's the difference between this and {@link transposeArray2D} from the {@link "array2d"} submodule,
10
+ * then be my guest, because I am just as puzzled as you.
11
+ * perhaps I forgot that I made one or the other, resulting in duplication.
12
+ *
13
+ * however, there are a few implementation differences between the these two functions:
14
+ * - {@link transpose2D} works by calling the array `map` method.
15
+ * - {@link transposeArray2D} works by assigning values to the new array's transposed indexes.
16
+ *
17
+ * similarities between the two functions:
18
+ * - both transpose sparse 2d arrays to full 2d arrays with the sparse entries replaced with `undefined`.
19
+ * - both use the first element (the first row) to determine the number of columns your 2d array has.
20
+ * this can mean disastrous cropped results if a sparse 2d array is provided where the first row's
21
+ * number of elements (i.e. number of columns) is not the greatest out of all the other rows.
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * import { assertEquals } from "jsr:@std/assert"
26
+ *
27
+ * const sparse_arr2d: Array<number[]> = [
28
+ * [1 , 2 , 3 , 4 , 5 ],
29
+ * [6 , 7 , 8 , 9],
30
+ * [11, 12, 13],
31
+ * [16, 17, 18, 19, 20],
32
+ * ]
33
+ *
34
+ * const sparse_arr2d_transposed = transpose2D(sparse_arr2d)
35
+ *
36
+ * sparse_arr2d_transposed satisfies Array<number>[]
37
+ *
38
+ * assertEquals(sparse_arr2d_transposed, [
39
+ * [1 , 6 , 11 , 16],
40
+ * [2 , 7 , 12 , 17],
41
+ * [3 , 8 , 13 , 18],
42
+ * [4 , 9 , undefined , 19],
43
+ * [5 , undefined , undefined , 20],
44
+ * ])
45
+ * ```
46
+ */
47
+ export const transpose2D = (matrix) => (matrix[0].map((_row_0_col_i, i) => matrix.map(row_arr => row_arr[i])));
48
+ /** compute the left-to-right running difference between successive elements.
49
+ *
50
+ * the returned array's length is decremented by one.
51
+ * as a result, a single element array will turn into an empty array.
52
+ *
53
+ * > [!note]
54
+ * > be careful when using with unsigned typed arrays.
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * import { assertEquals } from "jsr:@std/assert"
59
+ *
60
+ * // basic example
61
+ * const arr1 = [1, 2, 3, 4, 5, 99, 88]
62
+ * const arr1_diff = diff(arr1)
63
+ * assertEquals(arr1_diff, [1, 1, 1, 1, 94, -11])
64
+ *
65
+ * // subarray slicing example
66
+ * const arr2 = [1, 2, 3, 4, 5, 99, 88]
67
+ * const arr2_diff = diff(arr2, 2, -1)
68
+ * assertEquals(arr2_diff, [1, 1, 94])
69
+ * ```
70
+ */
71
+ export const diff = (arr, start, end) => {
72
+ [start, end] = resolveRange(start, end, arr.length);
73
+ const diff_arr = arr.slice(start + 1, end);
74
+ for (let i = 0; i < diff_arr.length; i++) {
75
+ diff_arr[i] -= arr[start + i];
76
+ }
77
+ return diff_arr;
78
+ };
79
+ /** compute the right-to-left (ie reverse) running difference between preceding elements.
80
+ *
81
+ * the returned array's length is decremented by one.
82
+ * as a result, a single element array will turn into an empty array.
83
+ *
84
+ * > [!note]
85
+ * > be careful when using with unsigned typed arrays.
86
+ *
87
+ * @example
88
+ * ```ts
89
+ * import { assertEquals } from "jsr:@std/assert"
90
+ *
91
+ * // basic example
92
+ * const arr1 = [1, 2, 3, 4, 5, 99, 88]
93
+ * const arr1_diff = diff_right(arr1)
94
+ * assertEquals(arr1_diff, [-1, -1, -1, -1, -94, 11])
95
+ *
96
+ * // subarray slicing example
97
+ * const arr2 = [1, 2, 3, 4, 5, 99, 88]
98
+ * const arr2_diff = diff_right(arr2, 2, -1)
99
+ * assertEquals(arr2_diff, [-1, -1, -94])
100
+ * ```
101
+ */
102
+ export const diff_right = (arr, start, end) => {
103
+ [start, end] = resolveRange(start, end, arr.length);
104
+ const diff_arr = arr.slice(start, end - 1);
105
+ for (let i = 0; i < diff_arr.length; i++) {
106
+ diff_arr[i] -= arr[start + i + 1];
107
+ }
108
+ return diff_arr;
109
+ };
110
+ /** cumulative summation of an array.
111
+ *
112
+ * the returned array has its length increased by one.
113
+ *
114
+ * @example
115
+ * ```ts
116
+ * import { assertEquals } from "jsr:@std/assert"
117
+ *
118
+ * // basic example
119
+ * const arr1 = [10, 20, 30, 40, 50]
120
+ * const arr1_cum_sum = cumulativeSum(arr1)
121
+ * assertEquals(arr1_cum_sum, [0, 10, 30, 60, 100, 150])
122
+ * ```
123
+ */
124
+ export const cumulativeSum = (arr) => {
125
+ const len = arr.length, cum_sum = new (constructorOf(arr))(len + 1).fill(0);
126
+ for (let i = 0; i < len; i++) {
127
+ cum_sum[i + 1] = cum_sum[i] + arr[i];
128
+ }
129
+ return cum_sum;
130
+ };
131
+ /** conduct in-place unary arithmetic operations on numeric arrays
132
+ * TODO: find out why I'm not exporting this function. did I simply forget?
133
+ * @category inplace
134
+ */
135
+ const unaryArithmetic = (operation, arr, start, end) => {
136
+ const [xs, xe] = resolveRange(start, end, arr.length);
137
+ switch (operation) {
138
+ case "abs": return abs(arr, xs, xe);
139
+ case "neg": return neg(arr, xs, xe);
140
+ case "comp": return bcomp(arr, xs, xe);
141
+ }
142
+ };
143
+ /** conduct in-place scalar arithmetic operations on numeric arrays
144
+ * TODO: find out why I'm not exporting this function. did I simply forget?
145
+ * @category inplace
146
+ */
147
+ const scalarArithmetic = (operation, arr, value, start, end) => {
148
+ const [xs, xe] = resolveRange(start, end, arr.length);
149
+ switch (operation) {
150
+ case "add": return add(arr, value, xs, xe);
151
+ case "sub": return sub(arr, value, xs, xe);
152
+ case "mult": return mult(arr, value, xs, xe);
153
+ case "div": return div(arr, value, xs, xe);
154
+ case "pow": return pow(arr, value, xs, xe);
155
+ case "rem": return rem(arr, value, xs, xe);
156
+ case "mod": return mod(arr, value, xs, xe);
157
+ case "and": return band(arr, value, xs, xe);
158
+ case "or": return bor(arr, value, xs, xe);
159
+ case "xor": return bxor(arr, value, xs, xe);
160
+ case "<<": return blsh(arr, value, xs, xe);
161
+ case ">>": return brsh(arr, value, xs, xe);
162
+ case ">>>": return bursh(arr, value, xs, xe);
163
+ }
164
+ };
165
+ /// UNARY OPERATIONS
166
+ /** mutate array in-place to get **absolute** value of elements.
167
+ *
168
+ * @category unaryOperator
169
+ * @category inplace
170
+ */
171
+ export const abs = (arr, start = 0, end) => {
172
+ [start, end] = resolveRange(start, end, arr.length);
173
+ for (let i = start; i < end; i++) {
174
+ arr[i] *= arr[i] < 0 ? -1 : 1;
175
+ }
176
+ return arr;
177
+ };
178
+ /** mutate array in-place to get **negative** value of elements.
179
+ *
180
+ * @category unaryOperator
181
+ * @category inplace
182
+ */
183
+ export const neg = (arr, start = 0, end) => {
184
+ [start, end] = resolveRange(start, end, arr.length);
185
+ for (let i = start; i < end; i++) {
186
+ arr[i] *= -1;
187
+ }
188
+ return arr;
189
+ };
190
+ /** mutate array in-place to get **bitwise complement** value of elements.
191
+ *
192
+ * @category unaryOperator
193
+ * @category inplace
194
+ */
195
+ export const bcomp = (arr, start, end) => {
196
+ [start, end] = resolveRange(start, end, arr.length);
197
+ for (let i = start; i < end; i++) {
198
+ arr[i] = ~arr[i];
199
+ }
200
+ return arr;
201
+ };
202
+ /// SCALAR OPERATIONS
203
+ /// TODO consider replacing some functions entirely with a linear function `y = ax + b`.
204
+ /** mutate array in-place to get **bitwise and** against a scalar `value`.
205
+ *
206
+ * @category scalarOperator
207
+ * @category inplace
208
+ */
209
+ export const band = (arr, value, start, end) => {
210
+ [start, end] = resolveRange(start, end, arr.length);
211
+ for (let i = start; i < end; i++) {
212
+ arr[i] &= value;
213
+ }
214
+ return arr;
215
+ };
216
+ /** mutate array in-place to get **bitwise or** against a scalar `value`.
217
+ *
218
+ * @category scalarOperator
219
+ * @category inplace
220
+ */
221
+ export const bor = (arr, value, start, end) => {
222
+ [start, end] = resolveRange(start, end, arr.length);
223
+ for (let i = start; i < end; i++) {
224
+ arr[i] |= value;
225
+ }
226
+ return arr;
227
+ };
228
+ /** mutate array in-place to get **bitwise xor** against a scalar `value`.
229
+ *
230
+ * @category scalarOperator
231
+ * @category inplace
232
+ */
233
+ export const bxor = (arr, value, start, end) => {
234
+ [start, end] = resolveRange(start, end, arr.length);
235
+ for (let i = start; i < end; i++) {
236
+ arr[i] ^= value;
237
+ }
238
+ return arr;
239
+ };
240
+ /** mutate array in-place to get **bitwise left-shift** (`<<`) against a scalar `value`.
241
+ *
242
+ * @category scalarOperator
243
+ * @category inplace
244
+ */
245
+ export const blsh = (arr, value, start, end) => {
246
+ [start, end] = resolveRange(start, end, arr.length);
247
+ for (let i = start; i < end; i++) {
248
+ arr[i] <<= value;
249
+ }
250
+ return arr;
251
+ };
252
+ /** mutate array in-place to get **bitwise right-shift** (`>>`) against a scalar `value`.
253
+ *
254
+ * @category scalarOperator
255
+ * @category inplace
256
+ */
257
+ export const brsh = (arr, value, start, end) => {
258
+ [start, end] = resolveRange(start, end, arr.length);
259
+ for (let i = start; i < end; i++) {
260
+ arr[i] >>= value;
261
+ }
262
+ return arr;
263
+ };
264
+ /** mutate array in-place to get **bitwise unsigned right-shift** (`>>>`) against a scalar `value`.
265
+ *
266
+ * @category scalarOperator
267
+ * @category inplace
268
+ */
269
+ export const bursh = (arr, value, start, end) => {
270
+ [start, end] = resolveRange(start, end, arr.length);
271
+ for (let i = start; i < end; i++) {
272
+ arr[i] >>>= value;
273
+ }
274
+ return arr;
275
+ };
276
+ /** mutate array in-place to **add** a scalar `value`.
277
+ *
278
+ * @category scalarOperator
279
+ * @category inplace
280
+ */
281
+ export const add = (arr, value, start, end) => {
282
+ [start, end] = resolveRange(start, end, arr.length);
283
+ for (let i = start; i < end; i++) {
284
+ arr[i] += value;
285
+ }
286
+ return arr;
287
+ };
288
+ /** mutate array in-place to **subtract** a scalar `value`.
289
+ *
290
+ * @category scalarOperator
291
+ * @category inplace
292
+ */
293
+ export const sub = (arr, value, start, end) => {
294
+ [start, end] = resolveRange(start, end, arr.length);
295
+ for (let i = start; i < end; i++) {
296
+ arr[i] -= value;
297
+ }
298
+ return arr;
299
+ };
300
+ /** mutate array in-place to **multiply** by a scalar `value`.
301
+ *
302
+ * @category scalarOperator
303
+ * @category inplace
304
+ */
305
+ export const mult = (arr, value, start, end) => {
306
+ [start, end] = resolveRange(start, end, arr.length);
307
+ for (let i = start; i < end; i++) {
308
+ arr[i] *= value;
309
+ }
310
+ return arr;
311
+ };
312
+ /** mutate array in-place to **divide** by a scalar `value`.
313
+ *
314
+ * @category scalarOperator
315
+ * @category inplace
316
+ */
317
+ export const div = (arr, value, start, end) => {
318
+ [start, end] = resolveRange(start, end, arr.length);
319
+ for (let i = start; i < end; i++) {
320
+ arr[i] /= value;
321
+ }
322
+ return arr;
323
+ };
324
+ /** mutate array in-place to raise it to the **power** of a scalar `value`.
325
+ *
326
+ * @category scalarOperator
327
+ * @category inplace
328
+ */
329
+ export const pow = (arr, value, start, end) => {
330
+ [start, end] = resolveRange(start, end, arr.length);
331
+ for (let i = start; i < end; i++) {
332
+ arr[i] **= value;
333
+ }
334
+ return arr;
335
+ };
336
+ /** mutate array in-place to get the **remainder** (`%`) when divided by scalar `value`.
337
+ *
338
+ * note that this is slightly different from the modulo {@link mod} operator, as this can have a negative sign.
339
+ *
340
+ * @category scalarOperator
341
+ * @category inplace
342
+ */
343
+ export const rem = (arr, value, start, end) => {
344
+ [start, end] = resolveRange(start, end, arr.length);
345
+ for (let i = start; i < end; i++) {
346
+ arr[i] %= value;
347
+ }
348
+ return arr;
349
+ };
350
+ /** mutate array in-place to get the **modulo** when divided by scalar `value`.
351
+ *
352
+ * note that this is slightly different from the remainder {@link rem} operator, as this always returns a positive number.
353
+ *
354
+ * @category scalarOperator
355
+ * @category inplace
356
+ */
357
+ export const mod = (arr, value, start, end) => {
358
+ [start, end] = resolveRange(start, end, arr.length);
359
+ for (let i = start; i < end; i++) {
360
+ arr[i] = ((arr[i] % value) + value) % value;
361
+ }
362
+ return arr;
363
+ };
@@ -0,0 +1,233 @@
1
+ /** utility functions for common number manipulation functions.
2
+ *
3
+ * these functions go nicely with the {@link "mapper"} and {@link "lambdacalc"} submodules.
4
+ *
5
+ * @module
6
+ */
7
+ import type { UnitInterval } from "./typedefs.js";
8
+ /** clamp a `number` to inclusive `min` and `max` intervals.
9
+ *
10
+ * you can also provide a type alias for the output interval `OutInterval` number through the use of the generic parameter.
11
+ *
12
+ * @param value value to clamp
13
+ * @param min inclusive minimum of the interval
14
+ * @param max inclusive maximum of the interval
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * import { assertEquals } from "jsr:@std/assert"
19
+ *
20
+ * assertEquals(clamp(-5, -1, 10), -1)
21
+ * assertEquals(clamp(5, -1, 10), 5)
22
+ * assertEquals(clamp(15, -1, 10), 10)
23
+ * ```
24
+ */
25
+ export declare const clamp: <OutInterval extends number = number>(value: number, min?: OutInterval, max?: OutInterval) => OutInterval;
26
+ /** get the mathematical modulo: `value` **mod** `mod`.
27
+ *
28
+ * **modulo** is different from javascript's `%` **remainder** operator in that the **modulo** operation always returns a positive number.
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * import { assertEquals } from "jsr:@std/assert"
33
+ *
34
+ * assertEquals(modulo( 5, 3), 2)
35
+ * assertEquals(modulo(-5, 3), 1)
36
+ * assertEquals(modulo(-4, 3), 2)
37
+ * assertEquals(modulo(-3, 3), 0)
38
+ * assertEquals( 5 % 3, 2)
39
+ * assertEquals(-5 % 3, -2)
40
+ * assertEquals(-4 % 3, -1)
41
+ * assertEquals(-3 % 3, -0)
42
+ * ```
43
+ */
44
+ export declare const modulo: (value: number, mod: number) => number;
45
+ /** get the linearly interpolated value between two scalar points `x0` and `x1`, decided by unit interval time `t`.
46
+ *
47
+ * in other words:
48
+ * - `lerp(x0, x1, 0.0) === x0`
49
+ * - `lerp(x0, x1, 1.0) === x1`
50
+ * - `x0 < lerp(x0, x1, t > 0.0 && t < 1.0) < x1`
51
+ *
52
+ * > [!note]
53
+ * > this lerp function does not clamp the time parameter `t` to the closed {@link UnitInterval} `[0.0, 1.0]`.
54
+ * > to ensure clamping of `t` to the unit interval, use the {@link lerpClamped} function.
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * import { assertEquals } from "jsr:@std/assert"
59
+ *
60
+ * assertEquals(lerp( 0, 100, 0.5), 50)
61
+ * assertEquals(lerp(50, 100, 0.5), 75)
62
+ * assertEquals(lerp(50, 100, 0.0), 50)
63
+ * assertEquals(lerp(50, 100, 1.0), 100)
64
+ * assertEquals(lerp(50, 100, 1.5), 125)
65
+ * assertEquals(lerp(50, 100, -0.5), 25)
66
+ * assertEquals(lerp(50, 100, -1.0), 0)
67
+ * assertEquals(lerp(50, 100, -2.5), -75)
68
+ * ```
69
+ */
70
+ export declare const lerp: (x0: number, x1: number, t: UnitInterval) => number;
71
+ /** same as {@link lerp}, except the time `t` is Clamped to the closed {@link UnitInterval} `[0.0, 1.0]`. */
72
+ export declare const lerpClamped: (x0: number, x1: number, t: UnitInterval) => number;
73
+ /** get the {@link lerp} interpolation of the `i`th dimension of two array vector points `v0` and `v1`, at time `t`.
74
+ *
75
+ * @example
76
+ * ```ts
77
+ * import { assertEquals } from "jsr:@std/assert"
78
+ *
79
+ * assertEquals(lerpi([ 0, 40], [100, 80], 0.5, 0), 50)
80
+ * assertEquals(lerpi([ 0, 40], [100, 80], 0.5, 1), 60)
81
+ * assertEquals(lerpi([50, 40], [100, 80], 0.5, 0), 75)
82
+ * assertEquals(lerpi([50, 40], [100, 80], 0.0, 0), 50)
83
+ * assertEquals(lerpi([50, 40], [100, 80], 1.0, 0), 100)
84
+ * assertEquals(lerpi([50, 40], [100, 80], 1.5, 0), 125)
85
+ * assertEquals(lerpi([50, 40], [100, 80], -0.5, 0), 25)
86
+ * assertEquals(lerpi([50, 40], [100, 80], -1.0, 0), 0)
87
+ * assertEquals(lerpi([50, 40], [100, 80], -2.5, 0), -75)
88
+ * ```
89
+ */
90
+ export declare const lerpi: <Vec extends number[] = number[]>(v0: Vec, v1: Vec, t: UnitInterval, i: number) => number;
91
+ /** get the {@link lerpClamped} interpolation of the `i`th dimension of two array vector points `v0` and `v1`, at time `t`. */
92
+ export declare const lerpiClamped: <Vec extends number[] = number[]>(v0: Vec, v1: Vec, t: UnitInterval, i: number) => number;
93
+ /** get the {@link lerp} interpolation vector between two array vector points `v0` and `v1`, at time `t`.
94
+ *
95
+ * @example
96
+ * ```ts
97
+ * import { assertEquals } from "jsr:@std/assert"
98
+ *
99
+ * assertEquals(lerpv([ 0, 40], [100, 80], 0.5), [ 50, 60])
100
+ * assertEquals(lerpv([50, 0], [100, 80], 0.5), [ 75, 40])
101
+ * assertEquals(lerpv([50, 40], [100, 80], 0.0), [ 50, 40])
102
+ * assertEquals(lerpv([50, 40], [100, 80], 1.0), [100, 80])
103
+ * assertEquals(lerpv([50, 40], [100, 80], 1.5), [125, 100])
104
+ * assertEquals(lerpv([50, 40], [100, 80], -0.5), [ 25, 20])
105
+ * assertEquals(lerpv([50, 40], [100, 80], -1.0), [ 0, 0])
106
+ * assertEquals(lerpv([50, 40], [100, 80], -2.5), [-75, -60])
107
+ * assertEquals(lerpv(
108
+ * [ 0, 10, 100, 1000],
109
+ * [1000, 100, 10, 0],
110
+ * 0.25,
111
+ * ), [250, 32.5, 77.5, 750])
112
+ * ```
113
+ */
114
+ export declare const lerpv: <Vec extends number[] = number[]>(v0: Vec, v1: Vec, t: UnitInterval) => Vec;
115
+ /** get the {@link lerpClamped} interpolation vector between two array vector points `v0` and `v1`, at time `t`. */
116
+ export declare const lerpvClamped: <Vec extends number[] = number[]>(v0: Vec, v1: Vec, t: UnitInterval) => Vec;
117
+ /** get the inverse of the interpolation {@link lerp}`(x0, x1, t)`, which is to say:
118
+ * find the {@link UnitInterval} parameter `t`, given a scalar number `x` in the closed interval `[x0, x1]`.
119
+ *
120
+ * @example
121
+ * ```ts
122
+ * import { assertEquals } from "jsr:@std/assert"
123
+ *
124
+ * assertEquals(invlerp( 0, 100, 50), 0.5)
125
+ * assertEquals(invlerp(50, 100, 75), 0.5)
126
+ * assertEquals(invlerp(50, 100, 50), 0.0)
127
+ * assertEquals(invlerp(50, 100, 100), 1.0)
128
+ * assertEquals(invlerp(50, 100, 125), 1.5)
129
+ * assertEquals(invlerp(50, 100, 25), -0.5)
130
+ * assertEquals(invlerp(50, 100, 0), -1.0)
131
+ * assertEquals(invlerp(50, 100, -75), -2.5)
132
+ * ```
133
+ */
134
+ export declare const invlerp: (x0: number, x1: number, x: number) => UnitInterval;
135
+ /** same as {@link invlerp}, except that we force clamp the output {@link UnitInterval} `t` to the closed interval `[0, 1]`. */
136
+ export declare const invlerpClamped: (x0: number, x1: number, x: number) => UnitInterval;
137
+ /** get the {@link invlerp} (inverse interpolation) of the `i`th dimension of two vector point intervals `v0` and `v1`, at vector position `v`. */
138
+ export declare const invlerpi: <Vec extends number[] = number[]>(v0: Vec, v1: Vec, v: Vec, i: number) => UnitInterval;
139
+ /** get the {@link invlerpClamped} of the `i`th dimension of two array vector point intervals `v0` and `v1`, at vector position `v`. */
140
+ export declare const invlerpiClamped: <Vec extends number[] = number[]>(v0: Vec, v1: Vec, v: Vec, i: number) => UnitInterval;
141
+ /** `limp` is a made up abbreviation for _linear interval map_, which linearly maps:
142
+ * - a scalar value `x0`, that's in a
143
+ * - scalar interval `u0: [min: number, max: number]` to
144
+ * - a scalar output return value `x1`, that's in the
145
+ * - scalar interval `u1: [min: number, max: number]`
146
+ *
147
+ * the math equation is simply `x1 = u1[0] + (x - u0[0]) * (u1[1] - u1[0]) / (u0[1] - u0[0])`.
148
+ * which is basically doing inverse_lerp on `x0` to find `t`, then applying lerp onto interval `u1` with the found `t`.
149
+ *
150
+ * you may think of this function as a means for finding the "y-coordinate" (`x1`) of a point at the "x-coordinate" `x0`,
151
+ * that is between two connected line segment points `(u0[0], u1[0])` and `(u0[1], u1[1])`.
152
+ */
153
+ export declare const limp: (u0: [min: number, max: number], u1: [min: number, max: number], x0: number) => number;
154
+ /** same as {@link limp}, except the output `x1` is force clamped to the interval `u1`. */
155
+ export declare const limpClamped: (u0: [min: number, max: number], u1: [min: number, max: number], x0: number) => number;
156
+ /** sum up an array of numbers.
157
+ *
158
+ * @example
159
+ * ```ts
160
+ * import { assertEquals } from "jsr:@std/assert"
161
+ *
162
+ * assertEquals(sum([0, 1, 2, 3, 4]), 10)
163
+ * assertEquals(sum([-11, 7, 5, -8]), -7)
164
+ * ```
165
+ */
166
+ export declare const sum: (values: number[]) => number;
167
+ /** get the minimum between two numbers.
168
+ *
169
+ * this function is faster than `Math.min` as it uses the ternary conditional operator, which makes it highly JIT optimized.
170
+ */
171
+ export declare const min: (v0: number, v1: number) => number;
172
+ /** get the maximum between two numbers.
173
+ *
174
+ * this function is faster than `Math.max` as it uses the ternary conditional operator, which makes it highly JIT optimized.
175
+ */
176
+ export declare const max: (v0: number, v1: number) => number;
177
+ /** get the sign of a number. you'll get a `1` for positive numbers (or zero), and `-1` otherwise.
178
+ *
179
+ * this function is faster than `Math.sign` as it uses the ternary conditional operator, which makes it highly JIT optimized.
180
+ */
181
+ export declare const sign: (value: number) => (1 | -1);
182
+ /** get the absolute positive value of a number.
183
+ *
184
+ * this function is faster than `Math.abs` as it uses the ternary conditional operator, which makes it highly JIT optimized.
185
+ *
186
+ * the reason why we don't call this function `abs` is because one such function already exists in the numericarray submodule ({@link abs}).
187
+ */
188
+ export declare const absolute: (value: number) => number;
189
+ /** round a float number to a certain precision, so that floating floating-point arithmetic inaccuracies can be nullified.
190
+ *
191
+ * the way it works is by multiplying the initial `value` by a large number, so that it is at least a whole number,
192
+ * and then we round it to the closest integer value with `Math.round`,
193
+ * and finally we follow it up with a division by the very same old large number.
194
+ *
195
+ * @param value the floating number to round.
196
+ * @param precision an integer dictating the number of decimal points to which the `value` should be rounded to.
197
+ * you may use negative integer for rounding to `10s`, `100s`, etc..., or use a value of `0` for rounding to nearest integer.
198
+ * also, you would want to the `precision` to be less than the number of decimal digits representable by your js-runtime's floating-point.
199
+ * so for 64-bit runtime (double), the max precision limit is `15`, and for a 32-bit runtime (single), the limit is `7`.
200
+ * picking a precision that is higher than your runtime's limit will result in even worse value rounding than your original `value`.
201
+ * defaults to `9` (i.e. rounds to closest nano-number (10**(-9))).
202
+ * @returns the float number rounded to the given precision.
203
+ *
204
+ * @examples
205
+ * ```ts
206
+ * import { assert } from "jsr:@std/assert"
207
+ *
208
+ * // aliasing our function for brevity
209
+ * const fn = roundFloat
210
+ *
211
+ * // notice that due to floating inaccuracy `0.2 + 0.4` equals to `0.6000000000000001` instead of `0.6`
212
+ * assert((0.2 + 0.4) !== 0.6)
213
+ * assert((0.2 + 0.4) === 0.6000000000000001)
214
+ *
215
+ * // so, it is often desirable to round the resulting number to some precision to negate this slight deviation.
216
+ * assert(fn(0.2 + 0.4) === 0.6)
217
+ *
218
+ * // you can also provide a custom precision with the second parameter
219
+ * assert(fn(123.456789, 2) === 123.46) // rounding to 2 decimal places
220
+ * assert(fn(123.456789, 1) === 123.5) // rounding to 1 decimal places
221
+ * assert(fn(123.456789, 0) === 123) // rounding to 0 decimal places (i.e. closest integer)
222
+ * assert(fn(123.456789, -1) === 120) // rounding to -1 decimal places (i.e. closest 10s)
223
+ * assert(fn(123.456789, -2) === 100) // rounding to -2 decimal places (i.e. closest 100s)
224
+ *
225
+ * // other examples:
226
+ * assert( (0.2 - 0.7) === -0.49999999999999994)
227
+ * assert(fn(0.2 - 0.7) === -0.5)
228
+ * assert( (0.2 * 3.0) === 0.6000000000000001)
229
+ * assert(fn(0.2 * 3.0) === 0.6)
230
+ * ```
231
+ */
232
+ export declare const roundFloat: (value: number, precision?: number) => number;
233
+ //# sourceMappingURL=numericmethods.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"numericmethods.d.ts","sourceRoot":"","sources":["../../../../../../../src/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/numericmethods.ts"],"names":[],"mappings":"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"}