All files / packages/tools/src/store filterToolsWithMoveableHandles.ts

90.9% Statements 10/11
66.66% Branches 6/9
100% Functions 2/2
90.9% Lines 10/11

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                                            99x 99x   99x 31x 31x       31x             31x 9x         9x         99x    
import type { Types } from '@cornerstonejs/core';
 
import {
  ToolAnnotationsPair,
  ToolsWithMoveableHandles,
} from '../types/InternalToolTypes';
 
/**
 * Filters an array of tools, returning only tools with moveable handles at the mouse location that are not locked
 *
 * @param element - The element
 * @param ToolAndAnnotations - The input tool array.
 * @param canvasCoords - The coordinates of the mouse position.
 * @param interactionType - The type of interaction (e.g. 'mouse' or 'touch')
 * @returns The filtered array.
 */
export default function filterToolsWithMoveableHandles(
  element: HTMLDivElement,
  ToolAndAnnotations: ToolAnnotationsPair[],
  canvasCoords: Types.Point2,
  interactionType = 'mouse'
): ToolsWithMoveableHandles[] {
  const proximity = interactionType === 'touch' ? 36 : 6;
  const toolsWithMoveableHandles = [];
 
  ToolAndAnnotations.forEach(({ tool, annotations }) => {
    for (const annotation of annotations) {
      Iif (annotation.isLocked || !annotation.isVisible) {
        continue;
      }
 
      const handle = tool.getHandleNearImagePoint(
        element,
        annotation,
        canvasCoords,
        proximity
      );
 
      if (handle) {
        toolsWithMoveableHandles.push({
          tool,
          annotation,
          handle,
        });
        break;
      }
    }
  });
 
  return toolsWithMoveableHandles;
}