phaser/src/geom/rectangle/MergeRect.js

39 lines
990 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
// 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
/**
* [description]
*
* @function Phaser.Geom.Rectangle.MergeRect
* @since 3.0.0
*
* @param {Phaser.Geom.Rectangle} target - [description]
* @param {Phaser.Geom.Rectangle} source - [description]
*
* @return {Phaser.Geom.Rectangle} [description]
*/
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;