-
Notifications
You must be signed in to change notification settings - Fork 7.1k
/
ContainsRect.js
34 lines (31 loc) · 1022 Bytes
/
ContainsRect.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2013-2023 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
/**
* Tests if one rectangle fully contains another.
*
* @function Phaser.Geom.Rectangle.ContainsRect
* @since 3.0.0
*
* @param {Phaser.Geom.Rectangle} rectA - The first rectangle.
* @param {Phaser.Geom.Rectangle} rectB - The second rectangle.
*
* @return {boolean} True only if rectA fully contains rectB.
*/
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;
}
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)
);
};
module.exports = ContainsRect;