Browse Source

mol-model: Loci fixes

David Sehnal 5 years ago
parent
commit
ca5d1865cc

+ 9 - 5
src/mol-model/loci.ts

@@ -16,15 +16,15 @@ import { Structure } from './structure/structure';
 /** A Loci that includes every loci */
 export const EveryLoci = { kind: 'every-loci' as 'every-loci' }
 export type EveryLoci = typeof EveryLoci
-export function isEveryLoci(x: any): x is EveryLoci {
+export function isEveryLoci(x?: Loci): x is EveryLoci {
     return !!x && x.kind === 'every-loci';
 }
 
 /** A Loci that is empty */
 export const EmptyLoci = { kind: 'empty-loci' as 'empty-loci' }
 export type EmptyLoci = typeof EmptyLoci
-export function isEmptyLoci(x: Loci): x is EmptyLoci {
-    return !!x && (x.kind === 'empty-loci' || (x.kind === 'element-loci' && x.elements.length === 0));
+export function isEmptyLoci(x?: Loci): x is EmptyLoci {
+    return !!x && x.kind === 'empty-loci';
 }
 
 /** A generic data loci */
@@ -34,7 +34,7 @@ export interface DataLoci {
     readonly tag: string
     readonly indices: OrderedSet<number>
 }
-export function isDataLoci(x: any): x is DataLoci {
+export function isDataLoci(x?: Loci): x is DataLoci {
     return !!x && x.kind === 'data-loci';
 }
 export function areDataLociEqual(a: DataLoci, b: DataLoci) {
@@ -76,7 +76,11 @@ namespace Loci {
         return false
     }
 
-    export function isEmpty(loci: Loci): boolean {
+    export function isEvery(loci?: Loci): loci is EveryLoci {
+        return !!loci && loci.kind === 'every-loci';
+    }
+
+    export function isEmpty(loci: Loci): loci is EmptyLoci {
         if (isEveryLoci(loci)) return false
         if (isEmptyLoci(loci)) return true
         if (isDataLoci(loci)) return isDataLociEmpty(loci)

+ 1 - 1
src/mol-plugin/behavior/dynamic/volume-streaming/behavior.ts

@@ -259,7 +259,7 @@ export namespace VolumeStreaming {
         }
 
         private getBoxFromLoci(loci: StructureElement.Loci | EmptyLoci): Box3D {
-            if (isEmptyLoci(loci) || StructureElement.Loci.isEmpty(loci)) {
+            if (Loci.isEmpty(loci)) {
                 return Box3D.empty();
             }
 

+ 1 - 0
src/mol-plugin/util/structure-element-selection.ts

@@ -161,6 +161,7 @@ class StructureElementSelectionManager {
         if (!entry) return;
 
         let xs = loci.elements[0];
+        if (!xs) return;
         let e: StructureElement.Loci['elements'][0] | undefined;
         for (const _e of entry.selection.elements) {
             if (xs.unit === _e.unit) {