function testCirclePolygon(circle, polygon) {
  // TODO handle polygon that is a straight line, current impl will interrept it is a true, if radius is extended onto any of the edges
  if (toFewEdges(polygon) || circleHasNoSize(circle)) {
    return false;
  }

  const center = { x: circle.cx, y: circle.cy };
  if (testPolygonPoint(polygon, center)) {
    return true;
  }

  const num = polygon.edges.length;

  for (let i = 0; i < num; i++) {
    const edge = pointsToLine(polygon.edges[i]);
    if (testCircleLine(circle, edge)) {
      return true;
    }
  }

  return false;
}
/**
 * Test if a Circle collide with Polygon. If so, returns true and false otherwise.
 * Circle muse have a radius greater then 0.
 * Polygon must contain at least 2 vertices
 * @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} polygon
 * @param {Array} polygon.vertices - Array of vertices
 * @param {object} polygon.vertices.vertex
 * @param {number} polygon.vertices.vertex.x - x-coordinate
 * @param {number} polygon.vertices.vertex.y - y-coordinate
 * @param {Array} polygon.edges - Array of edges
 * @param {Array} polygon.edges.edge - Array of points
 * @param {object} polygon.edges.edge.point
 * @param {number} polygon.edges.edge.point.x - x-coordinate
 * @param {number} polygon.edges.edge.point.y - y-coordinate
 * @return {boolean} true if circle collide with polygon
 */
Test if a Circle collide with Polygon. If so, returns true and false otherwise.
Circle muse have a radius greater then 0.
Test if a Circle collide with Polygon . If so returns true and false otherwise . Circle muse have a radius greater then 0 .
function testCirclePolygon(circle, polygon) {
  if (toFewEdges(polygon) || circleHasNoSize(circle)) {
    return false;
  }
  const center = { x: circle.cx, y: circle.cy };
  if (testPolygonPoint(polygon, center)) {
    return true;
  }
  const num = polygon.edges.length;
  for (let i = 0; i < num; i++) {
    const edge = pointsToLine(polygon.edges[i]);
    if (testCircleLine(circle, edge)) {
      return true;
    }
  }
  return false;
}
function testCirclePolygon ( circle , polygon ) { if ( toFewEdges ( polygon ) || circleHasNoSize ( circle ) ) { return false ; } const center = { x : circle . cx , y : circle . cy } ; if ( testPolygonPoint ( polygon , center ) ) { return true ; } const num = polygon . edges . length ; for ( let i = 0 ; i < num ; i ++ ) { const edge = pointsToLine ( polygon . edges [ i ] ) ; if ( testCircleLine ( circle , edge ) ) { return true ; } } return false ; }
Test if a Circle collide with Polygon.
Test if a Circle collide with Polygon .
// TODO handle polygon that is a straight line, current impl will interrept it is a true, if radius is extended onto any of the edges