From eb4a570a70a1cf07081eab2e77cb4f670ccc97b4 Mon Sep 17 00:00:00 2001 From: igurielidze Date: Mon, 30 Mar 2026 15:17:18 +0400 Subject: [PATCH] Fix EPC waypoint jumping: defer bounds recalc to mouseup Updating sym.w/h mid-drag shifted the rotation center used by toSymbolLocal, causing waypoints to jump. Now recalcEpcBounds only runs on mouseup, keeping the coordinate transform stable. Also removed the endpoint slide constraint that was causing instability due to using the moving position as direction source. Co-Authored-By: Claude Opus 4.6 (1M context) --- svelte-app/src/lib/canvas/interactions.ts | 26 ++++------------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/svelte-app/src/lib/canvas/interactions.ts b/svelte-app/src/lib/canvas/interactions.ts index c4559aa..70fe533 100644 --- a/svelte-app/src/lib/canvas/interactions.ts +++ b/svelte-app/src/lib/canvas/interactions.ts @@ -469,29 +469,9 @@ function onMousemove(e: MouseEvent) { localY = worldSnappedY - sym.y; } - // Constrain first/last waypoint to slide along their segment direction only - // (extend/shorten without rotating the end boxes) - if (wpIdx === 0 && wps.length >= 2) { - const next = wps[1]; - const dx = wps[0].x - next.x, dy = wps[0].y - next.y; - const len = Math.sqrt(dx * dx + dy * dy) || 1; - const ux = dx / len, uy = dy / len; - const dot = (localX - next.x) * ux + (localY - next.y) * uy; - localX = next.x + ux * dot; - localY = next.y + uy * dot; - } else if (wpIdx === wps.length - 1 && wps.length >= 2) { - const prev = wps[wps.length - 2]; - const dx = wps[wpIdx].x - prev.x, dy = wps[wpIdx].y - prev.y; - const len = Math.sqrt(dx * dx + dy * dy) || 1; - const ux = dx / len, uy = dy / len; - const dot = (localX - prev.x) * ux + (localY - prev.y) * uy; - localX = prev.x + ux * dot; - localY = prev.y + uy * dot; - } - wps[wpIdx] = { x: localX, y: localY }; - // Recalculate bounding box - recalcEpcBounds(sym); + // Defer recalcEpcBounds to mouseup — updating w/h mid-drag shifts + // the rotation center in toSymbolLocal, causing waypoints to jump. layout.markDirty(); } @@ -738,6 +718,8 @@ function onMouseup(e: MouseEvent) { } if (dragState.type === 'epc-waypoint' && dragState.dragActivated) { + const sym = layout.symbols.find(s => s.id === dragState!.placedId); + if (sym) recalcEpcBounds(sym); layout.markDirty(); layout.saveMcmState(); }