All files / Sources/Widgets/Core/StateBuilder originMixin.js

88.88% Statements 16/18
80% Branches 4/5
75% Functions 3/4
88.88% Lines 16/18

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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56              139x 139x       139x 761x 761x 449x   312x 216x   96x       96x 96x 96x                         1x               139x 139x 139x            
import macro from 'vtk.js/Sources/macros';
import vtkMath from 'vtk.js/Sources/Common/Core/Math';
import { getPixelWorldHeightAtCoord } from 'vtk.js/Sources/Widgets/Core/WidgetManager';
 
// ----------------------------------------------------------------------------
 
function vtkOriginMixin(publicAPI, model) {
  const superClass = { ...publicAPI };
  publicAPI.translate = (dx, dy, dz) => {
    const [x, y, z] = publicAPI.getOriginByReference();
    publicAPI.setOrigin(x + dx, y + dy, z + dz);
  };
  publicAPI.getOrigin = (displayScaleParams) => {
    const origin = superClass.getOrigin();
    if (!model.offset) {
      return origin;
    }
    if (!displayScaleParams) {
      return vtkMath.add(origin, model.offset, origin);
    }
    const pixelWorldHeight = getPixelWorldHeightAtCoord(
      origin,
      displayScaleParams
    );
    const { rendererPixelDims } = displayScaleParams;
    const totalSize = Math.min(rendererPixelDims[0], rendererPixelDims[1]);
    return vtkMath.multiplyAccumulate(
      origin,
      model.offset,
      totalSize * pixelWorldHeight,
      origin
    );
  };
}
 
// ----------------------------------------------------------------------------
/**
 * offset: optional offset that can be scaled to pixel screen space.
 */
const DEFAULT_VALUES = {
  origin: null,
  offset: null,
};
 
// ----------------------------------------------------------------------------
 
export function extend(publicAPI, model, initialValues = {}) {
  Object.assign(model, DEFAULT_VALUES, initialValues);
  macro.setGetArray(publicAPI, model, ['origin', 'offset'], 3);
  vtkOriginMixin(publicAPI, model);
}
 
// ----------------------------------------------------------------------------
 
export default { extend };