cornerstone3D icon indicating copy to clipboard operation
cornerstone3D copied to clipboard

fix: Fix potential divide by 0 in Viewport.resetCamera

Open abustany opened this issue 2 weeks ago • 2 comments

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

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

Code

  • [x] 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

  • [x] OS: macOS
  • [x] Node version: 22
  • [x] Browser: Firefox 146

abustany avatar Dec 11 '25 13:12 abustany

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

sedghi avatar Dec 11 '25 14:12 sedghi

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

abustany avatar Dec 11 '25 15:12 abustany