@thi.ng/arrays 2.2.5 → 2.3.2

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2022-06-09T16:14:01Z
3
+ - **Last updated**: 2022-08-01T14:53:59Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
@@ -9,6 +9,12 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
9
9
  **Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
10
10
  and/or version bumps of transitive dependencies.
11
11
 
12
+ ## [2.3.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/arrays@2.3.0) (2022-07-08)
13
+
14
+ #### 🚀 Features
15
+
16
+ - add blit1d/2d() functions ([56e8373](https://github.com/thi-ng/umbrella/commit/56e8373))
17
+
12
18
  ## [2.2.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/arrays@2.2.0) (2022-03-11)
13
19
 
14
20
  #### 🚀 Features
package/README.md CHANGED
@@ -51,7 +51,7 @@ node --experimental-repl-await
51
51
  > const arrays = await import("@thi.ng/arrays");
52
52
  ```
53
53
 
54
- Package sizes (gzipped, pre-treeshake): ESM: 2.30 KB
54
+ Package sizes (gzipped, pre-treeshake): ESM: 2.51 KB
55
55
 
56
56
  ## Dependencies
57
57
 
@@ -70,6 +70,7 @@ Package sizes (gzipped, pre-treeshake): ESM: 2.30 KB
70
70
  - [argSort()](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/arg-sort.ts)
71
71
  - [binarySearch()](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/binary-search.ts)
72
72
  - [bisect()](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/bisect.ts)
73
+ - [blit1d() / blit2d()](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/blit.ts)
73
74
  - [endsWith()](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/ends-with.ts)
74
75
  - [ensureArray()](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/ensure-array.ts)
75
76
  - [ensureIterable()](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/ensure-iterable.ts)
package/blit.d.ts ADDED
@@ -0,0 +1,46 @@
1
+ import type { TypedArray } from "@thi.ng/api";
2
+ /**
3
+ * Selectively copies all non-`mask` values from `src` into `dest` starting from
4
+ * destination position `dx`. Returns `dest`.
5
+ *
6
+ * @remarks
7
+ * Where `src` values are the same as `mask`, the corresponding `dest` values
8
+ * will be left unchanged. Performs region clipping, i.e. `dx` can be outside
9
+ * the [0..dest.length) interval.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * blit1d(
14
+ * // dest array
15
+ * [1, 1, 1, 1, 1, 1, 1, 1, 1],
16
+ * // paste from index 2
17
+ * 2,
18
+ * // source array
19
+ * [2, 3, 2, 3, 2],
20
+ * // mask value
21
+ * 3
22
+ * )
23
+ * //[1, 1, 2, 1, 2, 1, 2, 1, 1]
24
+ * ```
25
+ *
26
+ * @param dest
27
+ * @param src
28
+ * @param dx
29
+ * @param mask
30
+ */
31
+ export declare function blit1d<T extends TypedArray>(dest: T, dx: number, src: ArrayLike<number>, mask: number): T;
32
+ export declare function blit1d<T>(dest: T[], dx: number, src: ArrayLike<T>, mask: T): T[];
33
+ /**
34
+ * 2D version of {@link blit1d} (also with region clipping). Positions and sizes
35
+ * are given as 2D vectors.
36
+ *
37
+ * @param dest
38
+ * @param dpos
39
+ * @param dsize
40
+ * @param src
41
+ * @param ssize
42
+ * @param mask
43
+ */
44
+ export declare function blit2d<T extends TypedArray>(dest: T, dpos: ArrayLike<number>, dsize: ArrayLike<number>, src: ArrayLike<number>, ssize: ArrayLike<number>, mask: number): T;
45
+ export declare function blit2d<T>(dest: T[], dpos: ArrayLike<number>, dsize: ArrayLike<number>, src: ArrayLike<T>, ssize: ArrayLike<number>, mask: T): T[];
46
+ //# sourceMappingURL=blit.d.ts.map
package/blit.js ADDED
@@ -0,0 +1,36 @@
1
+ export function blit1d(dest, x, src, mask) {
2
+ const [sx, sw, dx, dw] = __clip(0, src.length, x, dest.length);
3
+ if (sw < 1 || dx >= dw)
4
+ return dest;
5
+ for (let i = 0; i < sw; i++) {
6
+ const val = src[sx + i];
7
+ val !== mask && (dest[dx + i] = val);
8
+ }
9
+ return dest;
10
+ }
11
+ export function blit2d(dest, dpos, dsize, src, ssize, mask) {
12
+ const [sx, sw, dx, dw] = __clip(0, ssize[0], dpos[0], dsize[0]);
13
+ const [sy, sh, dy, dh] = __clip(0, ssize[1], dpos[1], dsize[1]);
14
+ if (sw < 1 || sh < 1 || dx >= dw || dy >= dh)
15
+ return dest;
16
+ const sstride = ssize[0];
17
+ const dstride = dsize[0];
18
+ for (let y = 0; y < sh; y++) {
19
+ for (let x = 0, soff = (sy + y) * sstride + sx, doff = (dy + y) * dstride + dx; x < sw; x++) {
20
+ const val = src[soff + x];
21
+ val !== mask && (dest[doff + x] = val);
22
+ }
23
+ }
24
+ return dest;
25
+ }
26
+ const __clip = (sx, sw, dx, dw) => {
27
+ if (dx < 0) {
28
+ sx -= dx;
29
+ sw += dx;
30
+ dx = 0;
31
+ }
32
+ else if (dx + sw > dw) {
33
+ sw = dw - dx;
34
+ }
35
+ return [sx, sw, dx, dw];
36
+ };
package/index.d.ts CHANGED
@@ -2,6 +2,7 @@ export * from "./api.js";
2
2
  export * from "./arg-sort.js";
3
3
  export * from "./binary-search.js";
4
4
  export * from "./bisect.js";
5
+ export * from "./blit.js";
5
6
  export * from "./ends-with.js";
6
7
  export * from "./ensure-array.js";
7
8
  export * from "./ensure-iterable.js";
package/index.js CHANGED
@@ -2,6 +2,7 @@ export * from "./api.js";
2
2
  export * from "./arg-sort.js";
3
3
  export * from "./binary-search.js";
4
4
  export * from "./bisect.js";
5
+ export * from "./blit.js";
5
6
  export * from "./ends-with.js";
6
7
  export * from "./ensure-array.js";
7
8
  export * from "./ensure-iterable.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/arrays",
3
- "version": "2.2.5",
3
+ "version": "2.3.2",
4
4
  "description": "Array / Arraylike utilities",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -34,20 +34,20 @@
34
34
  "test": "testament test"
35
35
  },
36
36
  "dependencies": {
37
- "@thi.ng/api": "^8.3.7",
38
- "@thi.ng/checks": "^3.2.1",
39
- "@thi.ng/compare": "^2.1.7",
40
- "@thi.ng/equiv": "^2.1.7",
41
- "@thi.ng/errors": "^2.1.7",
42
- "@thi.ng/random": "^3.3.2"
37
+ "@thi.ng/api": "^8.3.9",
38
+ "@thi.ng/checks": "^3.2.3",
39
+ "@thi.ng/compare": "^2.1.9",
40
+ "@thi.ng/equiv": "^2.1.9",
41
+ "@thi.ng/errors": "^2.1.9",
42
+ "@thi.ng/random": "^3.3.4"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@microsoft/api-extractor": "^7.25.0",
46
- "@thi.ng/testament": "^0.2.8",
46
+ "@thi.ng/testament": "^0.2.10",
47
47
  "rimraf": "^3.0.2",
48
48
  "tools": "^0.0.1",
49
49
  "typedoc": "^0.22.17",
50
- "typescript": "^4.7.3"
50
+ "typescript": "^4.7.4"
51
51
  },
52
52
  "keywords": [
53
53
  "aos",
@@ -85,6 +85,9 @@
85
85
  "./bisect": {
86
86
  "default": "./bisect.js"
87
87
  },
88
+ "./blit": {
89
+ "default": "./blit.js"
90
+ },
88
91
  "./ends-with": {
89
92
  "default": "./ends-with.js"
90
93
  },
@@ -143,5 +146,5 @@
143
146
  "thi.ng": {
144
147
  "year": 2018
145
148
  },
146
- "gitHead": "ab0188234419f2d9f471de80871df930e5555bd6\n"
149
+ "gitHead": "976ccd698cedaa60dcef2e69030a5eb98898cc4a\n"
147
150
  }