mirror of
https://github.com/photonstorm/phaser
synced 2024-11-23 21:24:09 +00:00
Circle.isEmpty and Circle Intersection functions.
This commit is contained in:
parent
14fe0b1713
commit
b5b86595d9
3 changed files with 49 additions and 0 deletions
|
@ -39,6 +39,11 @@ Circle.prototype = {
|
|||
this.y = y;
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
isEmpty: function ()
|
||||
{
|
||||
return (this._radius <= 0);
|
||||
}
|
||||
|
||||
};
|
||||
|
|
8
v3/src/geom/intersects/CircleVsCircle.js
Normal file
8
v3/src/geom/intersects/CircleVsCircle.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
var DistanceBetween = require('../../math/distance/DistanceBetween');
|
||||
|
||||
var CircleVsCircle = function (circleA, circleB)
|
||||
{
|
||||
return (DistanceBetween(circleA.x, circleA.y, circleB.x, circleB.y) <= (circleA.radius + circleB.radius));
|
||||
};
|
||||
|
||||
module.exports = CircleVsCircle;
|
36
v3/src/geom/intersects/CircleVsRectangle.js
Normal file
36
v3/src/geom/intersects/CircleVsRectangle.js
Normal file
|
@ -0,0 +1,36 @@
|
|||
var CircleVsRectangle = function (circle, rectangle)
|
||||
{
|
||||
var halfWidth = rectangle.width / 2;
|
||||
var halfHeight = rectangle.height / 2;
|
||||
|
||||
var cx = Math.abs(circle.x - rectangle.x - halfWidth);
|
||||
var xDist = halfWidth + circle.radius;
|
||||
|
||||
if (cx > xDist)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var cy = Math.abs(circle.y - rectangle.y - halfHeight);
|
||||
var yDist = halfHeight + circle.radius;
|
||||
|
||||
if (cy > yDist)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (cx <= halfWidth || cy <= halfHeight)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
var xCornerDist = cx - halfWidth;
|
||||
var yCornerDist = cy - halfHeight;
|
||||
var xCornerDistSq = xCornerDist * xCornerDist;
|
||||
var yCornerDistSq = yCornerDist * yCornerDist;
|
||||
var maxCornerDistSq = circle.radius * circle.radius;
|
||||
|
||||
return xCornerDistSq + yCornerDistSq <= maxCornerDistSq;
|
||||
};
|
||||
|
||||
module.exports = CircleVsRectangle;
|
Loading…
Reference in a new issue