Skip to content

Commit 9ea2070

Browse files
committed
Spline.addPoints method will take multi-format data types
1 parent cfec61f commit 9ea2070

1 file changed

Lines changed: 35 additions & 1 deletion

File tree

v3/src/paths/curves/spline/SplineCurve.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,41 @@ var SplineCurve = new Class({
2020

2121
Curve.call(this);
2222

23-
this.points = points;
23+
// if points is an array of numbers ...
24+
25+
this.points = [];
26+
27+
this.addPoints(points);
28+
},
29+
30+
addPoints: function (points)
31+
{
32+
for (var i = 0; i < points.length; i++)
33+
{
34+
var p = new Vector2();
35+
36+
if (typeof points[i] === 'number')
37+
{
38+
p.x = points[i];
39+
p.y = points[i + 1];
40+
i++;
41+
}
42+
else if (Array.isArray(entry))
43+
{
44+
// An array of arrays?
45+
p.x = points[i][0];
46+
p.y = points[i][1];
47+
}
48+
else
49+
{
50+
p.x = points[i].x;
51+
p.y = points[i].y;
52+
}
53+
54+
this.points.push(p);
55+
}
56+
57+
return this;
2458
},
2559

2660
addPoint: function (x, y)

0 commit comments

Comments
 (0)