SHARE
TWEET

circleRectangleIntersection

ulfben Jan 10th, 2016 99 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public function circleRectangleIntersection(circle:Entity, rect:Entity):Boolean
  2. {
  3.     var closestX:Number = circle.x < rect.x ? rect.x : circle.x > (rect.x+rect.width) ? (rect.x+rect.width) : circle.x;
  4.     var closestY:Number = circle.y < rect.y ? rect.y : circle.y > (rect.y+rect.height) ? (rect.y+rect.height) : circle.y;
  5.     var dx:Number = closestX-circle.x;
  6.     var dy:Number = closestY-circle.y;
  7.     return ((dy*dy)+(dx*dx) < (circle.radius*circle.radius));
  8. }
RAW Paste Data
Top