From d43fc62994476027b751cdec08acfaa5c2baa95d Mon Sep 17 00:00:00 2001 From: Quincy Morgan <2046746+quincylvania@users.noreply.github.com> Date: Fri, 9 Oct 2020 09:48:52 -0400 Subject: [PATCH] Divide up the `step_count` tag value proportionally when splitting ways (close #8069) --- modules/actions/split.js | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/modules/actions/split.js b/modules/actions/split.js index 4baea8648..24874f199 100644 --- a/modules/actions/split.js +++ b/modules/actions/split.js @@ -120,16 +120,49 @@ export function actionSplit(nodeIds, newWayIds) { nodesB = wayA.nodes.slice(idx); } + var lengthA = totalLengthBetweenNodes(graph, nodesA); + var lengthB = totalLengthBetweenNodes(graph, nodesB); + if (_keepHistoryOn === 'longest' && - totalLengthBetweenNodes(graph, nodesB) > totalLengthBetweenNodes(graph, nodesA)) { + lengthB > lengthA) { // keep the history on the longer way, regardless of the node count wayA = wayA.update({ nodes: nodesB }); wayB = wayB.update({ nodes: nodesA }); + + var temp = lengthA; + lengthA = lengthB; + lengthB = temp; } else { wayA = wayA.update({ nodes: nodesA }); wayB = wayB.update({ nodes: nodesB }); } + if (wayA.tags.step_count) { + // divide up the the step count proportionally between the two ways + + var stepCount = parseFloat(wayA.tags.step_count); + if (stepCount && + // ensure a number + isFinite(stepCount) && + // ensure positive + stepCount > 0 && + // ensure integer + Math.round(stepCount) === stepCount) { + + var tagsA = Object.assign({}, wayA.tags); + var tagsB = Object.assign({}, wayB.tags); + + var ratioA = lengthA / (lengthA + lengthB); + var countA = Math.round(stepCount * ratioA); + tagsA.step_count = countA.toString(); + tagsB.step_count = (stepCount - countA).toString(); + + wayA = wayA.update({ tags: tagsA }); + wayB = wayB.update({ tags: tagsB }); + } + } + + graph = graph.replace(wayA); graph = graph.replace(wayB);