Skip to content

Commit 9596f7c

Browse files
authored
Merge pull request phaserjs#4864 from rexrainbow/curve-improvement
Curve improvement
2 parents a52831d + 4c6cac5 commit 9596f7c

2 files changed

Lines changed: 32 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 divisions is falsy. Ignored if divisions is positive.
300+
* @param {(array|Phaser.Math.Vector2[])} [out] - An optional array to store the points in.
299301
*
300-
* @return {Phaser.Math.Vector2[]} [description]
302+
* @return {(array|Phaser.Math.Vector2[])} An array of Points from the curve.
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
/**

src/curves/LineCurve.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,18 @@ var LineCurve = new Class({
6161
* @since 3.0.0
6262
*/
6363
this.p1 = p1;
64+
65+
// Override default Curve.arcLengthDivisions
66+
67+
/**
68+
* The quantity of arc length divisions within the curve.
69+
*
70+
* @name Phaser.Curves.Line#arcLengthDivisions
71+
* @type {integer}
72+
* @default 1
73+
* @since 3.0.0
74+
*/
75+
this.arcLengthDivisions = 1;
6476
},
6577

6678
/**

0 commit comments

Comments
 (0)