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

100% Statements 32/32
50% Branches 1/2
100% Functions 12/12
100% Lines 31/31

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          838x 13468x 2514x 198x         1x       1x         1x   1x     3x             837x 837x     837x     837x             837x 6696x   837x 5022x     837x     2511x           837x   6619x   6619x 6619x           837x   103x   103x 103x           837x   12x   12x 12x                          
/* eslint-disable arrow-body-style */
import otherStaticMethods from 'vtk.js/Sources/Rendering/Core/Mapper/Static';
import macro from 'vtk.js/Sources/macros';
 
function addCoincidentTopologyMethods(publicAPI, model, nameList) {
  nameList.forEach((item) => {
    publicAPI[`get${item.method}`] = () => model[item.key];
    publicAPI[`set${item.method}`] = (factor, offset) => {
      model[item.key] = { 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 staticOffsetAPI = {};
 
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).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,
};