All files / Sources/Widgets/Widgets3D/EllipseWidget behavior.js

0% Statements 0/22
0% Branches 0/2
0% Functions 0/2
0% Lines 0/22

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                                                                                     
import shapeBehavior from 'vtk.js/Sources/Widgets/Widgets3D/ShapeWidget/behavior';
import { vec3 } from 'gl-matrix';
 
export default function widgetBehavior(publicAPI, model) {
  model.shapeHandle = model.widgetState.getEllipseHandle();
  model.point1Handle = model.widgetState.getPoint1Handle();
  model.point2Handle = model.widgetState.getPoint2Handle();
  model.point1Handle.setManipulator(model.manipulator);
  model.point2Handle.setManipulator(model.manipulator);
 
  // We inherit shapeBehavior
  shapeBehavior(publicAPI, model);
  const superClass = { ...publicAPI };
 
  model.classHierarchy.push('vtkEllipseWidgetProp');
 
  publicAPI.setCorners = (point1, point2) => {
    if (superClass.setCorners) {
      superClass.setCorners(point1, point2);
    }
 
    const center = [
      0.5 * (point1[0] + point2[0]),
      0.5 * (point1[1] + point2[1]),
      0.5 * (point1[2] + point2[2]),
    ];
 
    const diagonal = [0, 0, 0];
    vec3.subtract(diagonal, point2, center);
 
    const right = model.shapeHandle.getRight();
    const up = model.shapeHandle.getUp();
    const dir = model.shapeHandle.getDirection();
 
    const rightComponent = vec3.dot(diagonal, right);
    const upComponent = vec3.dot(diagonal, up);
    const dirComponent = vec3.dot(diagonal, dir);
 
    model.shapeHandle.setOrigin(center);
    model.shapeHandle.setScale3([rightComponent, upComponent, dirComponent]);
  };
}