function testPolygonRect(polygon, rect) {
  // 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 (testRectLine(rect, edge)) {
      return true;
    }
  }

  const [p1, p2, p3, p4] = rectToPoints(rect);
  return (
    testPolygonPoint(polygon, p1) ||
    testPolygonPoint(polygon, p2) ||
    testPolygonPoint(polygon, p3) ||
    testPolygonPoint(polygon, p4)
  );
}
/**
 * Test if a Polygon collider with a rectangle. If so, returns true and false otherwise.
 * Polygon must contain at least 3 edges.
 * Rectangle must width and height 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} rect
 * @param {number} rect.x - x-coordinate
 * @param {number} rect.y - y-coordinate
 * @param {number} rect.width - width
 * @param {number} rect.height - height
 * @return {boolean} true if polygon collider with rect
 */
Test if a Polygon collider with a rectangle. If so, returns true and false otherwise.
Polygon must contain at least 3 edges.
Rectangle must width and height greater then 0.
Test if a Polygon collider with a rectangle . If so returns true and false otherwise . Polygon must contain at least 3 edges . Rectangle must width and height greater then 0 .
function testPolygonRect(polygon, rect) {
  if (toFewEdges(polygon)) {
    return false;
  }
  for (let i = 0, num = polygon.edges.length; i < num; i++) {
    const edge = pointsToLine(polygon.edges[i]);
    if (testRectLine(rect, edge)) {
      return true;
    }
  }
  const [p1, p2, p3, p4] = rectToPoints(rect);
  return (
    testPolygonPoint(polygon, p1) ||
    testPolygonPoint(polygon, p2) ||
    testPolygonPoint(polygon, p3) ||
    testPolygonPoint(polygon, p4)
  );
}
function testPolygonRect ( polygon , rect ) { if ( toFewEdges ( polygon ) ) { return false ; } for ( let i = 0 , num = polygon . edges . length ; i < num ; i ++ ) { const edge = pointsToLine ( polygon . edges [ i ] ) ; if ( testRectLine ( rect , edge ) ) { return true ; } } const [ p1 , p2 , p3 , p4 ] = rectToPoints ( rect ) ; return ( testPolygonPoint ( polygon , p1 ) || testPolygonPoint ( polygon , p2 ) || testPolygonPoint ( polygon , p3 ) || testPolygonPoint ( polygon , p4 ) ) ; }
Test if a Polygon collider with a rectangle.
Test if a Polygon collider with a rectangle .
// TODO handle polygon that is a straight line, current impl gives a non-deterministic output, that is depending on number of vertices