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:
parent
072c80e886
commit
6b94339af2
@ -556,13 +556,12 @@ function drawConveyanceLabel(ctx: CanvasRenderingContext2D, sym: PlacedSymbol) {
|
|||||||
let cx: number, cy: number, availW: number, availH: number;
|
let cx: number, cy: number, availW: number, availH: number;
|
||||||
if (isSpurType(sym.symbolId)) {
|
if (isSpurType(sym.symbolId)) {
|
||||||
const w2 = sym.w2 ?? sym.w;
|
const w2 = sym.w2 ?? sym.w;
|
||||||
// Use the width at 40% from top (biased toward narrow end for safe fit)
|
// Position text toward the wider end where there's more room
|
||||||
const t = 0.4;
|
const t = 0.65;
|
||||||
const widthAtT = w2 + t * (sym.w - w2);
|
const widthAtT = w2 + t * (sym.w - w2);
|
||||||
cx = sym.x + widthAtT / 2;
|
cx = sym.x + widthAtT / 2;
|
||||||
cy = sym.y + sym.h * t;
|
cy = sym.y + sym.h * t;
|
||||||
// Use narrower of top/bottom edge with padding for safe text fit
|
availW = widthAtT - pad * 2;
|
||||||
availW = Math.min(w2, widthAtT) - pad * 2;
|
|
||||||
availH = sym.h - pad * 2;
|
availH = sym.h - pad * 2;
|
||||||
} else {
|
} else {
|
||||||
cx = sym.x + sym.w / 2;
|
cx = sym.x + sym.w / 2;
|
||||||
@ -571,11 +570,11 @@ function drawConveyanceLabel(ctx: CanvasRenderingContext2D, sym: PlacedSymbol) {
|
|||||||
availH = sym.h - pad * 2;
|
availH = sym.h - pad * 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute text correction so text is always readable:
|
// Compute text correction so text is always readable.
|
||||||
// - Counter-rotate if symbol rotation makes text upside-down (91-269 deg)
|
// Mirror flips the effective angle: visual angle = (360 - rot) when mirrored.
|
||||||
// - Counter-mirror if symbol is mirrored (so text doesn't read backwards)
|
|
||||||
const rot = ((sym.rotation || 0) % 360 + 360) % 360;
|
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 needsMirrorFix = !!sym.mirrored;
|
||||||
const hasCorrection = needsFlip || needsMirrorFix;
|
const hasCorrection = needsFlip || needsMirrorFix;
|
||||||
|
|
||||||
|
|||||||
@ -44,11 +44,11 @@ function emitConveyanceLabelInner(lines: string[], sym: PlacedSymbol) {
|
|||||||
textRotDeg = (textRotRad * 180) / Math.PI;
|
textRotDeg = (textRotRad * 180) / Math.PI;
|
||||||
} else if (isSpurType(sym.symbolId)) {
|
} else if (isSpurType(sym.symbolId)) {
|
||||||
const w2 = sym.w2 ?? sym.w;
|
const w2 = sym.w2 ?? sym.w;
|
||||||
const t = 0.4;
|
const t = 0.65;
|
||||||
const widthAtT = w2 + t * (sym.w - w2);
|
const widthAtT = w2 + t * (sym.w - w2);
|
||||||
labelCx = sym.x + widthAtT / 2;
|
labelCx = sym.x + widthAtT / 2;
|
||||||
labelCy = sym.y + sym.h * t;
|
labelCy = sym.y + sym.h * t;
|
||||||
availH = Math.min(sym.h - 4, widthAtT - 4);
|
availH = sym.h - 4;
|
||||||
} else if (isInductionType(sym.symbolId)) {
|
} else if (isInductionType(sym.symbolId)) {
|
||||||
const stripTopY = sym.y + sym.h * INDUCTION_CONFIG.stripTopFrac;
|
const stripTopY = sym.y + sym.h * INDUCTION_CONFIG.stripTopFrac;
|
||||||
const stripBottomY = sym.y + sym.h * INDUCTION_CONFIG.stripBottomFrac;
|
const stripBottomY = sym.y + sym.h * INDUCTION_CONFIG.stripBottomFrac;
|
||||||
@ -65,7 +65,8 @@ function emitConveyanceLabelInner(lines: string[], sym: PlacedSymbol) {
|
|||||||
let needsMirrorFix = false;
|
let needsMirrorFix = false;
|
||||||
if (!isCurvedType(sym.symbolId)) {
|
if (!isCurvedType(sym.symbolId)) {
|
||||||
const rot = ((sym.rotation || 0) % 360 + 360) % 360;
|
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;
|
needsMirrorFix = !!sym.mirrored;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user