From 8d2c2f5fda57217bdba5533db60192321eb55f95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Fri, 1 Mar 2013 14:28:32 -0800 Subject: [PATCH] Fix an issue with PathFitter where path with only one segment would throw an error. Closes #175. --- src/path/PathFitter.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/path/PathFitter.js b/src/path/PathFitter.js index 42b0d801..2fab15fd 100644 --- a/src/path/PathFitter.js +++ b/src/path/PathFitter.js @@ -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; },