All files / Sources/Rendering/Core/Mapper CoincidentTopologyHelper.js

100% Statements 34/34
50% Branches 1/2
100% Functions 13/13
100% Lines 32/32

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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120                  846x 13581x 2538x                     1x       1x         4x 1x       1x     3x             845x 845x     845x     845x             845x 7605x   845x 5915x   5070x     845x     2535x           845x   6664x   6664x 6664x           845x   103x   103x 103x           845x   22x   22x 22x                            
/* eslint-disable arrow-body-style */
import otherStaticMethods, {
  Resolve,
} from 'vtk.js/Sources/Rendering/Core/Mapper/Static';
import macro from 'vtk.js/Sources/macros';
 
export { Resolve } from 'vtk.js/Sources/Rendering/Core/Mapper/Static';
 
function addCoincidentTopologyMethods(publicAPI, model, nameList) {
  nameList.forEach((item) => {
    publicAPI[`get${item.method}`] = () => model[item.key];
    publicAPI[`set${item.method}`] = macro.objectSetterMap.object(
      publicAPI,
      model,
      {
        name: item.key,
        params: ['factor', 'offset'],
      }
    );
  });
}
 
export const CATEGORIES = ['Polygon', 'Line', 'Point'];
 
// CoincidentTopology static methods ------------------------------------------
 
const staticOffsetModel = {
  Polygon: { factor: 2, offset: 0 },
  Line: { factor: 1, offset: -1 },
  Point: { factor: 0, offset: -2 },
};
const noOp = () => undefined;
const staticOffsetAPI = {
  modified: noOp,
};
 
addCoincidentTopologyMethods(
  staticOffsetAPI,
  staticOffsetModel,
  CATEGORIES.map((key) => ({
    key,
    method: `ResolveCoincidentTopology${key}OffsetParameters`,
  }))
);
 
function implementCoincidentTopologyMethods(publicAPI, model) {
  if (model.resolveCoincidentTopology === undefined) {
    model.resolveCoincidentTopology = false;
  }
 
  macro.setGet(publicAPI, model, ['resolveCoincidentTopology']);
 
  // Relative methods
  model.topologyOffset = {
    Polygon: { factor: 0, offset: 0 },
    Line: { factor: 0, offset: 0 },
    Point: { factor: 0, offset: 0 },
  };
 
  // Add Static methods to our instance
  Object.keys(otherStaticMethods).forEach((methodName) => {
    publicAPI[methodName] = otherStaticMethods[methodName];
  });
  Object.keys(staticOffsetAPI)
    .filter((methodName) => methodName !== 'modified') // don't override instance's modified
    .forEach((methodName) => {
      publicAPI[methodName] = staticOffsetAPI[methodName];
    });
 
  addCoincidentTopologyMethods(
    publicAPI,
    model.topologyOffset,
    CATEGORIES.map((key) => ({
      key,
      method: `RelativeCoincidentTopology${key}OffsetParameters`,
    }))
  );
 
  publicAPI.getCoincidentTopologyPolygonOffsetParameters = () => {
    const globalValue =
      staticOffsetAPI.getResolveCoincidentTopologyPolygonOffsetParameters();
    const localValue =
      publicAPI.getRelativeCoincidentTopologyPolygonOffsetParameters();
    return {
      factor: globalValue.factor + localValue.factor,
      offset: globalValue.offset + localValue.offset,
    };
  };
 
  publicAPI.getCoincidentTopologyLineOffsetParameters = () => {
    const globalValue =
      staticOffsetAPI.getResolveCoincidentTopologyLineOffsetParameters();
    const localValue =
      publicAPI.getRelativeCoincidentTopologyLineOffsetParameters();
    return {
      factor: globalValue.factor + localValue.factor,
      offset: globalValue.offset + localValue.offset,
    };
  };
 
  publicAPI.getCoincidentTopologyPointOffsetParameter = () => {
    const globalValue =
      staticOffsetAPI.getResolveCoincidentTopologyPointOffsetParameters();
    const localValue =
      publicAPI.getRelativeCoincidentTopologyPointOffsetParameters();
    return {
      factor: globalValue.factor + localValue.factor,
      offset: globalValue.offset + localValue.offset,
    };
  };
}
 
export default {
  implementCoincidentTopologyMethods,
  staticOffsetAPI,
  otherStaticMethods,
  CATEGORIES,
  Resolve,
};