mirror of
https://github.com/photonstorm/phaser
synced 2025-01-26 03:45:08 +00:00
41 lines
1 KiB
JavaScript
41 lines
1 KiB
JavaScript
|
var GetPoint = require('./GetPoint');
|
||
|
var Perimeter = require('./Perimeter');
|
||
|
|
||
|
// Return an array of points from the perimeter of the rectangle
|
||
|
// each spaced out based on the quantity or step required
|
||
|
|
||
|
/**
|
||
|
* [description]
|
||
|
*
|
||
|
* @function Phaser.Geom.Rectangle.GetPoints
|
||
|
* @since 3.0.0
|
||
|
*
|
||
|
* @param {Phaser.Geom.Rectangle} rectangle - [description]
|
||
|
* @param {number} step - [description]
|
||
|
* @param {integer} quantity - [description]
|
||
|
* @param {array} [out] - [description]
|
||
|
*
|
||
|
* @return {Phaser.Geom.Point[]} [description]
|
||
|
*/
|
||
|
var GetPoints = function (rectangle, quantity, stepRate, out)
|
||
|
{
|
||
|
if (out === undefined) { out = []; }
|
||
|
|
||
|
// If quantity is a falsey value (false, null, 0, undefined, etc) then we calculate it based on the stepRate instead.
|
||
|
if (!quantity)
|
||
|
{
|
||
|
quantity = Perimeter(rectangle) / stepRate;
|
||
|
}
|
||
|
|
||
|
for (var i = 0; i < quantity; i++)
|
||
|
{
|
||
|
var position = i / quantity;
|
||
|
|
||
|
out.push(GetPoint(rectangle, position));
|
||
|
}
|
||
|
|
||
|
return out;
|
||
|
};
|
||
|
|
||
|
module.exports = GetPoints;
|