forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetNumberArray.js
More file actions
37 lines (32 loc) · 1.21 KB
/
Copy pathGetNumberArray.js
File metadata and controls
37 lines (32 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2020 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
// Export the points as an array of flat numbers, following the sequence [ x,y, x,y, x,y ]
/**
* Stores all of the points of a Polygon into a flat array of numbers following the sequence [ x,y, x,y, x,y ],
* i.e. each point of the Polygon, in the order it's defined, corresponds to two elements of the resultant
* array for the point's X and Y coordinate.
*
* @function Phaser.Geom.Polygon.GetNumberArray
* @since 3.0.0
*
* @generic {number[]} O - [output,$return]
*
* @param {Phaser.Geom.Polygon} polygon - The Polygon whose points to export.
* @param {(array|number[])} [output] - An array to which the points' coordinates should be appended.
*
* @return {(array|number[])} The modified `output` array, or a new array if none was given.
*/
var GetNumberArray = function (polygon, output)
{
if (output === undefined) { output = []; }
for (var i = 0; i < polygon.points.length; i++)
{
output.push(polygon.points[i].x);
output.push(polygon.points[i].y);
}
return output;
};
module.exports = GetNumberArray;