fix(CellArray): extractCellSizes function should return Array#3405
Open
TreatTrick wants to merge 7 commits intoKitware:masterfrom
Open
fix(CellArray): extractCellSizes function should return Array#3405TreatTrick wants to merge 7 commits intoKitware:masterfrom
TreatTrick wants to merge 7 commits intoKitware:masterfrom
Conversation
…ed after creation
…ned under specific conditions
finetjul
reviewed
Feb 7, 2026
Member
finetjul
left a comment
There was a problem hiding this comment.
I'm fine to enforce cellSizes to be of type Array.
The following code is 10 times faster though:
const cellSizes = [];
for (let i = 0; i < cellArray.length; i += cellArray[i] + 1) {
res.push(cellArray[i]);
}
Please improve index.d.ts to specialize the returned type any (and if possible, it would be great if you could also describe what this function is doing).
Contributor
Author
|
Done! I've refactored the function to use a for-loop for better performance and updated the index.d.ts with a detailed description and specific return type as requested. Thanks for the guidance! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
In
CellArray,cellSizesneeds to be updated in certain cases using a call likemodel.cellSizes.push(cellPointIds.length);. However, thepushmethod is only available for a javascriptregular Array.During the execution of
model.cellSizes = extractCellSizes(publicAPI.getData());, ifpublicAPI.getData()returns aTypedArrayinstead of aregular Array, callingmodel.cellSizes.pushwill cause the application to throw errors, asTypedArraysdo not support the push method.Results
The following example code is a modification based on the
TubeFilter example. When thesetTimeoutin the code is triggered, it leads to the aforementioned error, causing the application to throw errors.Changes
The solution is quite simple: just add
Array.frominside theextractCellSizesfunction to ensure that the returned value is always a regular array.PR and Code Checklist
npm run reformatto have correctly formatted codeTesting