fix: Fix potential divide by 0 in Viewport.resetCamera#2513
Open
abustany wants to merge 1 commit intocornerstonejs:mainfrom
Open
fix: Fix potential divide by 0 in Viewport.resetCamera#2513abustany wants to merge 1 commit intocornerstonejs:mainfrom
abustany wants to merge 1 commit intocornerstonejs:mainfrom
Conversation
getExtent returns array indices, not dimensions. This fixes a division by zero when displaying 1x1 pixel images.
Member
|
Do you have a 1x1 pixel image that we can test this with? |
sedghi
reviewed
Dec 11, 2025
|
|
||
| widthWorld = (extent[1] - extent[0]) * spacing[0]; | ||
| heightWorld = (extent[3] - extent[2]) * spacing[1]; | ||
| widthWorld = (1 + extent[1] - extent[0]) * spacing[0]; |
Member
There was a problem hiding this comment.
I checked and yeah seems like this was wrong, the extent is index so start at 0
All tests need to be updated as a result i guess (which we can do)
Double checking with @wayfarer3130
Contributor
Author
In our case it's a placeholder image that is generated (basically we build the pixel data by hand and have a custom loader). I did generate one using The Gimp though, attaching it here. |
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.
getExtent returns array indices, not dimensions. This fixes a division by zero when displaying 1x1 pixel images.
Context
Displaying 1x1 pixel images fails
Changes & Results
Viewport.resetCameracomputes widths/heights using VTK'sgetExtentfunction, but that function return indices, not dimensions. This PR fixes the computation to correct the off-by-one error.Testing
Checklist
PR
semantic-release format and guidelines.
Code
etc.)
Public Documentation Updates
additions or removals.
Tested Environment