Skip to content

Commit

Permalink
PanZoom: Fix very rapid zoom when using ctrl+scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
personalizedrefrigerator committed Sep 10, 2023
1 parent 876c5a1 commit be8e480
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/js-draw/src/tools/PanZoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,15 @@ export default class PanZoom extends BaseTool {
toCanvas.transformVec3(
Vec3.of(-delta.x, -delta.y, 0)
);
const pinchZoomScaleFactor = 1.03;

let pinchAmount = delta.z;

// Clamp the magnitude of pinchAmount
pinchAmount = Math.atan(pinchAmount / 2) * 2;

const pinchZoomScaleFactor = 1.04;
const transformUpdate = Mat33.scaling2D(
Math.max(0.25, Math.min(Math.pow(pinchZoomScaleFactor, -delta.z), 4)), canvasPos
Math.max(0.4, Math.min(Math.pow(pinchZoomScaleFactor, -pinchAmount), 4)), canvasPos
).rightMul(
Mat33.translation(translation)
);
Expand Down

0 comments on commit be8e480

Please sign in to comment.