From 12b3e705447427fb7d93b7eaa5f8502d8f20dc6a Mon Sep 17 00:00:00 2001 From: casperlamboo Date: Thu, 14 Dec 2017 13:28:39 +0100 Subject: [PATCH] Fix pen tool snapping Short lines causes shapes to be closed even if the start and end point of the shapes were far apart --- src/reducer/d2/tools/penReducer.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/reducer/d2/tools/penReducer.js b/src/reducer/d2/tools/penReducer.js index e20b6d0..e06e663 100644 --- a/src/reducer/d2/tools/penReducer.js +++ b/src/reducer/d2/tools/penReducer.js @@ -139,6 +139,16 @@ export default function penReducer(state, action) { .filter(({ distance }) => distance < snappingDistance) .sort((a, b) => a.distance - b.distance); + const hits = snappingPoints.map(snappingPoint => snappingPoint.hit); + if (hits.includes('start-end') && hits.includes('end-end')) { + const index = Math.max(hits.indexOf('start-end') && hits.indexOf('end-end')); + snappingPoints.splice(index, 1); + } + if (hits.includes('start-start') && hits.includes('end-start')) { + const index = Math.max(hits.indexOf('start-start') && hits.indexOf('end-start')); + snappingPoints.splice(index, 1); + } + // the active shape's start and end points can only be connected to one other shape, // this variable can be used to check if the start or end point is already been snapped to // when the point has a connection it stores the shape UID of the connected shape