Skip to content

Commit de239f9

Browse files
committed
Fix branch turn offset direction for both train directions
1 parent 645c604 commit de239f9

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

src/svgs/shmetro/main-shmetro.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,9 @@ export const _linePath = (
354354
const [xm, ym] = path['end'];
355355

356356
// turnX: vertical turn position, offset from bifurcation point towards branch
357-
const branchDirection = xBranch > xBifurcate ? 1 : -1;
357+
// Offset moves turnX in the opposite direction of train travel (towards branch)
358+
const branchOnRight = xBranch > xBifurcate;
359+
const branchDirection = branchOnRight ? 1 : -1;
358360
const turnX = xBifurcate + branchDirection * branchOffset;
359361

360362
if (type === 'main') {
@@ -369,7 +371,7 @@ export const _linePath = (
369371
} else {
370372
// main line, left direction, upper to center (merging back to main line)
371373
if (bend === 'rightangle') {
372-
return `M ${x},${y} V ${ym} H ${turnX} H ${xm}`;
374+
return `M ${x},${y} H ${turnX} V ${ym} H ${xm}`;
373375
}
374376
// upper to center/rightangle, center to lower/diagonal
375377
else return `M ${x - e1},${y} H ${xBranch + e2} L ${xm - e2},${ym} H ${xm}`;
@@ -404,7 +406,7 @@ export const _linePath = (
404406
} else {
405407
// pass line, left direction, upper to center (merging)
406408
if (bend === 'rightangle') {
407-
return `M ${x},${y} V ${ym} H ${turnX} H ${xm + e1}`;
409+
return `M ${x},${y} H ${turnX} V ${ym} H ${xm + e1}`;
408410
}
409411
// upper to center/rightangle, center to lower/diagonal
410412
else return `M ${x - e1},${y} H ${xBranch + e2} L ${xm - e2},${ym} H ${xm}`;

0 commit comments

Comments
 (0)