Fix an issue with PathFitter where path with only one segment would throw an error.

Closes #175.
This commit is contained in:
Jürg Lehni 2013-03-01 14:28:32 -08:00
parent b79e32194c
commit 8d2c2f5fda

View file

@ -32,13 +32,15 @@ var PathFitter = Base.extend({
},
fit: function() {
this.segments = [new Segment(this.points[0])];
this.fitCubic(0, this.points.length - 1,
var points = this.points,
length = points.length;
this.segments = length > 0 ? [new Segment(points[0])] : [];
if (length > 1)
this.fitCubic(0, length - 1,
// Left Tangent
this.points[1].subtract(this.points[0]).normalize(),
points[1].subtract(points[0]).normalize(),
// Right Tangent
this.points[this.points.length - 2].subtract(
this.points[this.points.length - 1]).normalize());
points[length - 2].subtract(points[length - 1]).normalize());
return this.segments;
},