From 7f9fb6608c81e1de02e336e33ca25a5007438cd5 Mon Sep 17 00:00:00 2001 From: igurielidze Date: Mon, 30 Mar 2026 21:43:15 +0400 Subject: [PATCH] Fix spur label clamping: align right edge of text to angled edge MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- svelte-app/src/lib/canvas/renderer.ts | 4 ++-- svelte-app/src/lib/export.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/svelte-app/src/lib/canvas/renderer.ts b/svelte-app/src/lib/canvas/renderer.ts index d3eaab1..1c86c71 100644 --- a/svelte-app/src/lib/canvas/renderer.ts +++ b/svelte-app/src/lib/canvas/renderer.ts @@ -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; diff --git a/svelte-app/src/lib/export.ts b/svelte-app/src/lib/export.ts index 2398881..4361fc5 100644 --- a/svelte-app/src/lib/export.ts +++ b/svelte-app/src/lib/export.ts @@ -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)) {