Browse Source

added Bond.getBoundingSphere (moved from model/loci)

Alexander Rose 5 years ago
parent
commit
312db7eec3
2 changed files with 33 additions and 14 deletions
  1. 2 14
      src/mol-model/loci.ts
  2. 31 0
      src/mol-model/structure/structure/unit/bonds.ts

+ 2 - 14
src/mol-model/loci.ts

@@ -119,7 +119,7 @@ namespace Loci {
         return loci
     }
 
-    const sphereHelper = new CentroidHelper(), tmpPos = Vec3.zero();
+    const sphereHelper = new CentroidHelper(), tmpPos = Vec3();
 
     export function getBoundingSphere(loci: Loci, boundingSphere?: Sphere3D): Sphere3D | undefined {
         if (loci.kind === 'every-loci' || loci.kind === 'empty-loci') return void 0;
@@ -132,19 +132,7 @@ namespace Loci {
         } else if (loci.kind === 'element-loci') {
             return Sphere3D.copy(boundingSphere, StructureElement.Loci.getBoundary(loci).sphere);
         } else if (loci.kind === 'bond-loci') {
-            for (const e of loci.bonds) {
-                e.aUnit.conformation.position(e.aUnit.elements[e.aIndex], tmpPos);
-                sphereHelper.includeStep(tmpPos);
-                e.bUnit.conformation.position(e.bUnit.elements[e.bIndex], tmpPos);
-                sphereHelper.includeStep(tmpPos);
-            }
-            sphereHelper.finishedIncludeStep();
-            for (const e of loci.bonds) {
-                e.aUnit.conformation.position(e.aUnit.elements[e.aIndex], tmpPos);
-                sphereHelper.radiusStep(tmpPos);
-                e.aUnit.conformation.position(e.bUnit.elements[e.bIndex], tmpPos);
-                sphereHelper.radiusStep(tmpPos);
-            }
+            return Bond.getBoundingSphere(loci, boundingSphere)
         } else if (loci.kind === 'interaction-loci') {
             const { unitsFeatures } = loci.interactions
             for (const e of loci.contacts) {

+ 31 - 0
src/mol-model/structure/structure/unit/bonds.ts

@@ -9,6 +9,9 @@ import { Unit, StructureElement } from '../../structure'
 import Structure from '../structure';
 import { BondType } from '../../model/types';
 import { SortedArray, Iterator } from '../../../../mol-data/int';
+import { CentroidHelper } from '../../../../mol-math/geometry/centroid-helper';
+import { Vec3 } from '../../../../mol-math/linear-algebra';
+import { Sphere3D } from '../../../../mol-math/geometry';
 
 export * from './bonds/data'
 export * from './bonds/intra-compute'
@@ -219,6 +222,34 @@ namespace Bond {
             this.hasNext = false
         }
     }
+
+    //
+
+    const sphereHelper = new CentroidHelper()
+    const tmpPos = Vec3()
+
+    export function getBoundingSphere(loci: Loci, boundingSphere?: Sphere3D) {
+        if (!boundingSphere) boundingSphere = Sphere3D()
+        sphereHelper.reset();
+
+        for (const e of loci.bonds) {
+            e.aUnit.conformation.position(e.aUnit.elements[e.aIndex], tmpPos);
+            sphereHelper.includeStep(tmpPos);
+            e.bUnit.conformation.position(e.bUnit.elements[e.bIndex], tmpPos);
+            sphereHelper.includeStep(tmpPos);
+        }
+        sphereHelper.finishedIncludeStep();
+        for (const e of loci.bonds) {
+            e.aUnit.conformation.position(e.aUnit.elements[e.aIndex], tmpPos);
+            sphereHelper.radiusStep(tmpPos);
+            e.aUnit.conformation.position(e.bUnit.elements[e.bIndex], tmpPos);
+            sphereHelper.radiusStep(tmpPos);
+        }
+
+        Vec3.copy(boundingSphere.center, sphereHelper.center)
+        boundingSphere.radius = Math.sqrt(sphereHelper.radiusSq)
+        return boundingSphere
+    }
 }
 
 export { Bond }