Просмотр исходного кода

avoid adding bonds multiple times

Alexander Rose 5 лет назад
Родитель
Сommit
bfd9595c1c

+ 1 - 1
src/mol-model/structure/structure/unit/bonds/inter-compute.ts

@@ -81,7 +81,7 @@ function findPairBonds(unitA: Unit.Atomic, unitB: Unit.Atomic, props: BondComput
             for (const se of structConnEntries) {
                 for (const p of se.partners) {
                     const _bI = SortedArray.indexOf(unitB.elements, p.atomIndex) as StructureElement.UnitIndex;
-                    if (_bI < 0) continue;
+                    if (_bI < 0 || _aI === _bI) continue;
                     // check if the bond is within MAX_RADIUS for this pair of units
                     if (getDistance(unitA, aI, unitB, p.atomIndex) > MAX_RADIUS) continue;
                     builder.add(_aI, _bI, { order: se.order, flag: se.flags });

+ 5 - 1
src/mol-model/structure/structure/unit/bonds/intra-compute.ts

@@ -67,15 +67,17 @@ function _computeBonds(unit: Unit.Atomic, props: BondComputationProps): IntraUni
         }
 
         const structConnEntries = props.forceCompute ? void 0 : structConn && structConn.getAtomEntries(aI);
+        const structConnAdded = new Set<StructureElement.UnitIndex>()
         if (structConnEntries) {
             for (const se of structConnEntries) {
                 for (const p of se.partners) {
                     const _bI = SortedArray.indexOf(unit.elements, p.atomIndex) as StructureElement.UnitIndex;
-                    if (_bI < 0) continue;
+                    if (_bI < 0 || _aI === _bI) continue;
                     atomA[atomA.length] = _aI;
                     atomB[atomB.length] = _bI;
                     flags[flags.length] = se.flags;
                     order[order.length] = se.order;
+                    structConnAdded.add(_bI)
                 }
             }
         }
@@ -104,6 +106,8 @@ function _computeBonds(unit: Unit.Atomic, props: BondComputationProps): IntraUni
 
         for (let ni = 0; ni < count; ni++) {
             const _bI = indices[ni];
+            if (structConnAdded.has(_bI)) continue;
+
             const bI = atoms[_bI];
             if (bI <= aI) continue;