All files / core/src/RenderingEngine/GenericViewport/Volume3D volume3DProjectionPresentation.ts

0% Statements 0/6
0% Branches 0/4
0% Functions 0/4
0% Lines 0/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51                                                                                                     
import { cloneVolume3DCamera } from './volume3DProjectionCamera';
import type {
  Volume3DProjectionPresentation,
  Volume3DProjectionSnapshot,
} from './Volume3DProjectionTypes';
import type { Volume3DCamera } from './viewport3DTypes';
 
function isWrappedVolume3DPresentation(
  presentation: Partial<Volume3DProjectionPresentation>
): presentation is Partial<Volume3DProjectionPresentation> & {
  camera: Partial<Volume3DCamera>;
} {
  return Object.prototype.hasOwnProperty.call(presentation, 'camera');
}
 
function getCameraPatch(
  presentation: Partial<Volume3DProjectionPresentation>
): Partial<Volume3DCamera> {
  if (isWrappedVolume3DPresentation(presentation)) {
    return presentation.camera ?? {};
  }
 
  return presentation as unknown as Partial<Volume3DCamera>;
}
 
/**
 * Converts a Volume3D projection snapshot to the existing wrapped camera
 * presentation shape used by 3D tools.
 */
export function getVolume3DProjectionPresentation(
  snapshot: Volume3DProjectionSnapshot
): Volume3DProjectionPresentation {
  return {
    ...snapshot.presentation,
    camera: cloneVolume3DCamera(snapshot.presentation.camera),
  };
}
 
/**
 * Applies wrapped or raw 3D camera presentation patches to the snapshot camera.
 */
export function withVolume3DProjectionPresentation(
  snapshot: Volume3DProjectionSnapshot,
  presentation: Partial<Volume3DProjectionPresentation>
): Volume3DCamera {
  return cloneVolume3DCamera({
    ...snapshot.presentation.camera,
    ...getCameraPatch(presentation),
  } as Volume3DCamera);
}