Fix spur label clamping: align right edge of text to angled edge

Previous min() was wrong — pushed text further right when text was
wider than available space. Now uses max() to keep text left-aligned
within the trapezoid while right edge stays at the angled boundary.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
igurielidze 2026-03-30 21:43:15 +04:00
parent 07ace0d3f4
commit 7f9fb6608c
2 changed files with 3 additions and 3 deletions

View File

@ -565,8 +565,8 @@ function drawConveyanceLabel(ctx: CanvasRenderingContext2D, sym: PlacedSymbol) {
// Right edge at top of text — text must not exceed this
const textTop = optCy - th / 2;
const rightEdge = w2 + (Math.max(0, textTop) / sym.h) * (sym.w - w2);
// Place text so right side of text = rightEdge (hard clamp)
cx = sym.x + Math.min(rightEdge / 2, rightEdge - maxTextW / 2);
// Align text right edge to the angled edge, clamped left at 0
cx = sym.x + Math.max(maxTextW / 2, rightEdge - maxTextW / 2);
cy = sym.y + optCy;
availW = Infinity;
availH = sym.h;

View File

@ -51,7 +51,7 @@ function emitConveyanceLabelInner(lines: string[], sym: PlacedSymbol) {
const rightEdge = w2 + (Math.max(0, textTop) / sym.h) * (sym.w - w2);
// Estimate text width (~8px per char at 14px bold)
const estTextW = Math.max(...textLines.map(l => l.length * 8));
labelCx = sym.x + Math.min(rightEdge / 2, rightEdge - estTextW / 2);
labelCx = sym.x + Math.max(estTextW / 2, rightEdge - estTextW / 2);
labelCy = sym.y + optCy;
availH = sym.h;
} else if (isInductionType(sym.symbolId)) {