All files / packages/tools/src/utilities/viewportFilters filterViewportsWithParallelNormals.ts

100% Statements 4/4
100% Branches 1/1
100% Functions 2/2
100% Lines 4/4

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                            101x 102x     102x     102x          
import { vec3 } from 'gl-matrix';
 
/**
 * It filters the viewports that are looking in the same view as the camera
 * It basically checks if the viewPlaneNormal is parallel to the camera viewPlaneNormal
 * @param viewports - Array of viewports to filter
 * @param camera - Camera to compare against
 * @returns - Array of viewports with the same view
 */
export function filterViewportsWithParallelNormals(
  viewports,
  camera,
  EPS = 0.999
) {
  return viewports.filter((viewport) => {
    const vpCamera = viewport.getCamera();
 
    const isParallel =
      Math.abs(vec3.dot(vpCamera.viewPlaneNormal, camera.viewPlaneNormal)) >
      EPS;
 
    return isParallel;
  });
}
 
export default filterViewportsWithParallelNormals;