phaser/src/geom/rectangle/ContainsRect.js

35 lines
1,017 B
JavaScript
Raw Normal View History

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-13 13:11:54 +00:00
/**
2018-10-19 11:32:43 +00:00
* Tests if one rectangle fully contains another.
2017-10-13 13:11:54 +00:00
*
* @function Phaser.Geom.Rectangle.ContainsRect
* @since 3.0.0
*
2018-10-19 11:32:43 +00:00
* @param {Phaser.Geom.Rectangle} rectA - The first rectangle.
* @param {Phaser.Geom.Rectangle} rectB - The second rectangle.
2017-10-13 13:11:54 +00:00
*
2018-10-19 11:32:43 +00:00
* @return {boolean} True only if rectA fully contains rectB.
2017-10-13 13:11:54 +00:00
*/
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) &&
2018-02-16 18:17:51 +00:00
(rectB.y > rectA.y && rectB.y < rectA.bottom) &&
2017-01-25 12:16:47 +00:00
(rectB.bottom > rectA.y && rectB.bottom < rectA.bottom)
);
2016-12-20 17:07:16 +00:00
};
module.exports = ContainsRect;