food_chain/gestures.js

5 lines
422 B
JavaScript
Raw Permalink Normal View History

2026-09-29 19:10:03 +09:00
// Keep the world point under the gesture midpoint while fingers move or zoom.
export function pinchCamera(start,a,b,rect,view,worldWidth,worldHeight){
const zoom=Math.max(1,Math.min(32,start.zoom*Math.hypot(a.x-b.x,a.y-b.y)/start.distance)),s=zoom*view.base;
return {zoom,panX:(a.x+b.x)/2-rect.left-start.anchorX*s-(view.width-worldWidth*s)/2,panY:(a.y+b.y)/2-rect.top-start.anchorY*s-(view.height-worldHeight*s)/2};
}