From db12a30701e9017fc4015fdd90f785fdaa315993 Mon Sep 17 00:00:00 2001 From: igurielidze Date: Mon, 30 Mar 2026 15:20:33 +0400 Subject: [PATCH] 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) --- svelte-app/src/lib/canvas/interactions.ts | 34 ++--------------------- 1 file changed, 3 insertions(+), 31 deletions(-) diff --git a/svelte-app/src/lib/canvas/interactions.ts b/svelte-app/src/lib/canvas/interactions.ts index 541214a..01dcb22 100644 --- a/svelte-app/src/lib/canvas/interactions.ts +++ b/svelte-app/src/lib/canvas/interactions.ts @@ -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 {