@thi.ng/api 8.0.6 → 8.3.1
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/CHANGELOG.md +324 -227
- package/README.md +1 -1
- package/grid.d.ts +351 -0
- package/grid.js +1 -0
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/mixin.d.ts +2 -2
- package/mixin.js +3 -3
- package/mixins/igrid.d.ts +17 -0
- package/mixins/igrid.js +163 -0
- package/mixins/inotify.js +1 -1
- package/package.json +225 -214
- package/typedarray.d.ts +4 -0
- package/typedarray.js +4 -0
package/README.md
CHANGED
package/grid.d.ts
ADDED
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
import type { NumericArray, TypedArray } from "./typedarray.js";
|
|
2
|
+
export interface INDBase<BUF extends any[] | TypedArray = any[]> {
|
|
3
|
+
size: NumericArray;
|
|
4
|
+
stride: NumericArray;
|
|
5
|
+
offset: number;
|
|
6
|
+
data: BUF;
|
|
7
|
+
readonly dim: number;
|
|
8
|
+
order(): number[];
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Semi-typechecked interface for cases accepting 1D-4D grids, i.e.
|
|
12
|
+
* {@link IGrid1D} - {@link IGrid4D}.
|
|
13
|
+
*/
|
|
14
|
+
export interface IGridND<BUF extends any[] | TypedArray = any[], T = any> extends INDBase<BUF> {
|
|
15
|
+
/**
|
|
16
|
+
* Returns true if given position is valid (i.e. within grid bounds).
|
|
17
|
+
*
|
|
18
|
+
* @param pos -
|
|
19
|
+
*/
|
|
20
|
+
includes(...pos: [number] | [number, number] | [number, number, number] | [number, number, number, number]): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Returns index for given position. Returns negative value if outside the
|
|
23
|
+
* grid's defined region.
|
|
24
|
+
*
|
|
25
|
+
* @param pos -
|
|
26
|
+
*/
|
|
27
|
+
indexAt(...pos: [number] | [number, number] | [number, number, number] | [number, number, number, number]): number;
|
|
28
|
+
/**
|
|
29
|
+
* Non-boundschecked version of {@link IGridND.indexAt}. Assumes given
|
|
30
|
+
* position is valid.
|
|
31
|
+
*
|
|
32
|
+
* @param pos -
|
|
33
|
+
*/
|
|
34
|
+
indexAtUnsafe(...pos: [number] | [number, number] | [number, number, number] | [number, number, number, number]): number;
|
|
35
|
+
/**
|
|
36
|
+
* Returns value at given position. If outside the grid's defined region,
|
|
37
|
+
* returns a suitable zero value.
|
|
38
|
+
*
|
|
39
|
+
* @param pos -
|
|
40
|
+
*/
|
|
41
|
+
getAt(...pos: [number] | [number, number] | [number, number, number] | [number, number, number, number]): T;
|
|
42
|
+
/**
|
|
43
|
+
* Non-boundschecked version of {@link IGridND.getAt}. Assumes given
|
|
44
|
+
* position is valid.
|
|
45
|
+
*
|
|
46
|
+
* @param pos -
|
|
47
|
+
*/
|
|
48
|
+
getAtUnsafe(...pos: [number] | [number, number] | [number, number, number] | [number, number, number, number]): T;
|
|
49
|
+
/**
|
|
50
|
+
* Writes value at given position. Has no effect if outside of the defined
|
|
51
|
+
* region. Returns true, if succeeded.
|
|
52
|
+
*
|
|
53
|
+
* @param args -
|
|
54
|
+
*/
|
|
55
|
+
setAt(...args: [number, T] | [number, number, T] | [number, number, number, T] | [number, number, number, number, T]): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Non-boundschecked version of {@link IGridND.setAt}. Assumes given
|
|
58
|
+
* position is valid. Returns true, if succeeded.
|
|
59
|
+
*
|
|
60
|
+
* @param args -
|
|
61
|
+
*/
|
|
62
|
+
setAtUnsafe(...args: [number, T] | [number, number, T] | [number, number, number, T] | [number, number, number, number, T]): boolean;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Gridlike container for 1D accessible data.
|
|
66
|
+
*
|
|
67
|
+
* @remarks
|
|
68
|
+
* See {@link IGrid1DMixin} for mixin implementation.
|
|
69
|
+
*/
|
|
70
|
+
export interface IGrid1D<BUF extends any[] | TypedArray = any[], T = any> extends INDBase<BUF> {
|
|
71
|
+
readonly dim: 1;
|
|
72
|
+
/**
|
|
73
|
+
* Returns true if given position is valid (i.e. within grid bounds).
|
|
74
|
+
*
|
|
75
|
+
* @param d0 -
|
|
76
|
+
*/
|
|
77
|
+
includes(d0: number): boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Returns index for given position. Returns negative value if outside the
|
|
80
|
+
* grid's defined region.
|
|
81
|
+
*
|
|
82
|
+
* @param d0 -
|
|
83
|
+
*/
|
|
84
|
+
indexAt(d0: number): number;
|
|
85
|
+
/**
|
|
86
|
+
* Non-boundschecked version of {@link IGrid1D.indexAt}. Assumes given
|
|
87
|
+
* position is valid.
|
|
88
|
+
*
|
|
89
|
+
* @param d0 -
|
|
90
|
+
*/
|
|
91
|
+
indexAtUnsafe(d0: number): number;
|
|
92
|
+
/**
|
|
93
|
+
* Returns value at given position. If outside the grid's defined region,
|
|
94
|
+
* returns a suitable zero value.
|
|
95
|
+
*
|
|
96
|
+
* @param d0 -
|
|
97
|
+
*/
|
|
98
|
+
getAt(d0: number): T;
|
|
99
|
+
/**
|
|
100
|
+
* Non-boundschecked version of {@link IGrid1D.getAt}. Assumes given
|
|
101
|
+
* position is valid.
|
|
102
|
+
*
|
|
103
|
+
* @param d0 -
|
|
104
|
+
*/
|
|
105
|
+
getAtUnsafe(d0: number): T;
|
|
106
|
+
/**
|
|
107
|
+
* Writes value at given position. Has no effect if outside of the defined
|
|
108
|
+
* region. Returns true, if succeeded.
|
|
109
|
+
*
|
|
110
|
+
* @param d0 -
|
|
111
|
+
* @param value -
|
|
112
|
+
*/
|
|
113
|
+
setAt(d0: number, value: T): boolean;
|
|
114
|
+
/**
|
|
115
|
+
* Non-boundschecked version of {@link IGrid1D.setAt}. Assumes given
|
|
116
|
+
* position is valid. Returns true, if succeeded.
|
|
117
|
+
*
|
|
118
|
+
* @param d0 -
|
|
119
|
+
* @param value -
|
|
120
|
+
*/
|
|
121
|
+
setAtUnsafe(d0: number, value: T): boolean;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Gridlike container for 2D accessible data.
|
|
125
|
+
*
|
|
126
|
+
* @remarks
|
|
127
|
+
* See {@link IGrid2DMixin} for mixin implementation.
|
|
128
|
+
*/
|
|
129
|
+
export interface IGrid2D<BUF extends any[] | TypedArray = any[], T = any> extends INDBase<BUF> {
|
|
130
|
+
readonly dim: 2;
|
|
131
|
+
/**
|
|
132
|
+
* Returns true if given position is valid (i.e. within grid bounds).
|
|
133
|
+
*
|
|
134
|
+
* @param d0 -
|
|
135
|
+
* @param d1 -
|
|
136
|
+
*/
|
|
137
|
+
includes(d0: number, d1: number): boolean;
|
|
138
|
+
/**
|
|
139
|
+
* Returns index for given position (stated in same order as
|
|
140
|
+
* {@link IGrid2D.size} and {@link IGrid2D.stride}). Returns negative value
|
|
141
|
+
* if outside the grid's defined region.
|
|
142
|
+
*
|
|
143
|
+
* @param d0 -
|
|
144
|
+
* @param d1 -
|
|
145
|
+
*/
|
|
146
|
+
indexAt(d0: number, d1: number): number;
|
|
147
|
+
/**
|
|
148
|
+
* Non-boundschecked version of {@link IGrid2D.indexAt}. Assumes given
|
|
149
|
+
* position is valid.
|
|
150
|
+
*
|
|
151
|
+
* @param d0 -
|
|
152
|
+
* @param d1 -
|
|
153
|
+
*/
|
|
154
|
+
indexAtUnsafe(d0: number, d1: number): number;
|
|
155
|
+
/**
|
|
156
|
+
* Returns value at given position (given in same order as
|
|
157
|
+
* {@link IGrid2D.size} and {@link IGrid2D.stride}). If outside the grid's
|
|
158
|
+
* defined region, returns a suitable zero value.
|
|
159
|
+
*
|
|
160
|
+
* @param d0 -
|
|
161
|
+
* @param d1 -
|
|
162
|
+
*/
|
|
163
|
+
getAt(d0: number, d1: number): T;
|
|
164
|
+
/**
|
|
165
|
+
* Non-boundschecked version of {@link IGrid2D.getAt}. Assumes given
|
|
166
|
+
* position is valid.
|
|
167
|
+
*
|
|
168
|
+
* @param d0 -
|
|
169
|
+
* @param d1 -
|
|
170
|
+
*/
|
|
171
|
+
getAtUnsafe(d0: number, d1: number): T;
|
|
172
|
+
/**
|
|
173
|
+
* Writes value at given position (given in same order as
|
|
174
|
+
* {@link IGrid2D.size} and {@link IGrid2D.stride}). Has no effect if
|
|
175
|
+
* outside of the defined region. Returns true, if succeeded.
|
|
176
|
+
*
|
|
177
|
+
* @param d0 -
|
|
178
|
+
* @param d1 -
|
|
179
|
+
* @param value -
|
|
180
|
+
*/
|
|
181
|
+
setAt(d0: number, d1: number, value: T): boolean;
|
|
182
|
+
/**
|
|
183
|
+
* Non-boundschecked version of {@link IGrid2D.setAt}. Assumes given
|
|
184
|
+
* position is valid. Returns true, if succeeded.
|
|
185
|
+
*
|
|
186
|
+
* @param d0 -
|
|
187
|
+
* @param d1 -
|
|
188
|
+
* @param value -
|
|
189
|
+
*/
|
|
190
|
+
setAtUnsafe(d0: number, d1: number, value: T): boolean;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Gridlike container for 3D accessible data.
|
|
194
|
+
*
|
|
195
|
+
* @remarks
|
|
196
|
+
* See {@link IGrid3DMixin} for mixin implementation.
|
|
197
|
+
*/
|
|
198
|
+
export interface IGrid3D<BUF extends any[] | TypedArray = any[], T = any> extends INDBase<BUF> {
|
|
199
|
+
readonly dim: 3;
|
|
200
|
+
/**
|
|
201
|
+
* Returns true if given position is valid (i.e. within grid bounds).
|
|
202
|
+
*
|
|
203
|
+
* @param d0 -
|
|
204
|
+
* @param d1 -
|
|
205
|
+
* @param d2 -
|
|
206
|
+
*/
|
|
207
|
+
includes(d0: number, d1: number, d2: number): boolean;
|
|
208
|
+
/**
|
|
209
|
+
* Returns index for given position (stated in same order as
|
|
210
|
+
* {@link IGrid3D.size} and {@link IGrid3D.stride}). Returns negative value
|
|
211
|
+
* if outside the grid's defined region.
|
|
212
|
+
*
|
|
213
|
+
* @param d0 -
|
|
214
|
+
* @param d1 -
|
|
215
|
+
* @param d2 -
|
|
216
|
+
*/
|
|
217
|
+
indexAt(d0: number, d1: number, d2: number): number;
|
|
218
|
+
/**
|
|
219
|
+
* Non-boundschecked version of {@link IGrid3D.indexAt}. Assumes given
|
|
220
|
+
* position is valid.
|
|
221
|
+
*
|
|
222
|
+
* @param d0 -
|
|
223
|
+
* @param d1 -
|
|
224
|
+
* @param d2 -
|
|
225
|
+
*/
|
|
226
|
+
indexAtUnsafe(d0: number, d1: number, d2: number): number;
|
|
227
|
+
/**
|
|
228
|
+
* Returns value at given position (given in same order as
|
|
229
|
+
* {@link IGrid3D.size} and {@link IGrid3D.stride}). If outside the grid's
|
|
230
|
+
* defined region, returns a suitable zero value.
|
|
231
|
+
*
|
|
232
|
+
* @param d0 -
|
|
233
|
+
* @param d1 -
|
|
234
|
+
* @param d2 -
|
|
235
|
+
*/
|
|
236
|
+
getAt(d0: number, d1: number, d2: number): T;
|
|
237
|
+
/**
|
|
238
|
+
* Non-boundschecked version of {@link IGrid3D.getAt}. Assumes given
|
|
239
|
+
* position is valid.
|
|
240
|
+
*
|
|
241
|
+
* @param d0 -
|
|
242
|
+
* @param d1 -
|
|
243
|
+
* @param d2 -
|
|
244
|
+
*/
|
|
245
|
+
getAtUnsafe(d0: number, d1: number, d2: number): T;
|
|
246
|
+
/**
|
|
247
|
+
* Writes value at given position (given in same order as
|
|
248
|
+
* {@link IGrid3D.size} and {@link IGrid3D.stride}). Has no effect if
|
|
249
|
+
* outside of the defined region. Returns true, if succeeded.
|
|
250
|
+
*
|
|
251
|
+
* @param d0 -
|
|
252
|
+
* @param d1 -
|
|
253
|
+
* @param d2 -
|
|
254
|
+
* @param value -
|
|
255
|
+
*/
|
|
256
|
+
setAt(d0: number, d1: number, d2: number, value: T): boolean;
|
|
257
|
+
/**
|
|
258
|
+
* Non-boundschecked version of {@link IGrid3D.setAt}. Assumes given
|
|
259
|
+
* position is valid. Returns true, if succeeded.
|
|
260
|
+
*
|
|
261
|
+
* @param d0 -
|
|
262
|
+
* @param d1 -
|
|
263
|
+
* @param d2 -
|
|
264
|
+
* @param value -
|
|
265
|
+
*/
|
|
266
|
+
setAtUnsafe(d0: number, d1: number, d2: number, value: T): boolean;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Gridlike container for 4D accessible data.
|
|
270
|
+
*
|
|
271
|
+
* @remarks
|
|
272
|
+
* See {@link IGrid4DMixin} for mixin implementation.
|
|
273
|
+
*/
|
|
274
|
+
export interface IGrid4D<BUF extends any[] | TypedArray = any[], T = any> extends INDBase<BUF> {
|
|
275
|
+
readonly dim: 4;
|
|
276
|
+
/**
|
|
277
|
+
* Returns true if given position is valid (i.e. within grid bounds).
|
|
278
|
+
*
|
|
279
|
+
* @param d0 -
|
|
280
|
+
* @param d1 -
|
|
281
|
+
* @param d2 -
|
|
282
|
+
* @param d3 -
|
|
283
|
+
*/
|
|
284
|
+
includes(d0: number, d1: number, d2: number, d3: number): boolean;
|
|
285
|
+
/**
|
|
286
|
+
* Returns index for given position (stated in same order as
|
|
287
|
+
* {@link IGrid4D.size} and {@link IGrid4D.stride}). Returns negative value
|
|
288
|
+
* if outside the grid's defined region.
|
|
289
|
+
*
|
|
290
|
+
* @param d0 -
|
|
291
|
+
* @param d1 -
|
|
292
|
+
* @param d2 -
|
|
293
|
+
* @param d3 -
|
|
294
|
+
*/
|
|
295
|
+
indexAt(d0: number, d1: number, d2: number, d3: number): number;
|
|
296
|
+
/**
|
|
297
|
+
* Non-boundschecked version of {@link IGrid4D.indexAt}. Assumes given
|
|
298
|
+
* position is valid.
|
|
299
|
+
*
|
|
300
|
+
* @param d0 -
|
|
301
|
+
* @param d1 -
|
|
302
|
+
* @param d2 -
|
|
303
|
+
* @param d3 -
|
|
304
|
+
*/
|
|
305
|
+
indexAtUnsafe(d0: number, d1: number, d2: number, d3: number): number;
|
|
306
|
+
/**
|
|
307
|
+
* Returns value at given position (given in same order as
|
|
308
|
+
* {@link IGrid4D.size} and {@link IGrid4D.stride}). If outside the grid's
|
|
309
|
+
* defined region, returns a suitable zero value.
|
|
310
|
+
*
|
|
311
|
+
* @param d0 -
|
|
312
|
+
* @param d1 -
|
|
313
|
+
* @param d2 -
|
|
314
|
+
* @param d3 -
|
|
315
|
+
*/
|
|
316
|
+
getAt(d0: number, d1: number, d2: number, d3: number): T;
|
|
317
|
+
/**
|
|
318
|
+
* Non-boundschecked version of {@link IGrid4D.getAt}. Assumes given
|
|
319
|
+
* position is valid.
|
|
320
|
+
*
|
|
321
|
+
* @param d0 -
|
|
322
|
+
* @param d1 -
|
|
323
|
+
* @param d2 -
|
|
324
|
+
* @param d3 -
|
|
325
|
+
*/
|
|
326
|
+
getAtUnsafe(d0: number, d1: number, d2: number, d3: number): T;
|
|
327
|
+
/**
|
|
328
|
+
* Writes value at given position (given in same order as
|
|
329
|
+
* {@link IGrid4D.size} and {@link IGrid4D.stride}). Has no effect if
|
|
330
|
+
* outside of the defined region. Returns true, if succeeded.
|
|
331
|
+
*
|
|
332
|
+
* @param d0 -
|
|
333
|
+
* @param d1 -
|
|
334
|
+
* @param d2 -
|
|
335
|
+
* @param d3 -
|
|
336
|
+
* @param value -
|
|
337
|
+
*/
|
|
338
|
+
setAt(d0: number, d1: number, d2: number, d3: number, value: T): boolean;
|
|
339
|
+
/**
|
|
340
|
+
* Non-boundschecked version of {@link IGrid4D.setAt}. Assumes given
|
|
341
|
+
* position is valid. Returns true, if succeeded.
|
|
342
|
+
*
|
|
343
|
+
* @param d0 -
|
|
344
|
+
* @param d1 -
|
|
345
|
+
* @param d2 -
|
|
346
|
+
* @param d3 -
|
|
347
|
+
* @param value -
|
|
348
|
+
*/
|
|
349
|
+
setAtUnsafe(d0: number, d1: number, d2: number, d3: number, value: T): boolean;
|
|
350
|
+
}
|
|
351
|
+
//# sourceMappingURL=grid.d.ts.map
|
package/grid.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export * from "./equiv.js";
|
|
|
13
13
|
export * from "./event.js";
|
|
14
14
|
export * from "./fn.js";
|
|
15
15
|
export * from "./get.js";
|
|
16
|
+
export * from "./grid.js";
|
|
16
17
|
export * from "./hash.js";
|
|
17
18
|
export * from "./hiccup.js";
|
|
18
19
|
export * from "./id.js";
|
|
@@ -43,6 +44,7 @@ export * from "./decorators/deprecated.js";
|
|
|
43
44
|
export * from "./decorators/nomixin.js";
|
|
44
45
|
export * from "./decorators/sealed.js";
|
|
45
46
|
export * from "./mixins/ienable.js";
|
|
47
|
+
export * from "./mixins/igrid.js";
|
|
46
48
|
export * from "./mixins/inotify.js";
|
|
47
49
|
export * from "./mixins/iterable.js";
|
|
48
50
|
export * from "./mixins/iwatch.js";
|
package/index.js
CHANGED
|
@@ -13,6 +13,7 @@ export * from "./equiv.js";
|
|
|
13
13
|
export * from "./event.js";
|
|
14
14
|
export * from "./fn.js";
|
|
15
15
|
export * from "./get.js";
|
|
16
|
+
export * from "./grid.js";
|
|
16
17
|
export * from "./hash.js";
|
|
17
18
|
export * from "./hiccup.js";
|
|
18
19
|
export * from "./id.js";
|
|
@@ -43,6 +44,7 @@ export * from "./decorators/deprecated.js";
|
|
|
43
44
|
export * from "./decorators/nomixin.js";
|
|
44
45
|
export * from "./decorators/sealed.js";
|
|
45
46
|
export * from "./mixins/ienable.js";
|
|
47
|
+
export * from "./mixins/igrid.js";
|
|
46
48
|
export * from "./mixins/inotify.js";
|
|
47
49
|
export * from "./mixins/iterable.js";
|
|
48
50
|
export * from "./mixins/iwatch.js";
|
package/mixin.d.ts
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Class behavior mixin based on:
|
|
3
3
|
* {@link http://raganwald.com/2015/06/26/decorators-in-es7.html}
|
|
4
4
|
*
|
|
5
|
-
* Additionally only injects/overwrites properties in target, which are
|
|
6
|
-
*
|
|
5
|
+
* Additionally only injects/overwrites properties in target, which are NOT
|
|
6
|
+
* marked with `@nomixin` (i.e. those which haven't set their `configurable`
|
|
7
7
|
* property descriptor flag to `false`)
|
|
8
8
|
*
|
|
9
9
|
* @param behaviour - to mixin
|
package/mixin.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Class behavior mixin based on:
|
|
3
3
|
* {@link http://raganwald.com/2015/06/26/decorators-in-es7.html}
|
|
4
4
|
*
|
|
5
|
-
* Additionally only injects/overwrites properties in target, which are
|
|
6
|
-
*
|
|
5
|
+
* Additionally only injects/overwrites properties in target, which are NOT
|
|
6
|
+
* marked with `@nomixin` (i.e. those which haven't set their `configurable`
|
|
7
7
|
* property descriptor flag to `false`)
|
|
8
8
|
*
|
|
9
9
|
* @param behaviour - to mixin
|
|
@@ -24,7 +24,7 @@ export const mixin = (behaviour, sharedBehaviour = {}) => {
|
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
26
|
else {
|
|
27
|
-
console.log(`not patching: ${clazz.name}.${key.toString()}`);
|
|
27
|
+
// console.log(`not patching: ${clazz.name}.${key.toString()}`);
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
Object.defineProperty(clazz.prototype, typeTag, { value: true });
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default implementation for {@link IGrid1D} methods.
|
|
3
|
+
*/
|
|
4
|
+
export declare const IGrid1DMixin: (clazz: any) => any;
|
|
5
|
+
/**
|
|
6
|
+
* Default implementation for {@link IGrid2D} methods.
|
|
7
|
+
*/
|
|
8
|
+
export declare const IGrid2DMixin: (clazz: any) => any;
|
|
9
|
+
/**
|
|
10
|
+
* Default implementation for {@link IGrid3D} methods.
|
|
11
|
+
*/
|
|
12
|
+
export declare const IGrid3DMixin: (clazz: any) => any;
|
|
13
|
+
/**
|
|
14
|
+
* Default implementation for {@link IGrid4D} methods.
|
|
15
|
+
*/
|
|
16
|
+
export declare const IGrid4DMixin: (clazz: any) => any;
|
|
17
|
+
//# sourceMappingURL=igrid.d.ts.map
|
package/mixins/igrid.js
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { mixin } from "../mixin.js";
|
|
2
|
+
/**
|
|
3
|
+
* Default implementation for {@link IGrid1D} methods.
|
|
4
|
+
*/
|
|
5
|
+
export const IGrid1DMixin = mixin({
|
|
6
|
+
order() {
|
|
7
|
+
return [0];
|
|
8
|
+
},
|
|
9
|
+
includes(x) {
|
|
10
|
+
return x >= 0 && x < this.size[0];
|
|
11
|
+
},
|
|
12
|
+
indexAt(x) {
|
|
13
|
+
return this.includes(x) ? this.indexAtUnsafe(x) : -1;
|
|
14
|
+
},
|
|
15
|
+
indexAtUnsafe(x) {
|
|
16
|
+
return this.offset + (x | 0) * this.stride[0];
|
|
17
|
+
},
|
|
18
|
+
getAt(x) {
|
|
19
|
+
return this.includes(x) ? this.data[this.indexAtUnsafe(x)] : 0;
|
|
20
|
+
},
|
|
21
|
+
getAtUnsafe(x) {
|
|
22
|
+
return this.data[this.indexAtUnsafe(x)];
|
|
23
|
+
},
|
|
24
|
+
setAt(x, val) {
|
|
25
|
+
return this.includes(x)
|
|
26
|
+
? ((this.data[this.indexAtUnsafe(x)] = val), true)
|
|
27
|
+
: false;
|
|
28
|
+
},
|
|
29
|
+
setAtUnsafe(x, val) {
|
|
30
|
+
this.data[this.indexAtUnsafe(x)] = val;
|
|
31
|
+
return true;
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
/**
|
|
35
|
+
* Default implementation for {@link IGrid2D} methods.
|
|
36
|
+
*/
|
|
37
|
+
export const IGrid2DMixin = mixin({
|
|
38
|
+
order() {
|
|
39
|
+
return Math.abs(this.stride[1]) > Math.abs(this.stride[0])
|
|
40
|
+
? [1, 0]
|
|
41
|
+
: [0, 1];
|
|
42
|
+
},
|
|
43
|
+
includes(x, y) {
|
|
44
|
+
const size = this.size;
|
|
45
|
+
return x >= 0 && x < size[0] && y >= 0 && y < size[1];
|
|
46
|
+
},
|
|
47
|
+
indexAt(x, y) {
|
|
48
|
+
return this.includes(x, y) ? this.indexAtUnsafe(x, y) : -1;
|
|
49
|
+
},
|
|
50
|
+
indexAtUnsafe(x, y) {
|
|
51
|
+
return (this.offset + (x | 0) * this.stride[0] + (y | 0) * this.stride[1]);
|
|
52
|
+
},
|
|
53
|
+
getAt(x, y) {
|
|
54
|
+
return this.includes(x, y) ? this.data[this.indexAtUnsafe(x, y)] : 0;
|
|
55
|
+
},
|
|
56
|
+
getAtUnsafe(x, y) {
|
|
57
|
+
return this.data[this.indexAtUnsafe(x, y)];
|
|
58
|
+
},
|
|
59
|
+
setAt(x, y, val) {
|
|
60
|
+
return this.includes(x, y)
|
|
61
|
+
? ((this.data[this.indexAtUnsafe(x, y)] = val), true)
|
|
62
|
+
: false;
|
|
63
|
+
},
|
|
64
|
+
setAtUnsafe(x, y, val) {
|
|
65
|
+
this.data[this.indexAtUnsafe(x, y)] = val;
|
|
66
|
+
return true;
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
/**
|
|
70
|
+
* Default implementation for {@link IGrid3D} methods.
|
|
71
|
+
*/
|
|
72
|
+
export const IGrid3DMixin = mixin({
|
|
73
|
+
order() {
|
|
74
|
+
return strideOrder(this.stride);
|
|
75
|
+
},
|
|
76
|
+
includes(x, y, z) {
|
|
77
|
+
const size = this.size;
|
|
78
|
+
return (x >= 0 &&
|
|
79
|
+
x < size[0] &&
|
|
80
|
+
y >= 0 &&
|
|
81
|
+
y < size[1] &&
|
|
82
|
+
z >= 0 &&
|
|
83
|
+
z < size[2]);
|
|
84
|
+
},
|
|
85
|
+
indexAt(x, y, z) {
|
|
86
|
+
return this.includes(x, y, z) ? this.indexAtUnsafe(x, y, z) : -1;
|
|
87
|
+
},
|
|
88
|
+
indexAtUnsafe(x, y, z) {
|
|
89
|
+
const stride = this.stride;
|
|
90
|
+
return (this.offset +
|
|
91
|
+
(x | 0) * stride[0] +
|
|
92
|
+
(y | 0) * stride[1] +
|
|
93
|
+
(z | 0) * stride[2]);
|
|
94
|
+
},
|
|
95
|
+
getAt(x, y, z) {
|
|
96
|
+
return this.includes(x, y, z)
|
|
97
|
+
? this.data[this.indexAtUnsafe(x, y, z)]
|
|
98
|
+
: 0;
|
|
99
|
+
},
|
|
100
|
+
getAtUnsafe(x, y, z) {
|
|
101
|
+
return this.data[this.indexAtUnsafe(x, y, z)];
|
|
102
|
+
},
|
|
103
|
+
setAt(x, y, z, val) {
|
|
104
|
+
return this.includes(x, y, z)
|
|
105
|
+
? ((this.data[this.indexAtUnsafe(x, y, z)] = val), true)
|
|
106
|
+
: false;
|
|
107
|
+
},
|
|
108
|
+
setAtUnsafe(x, y, z, val) {
|
|
109
|
+
this.data[this.indexAtUnsafe(x, y, z)] = val;
|
|
110
|
+
return true;
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
/**
|
|
114
|
+
* Default implementation for {@link IGrid4D} methods.
|
|
115
|
+
*/
|
|
116
|
+
export const IGrid4DMixin = mixin({
|
|
117
|
+
order() {
|
|
118
|
+
return strideOrder(this.stride);
|
|
119
|
+
},
|
|
120
|
+
includes(x, y, z, w) {
|
|
121
|
+
const size = this.size;
|
|
122
|
+
return (x >= 0 &&
|
|
123
|
+
x < size[0] &&
|
|
124
|
+
y >= 0 &&
|
|
125
|
+
y < size[1] &&
|
|
126
|
+
z >= 0 &&
|
|
127
|
+
z < size[2] &&
|
|
128
|
+
w >= 0 &&
|
|
129
|
+
w < size[3]);
|
|
130
|
+
},
|
|
131
|
+
indexAt(x, y, z, w) {
|
|
132
|
+
return this.includes(x, y, z, w) ? this.indexAtUnsafe(x, y, z, w) : -1;
|
|
133
|
+
},
|
|
134
|
+
indexAtUnsafe(x, y, z, w) {
|
|
135
|
+
const stride = this.stride;
|
|
136
|
+
return (this.offset +
|
|
137
|
+
(x | 0) * stride[0] +
|
|
138
|
+
(y | 0) * stride[1] +
|
|
139
|
+
(z | 0) * stride[2] +
|
|
140
|
+
(w | 0) * stride[3]);
|
|
141
|
+
},
|
|
142
|
+
getAt(x, y, z, w) {
|
|
143
|
+
return this.includes(x, y, z, w)
|
|
144
|
+
? this.data[this.indexAtUnsafe(x, y, z, w)]
|
|
145
|
+
: 0;
|
|
146
|
+
},
|
|
147
|
+
getAtUnsafe(x, y, z, w) {
|
|
148
|
+
return this.data[this.indexAtUnsafe(x, y, z, w)];
|
|
149
|
+
},
|
|
150
|
+
setAt(x, y, z, w, val) {
|
|
151
|
+
return this.includes(x, y, z, w)
|
|
152
|
+
? ((this.data[this.indexAtUnsafe(x, y, z, w)] = val), true)
|
|
153
|
+
: false;
|
|
154
|
+
},
|
|
155
|
+
setAtUnsafe(x, y, z, w, val) {
|
|
156
|
+
this.data[this.indexAtUnsafe(x, y, z, w)] = val;
|
|
157
|
+
return true;
|
|
158
|
+
},
|
|
159
|
+
});
|
|
160
|
+
const strideOrder = (strides) => [...strides]
|
|
161
|
+
.map((x, i) => [x, i])
|
|
162
|
+
.sort((a, b) => Math.abs(b[0]) - Math.abs(a[0]))
|
|
163
|
+
.map((x) => x[1]);
|
package/mixins/inotify.js
CHANGED