src/rect.js
function doesIntersect (rect1, rect2) {
  let intersectLeftRight;
  let intersectTopBottom;

  const rect1Points = rectToPoints(rect1);
  const rect2Points = rectToPoints(rect2);

  if (rect1.width >= 0) {
    if (rect2.width >= 0) {
      intersectLeftRight = !((rect1Points.bottomRight.x <= rect2Points.topLeft.x) || (rect2Points.bottomRight.x <= rect1Points.topLeft.x));
    } else {
      intersectLeftRight = !((rect1Points.bottomRight.x <= rect2Points.bottomRight.x) || (rect2Points.topLeft.x <= rect1Points.topLeft.x));
    }
  } else if (rect2.width >= 0) {
    intersectLeftRight = !((rect1Points.topLeft.x <= rect2Points.topLeft.x) || (rect2Points.bottomRight.x <= rect1Points.bottomRight.x));
  } else {
    intersectLeftRight = !((rect1Points.topLeft.x <= rect2Points.bottomRight.x) || (rect2Points.topLeft.x <= rect1Points.bottomRight.x));
  }

  if (rect1.height >= 0) {
    if (rect2.height >= 0) {
      intersectTopBottom = !((rect1Points.bottomRight.y <= rect2Points.topLeft.y) || (rect2Points.bottomRight.y <= rect1Points.topLeft.y));
    } else {
      intersectTopBottom = !((rect1Points.bottomRight.y <= rect2Points.bottomRight.y) || (rect2Points.topLeft.y <= rect1Points.topLeft.y));
    }
  } else if (rect2.height >= 0) {
    intersectTopBottom = !((rect1Points.topLeft.y <= rect2Points.topLeft.y) || (rect2Points.bottomRight.y <= rect1Points.bottomRight.y));
  } else {
    intersectTopBottom = !((rect1Points.topLeft.y <= rect2Points.bottomRight.y) || (rect2Points.top <= rect1Points.bottomRight.y));
  }

  return intersectLeftRight && intersectTopBottom;
}
function doesIntersect (rect1, rect2) {
  let intersectLeftRight;
  let intersectTopBottom;

  const rect1Points = rectToPoints(rect1);
  const rect2Points = rectToPoints(rect2);

  if (rect1.width >= 0) {
    if (rect2.width >= 0) {
      intersectLeftRight = !((rect1Points.bottomRight.x <= rect2Points.topLeft.x) || (rect2Points.bottomRight.x <= rect1Points.topLeft.x));
    } else {
      intersectLeftRight = !((rect1Points.bottomRight.x <= rect2Points.bottomRight.x) || (rect2Points.topLeft.x <= rect1Points.topLeft.x));
    }
  } else if (rect2.width >= 0) {
    intersectLeftRight = !((rect1Points.topLeft.x <= rect2Points.topLeft.x) || (rect2Points.bottomRight.x <= rect1Points.bottomRight.x));
  } else {
    intersectLeftRight = !((rect1Points.topLeft.x <= rect2Points.bottomRight.x) || (rect2Points.topLeft.x <= rect1Points.bottomRight.x));
  }

  if (rect1.height >= 0) {
    if (rect2.height >= 0) {
      intersectTopBottom = !((rect1Points.bottomRight.y <= rect2Points.topLeft.y) || (rect2Points.bottomRight.y <= rect1Points.topLeft.y));
    } else {
      intersectTopBottom = !((rect1Points.bottomRight.y <= rect2Points.bottomRight.y) || (rect2Points.topLeft.y <= rect1Points.topLeft.y));
    }
  } else if (rect2.height >= 0) {
    intersectTopBottom = !((rect1Points.topLeft.y <= rect2Points.topLeft.y) || (rect2Points.bottomRight.y <= rect1Points.bottomRight.y));
  } else {
    intersectTopBottom = !((rect1Points.topLeft.y <= rect2Points.bottomRight.y) || (rect2Points.top <= rect1Points.bottomRight.y));
  }

  return intersectLeftRight && intersectTopBottom;
}
function doesIntersect ( rect1 , rect2 ) { let intersectLeftRight ; let intersectTopBottom ; const rect1Points = rectToPoints ( rect1 ) ; const rect2Points = rectToPoints ( rect2 ) ; if ( rect1 . width >= 0 ) { if ( rect2 . width >= 0 ) { intersectLeftRight = ! ( ( rect1Points . bottomRight . x <= rect2Points . topLeft . x ) || ( rect2Points . bottomRight . x <= rect1Points . topLeft . x ) ) ; } else { intersectLeftRight = ! ( ( rect1Points . bottomRight . x <= rect2Points . bottomRight . x ) || ( rect2Points . topLeft . x <= rect1Points . topLeft . x ) ) ; } } else if ( rect2 . width >= 0 ) { intersectLeftRight = ! ( ( rect1Points . topLeft . x <= rect2Points . topLeft . x ) || ( rect2Points . bottomRight . x <= rect1Points . bottomRight . x ) ) ; } else { intersectLeftRight = ! ( ( rect1Points . topLeft . x <= rect2Points . bottomRight . x ) || ( rect2Points . topLeft . x <= rect1Points . bottomRight . x ) ) ; } if ( rect1 . height >= 0 ) { if ( rect2 . height >= 0 ) { intersectTopBottom = ! ( ( rect1Points . bottomRight . y <= rect2Points . topLeft . y ) || ( rect2Points . bottomRight . y <= rect1Points . topLeft . y ) ) ; } else { intersectTopBottom = ! ( ( rect1Points . bottomRight . y <= rect2Points . bottomRight . y ) || ( rect2Points . topLeft . y <= rect1Points . topLeft . y ) ) ; } } else if ( rect2 . height >= 0 ) { intersectTopBottom = ! ( ( rect1Points . topLeft . y <= rect2Points . topLeft . y ) || ( rect2Points . bottomRight . y <= rect1Points . bottomRight . y ) ) ; } else { intersectTopBottom = ! ( ( rect1Points . topLeft . y <= rect2Points . bottomRight . y ) || ( rect2Points . top <= rect1Points . bottomRight . y ) ) ; } return intersectLeftRight && intersectTopBottom ; }
Returns whether two non-rotated rectangles are intersected
Returns whether two non - rotated rectangles are intersected