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

0% Statements 0/7
0% Branches 0/4
0% Functions 0/1
0% Lines 0/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                                                                 
import calculateTransform from './calculateTransform';
import type { 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 {
  if (enabledElement === undefined) {
    throw new Error(
      'setToPixelCoordinateSystem: parameter enabledElement must not be undefined'
    );
  }
  if (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]);
}