phaser/src/geom/rectangle/Contains.js
2018-10-19 12:32:43 +01:00

29 lines
871 B
JavaScript

/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2018 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
/**
* Checks if a given point is inside a Rectangle's bounds.
*
* @function Phaser.Geom.Rectangle.Contains
* @since 3.0.0
*
* @param {Phaser.Geom.Rectangle} rect - The Rectangle to check.
* @param {number} x - The X coordinate of the point to check.
* @param {number} y - The Y coordinate of the point to check.
*
* @return {boolean} `true` if the point is within the Rectangle's bounds, otherwise `false`.
*/
var Contains = function (rect, x, y)
{
if (rect.width <= 0 || rect.height <= 0)
{
return false;
}
return (rect.x <= x && rect.x + rect.width >= x && rect.y <= y && rect.y + rect.height >= y);
};
module.exports = Contains;