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

88.88% Statements 8/9
60% Branches 6/10
100% Functions 1/1
88.88% Lines 8/9

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 27 28 29                      36x 4x   4x     4x 4x 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 targetIdTokens = targetId.split('volumeId:');
    const volumeId =
      targetIdTokens.length > 1
        ? targetIdTokens[1].split('?')[0]
        : targetIdTokens[0];
    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 };