feat: routes - auto-update - add connections

This commit is contained in:
Azgaar 2024-08-13 17:28:47 +02:00
parent e09c0e5344
commit 9e7fd25afd
2 changed files with 21 additions and 6 deletions

View file

@ -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;
}
}
}
}
}

View file

@ -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;