phaser
Version:
A fast, free and fun HTML5 Game Framework for Desktop and Mobile web browsers from the team at Phaser Studio Inc.
32 lines (27 loc) • 1.13 kB
JavaScript
/**
* @author Richard Davey <rich@phaser.io>
* @copyright 2013-2026 Phaser Studio Inc.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
/**
* Creates an array of plain `{x, y}` point objects for each of the four corners of a Rectangle, in the order: top-left, top-right, bottom-right, bottom-left.
* If an output array is provided, each point object will be pushed to the end of it, otherwise a new array will be created and returned.
*
* @function Phaser.Geom.Rectangle.Decompose
* @since 3.0.0
*
* @param {Phaser.Geom.Rectangle} rect - The Rectangle object to be decomposed.
* @param {array} [out] - If provided, each point will be added to this array.
*
* @return {array} Will return the array you specified or a new array containing the points of the Rectangle.
*/
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;