in packages/miew/src/gfx/geometries/SSIsosurfaceGeometry.js [568:624]
addVertexToGeo(geoOut, vAdd) {
let entry;
const oneHynberes = 0.01;
const n815851 = 815851;
const n37633 = 37633;
const n2453543 = 2453543;
const r106 = 1.0e-6;
const hashResolution = this.marCubeResoultion << 2;
const v = new THREE.Vector3();
const ix = Math.floor(hashResolution * (vAdd.x - this.vBoxMin.x) / (this.vBoxMax.x + oneHynberes - this.vBoxMin.x));
const iy = Math.floor(hashResolution * (vAdd.y - this.vBoxMin.y) / (this.vBoxMax.y + oneHynberes - this.vBoxMin.y));
const iz = Math.floor(hashResolution * (vAdd.z - this.vBoxMin.z) / (this.vBoxMax.z + oneHynberes - this.vBoxMin.z));
let iHash = ix * n815851 + iz * n37633 + iy * n2453543;
iHash &= (HASH_SIZE - 1);
const hLineIndex = iHash + iHash;
// search vertex via hash
// search in hash list
if (this.vBoxMin !== null && this.vBoxMax !== null) {
for (entry = this.hashLines[hLineIndex + 1]; entry >= 0; entry = this.hashEntries[entry * 2 + 1]) {
const ind = this.hashEntries[entry * 2 + 0]; // vertex index
v.copy(geoOut._vertices[ind]);
v.x -= vAdd.x;
v.y -= vAdd.y;
v.z -= vAdd.z;
const dot2 = v.x * v.x + v.y * v.y + v.z * v.z;
if (dot2 < r106) {
return ind;
} // if (found)
} // for (entry)
} // search
// add new vertex to geometry
if (geoOut._numVertices >= this.maxNumVertices) {
return 0 - 1;
}
const iVertAdd = geoOut._numVertices;
geoOut._vertices[iVertAdd].copy(vAdd);
// add to hash
if (this.vBoxMin !== null && this.vBoxMax !== null) {
entry = this.getNewHashEntry();
if (entry < 0) {
return 0 - 1;
}
const entryFirst = this.hashLines[hLineIndex + 1];
this.hashLines[hLineIndex + 1] = entry;
this.hashEntries[entry * 2 + 0] = iVertAdd;
this.hashEntries[entry * 2 + 1] = entryFirst;
this.hashLines[hLineIndex + 0]++; // num vertices in line ++
}
geoOut._numVertices++;
return iVertAdd;
}