All files / core/src/loaders/utils/contourSet validateContourSet.ts

58.33% Statements 7/12
73.68% Branches 14/19
100% Functions 3/3
58.33% Lines 7/12

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      8x             8x           8x           8x 32x           32x 1192x                
import type { PublicContourSetData } from '../../../types';
 
export function validateContourSet(contourSetData: PublicContourSetData) {
  Iif (!contourSetData || contourSetData.data.length === 0) {
    throw new Error(
      'Invalid contour set data, see publicContourSetData type for more info'
    );
  }
 
  // make sure it each has id, and each has data of type Point3[]
  Iif (!contourSetData.id) {
    throw new Error(
      'Invalid contour set data, each contour set must have an id'
    );
  }
 
  Iif (!contourSetData.data || !Array.isArray(contourSetData.data)) {
    throw new Error(
      'Invalid contour set data, each contour set must have an array of contours'
    );
  }
 
  contourSetData.data.forEach((contourData) => {
    Iif (!contourData.points || !Array.isArray(contourData.points)) {
      throw new Error(
        'Invalid contour set data, each contour must have an array of points'
      );
    }
 
    contourData.points.forEach((point) => {
      Iif (!point || !Array.isArray(point) || point.length !== 3) {
        throw new Error(
          'Invalid contour set data, each point must be an array of length 3'
        );
      }
    });
  });
}