Skip to content

Commit 5f53466

Browse files
committed
Add stepRate argument in getPoints method
1 parent a52831d commit 5f53466

1 file changed

Lines changed: 20 additions & 7 deletions

File tree

src/curves/Curve.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -295,22 +295,35 @@ var Curve = new Class({
295295
* @method Phaser.Curves.Curve#getPoints
296296
* @since 3.0.0
297297
*
298-
* @param {integer} [divisions] - [description]
298+
* @param {integer} divisions - The number of evenly spaced points from the curve to return. If falsy, step param will be used to calculate the number of points.
299+
* @param {number} step - Step between points. Used to calculate the number of points to return when quantity is falsy. Ignored if quantity is positive.
300+
* @param {(array|Phaser.Geom.Point[])} [out] - An optional array to store the points in.
299301
*
300-
* @return {Phaser.Math.Vector2[]} [description]
302+
* @return {(array|Phaser.Geom.Point[])} An array of Points from the perimeter of the rectangle.
301303
*/
302-
getPoints: function (divisions)
304+
getPoints: function (divisions, stepRate, out)
303305
{
304-
if (divisions === undefined) { divisions = this.defaultDivisions; }
306+
if (out === undefined) { out = []; }
305307

306-
var points = [];
308+
// If divisions is a falsey value (false, null, 0, undefined, etc) then we calculate it based on the stepRate instead.
309+
if (!divisions)
310+
{
311+
if (!stepRate)
312+
{
313+
divisions = this.defaultDivisions;
314+
}
315+
else
316+
{
317+
divisions = this.getLength() / stepRate;
318+
}
319+
}
307320

308321
for (var d = 0; d <= divisions; d++)
309322
{
310-
points.push(this.getPoint(d / divisions));
323+
out.push(this.getPoint(d / divisions));
311324
}
312325

313-
return points;
326+
return out;
314327
},
315328

316329
/**

0 commit comments

Comments
 (0)