-
Notifications
You must be signed in to change notification settings - Fork 7.1k
/
MergeXY.js
38 lines (32 loc) · 1.08 KB
/
MergeXY.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
35
36
37
38
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2013-2023 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
/**
* Merges a Rectangle with a point by repositioning and/or resizing it so that the point is on or within its bounds.
*
* @function Phaser.Geom.Rectangle.MergeXY
* @since 3.0.0
*
* @generic {Phaser.Geom.Rectangle} O - [target,$return]
*
* @param {Phaser.Geom.Rectangle} target - The Rectangle which should be merged and modified.
* @param {number} x - The X coordinate of the point which should be merged.
* @param {number} y - The Y coordinate of the point which should be merged.
*
* @return {Phaser.Geom.Rectangle} The modified `target` Rectangle.
*/
var MergeXY = function (target, x, y)
{
var minX = Math.min(target.x, x);
var maxX = Math.max(target.right, x);
target.x = minX;
target.width = maxX - minX;
var minY = Math.min(target.y, y);
var maxY = Math.max(target.bottom, y);
target.y = minY;
target.height = maxY - minY;
return target;
};
module.exports = MergeXY;