Fix EPC jump on mouseup: stop shifting origin in recalcEpcBounds

Just expand w/h to cover the full waypoint extent without moving
sym.x/y. The origin-shifting math was causing the symbol to jump
in the direction of waypoint movement on mouse release.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
igurielidze 2026-03-30 15:20:33 +04:00
parent c3da2da20d
commit db12a30701

View File

@ -370,37 +370,9 @@ function recalcEpcBounds(sym: typeof layout.symbols[0]) {
// Add small padding
minX -= 1; minY -= 1; maxX += 1; maxY += 1;
const newW = Math.max(maxX - minX, 1);
const newH = Math.max(maxY - minY, 1);
// Compute old and new rotation centers (local space)
const oldCx = sym.w / 2;
const oldCy = sym.h / 2;
const newCx = minX + newW / 2;
const newCy = minY + newH / 2;
// Shift origin so the rotation center stays at the same world position.
// For rotated symbols, the center offset must be rotated into world space.
const dCx = newCx - oldCx;
const dCy = newCy - oldCy;
if (sym.rotation) {
const rad = (sym.rotation * Math.PI) / 180;
const cos = Math.cos(rad), sin = Math.sin(rad);
sym.x += cos * dCx - sin * dCy;
sym.y += sin * dCx + cos * dCy;
} else {
sym.x += dCx;
sym.y += dCy;
}
// Adjust waypoints so their local coords are relative to the new origin
for (const wp of wps) {
wp.x -= minX;
wp.y -= minY;
}
sym.w = newW;
sym.h = newH;
// Don't shift origin — just expand w/h to cover full extent from (0,0)
sym.w = Math.max(maxX - Math.min(minX, 0), 1);
sym.h = Math.max(maxY - Math.min(minY, 0), 1);
}
function snapWidth(w: number, ctrlKey: boolean, minW: number = CONVEYOR_MIN_W): number {