phaser/src/geom/rectangle/Decompose.js

32 lines
1,016 B
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
*/
2017-10-13 13:11:54 +00:00
/**
2018-09-24 22:20:43 +00:00
* Create an array of points for each corner of a Rectangle
* If an array is specified, each point object will be added to the end of the array, otherwise a new array will be created.
2017-10-13 13:11:54 +00:00
*
* @function Phaser.Geom.Rectangle.Decompose
* @since 3.0.0
*
2018-09-24 22:20:43 +00:00
* @param {Phaser.Geom.Rectangle} rect - The Rectangle object to be decomposed.
* @param {array} [out] - If provided, each point will be added to this array.
2017-10-13 13:11:54 +00:00
*
2018-09-24 22:20:43 +00:00
* @return {array} Will return the array you specified or a new array containing the points of the Rectangle.
2017-10-13 13:11:54 +00:00
*/
var Decompose = function (rect, out)
{
if (out === undefined) { out = []; }
out.push({ x: rect.x, y: rect.y });
out.push({ x: rect.right, y: rect.y });
out.push({ x: rect.right, y: rect.bottom });
out.push({ x: rect.x, y: rect.bottom });
return out;
};
module.exports = Decompose;