phaser/src/geom/rectangle/ContainsRect.js

37 lines
1,022 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}
*/
2016-12-20 17:07:16 +00:00
// Checks if rectB is fully contained within rectA
2017-10-13 13:11:54 +00:00
/**
* [description]
*
* @function Phaser.Geom.Rectangle.ContainsRect
* @since 3.0.0
*
* @param {Phaser.Geom.Rectangle} rectA - [description]
* @param {Phaser.Geom.Rectangle} rectB - [description]
*
* @return {boolean} [description]
*/
2016-12-20 17:07:16 +00:00
var ContainsRect = function (rectA, rectB)
{
// Volume check (if rectB volume > rectA then rectA cannot contain it)
if ((rectB.width * rectB.height) > (rectA.width * rectA.height))
{
return false;
}
2017-01-25 12:16:47 +00:00
return (
(rectB.x > rectA.x && rectB.x < rectA.right) &&
(rectB.right > rectA.x && rectB.right < rectA.right) &&
(rectB.y > rectA.y && rectB.y < rectA.bottom) &&
(rectB.bottom > rectA.y && rectB.bottom < rectA.bottom)
);
2016-12-20 17:07:16 +00:00
};
module.exports = ContainsRect;