From be8992f6818e8e23129451dc112eea1c6dc73de1 Mon Sep 17 00:00:00 2001 From: Rishabh Gupta Date: Mon, 4 Nov 2024 18:53:47 +0530 Subject: [PATCH] fix: drag Sensitivity is constant through out --- src/Schematic.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Schematic.tsx b/src/Schematic.tsx index 207baa8..53d6f41 100644 --- a/src/Schematic.tsx +++ b/src/Schematic.tsx @@ -138,12 +138,16 @@ export const SchematicWithoutContext = ({ const dy = e.clientY - lastMousePosRef.current.y lastMousePosRef.current = { x: e.clientX, y: e.clientY } - const scale = transformRef.current.a // Assuming uniform scaling - const dragSensitivity = 150 / scale // Adjust this value to change drag speed + // Transform the mouse movement to world space + const inverseTransform = inverse(transformRef.current) + const dragStart = applyToPoint(inverseTransform, { x: 0, y: 0 }) + const dragEnd = applyToPoint(inverseTransform, { x: dx, y: dy }) + const worldDx = dragEnd.x - dragStart.x + const worldDy = dragEnd.y - dragStart.y const newTransform = compose( - translate(dx * dragSensitivity, dy * dragSensitivity), transformRef.current, + translate(worldDx, worldDy), ) updateTransform(newTransform) },