Skip to content

Commit

Permalink
Merge pull request #71 from tscircuit/fix/drag-sensitivity
Browse files Browse the repository at this point in the history
fix: drag Sensitivity is constant through out
  • Loading branch information
imrishabh18 authored Nov 4, 2024
2 parents 7ac06b3 + be8992f commit ccd89fe
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Schematic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
Expand Down

0 comments on commit ccd89fe

Please sign in to comment.