From 2ad47ce8de3f05106cc50fb409a0c74bbe16ff8e Mon Sep 17 00:00:00 2001 From: Aron Helser Date: Tue, 15 May 2018 15:18:10 -0400 Subject: [PATCH] fix(InpHelper): use minmax to fill interior of coreshape with 1 More pleasing calculated coreshape, filling in the interior based on the display technique from ImageGenerator. --- src/utils/ImageGenerator.js | 23 ++--------------------- src/utils/InpHelper.js | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 21 deletions(-) diff --git a/src/utils/ImageGenerator.js b/src/utils/ImageGenerator.js index 29868be..2699daf 100644 --- a/src/utils/ImageGenerator.js +++ b/src/utils/ImageGenerator.js @@ -3,6 +3,7 @@ import vtkColorTransferFunction from 'vtk.js/Sources/Rendering/Core/ColorTransfe import ColorManager from './ColorManager'; import ImageReady from './ImageReady'; import ModelHelper from './ModelHelper'; +import InpHelper from './InpHelper'; let idFor3D = 1; @@ -298,27 +299,7 @@ function updateLayoutImage( if (item.coreShape) { // display an indication of the core shape on editor coremaps. ctx.beginPath(); - const minmax = []; - minmax[-1] = [width, -1]; - for (let j = 0; j < width; j++) { - const halfJ = j < width / 2 ? j : width - j - 1; - let minI = width; - let maxI = -1; - for (let i = 0; i < width; i++) { - if (item.coreShape[j * width + i]) { - minI = Math.min(minI, i); - maxI = Math.max(maxI, i + 1); - } - } - minmax[halfJ] = minmax[halfJ] - ? [Math.min(minI, minmax[halfJ][0]), Math.max(maxI, minmax[halfJ][1])] - : [minI, maxI]; - } - for (let j = 1; j < width / 2; j++) { - // the previous row, away from the middle, sets a bound. - minmax[j][0] = Math.min(minmax[j - 1][0], minmax[j][0]); - minmax[j][1] = Math.max(minmax[j - 1][1], minmax[j][1]); - } + const minmax = InpHelper.getCoreShapeMinMax(item.coreShape, width); // console.log(...minmax); for (let j = 0; j <= width; j++) { const halfJ = j < width / 2 ? j : width - j - 1; diff --git a/src/utils/InpHelper.js b/src/utils/InpHelper.js index a374c68..2723f6a 100644 --- a/src/utils/InpHelper.js +++ b/src/utils/InpHelper.js @@ -190,6 +190,31 @@ function stripCoreZeros(textMap, coreMap, pad = '') { return lines.join(`\n${pad}`); } +function getCoreShapeMinMax(coreShape, width) { + const minmax = []; + minmax[-1] = [width, -1]; + for (let j = 0; j < width; j++) { + const halfJ = j < width / 2 ? j : width - j - 1; + let minI = width; + let maxI = -1; + for (let i = 0; i < width; i++) { + if (+coreShape[j * width + i]) { + minI = Math.min(minI, i); + maxI = Math.max(maxI, i + 1); + } + } + minmax[halfJ] = minmax[halfJ] + ? [Math.min(minI, minmax[halfJ][0]), Math.max(maxI, minmax[halfJ][1])] + : [minI, maxI]; + } + for (let j = 1; j < width / 2; j++) { + // the previous row, away from the middle, sets a bound. + minmax[j][0] = Math.min(minmax[j - 1][0], minmax[j][0]); + minmax[j][1] = Math.max(minmax[j - 1][1], minmax[j][1]); + } + return minmax; +} + function getCoreShape(coremaps, inShapeMap = null) { let coreShapeMap = inShapeMap; // build a core_shape array. @@ -205,6 +230,17 @@ function getCoreShape(coremaps, inShapeMap = null) { } }); if (coreShapeMap) { + // fill in interior locations with 1 for sparse maps. + const width = Math.sqrt(coreShapeMap.length); + const minmax = getCoreShapeMinMax(coreShapeMap, width); + for (let j = 0; j < width; j++) { + const halfJ = j < width / 2 ? j : width - j - 1; + for (let i = 0; i < width; i++) { + if (i >= minmax[halfJ][0] && i < minmax[halfJ][1]) { + coreShapeMap[j * width + i] = 1; + } + } + } return { type: 'coremaps', symmetry: 'none', @@ -352,6 +388,7 @@ function writeToInp(state, GROUP_TYPES) { export default { getCoreShape, + getCoreShapeMinMax, getNumPins, getTextMap, getFullMap,