Skip to content

Commit aaa90ba

Browse files
committed
Tidied up the EllipseCurve arguments
1 parent 05d251a commit aaa90ba

1 file changed

Lines changed: 19 additions & 6 deletions

File tree

v3/src/paths/curves/ellipse/EllipseCurve.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
var Curve = require('../Curve');
44
var Class = require('../../../utils/Class');
5+
var DegToRad = require('../../../math/DegToRad');
6+
var Vector2 = require('../../../math/Vector2');
57

68
// Phaser.Curves.Ellipse
79

@@ -13,6 +15,12 @@ var EllipseCurve = new Class({
1315

1416
function EllipseCurve (aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation)
1517
{
18+
if (yRadius === undefined) { yRadius = xRadius; }
19+
if (aStartAngle === undefined) { aStartAngle = 0; }
20+
if (aEndAngle === undefined) { aEndAngle = 360; }
21+
if (aClockwise === undefined) { aClockwise = false; }
22+
if (aRotation === undefined) { aRotation = 0; }
23+
1624
Curve.call(this);
1725

1826
this.aX = aX;
@@ -21,16 +29,21 @@ var EllipseCurve = new Class({
2129
this.xRadius = xRadius;
2230
this.yRadius = yRadius;
2331

24-
this.aStartAngle = aStartAngle;
25-
this.aEndAngle = aEndAngle;
32+
// Radians
33+
this.aStartAngle = DegToRad(aStartAngle);
34+
this.aEndAngle = DegToRad(aEndAngle);
2635

36+
// Boolean (anti-clockwise direction)
2737
this.aClockwise = aClockwise;
2838

29-
this.aRotation = aRotation || 0;
39+
// The rotation of the arc
40+
this.aRotation = DegToRad(aRotation);
3041
},
3142

32-
getPoint: function (t)
43+
getPoint: function (t, out)
3344
{
45+
if (out === undefined) { out = new Vector2(); }
46+
3447
var twoPi = Math.PI * 2;
3548
var deltaAngle = this.aEndAngle - this.aStartAngle;
3649
var samePoints = Math.abs( deltaAngle ) < Number.EPSILON;
@@ -58,7 +71,7 @@ var EllipseCurve = new Class({
5871
}
5972
}
6073

61-
if (this.aClockwise === true && ! samePoints)
74+
if (this.aClockwise && ! samePoints)
6275
{
6376
if (deltaAngle === twoPi)
6477
{
@@ -87,7 +100,7 @@ var EllipseCurve = new Class({
87100
y = tx * sin + ty * cos + this.aY;
88101
}
89102

90-
return new Vector2(x, y);
103+
return out.set(x, y);
91104
}
92105

93106
});

0 commit comments

Comments
 (0)