in packages/miew/src/gfx/geometries/SSIsosurfaceGeometry.js [450:511]
calculateGridCorners(corners, side, vBoxMin, vBoxMax, atoms, probeRad) {
const side2 = side * side;
const side3 = side2 * side;
const vCorner = new THREE.Vector3();
const vDif = new THREE.Vector3();
/* eslint-disable no-magic-numbers */
const aLot = +1.0e12;
/* eslint-enable no-magic-numbers */
for (let i = 0; i < side3; i++) {
corners[i] = aLot; // to large value
}
const xScale = (side - 1) / (vBoxMax.x - vBoxMin.x);
const yScale = (side - 1) / (vBoxMax.y - vBoxMin.y);
const zScale = (side - 1) / (vBoxMax.z - vBoxMin.z);
for (let s = 0, numAtoms = atoms.length; s < numAtoms; s++) {
const atom = atoms[s];
const radius = atom.radius + probeRad;
const fx = ((atom.coord.x - radius) - vBoxMin.x) * xScale;
const fy = ((atom.coord.y - radius) - vBoxMin.y) * yScale;
const fz = ((atom.coord.z - radius) - vBoxMin.z) * zScale;
const indXMin = Math.floor(fx);
const indYMin = Math.floor(fy);
const indZMin = Math.floor(fz);
let indXMax = Math.floor(((atom.coord.x + radius) - vBoxMin.x) * xScale);
let indYMax = Math.floor(((atom.coord.y + radius) - vBoxMin.y) * yScale);
let indZMax = Math.floor(((atom.coord.z + radius) - vBoxMin.z) * zScale);
indXMax++;
indYMax++;
indZMax++;
indXMax = (indXMax <= (side - 1)) ? indXMax : (side - 1);
indYMax = (indYMax <= (side - 1)) ? indYMax : (side - 1);
indZMax = (indZMax <= (side - 1)) ? indZMax : (side - 1);
for (let y = indYMin; y <= indYMax; y++) {
const indY = y * side2;
for (let z = indZMin; z <= indZMax; z++) {
const indZ = z * side;
for (let x = indXMin; x <= indXMax; x++) {
const ind = indY + indZ + x;
this.getCornerCoord(vBoxMin, vBoxMax, x, y, z, side, vCorner);
vDif.x = vCorner.x - atom.coord.x;
vDif.y = vCorner.y - atom.coord.y;
vDif.z = vCorner.z - atom.coord.z;
const distToSphere = Math.sqrt(vDif.x * vDif.x + vDif.y * vDif.y + vDif.z * vDif.z);
// val: < 0, if inside sphere
// val: > 0, if outside sphere
const val = distToSphere - radius;
if (val < corners[ind]) {
corners[ind] = val;
}
} // for (x)
} // for (z)
} // for (y)
} // for (s)
}