All files / packages/tools/src/utilities/math/polyline getWindingDirection.ts

100% Statements 2/2
50% Branches 1/2
100% Functions 1/1
100% Lines 2/2

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                  2x     2x    
import type { Types } from '@cornerstonejs/core';
import getSignedArea from './getSignedArea';
 
/**
 * Calculate the winding direction (CW or CCW) of a polyline
 * @param polyline - Polyline (2D)
 * @returns 1 for CW or -1 for CCW polylines
 */
export default function getWindingDirection(polyline: Types.Point2[]): number {
  const signedArea = getSignedArea(polyline);
 
  // Return 1 or -1 which is also possible to convert into ContourOrientation
  return signedArea >= 0 ? 1 : -1;
}