Fix spur label: position at wider end, correct mirrored angle calculation

- Move text to 65% from top (wider end) so it fits without shrinking
- Fix effective angle for mirrored symbols: use (360-rot) to determine
  if flip is needed, preventing incorrect upside-down detection

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
igurielidze 2026-03-30 21:28:04 +04:00
parent 072c80e886
commit 6b94339af2
2 changed files with 11 additions and 11 deletions

View File

@ -556,13 +556,12 @@ function drawConveyanceLabel(ctx: CanvasRenderingContext2D, sym: PlacedSymbol) {
let cx: number, cy: number, availW: number, availH: number;
if (isSpurType(sym.symbolId)) {
const w2 = sym.w2 ?? sym.w;
// Use the width at 40% from top (biased toward narrow end for safe fit)
const t = 0.4;
// Position text toward the wider end where there's more room
const t = 0.65;
const widthAtT = w2 + t * (sym.w - w2);
cx = sym.x + widthAtT / 2;
cy = sym.y + sym.h * t;
// Use narrower of top/bottom edge with padding for safe text fit
availW = Math.min(w2, widthAtT) - pad * 2;
availW = widthAtT - pad * 2;
availH = sym.h - pad * 2;
} else {
cx = sym.x + sym.w / 2;
@ -571,11 +570,11 @@ function drawConveyanceLabel(ctx: CanvasRenderingContext2D, sym: PlacedSymbol) {
availH = sym.h - pad * 2;
}
// Compute text correction so text is always readable:
// - Counter-rotate if symbol rotation makes text upside-down (91-269 deg)
// - Counter-mirror if symbol is mirrored (so text doesn't read backwards)
// Compute text correction so text is always readable.
// Mirror flips the effective angle: visual angle = (360 - rot) when mirrored.
const rot = ((sym.rotation || 0) % 360 + 360) % 360;
const needsFlip = rot > 90 && rot < 270;
const effectiveAngle = sym.mirrored ? ((360 - rot) % 360) : rot;
const needsFlip = effectiveAngle > 90 && effectiveAngle < 270;
const needsMirrorFix = !!sym.mirrored;
const hasCorrection = needsFlip || needsMirrorFix;

View File

@ -44,11 +44,11 @@ function emitConveyanceLabelInner(lines: string[], sym: PlacedSymbol) {
textRotDeg = (textRotRad * 180) / Math.PI;
} else if (isSpurType(sym.symbolId)) {
const w2 = sym.w2 ?? sym.w;
const t = 0.4;
const t = 0.65;
const widthAtT = w2 + t * (sym.w - w2);
labelCx = sym.x + widthAtT / 2;
labelCy = sym.y + sym.h * t;
availH = Math.min(sym.h - 4, widthAtT - 4);
availH = sym.h - 4;
} else if (isInductionType(sym.symbolId)) {
const stripTopY = sym.y + sym.h * INDUCTION_CONFIG.stripTopFrac;
const stripBottomY = sym.y + sym.h * INDUCTION_CONFIG.stripBottomFrac;
@ -65,7 +65,8 @@ function emitConveyanceLabelInner(lines: string[], sym: PlacedSymbol) {
let needsMirrorFix = false;
if (!isCurvedType(sym.symbolId)) {
const rot = ((sym.rotation || 0) % 360 + 360) % 360;
if (rot > 90 && rot < 270) textRotDeg = 180;
const effectiveAngle = sym.mirrored ? ((360 - rot) % 360) : rot;
if (effectiveAngle > 90 && effectiveAngle < 270) textRotDeg = 180;
needsMirrorFix = !!sym.mirrored;
}