@thi.ng/api 8.7.6 → 8.8.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 +7 -1
- package/README.md +1 -1
- package/package.json +6 -6
- package/typedarray.d.ts +26 -0
- package/typedarray.js +11 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2023-
|
|
3
|
+
- **Last updated**: 2023-05-11T12:16:33Z
|
|
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
|
+
## [8.8.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/api@8.8.0) (2023-04-19)
|
|
13
|
+
|
|
14
|
+
#### 🚀 Features
|
|
15
|
+
|
|
16
|
+
- add typedArrayOfVec() ([39307bf](https://github.com/thi-ng/umbrella/commit/39307bf))
|
|
17
|
+
|
|
12
18
|
## [8.7.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/api@8.7.0) (2023-02-05)
|
|
13
19
|
|
|
14
20
|
#### 🚀 Features
|
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/api",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.8.1",
|
|
4
4
|
"description": "Common, generic types, interfaces & mixins",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -37,11 +37,11 @@
|
|
|
37
37
|
"test": "testament test"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@microsoft/api-extractor": "^7.34.
|
|
41
|
-
"@thi.ng/testament": "^0.3.
|
|
42
|
-
"rimraf": "^
|
|
40
|
+
"@microsoft/api-extractor": "^7.34.8",
|
|
41
|
+
"@thi.ng/testament": "^0.3.16",
|
|
42
|
+
"rimraf": "^5.0.0",
|
|
43
43
|
"tools": "^0.0.1",
|
|
44
|
-
"typedoc": "^0.
|
|
44
|
+
"typedoc": "^0.24.6",
|
|
45
45
|
"typescript": "^5.0.4"
|
|
46
46
|
},
|
|
47
47
|
"keywords": [
|
|
@@ -225,5 +225,5 @@
|
|
|
225
225
|
"default": "./watch.js"
|
|
226
226
|
}
|
|
227
227
|
},
|
|
228
|
-
"gitHead": "
|
|
228
|
+
"gitHead": "20ab11b687a13228f6a8cecdc5f05ba9105122ea\n"
|
|
229
229
|
}
|
package/typedarray.d.ts
CHANGED
|
@@ -158,6 +158,32 @@ export declare function typedArray<T extends Type | GLType>(type: T, buf: ArrayB
|
|
|
158
158
|
export declare function typedArray<T extends BigType>(type: T, length: number): BigTypedArrayTypeMap[T];
|
|
159
159
|
export declare function typedArray<T extends BigType>(type: T, src: ArrayLike<bigint> | ArrayBufferLike): BigTypedArrayTypeMap[T];
|
|
160
160
|
export declare function typedArray<T extends BigType>(type: T, buf: ArrayBufferLike, byteOffset: number, length?: number): BigTypedArrayTypeMap[T];
|
|
161
|
+
/**
|
|
162
|
+
* Constructs a typed array for given `type` and populates it with given vector
|
|
163
|
+
* values.
|
|
164
|
+
*
|
|
165
|
+
* @remarks
|
|
166
|
+
* The size of the array will be `data.length * stride`, where `stride` is the
|
|
167
|
+
* number of elements per item and defaulting to the size of the first data
|
|
168
|
+
* item/vector given.
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```ts
|
|
172
|
+
* // inferred stride=2 (2d vectors)
|
|
173
|
+
* typedArrayOfVec("f32", [[1,2], [3,4], [-10,20]]);
|
|
174
|
+
* // Float32Array(6) [ 1, 2, 3, 4, -10, 20 ]
|
|
175
|
+
*
|
|
176
|
+
* // with custom stride=4
|
|
177
|
+
* typedArrayOfVec("f32", [[1,2], [3,4], [-10,20]], 4);
|
|
178
|
+
* // Float32Array(12) [ 1, 2, 0, 0, 3,4, 0, 0, -10, 20, 0, 0 ]
|
|
179
|
+
* ```
|
|
180
|
+
*
|
|
181
|
+
* @param type
|
|
182
|
+
* @param data
|
|
183
|
+
* @param stride
|
|
184
|
+
*/
|
|
185
|
+
export declare function typedArrayOfVec<T extends Type | GLType>(type: T, data: Iterable<ArrayLike<number>>, stride?: number): TypedArrayTypeMap[T];
|
|
186
|
+
export declare function typedArrayOfVec<T extends BigType>(type: T, data: Iterable<ArrayLike<bigint>>, stride?: number): BigTypedArrayTypeMap[T];
|
|
161
187
|
/**
|
|
162
188
|
* Takes an {@link NumericArray} and returns its corresponding {@link Type} ID.
|
|
163
189
|
* Standard JS arrays will default to {@link "f64"}.
|
package/typedarray.js
CHANGED
|
@@ -149,6 +149,17 @@ export function typedArray(type, ...xs) {
|
|
|
149
149
|
const ctor = BIGINT_ARRAY_CTORS[type];
|
|
150
150
|
return new (ctor || TYPEDARRAY_CTORS[asNativeType(type)])(...xs);
|
|
151
151
|
}
|
|
152
|
+
export function typedArrayOfVec(type, data, stride) {
|
|
153
|
+
const $data = Array.isArray(data) ? data : [...data];
|
|
154
|
+
if (stride === undefined)
|
|
155
|
+
stride = $data[0].length;
|
|
156
|
+
const num = $data.length;
|
|
157
|
+
const res = typedArray(type, num * stride);
|
|
158
|
+
for (let i = 0, j = 0; i < num; i++, j += stride) {
|
|
159
|
+
res.set($data[i], j);
|
|
160
|
+
}
|
|
161
|
+
return res;
|
|
162
|
+
}
|
|
152
163
|
/**
|
|
153
164
|
* Takes an {@link NumericArray} and returns its corresponding {@link Type} ID.
|
|
154
165
|
* Standard JS arrays will default to {@link "f64"}.
|