Geom.Polygon.Translate is a new function that allows you to translate all the points of a polygon by the given values.

This commit is contained in:
Richard Davey 2020-07-30 12:58:35 +01:00
parent 4c6458b500
commit ce9c750175
2 changed files with 35 additions and 0 deletions

View file

@ -0,0 +1,34 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2020 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
/**
* Tranlates the points of the given Polygon.
*
* @function Phaser.Geom.Polygon.Translate
* @since 3.25.0
*
* @generic {Phaser.Geom.Polygon} O - [polygon,$return]
*
* @param {Phaser.Geom.Polygon} polygon - The Polygon to modify.
* @param {number} x - The amount to horizontally translate the points by.
* @param {number} y - The amount to vertically translate the points by.
*
* @return {Phaser.Geom.Polygon} The modified Polygon.
*/
var Translate = function (polygon, x, y)
{
var points = polygon.points;
for (var i = 0; i < points.length; i++)
{
points[i].x += x;
points[i].y += y;
}
return polygon;
};
module.exports = Translate;

View file

@ -15,5 +15,6 @@ Polygon.GetPoints = require('./GetPoints');
Polygon.Perimeter = require('./Perimeter');
Polygon.Reverse = require('./Reverse');
Polygon.Smooth = require('./Smooth');
Polygon.Translate = require('./Translate');
module.exports = Polygon;