All files / packages/core/src/RenderingEngine/helpers/cpuFallback/rendering doesImageNeedToBeRendered.ts

100% Statements 3/3
9.09% Branches 1/11
100% Functions 1/1
100% Lines 3/3

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 30 31 32 33 34 35 36 37                                34x   34x   34x                                
import { CPUFallbackEnabledElement, IImage } from '../../../../types';
 
/**
 * Determine whether or not an Enabled Element needs to be re-rendered.
 *
 * If the imageId has changed, or if any of the last rendered viewport
 * parameters have changed, this function will return true.
 *
 * @param enabledElement - An Enabled Element
 * @param image - An Image
 * @returns Whether - or not the Enabled Element needs to re-render its image
 */
export default function doesImageNeedToBeRendered(
  enabledElement: CPUFallbackEnabledElement,
  image: IImage
): boolean {
  const lastRenderedImageId = enabledElement.renderingTools.lastRenderedImageId;
  const lastRenderedViewport =
    enabledElement.renderingTools.lastRenderedViewport;
 
  return (
    image.imageId !== lastRenderedImageId ||
    !lastRenderedViewport ||
    lastRenderedViewport.windowCenter !==
      enabledElement.viewport.voi.windowCenter ||
    lastRenderedViewport.windowWidth !==
      enabledElement.viewport.voi.windowWidth ||
    lastRenderedViewport.invert !== enabledElement.viewport.invert ||
    lastRenderedViewport.rotation !== enabledElement.viewport.rotation ||
    lastRenderedViewport.hflip !== enabledElement.viewport.hflip ||
    lastRenderedViewport.vflip !== enabledElement.viewport.vflip ||
    lastRenderedViewport.modalityLUT !== enabledElement.viewport.modalityLUT ||
    lastRenderedViewport.voiLUT !== enabledElement.viewport.voiLUT ||
    lastRenderedViewport.colormap !== enabledElement.viewport.colormap
  );
}