Skip to content

Commit 0156f4f

Browse files
committed
Fixed order of returns
1 parent ffeff9d commit 0156f4f

1 file changed

Lines changed: 14 additions & 14 deletions

File tree

v3/src/geom/intersects/CircleToRectangle.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,28 @@ var CircleToRectangle = function (circle, rect)
1515
var halfHeight = rect.height / 2;
1616

1717
var cx = Math.abs(circle.x - rect.x - halfWidth);
18+
var cy = Math.abs(circle.y - rect.y - halfHeight);
1819
var xDist = halfWidth + circle.radius;
20+
var yDist = halfHeight + circle.radius;
1921

20-
if (cx <= halfWidth || cx > xDist)
22+
if (cx > xDist || cy > yDist)
2123
{
2224
return false;
2325
}
24-
25-
var cy = Math.abs(circle.y - rect.y - halfHeight);
26-
var yDist = halfHeight + circle.radius;
27-
28-
if (cy <= halfHeight || cy > yDist)
26+
else if (cx <= halfWidth || cy <= halfHeight)
2927
{
30-
return false;
28+
return true;
3129
}
30+
else
31+
{
32+
var xCornerDist = cx - halfWidth;
33+
var yCornerDist = cy - halfHeight;
34+
var xCornerDistSq = xCornerDist * xCornerDist;
35+
var yCornerDistSq = yCornerDist * yCornerDist;
36+
var maxCornerDistSq = circle.radius * circle.radius;
3237

33-
var xCornerDist = cx - halfWidth;
34-
var yCornerDist = cy - halfHeight;
35-
var xCornerDistSq = xCornerDist * xCornerDist;
36-
var yCornerDistSq = yCornerDist * yCornerDist;
37-
var maxCornerDistSq = circle.radius * circle.radius;
38-
39-
return (xCornerDistSq + yCornerDistSq <= maxCornerDistSq);
38+
return (xCornerDistSq + yCornerDistSq <= maxCornerDistSq);
39+
}
4040
};
4141

4242
module.exports = CircleToRectangle;

0 commit comments

Comments
 (0)