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) <noreply@anthropic.com>
This commit is contained in:
igurielidze 2026-03-30 15:17:18 +04:00
parent 81e0bd0f3d
commit eb4a570a70

View File

@ -469,29 +469,9 @@ function onMousemove(e: MouseEvent) {
localY = worldSnappedY - sym.y; 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 }; wps[wpIdx] = { x: localX, y: localY };
// Recalculate bounding box // Defer recalcEpcBounds to mouseup — updating w/h mid-drag shifts
recalcEpcBounds(sym); // the rotation center in toSymbolLocal, causing waypoints to jump.
layout.markDirty(); layout.markDirty();
} }
@ -738,6 +718,8 @@ function onMouseup(e: MouseEvent) {
} }
if (dragState.type === 'epc-waypoint' && dragState.dragActivated) { if (dragState.type === 'epc-waypoint' && dragState.dragActivated) {
const sym = layout.symbols.find(s => s.id === dragState!.placedId);
if (sym) recalcEpcBounds(sym);
layout.markDirty(); layout.markDirty();
layout.saveMcmState(); layout.saveMcmState();
} }