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

0% Statements 0/17
0% Branches 0/10
0% Functions 0/1
0% Lines 0/14

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                                                                 
import getImageFitScale from './getImageFitScale';
import { CPUFallbackEnabledElement } from '../../../../types';
 
/**
 * Resets the camera to the default position. which would be the center of the image.
 * with no translation, no flipping, no zoom and proper scale.
 */
export default function (
  enabledElement: CPUFallbackEnabledElement,
  resetPan = true,
  resetZoom = true
): void {
  const { canvas, image, viewport } = enabledElement;
  const scale = getImageFitScale(canvas, image, 0).scaleFactor;
 
  viewport.vflip = false;
  viewport.hflip = false;
 
  if (resetPan) {
    viewport.translation.x = 0;
    viewport.translation.y = 0;
  }
 
  if (resetZoom) {
    viewport.displayedArea.tlhc.x = 1;
    viewport.displayedArea.tlhc.y = 1;
    viewport.displayedArea.brhc.x = image.columns;
    viewport.displayedArea.brhc.y = image.rows;
 
    viewport.scale = scale;
  }
}