All files / packages/tools/src/utilities/boundingBox extend2DBoundingBoxInViewAxis.ts

0% Statements 0/7
0% Branches 0/2
0% Functions 0/2
0% Lines 0/6

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                                                           
import type { Types } from '@cornerstonejs/core';
 
/**
 * Uses the current bounds of the 2D rectangle and extends it in the view axis by numSlices
 * It compares min and max of each IJK to find the view axis (for axial, zMin === zMax) and
 * then calculates the extended range. It will assume the slice is relative to the
 * current slice and will add the given slices to the current max of the boundingBox.
 * @param boundsIJK - [[iMin, iMax], [jMin, jMax], [kMin, kMax]]
 * @param slices - number of slices to project before and after
 * @returns extended bounds
 */
function extend2DBoundingBoxInViewAxis(
  boundsIJK: [Types.Point2, Types.Point2, Types.Point2],
  numSlicesToProject: number
): [Types.Point2, Types.Point2, Types.Point2] {
  // find which index in boundsIJK has the same first and last value
  const sliceNormalIndex = boundsIJK.findIndex(([min, max]) => min === max);
 
  if (sliceNormalIndex === -1) {
    throw new Error('3D bounding boxes not supported in an oblique plane');
  }
 
  // get the index and subtract slices from the min and add to the max
  boundsIJK[sliceNormalIndex][0] -= numSlicesToProject;
  boundsIJK[sliceNormalIndex][1] += numSlicesToProject;
  return boundsIJK;
}
 
export default extend2DBoundingBoxInViewAxis;