phaser/src/geom/rectangle/Contains.js

30 lines
871 B
JavaScript
Raw Normal View History

2018-02-12 16:01:20 +00:00
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2018 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
2017-10-13 13:11:54 +00:00
/**
2018-10-19 11:32:43 +00:00
* Checks if a given point is inside a Rectangle's bounds.
2017-10-13 13:11:54 +00:00
*
* @function Phaser.Geom.Rectangle.Contains
* @since 3.0.0
*
2018-10-19 11:32:43 +00:00
* @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.
2017-10-13 13:11:54 +00:00
*
2018-10-19 11:32:43 +00:00
* @return {boolean} `true` if the point is within the Rectangle's bounds, otherwise `false`.
2017-10-13 13:11:54 +00:00
*/
2016-12-29 00:17:20 +00:00
var Contains = function (rect, x, y)
2016-12-20 17:07:16 +00:00
{
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);
};
2016-12-29 00:17:20 +00:00
module.exports = Contains;