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

71.42% Statements 5/7
50% Branches 2/4
100% Functions 1/1
71.42% Lines 5/7

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                                34x         34x           34x 34x   34x    
import calculateTransform from './calculateTransform';
import { CPUFallbackEnabledElement } from '../../../../types';
 
/**
 * Sets the canvas context transformation matrix to the pixel coordinate system.  This allows
 * geometry to be driven using the canvas context using coordinates in the pixel coordinate system
 * @param {EnabledElement} enabledElement The
 * @param {CanvasRenderingContext2D} context The CanvasRenderingContext2D for the enabledElement's Canvas
 * @param {Number} [scale] Optional scale to apply
 * @returns {void}
 */
export default function (
  enabledElement: CPUFallbackEnabledElement,
  context: CanvasRenderingContext2D,
  scale?: number
): void {
  Iif (enabledElement === undefined) {
    throw new Error(
      'setToPixelCoordinateSystem: parameter enabledElement must not be undefined'
    );
  }
  Iif (context === undefined) {
    throw new Error(
      'setToPixelCoordinateSystem: parameter context must not be undefined'
    );
  }
 
  const transform = calculateTransform(enabledElement, scale);
  const m = transform.getMatrix();
 
  context.setTransform(m[0], m[1], m[2], m[3], m[4], m[5]);
}