Browse Source

fix "zero radius" bounding sphere issue

David Sehnal 4 years ago
parent
commit
071740e7c1

+ 2 - 2
src/mol-math/geometry/boundary-helper.ts

@@ -46,7 +46,7 @@ export class BoundaryHelper {
     }
 
     includeSphere(s: Sphere3D) {
-        if (Sphere3D.hasExtrema(s)) {
+        if (Sphere3D.hasExtrema(s) && s.extrema.length > 1) {
             for (const e of s.extrema) {
                 this.includePosition(e);
             }
@@ -75,7 +75,7 @@ export class BoundaryHelper {
     }
 
     radiusSphere(s: Sphere3D) {
-        if (Sphere3D.hasExtrema(s)) {
+        if (Sphere3D.hasExtrema(s) && s.extrema.length > 1) {
             for (const e of s.extrema) {
                 this.radiusPosition(e);
             }

+ 4 - 0
src/mol-math/geometry/primitives/sphere3d.ts

@@ -197,6 +197,10 @@ namespace Sphere3D {
     export function expand(out: Sphere3D, sphere: Sphere3D, delta: number): Sphere3D {
         Vec3.copy(out.center, sphere.center);
         out.radius = sphere.radius + delta;
+        if (sphere.radius < 1e-12 || (sphere.extrema?.length ?? 0) <= 1) {
+            out.extrema = void 0;
+            return out;
+        }
         if (hasExtrema(sphere)) {
             setExtrema(out, sphere.extrema.map(e => {
                 Vec3.sub(tmpDir, e, sphere.center);