All files / tools/src/utilities/contours reverseIfAntiClockwise.ts

0% Statements 0/7
0% Branches 0/4
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';
import { getSignedArea } from '../math/polyline';
 
/**
 * _reverseIfAntiClockwise - If the contour's nodes run anti-clockwise,
 * reverse them.
 *
 * @param points - The points array.
 * @param otherListsToReverse - any number of additional lists to also reverse
 *       when the primary list is anti-clockwise.
 * @returns The contour, corrected to be clockwise if appropriate.
 */
export default function reverseIfAntiClockwise(
  points: Types.Point2[],
  ...otherListsToReverse: unknown[][]
) {
  const signedArea = getSignedArea(points);
 
  // signedArea will be less than zero for anti-clockwise
  if (signedArea < 0) {
    if (otherListsToReverse) {
      otherListsToReverse.forEach((list) => list.reverse());
    }
 
    return points.slice().reverse();
  }
 
  return points;
}