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

87.5% Statements 7/8
62.5% Branches 5/8
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 26                        36x 4x 4x 4x 32x 32x 32x              
import {
  cache,
  StackViewport,
  Types,
  BaseVolumeViewport,
  utilities,
} from '@cornerstonejs/core';
 
function isViewportPreScaled(
  viewport: Types.IStackViewport | Types.IVolumeViewport,
  targetId: string
): boolean {
  if (viewport instanceof BaseVolumeViewport) {
    const volumeId = utilities.getVolumeId(targetId);
    const volume = cache.getVolume(volumeId);
    return !!volume?.scaling && Object.keys(volume.scaling).length > 0;
  } else if (viewport instanceof StackViewport) {
    const { preScale } = viewport.getImageData() || {};
    return !!preScale?.scaled;
  } else E{
    return false;
  }
}
 
export { isViewportPreScaled };