function testPolygonLine(polygon, line) {
  // TODO handle polygon that is a straight line, current impl gives a non-deterministic output, that is depending on number of vertices
  if (toFewEdges(polygon)) {
    return false;
  }

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

  const [p1, p2] = lineToPoints(line);

  return testPolygonPoint(polygon, p1) || testPolygonPoint(polygon, p2);
}
/**
 * Test if a Polygon collider with a line. If so, returns true and false otherwise.
 * Polygon must contain at least 3 edges.
 * Line must have length greater then 0.
 * @private
 * @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
 * @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 polygon collider with line
 */
Test if a Polygon collider with a line. If so, returns true and false otherwise.
Polygon must contain at least 3 edges.
Line must have length greater then 0.
Test if a Polygon collider with a line . If so returns true and false otherwise . Polygon must contain at least 3 edges . Line must have length greater then 0 .
function testPolygonLine(polygon, line) {
  if (toFewEdges(polygon)) {
    return false;
  }
  for (let i = 0, num = polygon.edges.length; i < num; i++) {
    const edge = pointsToLine(polygon.edges[i]);
    if (testLineLine(line, edge)) {
      return true;
    }
  }
  const [p1, p2] = lineToPoints(line);
  return testPolygonPoint(polygon, p1) || testPolygonPoint(polygon, p2);
}
function testPolygonLine ( polygon , line ) { if ( toFewEdges ( polygon ) ) { return false ; } for ( let i = 0 , num = polygon . edges . length ; i < num ; i ++ ) { const edge = pointsToLine ( polygon . edges [ i ] ) ; if ( testLineLine ( line , edge ) ) { return true ; } } const [ p1 , p2 ] = lineToPoints ( line ) ; return testPolygonPoint ( polygon , p1 ) || testPolygonPoint ( polygon , p2 ) ; }
Test if a Polygon collider with a line.
Test if a Polygon collider with a line .
// TODO handle polygon that is a straight line, current impl gives a non-deterministic output, that is depending on number of vertices