Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions BREAKING_CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- **TypeScript declarations**: expanded coverage and corrected types may expose build errors. Remove conflicting local declaration shims and fix code rejected by the new types.
- **TypeScript libraries**: typed-array factories now declare BigInt support. Add `ES2020.BigInt` if your `lib` list does not include `ES2020` or later. Your `target` can stay unchanged.
- **Accessor types**: `setXFrom` methods and setters that return no value now declare `void`. Getter types include `null` or `undefined` where applicable.
- **`TYPED_ARRAYS` removed.** The named export and `macro.TYPED_ARRAYS` property are removed. Use native typed-array constructors, `newTypedArray(typeName, ...args)`, or `newTypedArrayFrom(typeName, values)`. Unknown or unavailable constructors still fall back to `Float64Array`.
- **`Point` type removed.** Import `Vector3` from `@kitware/vtk.js/types` instead.
- **vtkVolumeProperty**: replace `setAverageIPScalarRange(min, max)` with `setIpScalarRange(min, max)`.
- **vtkOpenGLFramebuffer**: replace `getColorTexture()` with `getColorBuffers()[0]`.
Expand Down
2 changes: 1 addition & 1 deletion Sources/Common/Core/DataArray/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ declare function createRangeHelper(): vtkRangeHelper;
*
* ```js
* const isFloat32 = ('Float32Array' === getDataType(array));
* const clone = new macro.TYPED_ARRAYS[getDataType(array)](array.length);
* const clone = macro.newTypedArray(getDataType(array), array.length);
* ```
*
* @param typedArray to extract its type from
Expand Down
8 changes: 3 additions & 5 deletions Sources/Common/DataModel/Planes/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import macro, { TYPED_ARRAYS } from 'vtk.js/Sources/macros';
import macro from 'vtk.js/Sources/macros';
import vtkDataArray from 'vtk.js/Sources/Common/Core/DataArray';
import vtkImplicitFunction from 'vtk.js/Sources/Common/DataModel/ImplicitFunction';
import vtkMath from 'vtk.js/Sources/Common/Core/Math';
Expand All @@ -17,10 +17,8 @@ function vtkPlanes(publicAPI, model) {
model.classHierarchy.push('vtkPlanes');

// Initialize internal variables
model.planes =
model.planes || macro.newTypedArray(TYPED_ARRAYS.Float64Array, 24);
model.bounds =
model.bounds || macro.newTypedArray(TYPED_ARRAYS.Float64Array, 6);
model.planes = model.planes || new Float64Array(24);
model.bounds = model.bounds || new Float64Array(6);

model.plane = vtkPlane.newInstance();

Expand Down
4 changes: 2 additions & 2 deletions Sources/Common/DataModel/Triangle/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import macro, { TYPED_ARRAYS } from 'vtk.js/Sources/macros';
import macro from 'vtk.js/Sources/macros';
import vtkCell from 'vtk.js/Sources/Common/DataModel/Cell';
import * as vtkMath from 'vtk.js/Sources/Common/Core/Math';
import vtkLine from 'vtk.js/Sources/Common/DataModel/Line';
Expand Down Expand Up @@ -670,7 +670,7 @@ function vtkTriangle(publicAPI, model) {
const J = [v1[0] - v0[0], v1[1] - v0[1], v2[0] - v0[0], v2[1] - v0[1]];

// Compute inverse Jacobian (expects flat array)
const JI = macro.newTypedArray(TYPED_ARRAYS.Float64Array, 4);
const JI = new Float64Array(4);
vtkMath.invertMatrix(J, JI, 2); // returns flat array [JI00, JI01, JI10, JI11]

// Compute derivatives
Expand Down
20 changes: 20 additions & 0 deletions Sources/Testing/testMacro.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
import { it, expect } from 'vitest';
import macro from 'vtk.js/Sources/macros';
import * as macros from 'vtk.js/Sources/macros';

it('Typed-array factories work without a public constructor registry', () => {
expect(macros).not.toHaveProperty('TYPED_ARRAYS');
expect(macro).not.toHaveProperty('TYPED_ARRAYS');

const values = macro.newTypedArray('Float64Array', 3);
expect(values).toBeInstanceOf(Float64Array);
expect(Array.from(values)).toEqual([0, 0, 0]);

const copy = macros.newTypedArrayFrom('Uint16Array', [1, 2, 3]);
expect(copy).toBeInstanceOf(Uint16Array);
expect(Array.from(copy)).toEqual([1, 2, 3]);

expect(macro.newTypedArray('UnknownArray', 2)).toBeInstanceOf(Float64Array);
const object = {};
macro.obj(object, { values: copy });
expect(object.getState().values).toEqual([1, 2, 3]);
object.delete();
});

const MY_ENUM = {
ZERO: 0,
Expand Down
13 changes: 6 additions & 7 deletions Sources/macros.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export function vtkOnceErrorMacro(str: string): void;
/**
* A way to create typed array based on its name without using the window namespace
*/
export const TYPED_ARRAYS: {
type TypedArrayConstructors = {
Float32Array: typeof Float32Array;
Float64Array: typeof Float64Array;
Uint8Array: typeof Uint8Array;
Expand All @@ -79,18 +79,18 @@ export const TYPED_ARRAYS: {
};

// Unavailable optional constructors use the Float64Array fallback.
type TypedArrayForName<T extends keyof typeof TYPED_ARRAYS> = {
type TypedArrayForName<T extends keyof TypedArrayConstructors> = {
[K in T]:
| InstanceType<NonNullable<(typeof TYPED_ARRAYS)[K]>>
| ({} extends Pick<typeof TYPED_ARRAYS, K> ? Float64Array : never);
| InstanceType<NonNullable<TypedArrayConstructors[K]>>
| ({} extends Pick<TypedArrayConstructors, K> ? Float64Array : never);
}[T];

/**
* Create a new typed array based on its name without using the window namespace
* @param type name of the typed array constructor (e.g. 'Float32Array')
* @param args arguments forwarded to the typed array constructor
*/
export function newTypedArray<K extends keyof typeof TYPED_ARRAYS>(
export function newTypedArray<K extends keyof TypedArrayConstructors>(
type: K,
...args: any[]
): TypedArrayForName<K>;
Expand All @@ -104,7 +104,7 @@ export function newTypedArray(
* @param type name of the typed array constructor (e.g. 'Float32Array')
* @param args arguments forwarded to the typed array's `from()` method
*/
export function newTypedArrayFrom<K extends keyof typeof TYPED_ARRAYS>(
export function newTypedArrayFrom<K extends keyof TypedArrayConstructors>(
type: K,
...args: any[]
): TypedArrayForName<K>;
Expand Down Expand Up @@ -802,7 +802,6 @@ declare const Macro: {
setLoggerFunction: typeof setLoggerFunction;
throttle: typeof throttle;
traverseInstanceTree: typeof traverseInstanceTree;
TYPED_ARRAYS: typeof TYPED_ARRAYS;
uncapitalize: typeof uncapitalize;
VOID: typeof VOID;
vtkDebugMacro: typeof vtkDebugMacro;
Expand Down
3 changes: 1 addition & 2 deletions Sources/macros.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export function vtkOnceErrorMacro(str) {
// TypedArray
// ----------------------------------------------------------------------------

export const TYPED_ARRAYS = Object.create(null);
const TYPED_ARRAYS = Object.create(null);
TYPED_ARRAYS.Float32Array = Float32Array;
TYPED_ARRAYS.Float64Array = Float64Array;
TYPED_ARRAYS.Uint8Array = Uint8Array;
Expand Down Expand Up @@ -1818,7 +1818,6 @@ export default {
setLoggerFunction,
throttle,
traverseInstanceTree,
TYPED_ARRAYS, // deprecated todo remove on breaking API revision
uncapitalize,
VOID,
vtkDebugMacro,
Expand Down
Loading