function testRectLine(rect, line) {
  if (lineHasNoLength(line) || rectHasNoSize(rect)) {
    return false;
  }

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

  if (testRectPoint(rect, p1) || testRectPoint(rect, p2)) {
    return true;
  }

  const rectEdges = rectToPoints(rect);
  let num = rectEdges.length;
  for (let i = 0; i < num; i++) {
    const edge = pointsToLine([rectEdges[i], rectEdges[i !== 3 ? i + 1 : 0]]);
    if (testLineLine(edge, line)) {
      return true;
    }
  }
  return false;
}
/**
 * Test if a Rectangle collider with a line. If so, returns true and false otherwise.
 * Rectangle must have a width and height greather then 0.
 * Line must have length greater then 0.
 * @private
 * @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
 * @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 rectangle collide with line
 */
Test if a Rectangle collider with a line. If so, returns true and false otherwise.
Rectangle must have a width and height greather then 0.
Line must have length greater then 0.
Test if a Rectangle collider with a line . If so returns true and false otherwise . Rectangle must have a width and height greather then 0 . Line must have length greater then 0 .
function testRectLine(rect, line) {
  if (lineHasNoLength(line) || rectHasNoSize(rect)) {
    return false;
  }
  const [p1, p2] = lineToPoints(line);
  if (testRectPoint(rect, p1) || testRectPoint(rect, p2)) {
    return true;
  }
  const rectEdges = rectToPoints(rect);
  let num = rectEdges.length;
  for (let i = 0; i < num; i++) {
    const edge = pointsToLine([rectEdges[i], rectEdges[i !== 3 ? i + 1 : 0]]);
    if (testLineLine(edge, line)) {
      return true;
    }
  }
  return false;
}
function testRectLine ( rect , line ) { if ( lineHasNoLength ( line ) || rectHasNoSize ( rect ) ) { return false ; } const [ p1 , p2 ] = lineToPoints ( line ) ; if ( testRectPoint ( rect , p1 ) || testRectPoint ( rect , p2 ) ) { return true ; } const rectEdges = rectToPoints ( rect ) ; let num = rectEdges . length ; for ( let i = 0 ; i < num ; i ++ ) { const edge = pointsToLine ( [ rectEdges [ i ] , rectEdges [ i !== 3 ? i + 1 : 0 ] ] ) ; if ( testLineLine ( edge , line ) ) { return true ; } } return false ; }
Test if a Rectangle collider with a line.
Test if a Rectangle collider with a line .