From 1803cd216ae6b5adb6410b5e13285b0a7fc04526 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ju=CC=88rg=20Lehni?= Date: Mon, 5 Jan 2015 00:42:00 +0100 Subject: [PATCH] Handle empty paths in Path#join() Closes #516 --- src/path/Path.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/path/Path.js b/src/path/Path.js index c02a2a0b..9f3805b5 100644 --- a/src/path/Path.js +++ b/src/path/Path.js @@ -1250,7 +1250,8 @@ var Path = PathItem.extend(/** @lends Path# */{ * Joins the path with the specified path, which will be removed in the * process. * - * @param {Path} path + * @param {Path} path the path to join this path with + * @return {Path} the joined path * * @example {@paperscript} * // Joining two paths: @@ -1316,19 +1317,20 @@ var Path = PathItem.extend(/** @lends Path# */{ var segments = path._segments, last1 = this.getLastSegment(), last2 = path.getLastSegment(); - if (last1._point.equals(last2._point)) + if (!last2) // an empty path? + return this; + if (last1 && last1._point.equals(last2._point)) path.reverse(); - var first1, - first2 = path.getFirstSegment(); - if (last1._point.equals(first2._point)) { + var first2 = path.getFirstSegment(); + if (last1 && last1._point.equals(first2._point)) { last1.setHandleOut(first2._handleOut); this._add(segments.slice(1)); } else { - first1 = this.getFirstSegment(); - if (first1._point.equals(first2._point)) + var first1 = this.getFirstSegment(); + if (first1 && first1._point.equals(first2._point)) path.reverse(); last2 = path.getLastSegment(); - if (first1._point.equals(last2._point)) { + if (first1 && first1._point.equals(last2._point)) { first1.setHandleIn(last2._handleIn); // Prepend all segments from path except the last one this._add(segments.slice(0, segments.length - 1), 0); @@ -1351,6 +1353,7 @@ var Path = PathItem.extend(/** @lends Path# */{ last.remove(); this.setClosed(true); } + return this; },