From 4108e9487b7c4bee9ead976bd8cfb60c52809ff2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Mon, 31 Mar 2014 19:33:38 +0200 Subject: [PATCH] Add optional joining behavior to PathItem#closePath() again and use it in #setPathData(). --- src/path/CompoundPath.js | 4 ++-- src/path/Path.js | 4 +++- src/path/PathItem.js | 6 ++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/path/CompoundPath.js b/src/path/CompoundPath.js index bc44bedd..9258f596 100644 --- a/src/path/CompoundPath.js +++ b/src/path/CompoundPath.js @@ -297,8 +297,8 @@ var CompoundPath = PathItem.extend(/** @lends CompoundPath# */{ this.moveTo(last ? point.add(last._point) : point); }, - closePath: function() { - getCurrentPath(this, true).closePath(); + closePath: function(join) { + getCurrentPath(this, true).closePath(join); } }; diff --git a/src/path/Path.js b/src/path/Path.js index 4dca46fb..48e0ea55 100644 --- a/src/path/Path.js +++ b/src/path/Path.js @@ -2515,8 +2515,10 @@ var Path = PathItem.extend(/** @lends Path# */{ } }, - closePath: function() { + closePath: function(join) { this.setClosed(true); + if (join) + this.join(); } }; }, { // A dedicated scope for the tricky bounds calculations diff --git a/src/path/PathItem.js b/src/path/PathItem.js index b80d9483..1b122257 100644 --- a/src/path/PathItem.js +++ b/src/path/PathItem.js @@ -227,7 +227,7 @@ var PathItem = Item.extend(/** @lends PathItem# */{ case 'l': var move = lower === 'm'; if (move && previous && previous !== 'z') - this.closePath(); + this.closePath(true); for (var j = 0; j < length; j += 2) this[j === 0 && move ? 'moveTo' : 'lineTo']( current = getPoint(j)); @@ -290,7 +290,7 @@ var PathItem = Item.extend(/** @lends PathItem# */{ } break; case 'z': - this.closePath(); + this.closePath(true); break; } previous = lower; @@ -563,6 +563,8 @@ var PathItem = Item.extend(/** @lends PathItem# */{ * * @name PathItem#closePath * @function + * @param {Boolean} join controls whether the method should attempt to merge + * the first segment with the last if they lie in the same location. * @see Path#closed */