UNPKG

@cornerstonejs/core

Version:
26 lines (25 loc) 1.18 kB
import { normalizePlanarScale } from './planarCameraScale.js'; import { normalizePlanarViewState } from './planarViewState.js'; export function getPlanarProjectionFallbackPan(viewState, canvasWidth, canvasHeight) { const anchorCanvas = viewState.anchorCanvas ?? [0.5, 0.5]; const anchorWorld = viewState.anchorWorld ?? [0, 0, 0]; const [scaleX, scaleY] = normalizePlanarScale(viewState.scale); return [ (0 - anchorWorld[0]) * scaleX + (anchorCanvas[0] - 0.5) * canvasWidth, (0 - anchorWorld[1]) * scaleY + (anchorCanvas[1] - 0.5) * canvasHeight, ]; } export function getPlanarProjectionFallbackViewStateWithPan(viewState, nextPan, canvasWidth, canvasHeight) { const currentPan = getPlanarProjectionFallbackPan(viewState, canvasWidth, canvasHeight); const [ax, ay] = viewState.anchorCanvas ?? [0.5, 0.5]; const deltaX = nextPan[0] - currentPan[0]; const deltaY = nextPan[1] - currentPan[1]; return normalizePlanarViewState({ ...viewState, anchorCanvas: [ ax + deltaX / Math.max(canvasWidth, 1), ay + deltaY / Math.max(canvasHeight, 1), ], displayArea: undefined, }); }