Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/hooks/useCanvasInteraction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ import { useEffect, useRef, useCallback } from 'react';
import type { RefObject } from 'react';
import { useAppStore } from '../store/useAppStore';
import { screenToImage, clamp, computeFitZoom, pointInRect } from '../lib/geometry';
import { MIN_ZOOM, MAX_ZOOM, ZOOM_STEP, MIN_BOX_SIZE, HANDLE_HALFSIZE_PX } from '../lib/constants';
import {
MIN_ZOOM,
MAX_ZOOM,
ZOOM_FACTOR,
MIN_BOX_SIZE,
HANDLE_HALFSIZE_PX,
} from '../lib/constants';
import type { DragHandle, DragState } from '../lib/types';

export interface DrawingState {
Expand Down Expand Up @@ -200,8 +206,8 @@ export function useCanvasInteraction(
if (e.ctrlKey || e.metaKey) {
// Zoom toward cursor — must prevent browser zoom
e.preventDefault();
const delta = e.deltaY < 0 ? ZOOM_STEP : -ZOOM_STEP;
applyZoom(zoom + delta, e.offsetX, e.offsetY);
const factor = e.deltaY < 0 ? ZOOM_FACTOR : 1 / ZOOM_FACTOR;
applyZoom(zoom * factor, e.offsetX, e.offsetY);
} else if (e.shiftKey) {
// Horizontal pan
const d = e.deltaX || e.deltaY;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ export const CLASSES: AnnotationClass[] = [

export const MIN_ZOOM = 0.25;
export const MAX_ZOOM = 5.0;
export const ZOOM_STEP = 0.1;
export const ZOOM_FACTOR = 1.1; // multiplicative zoom instead of additive
export const MIN_BOX_SIZE = 4; // px in image space, ignore smaller drags
export const HANDLE_HALFSIZE_PX = 4; // half-size of resize handles in screen pixels (8px total)
6 changes: 3 additions & 3 deletions src/store/useAppStore.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { create } from 'zustand';
import type { Annotation, EditMode } from '../lib/types';
import { CLASSES, MIN_ZOOM, MAX_ZOOM, ZOOM_STEP } from '../lib/constants';
import { CLASSES, MIN_ZOOM, MAX_ZOOM, ZOOM_FACTOR } from '../lib/constants';
import { clamp, computeFitZoom } from '../lib/geometry';

interface AppState {
Expand Down Expand Up @@ -175,7 +175,7 @@ export const useAppStore = create<AppState>((set) => ({
canvasWidth && imageWidth
? computeFitZoom(canvasWidth, canvasHeight, imageWidth, imageHeight)
: MIN_ZOOM;
const newZoom = clamp(zoom + ZOOM_STEP, minZoom, MAX_ZOOM);
const newZoom = clamp(zoom * ZOOM_FACTOR, minZoom, MAX_ZOOM);
if (newZoom === zoom) return;
const cx = canvasWidth / 2;
const cy = canvasHeight / 2;
Expand All @@ -191,7 +191,7 @@ export const useAppStore = create<AppState>((set) => ({
canvasWidth && imageWidth
? computeFitZoom(canvasWidth, canvasHeight, imageWidth, imageHeight)
: MIN_ZOOM;
const newZoom = clamp(zoom - ZOOM_STEP, minZoom, MAX_ZOOM);
const newZoom = clamp(zoom / ZOOM_FACTOR, minZoom, MAX_ZOOM);
if (newZoom === zoom) return;
const cx = canvasWidth / 2;
const cy = canvasHeight / 2;
Expand Down
Loading