All files / svg-shape/internal create-arc-path.ts

100% Statements 11/11
100% Branches 6/6
100% Functions 1/1
100% Lines 11/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        6x 6x     7x 7x 7x 7x 7x 2x 2x   5x 7x    
import { formatCoordinate } from './format-coordinate';
import { formatPoint } from './format-point';
import { polarToCartesian } from './polar-to-cartesian';
 
const FULL_TURN = 360;
const HALF_TURN = 180;
 
export function createArcPath(center: DOMPointReadOnly, radius: number, startAngle: number, endAngle: number): string {
  const sweep = endAngle - startAngle;
  const r = formatCoordinate(radius);
  const direction = sweep > 0 ? 1 : 0;
  const start = formatPoint(polarToCartesian(center, radius, startAngle));
  if (Math.abs(sweep) >= FULL_TURN) {
    const opposite = formatPoint(polarToCartesian(center, radius, startAngle + HALF_TURN));
    return `M ${start} A ${r} ${r} 0 1 ${direction} ${opposite} A ${r} ${r} 0 1 ${direction} ${start}`;
  }
  const largeArc = Math.abs(sweep) > HALF_TURN ? 1 : 0;
  return `M ${start} A ${r} ${r} 0 ${largeArc} ${direction} ${formatPoint(polarToCartesian(center, radius, endAngle))}`;
}