From 2e552853fd39c7b28226e0c9d321712d6f3e1a52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Tue, 13 Oct 2015 07:23:15 +0200 Subject: [PATCH] Handle paths as circular lists in CurveLocation.insert() as well. Relates to #805 --- src/path/CurveLocation.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/path/CurveLocation.js b/src/path/CurveLocation.js index 6326d802..5ba720d5 100644 --- a/src/path/CurveLocation.js +++ b/src/path/CurveLocation.js @@ -300,7 +300,7 @@ var CurveLocation = Base.extend(/** @lends CurveLocation# */{ // NOTE: We need to compare both by (index + parameter) and by // proximity of points, see: // https://github.com/paperjs/paper.js/issues/784#issuecomment-143161586 - // We need to wrap the diff value around the path beginning / end. + // We need to wrap the diff value around the path's beginning / end. var c1 = this.getCurve(), c2 = loc.getCurve(); diff = ((c1.isLast() && c2.isFirst() ? -1 : c1.getIndex()) @@ -488,6 +488,13 @@ new function() { // Scope for statics break; if (loc.equals(loc2)) return loc2; + // If we reach the beginning/end of the list, also compare with + // the location at the other end, as paths are circular lists. + if (i === 0 || i === length - 1) { + loc2 = locations[i === 0 ? length - 1 : 0]; + if (loc.equals(loc2)) + return loc2; + } } return null; }