Moved from private git forge to gitlab
This commit is contained in:
24
src/utils/interaction.ts
Normal file
24
src/utils/interaction.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import { ViewportOffset, CONSTANTS } from '../types';
|
||||
import { clamp, calculateDistance } from './math';
|
||||
|
||||
// Zoom-related functions
|
||||
export const calculateZoomDelta = (
|
||||
wheelDelta: number,
|
||||
accelerationFactor: number,
|
||||
baseMultiplier = 0.001
|
||||
): number => clamp(wheelDelta * baseMultiplier * accelerationFactor, -0.5, 0.5);
|
||||
|
||||
export const calculateInitialViewport = (initialZoom: number): ViewportOffset => ({
|
||||
x: (CONSTANTS.VIRTUAL_CANVAS_SIZE - window.innerWidth / initialZoom) / 2,
|
||||
y: (CONSTANTS.VIRTUAL_CANVAS_SIZE - window.innerHeight / initialZoom) / 2,
|
||||
});
|
||||
|
||||
export const clampZoom = (zoom: number): number =>
|
||||
clamp(zoom, CONSTANTS.ZOOM_LEVELS.min, CONSTANTS.ZOOM_LEVELS.max);
|
||||
|
||||
// Touch-related functions
|
||||
export const calculateTouchDistance = (touch1: React.Touch | Touch, touch2: React.Touch | Touch): number =>
|
||||
calculateDistance(touch1.clientX, touch1.clientY, touch2.clientX, touch2.clientY);
|
||||
|
||||
export const calculateZoomFactor = (currentDistance: number, startDistance: number): number =>
|
||||
startDistance > 0 ? currentDistance / startDistance : 1;
|
Reference in New Issue
Block a user