function testCircleLine(circle, line) {
  if (circleHasNoSize(circle) || lineHasNoLength(line)) {
    return false;
  }

  const [p1, p2] = lineToPoints(line);
  if (testCirclePoint(circle, p1) || testCirclePoint(circle, p2)) {
    return true;
  }

  const center = { x: circle.cx, y: circle.cy };
  const pointOnLine = closestPointToLine(p1, p2, center);
  const dist = sqrDistance(pointOnLine, center);

  return dist <= Math.pow(circle.r, 2) && isPointOnLine(p1, p2, pointOnLine);
}
/**
 * Test if a Circle collide with a line segment. If so, returns true and false otherwise.
 * Circle muse have a radius greater then 0.
 * Line must have a length greater then 0.
 * @private
 * @param {object} circle
 * @param {number} circle.cx - center x-coordinate
 * @param {number} circle.cy - center y-coordinate
 * @param {number} circle.r - circle radius
 * @param {object} line
 * @param {number} line.x1 - x-coordinate
 * @param {number} line.y1 - y-coordinate
 * @param {number} line.x1 - x-coordinate
 * @param {number} line.y1 - y-coordinate
 * @return {boolean} true if circle collide with line
 */
Test if a Circle collide with a line segment. If so, returns true and false otherwise.
Circle muse have a radius greater then 0.
Line must have a length greater then 0.
Test if a Circle collide with a line segment . If so returns true and false otherwise . Circle muse have a radius greater then 0 . Line must have a length greater then 0 .
function testCircleLine(circle, line) {
  if (circleHasNoSize(circle) || lineHasNoLength(line)) {
    return false;
  }
  const [p1, p2] = lineToPoints(line);
  if (testCirclePoint(circle, p1) || testCirclePoint(circle, p2)) {
    return true;
  }
  const center = { x: circle.cx, y: circle.cy };
  const pointOnLine = closestPointToLine(p1, p2, center);
  const dist = sqrDistance(pointOnLine, center);
  return dist <= Math.pow(circle.r, 2) && isPointOnLine(p1, p2, pointOnLine);
}
function testCircleLine ( circle , line ) { if ( circleHasNoSize ( circle ) || lineHasNoLength ( line ) ) { return false ; } const [ p1 , p2 ] = lineToPoints ( line ) ; if ( testCirclePoint ( circle , p1 ) || testCirclePoint ( circle , p2 ) ) { return true ; } const center = { x : circle . cx , y : circle . cy } ; const pointOnLine = closestPointToLine ( p1 , p2 , center ) ; const dist = sqrDistance ( pointOnLine , center ) ; return dist <= Math . pow ( circle . r , 2 ) && isPointOnLine ( p1 , p2 , pointOnLine ) ; }
Test if a Circle collide with a line segment.
Test if a Circle collide with a line segment .