parameters: (start, end, circle, *, fudge=0.5)
return_statement: return closest_distance <= circle.radius + fudge
docstring: Test whether a line segment and circle intersect.
  
      :param Entity start: The start of the line segment. (Needs x, y attributes)
      :param Entity end: The end of the line segment. (Needs x, y attributes)
      :param Entity circle: The circle to test against. (Needs x, y, r attributes)
      :param float fudge: A fudge factor; additional distance to leave between the segment and circle. (Probably set this to the ship radius, 0.5.)
      :return: True if intersects, False otherwise
      :rtype: bool
docstring_summary: Test whether a line segment and circle intersect.
docstring_tokens: Test whether a line segment and circle intersect .
function: def intersect_segment_circle(start, end, circle, *, fudge=0.5):
      """
      Test whether a line segment and circle intersect.
  
      :param Entity start: The start of the line segment. (Needs x, y attributes)
      :param Entity end: The end of the line segment. (Needs x, y attributes)
      :param Entity circle: The circle to test against. (Needs x, y, r attributes)
      :param float fudge: A fudge factor; additional distance to leave between the segment and circle. (Probably set this to the ship radius, 0.5.)
      :return: True if intersects, False otherwise
      :rtype: bool
      """
      # Derived with SymPy
      # Parameterize the segment as start + t * (end - start),
      # and substitute into the equation of a circle
      # Solve for t
      dx = end.x - start.x
      dy = end.y - start.y
  
      a = dx**2 + dy**2
      b = -2 * (start.x**2 - start.x*end.x - start.x*circle.x + end.x*circle.x +
                start.y**2 - start.y*end.y - start.y*circle.y + end.y*circle.y)
      c = (start.x - circle.x)**2 + (start.y - circle.y)**2
  
      if a == 0.0:
          # Start and end are the same point
          return start.calculate_distance_between(circle) <= circle.radius + fudge
  
      # Time along segment when closest to the circle (vertex of the quadratic)
      t = min(-b / (2 * a), 1.0)
      if t < 0:
          return False
  
      closest_x = start.x + dx * t
      closest_y = start.y + dy * t
      closest_distance = Position(closest_x, closest_y).calculate_distance_between(circle)
  
      return closest_distance <= circle.radius + fudge
function_tokens: def intersect_segment_circle ( start , end , circle , * , fudge = 0.5 ) : # Derived with SymPy # Parameterize the segment as start + t * (end - start), # and substitute into the equation of a circle # Solve for t dx = end . x - start . x dy = end . y - start . y a = dx ** 2 + dy ** 2 b = - 2 * ( start . x ** 2 - start . x * end . x - start . x * circle . x + end . x * circle . x + start . y ** 2 - start . y * end . y - start . y * circle . y + end . y * circle . y ) c = ( start . x - circle . x ) ** 2 + ( start . y - circle . y ) ** 2 if a == 0.0 : # Start and end are the same point return start . calculate_distance_between ( circle ) <= circle . radius + fudge # Time along segment when closest to the circle (vertex of the quadratic) t = min ( - b / ( 2 * a ) , 1.0 ) if t < 0 : return False closest_x = start . x + dx * t closest_y = start . y + dy * t closest_distance = Position ( closest_x , closest_y ) . calculate_distance_between ( circle ) return closest_distance <= circle . radius + fudge