function testCircleRect(circle, rect) {
  if (rectHasNoSize(rect) || circleHasNoSize(circle)) {
    return false;
  }
  const rX = rect.width / 2;
  const rY = rect.height / 2;
  const rcX = rect.x + rX;
  const rcY = rect.y + rY;
  const r = circle.r;
  const cx = circle.cx;
  const cy = circle.cy;
  const dX = Math.abs(cx - rcX);
  const dY = Math.abs(cy - rcY);

  if (dX > rX + r || dY > rY + r) {
    return false;
  }

  if (dX <= rX || dY <= rY) {
    return true;
  }

  const sqrDist = Math.pow(dX - rX, 2) + Math.pow(dY - rY, 2);

  return sqrDist <= Math.pow(r, 2);
}
/**
 * Test if a Circle collide with a rectangle. If so, returns true and false otherwise.
 * Circle muse have a radius greater then 0.
 * Rectangle must have a width and height greather then 0.
 * @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} 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 circle collide with rectangle
 */
Test if a Circle collide with a rectangle. If so, returns true and false otherwise.
Circle muse have a radius greater then 0.
Rectangle must have a width and height greather then 0.
Test if a Circle collide with a rectangle . If so returns true and false otherwise . Circle muse have a radius greater then 0 . Rectangle must have a width and height greather then 0 .
function testCircleRect(circle, rect) {
  if (rectHasNoSize(rect) || circleHasNoSize(circle)) {
    return false;
  }
  const rX = rect.width / 2;
  const rY = rect.height / 2;
  const rcX = rect.x + rX;
  const rcY = rect.y + rY;
  const r = circle.r;
  const cx = circle.cx;
  const cy = circle.cy;
  const dX = Math.abs(cx - rcX);
  const dY = Math.abs(cy - rcY);
  if (dX > rX + r || dY > rY + r) {
    return false;
  }
  if (dX <= rX || dY <= rY) {
    return true;
  }
  const sqrDist = Math.pow(dX - rX, 2) + Math.pow(dY - rY, 2);
  return sqrDist <= Math.pow(r, 2);
}
function testCircleRect ( circle , rect ) { if ( rectHasNoSize ( rect ) || circleHasNoSize ( circle ) ) { return false ; } const rX = rect . width / 2 ; const rY = rect . height / 2 ; const rcX = rect . x + rX ; const rcY = rect . y + rY ; const r = circle . r ; const cx = circle . cx ; const cy = circle . cy ; const dX = Math . abs ( cx - rcX ) ; const dY = Math . abs ( cy - rcY ) ; if ( dX > rX + r || dY > rY + r ) { return false ; } if ( dX <= rX || dY <= rY ) { return true ; } const sqrDist = Math . pow ( dX - rX , 2 ) + Math . pow ( dY - rY , 2 ) ; return sqrDist <= Math . pow ( r , 2 ) ; }
Test if a Circle collide with a rectangle.
Test if a Circle collide with a rectangle .