UNPKG

@cornerstonejs/core

Version:
26 lines (25 loc) 1.03 kB
import { mat4, vec3 } from 'gl-matrix'; export function normalizePlanarRotation(rotation = 0) { return ((rotation % 360) + 360) % 360; } export function rotatePlanarViewUp(args) { const { rotation = 0, viewPlaneNormal, viewUp } = args; const normalizedRotation = normalizePlanarRotation(rotation); if (normalizedRotation === 0) { return [...viewUp]; } const rotationMatrix = mat4.fromRotation(mat4.create(), (normalizedRotation * Math.PI) / 180, viewPlaneNormal); return vec3.transformMat4(vec3.create(), viewUp, rotationMatrix); } export function applyPlanarViewFlip(args) { const { flipHorizontal, flipVertical, viewPlaneNormal, viewUp } = args; const shouldFlipNormal = Boolean(flipHorizontal) !== Boolean(flipVertical); return { viewPlaneNormal: shouldFlipNormal ? vec3.negate(vec3.create(), viewPlaneNormal) : [...viewPlaneNormal], viewUp: flipVertical ? vec3.negate(vec3.create(), viewUp) : [...viewUp], }; }