mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -05:00
Fix an issue with PathFitter where path with only one segment would throw an error.
Closes #175.
This commit is contained in:
parent
b79e32194c
commit
8d2c2f5fda
1 changed files with 7 additions and 5 deletions
|
@ -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;
|
||||
},
|
||||
|
||||
|
|
Loading…
Reference in a new issue