Skip to content

fix: Fix potential divide by 0 in Viewport.resetCamera#2513

Open
abustany wants to merge 1 commit intocornerstonejs:mainfrom
abustany:fix-viewport-camera-reset
Open

fix: Fix potential divide by 0 in Viewport.resetCamera#2513
abustany wants to merge 1 commit intocornerstonejs:mainfrom
abustany:fix-viewport-camera-reset

Conversation

@abustany
Copy link
Copy Markdown
Contributor

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.resetCamera computes widths/heights using VTK's getExtent function, but that function return indices, not dimensions. This PR fixes the computation to correct the off-by-one error.

Testing

Checklist

PR

  • My Pull Request title is descriptive, accurate and follows the
    semantic-release format and guidelines.

Code

  • My code has been well-documented (function documentation, inline comments,
    etc.)

Public Documentation Updates

  • The documentation page has been updated as necessary for any public API
    additions or removals.

Tested Environment

  • OS: macOS
  • Node version: 22
  • Browser: Firefox 146

getExtent returns array indices, not dimensions. This fixes a division
by zero when displaying 1x1 pixel images.
@sedghi
Copy link
Copy Markdown
Member

sedghi commented Dec 11, 2025

Do you have a 1x1 pixel image that we can test this with?


widthWorld = (extent[1] - extent[0]) * spacing[0];
heightWorld = (extent[3] - extent[2]) * spacing[1];
widthWorld = (1 + extent[1] - extent[0]) * spacing[0];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@abustany
Copy link
Copy Markdown
Contributor Author

Do you have a 1x1 pixel image that we can test this with?

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.

1px.dcm.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants