Fix pen tool snapping

Short lines causes shapes to be closed even if the start and end point
of the shapes were far apart
This commit is contained in:
casperlamboo 2017-12-14 13:28:39 +01:00
parent 0c58b2b18c
commit 12b3e70544

View File

@ -139,6 +139,16 @@ export default function penReducer(state, action) {
.filter(({ distance }) => distance < snappingDistance) .filter(({ distance }) => distance < snappingDistance)
.sort((a, b) => a.distance - b.distance); .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, // 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 // 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 // when the point has a connection it stores the shape UID of the connected shape