2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2020-01-15 12:07:09 +00:00
|
|
|
* @copyright 2020 Photon Storm Ltd.
|
2019-05-10 15:15:04 +00:00
|
|
|
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
2018-02-12 16:01:20 +00:00
|
|
|
*/
|
|
|
|
|
2017-10-04 23:58:42 +00:00
|
|
|
/**
|
2018-01-26 04:18:22 +00:00
|
|
|
* Check to see if the Circle contains the given x / y coordinates.
|
2017-10-04 23:58:42 +00:00
|
|
|
*
|
|
|
|
* @function Phaser.Geom.Circle.Contains
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-01-26 04:18:22 +00:00
|
|
|
* @param {Phaser.Geom.Circle} circle - The Circle to check.
|
|
|
|
* @param {number} x - The x coordinate to check within the circle.
|
|
|
|
* @param {number} y - The y coordinate to check within the circle.
|
2017-10-13 13:11:54 +00:00
|
|
|
*
|
2018-01-26 04:18:22 +00:00
|
|
|
* @return {boolean} True if the coordinates are within the circle, otherwise false.
|
2017-10-04 23:58:42 +00:00
|
|
|
*/
|
2016-12-29 00:17:20 +00:00
|
|
|
var Contains = function (circle, x, y)
|
|
|
|
{
|
|
|
|
// Check if x/y are within the bounds first
|
|
|
|
if (circle.radius > 0 && x >= circle.left && x <= circle.right && y >= circle.top && y <= circle.bottom)
|
|
|
|
{
|
|
|
|
var dx = (circle.x - x) * (circle.x - x);
|
|
|
|
var dy = (circle.y - y) * (circle.y - y);
|
|
|
|
|
|
|
|
return (dx + dy) <= (circle.radius * circle.radius);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = Contains;
|