From c642375295820add563f721ff470deec7daf9c46 Mon Sep 17 00:00:00 2001 From: Casper Lamboo Date: Wed, 2 May 2018 17:39:27 +0200 Subject: [PATCH] update containLineInPath func --- src/sliceActions/helpers/comb.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/sliceActions/helpers/comb.js b/src/sliceActions/helpers/comb.js index 80e7b41..cabe83a 100644 --- a/src/sliceActions/helpers/comb.js +++ b/src/sliceActions/helpers/comb.js @@ -205,16 +205,18 @@ function findClosestPath(map, start, end) { } function containLineInPath(path, start, end, vertices) { - const line = [start]; + let line = [start]; for (let i = 0; i < path.length; i ++) { const { edge: [indexA, indexB] } = path[i]; const vertexA = vertices[indexA]; const vertexB = vertices[indexB]; + const lastPoint = line[line.length - 1]; - const intersection = lineIntersection(start, end, vertexA, vertexB); + const intersection = lineIntersection(lastPoint, end, vertexA, vertexB); if (!intersection) { - const lastPoint = line[line.length - 1]; + line = containLineInPath(path.slice(0, i), start, lastPoint, vertices); + const distanceA = distanceTo(lastPoint, vertexA) + distanceTo(vertexA, end); const distanceB = distanceTo(lastPoint, vertexB) + distanceTo(vertexB, end);