All files / packages/tools/src/utilities/math midPoint.ts

90% Statements 9/10
50% Branches 2/4
100% Functions 1/1
90% Lines 9/10

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          1x       51x 51x 51x 102x 102x 102x       51x     1x          
import { Types } from '@cornerstonejs/core';
 
/**
 * Return the midpoint (think average) of all the provided points.
 */
const midPoint = (
  ...args: (Types.Point2 | Types.Point3)[]
): Types.Point2 | Types.Point3 => {
  const ret =
    args[0].length === 2 ? <Types.Point2>[0, 0] : <Types.Point3>[0, 0, 0];
  const len = args.length;
  for (const arg of args) {
    ret[0] += arg[0] / len;
    ret[1] += arg[1] / len;
    Iif (ret.length === 3) {
      ret[2] += arg[2] / len;
    }
  }
  return ret;
};
 
const midPoint2 = midPoint as (...args: Types.Point2[]) => Types.Point2;
 
export default midPoint;
 
export { midPoint2 };