All files / packages/tools/src/utilities/viewport isViewportPreScaled.ts

88.88% Statements 8/9
66.66% Branches 4/6
100% Functions 1/1
87.5% Lines 7/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25                      35x 3x 3x 3x 32x 32x 32x              
import {
  cache,
  StackViewport,
  Types,
  BaseVolumeViewport,
} from '@cornerstonejs/core';
 
function isViewportPreScaled(
  viewport: Types.IStackViewport | Types.IVolumeViewport,
  targetId: string
): boolean {
  if (viewport instanceof BaseVolumeViewport) {
    const volumeId = targetId.split('volumeId:')[1];
    const volume = cache.getVolume(volumeId);
    return volume.scaling && Object.keys(volume.scaling).length > 0;
  } else Eif (viewport instanceof StackViewport) {
    const { preScale } = viewport.getImageData();
    return preScale.scaled;
  } else {
    throw new Error('Viewport is not a valid type');
  }
}
 
export { isViewportPreScaled };