phaser/src/geom/rectangle/MergeRect.js

42 lines
1.3 KiB
JavaScript
Raw Normal View History

2018-02-12 16:01:20 +00:00
/**
* @author Richard Davey <rich@photonstorm.com>
2019-01-15 16:20:22 +00:00
* @copyright 2019 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
*/
2016-12-20 17:07:16 +00:00
// Merges source rectangle into target rectangle and returns target
// Neither rect should have negative widths or heights
2017-10-13 13:11:54 +00:00
/**
2018-09-27 14:29:32 +00:00
* Merges the source rectangle into the target rectangle and returns the target.
* Neither rectangle should have a negative width or height.
2017-10-13 13:11:54 +00:00
*
* @function Phaser.Geom.Rectangle.MergeRect
* @since 3.0.0
*
2018-03-27 13:27:08 +00:00
* @generic {Phaser.Geom.Rectangle} O - [target,$return]
*
2018-09-27 14:29:32 +00:00
* @param {Phaser.Geom.Rectangle} target - Target rectangle. Will be modified to include source rectangle.
* @param {Phaser.Geom.Rectangle} source - Rectangle that will be merged into target rectangle.
2017-10-13 13:11:54 +00:00
*
2018-09-27 14:29:32 +00:00
* @return {Phaser.Geom.Rectangle} Modified target rectangle that contains source rectangle.
2017-10-13 13:11:54 +00:00
*/
2016-12-20 17:07:16 +00:00
var MergeRect = function (target, source)
{
var minX = Math.min(target.x, source.x);
var maxX = Math.max(target.right, source.right);
target.x = minX;
target.width = maxX - minX;
var minY = Math.min(target.y, source.y);
var maxY = Math.max(target.bottom, source.bottom);
target.y = minY;
target.height = maxY - minY;
return target;
};
module.exports = MergeRect;