From a9bf0b097e34cb47790c925159b61d4178112550 Mon Sep 17 00:00:00 2001 From: louisremi Date: Mon, 15 Dec 2014 14:56:25 +0100 Subject: [PATCH] Handle closed path in PathFitter --- src/path/PathFitter.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/path/PathFitter.js b/src/path/PathFitter.js index 772a05a8..8d193b85 100644 --- a/src/path/PathFitter.js +++ b/src/path/PathFitter.js @@ -33,6 +33,15 @@ var PathFitter = Base.extend({ prev = point; } } + + // we need to duplicate first and last segments when simplifying a + // closed path + if ( path._closed ) { + this._closed = true; + this.points.unshift( segments[l - 1].point.clone() ); + this.points.push( segments[0].point.clone() ); + } + this.error = error; }, @@ -46,6 +55,13 @@ var PathFitter = Base.extend({ points[1].subtract(points[0]).normalize(), // Right Tangent points[length - 2].subtract(points[length - 1]).normalize()); + + // remove the duplicated segments + if ( this._closed ) { + this.segments.shift(); + this.segments.pop(); + } + return this.segments; },