diff --git a/modules/dynamic/auto-update.js b/modules/dynamic/auto-update.js index 8de40683..7d25962e 100644 --- a/modules/dynamic/auto-update.js +++ b/modules/dynamic/auto-update.js @@ -867,9 +867,7 @@ export function resolveVersionConflicts(version) { delete cells.crossroad; pack.routes = []; - pack.cells.routes = {}; - - const POINT_DISTANCE = 10; + const POINT_DISTANCE = grid.spacing * 0.75; routes.selectAll("g").each(function () { const group = this.id; @@ -881,7 +879,7 @@ export function resolveVersionConflicts(version) { const increment = totalLength / Math.ceil(totalLength / POINT_DISTANCE); const points = []; - for (let i = 0; i <= totalLength; i += increment) { + for (let i = 0; i <= totalLength + 0.1; i += increment) { const point = node.getPointAtLength(i); const x = rn(point.x, 2); const y = rn(point.y, 2); @@ -900,5 +898,21 @@ export function resolveVersionConflicts(version) { routes.selectAll("path").remove(); if (layerIsOn("toggleRoutes")) drawRoutes(); + + const links = (pack.cells.routes = {}); + for (const route of pack.routes) { + for (let i = 0; i < route.points.length - 1; i++) { + const cellId = route.points[i][2]; + const nextCellId = route.points[i + 1][2]; + + if (cellId !== nextCellId) { + if (!links[cellId]) links[cellId] = {}; + links[cellId][nextCellId] = route.i; + + if (!links[nextCellId]) links[nextCellId] = {}; + links[nextCellId][cellId] = route.i; + } + } + } } } diff --git a/modules/routes-generator.js b/modules/routes-generator.js index c5a88988..376e9d03 100644 --- a/modules/routes-generator.js +++ b/modules/routes-generator.js @@ -179,10 +179,11 @@ window.Routes = (function () { for (const {points, i: routeId} of routes) { const cells = points.map(p => p[2]); - for (let i = 0; i < cells.length; i++) { + for (let i = 0; i < cells.length - 1; i++) { const cellId = cells[i]; const nextCellId = cells[i + 1]; - if (nextCellId && cellId !== nextCellId) { + + if (cellId !== nextCellId) { if (!links[cellId]) links[cellId] = {}; links[cellId][nextCellId] = routeId;