function intersects(circle, rect){
      var circleDistance = {};
      circleDistance.x = Math.abs(circle.x - rect.left);
      circleDistance.y = Math.abs(circle.y - rect.top);
  
      if (circleDistance.x > (rect.width/2 + circle.rad)) { return false; }
      if (circleDistance.y > (rect.height/2 + circle.rad)) { return false; }
  
      if (circleDistance.x <= (rect.width/2)) { return true; } 
      if (circleDistance.y <= (rect.height/2)) { return true; }
  
      var cornerDistance_sq = Math.pow(circleDistance.x - rect.width/2, 2) +
                              Math.pow(circleDistance.y - rect.height/2, 2);
  
      return (cornerDistance_sq <= Math.pow(circle.r, 2));
  }