Browse Source

moved Loci.areEqual

Alexander Rose 6 years ago
parent
commit
0bc83f4788

+ 20 - 22
src/mol-model/loci.ts

@@ -43,33 +43,31 @@ export function createDataLoci(data: any, tag: string, indices: OrderedSet<numbe
     return { kind: 'data-loci', data, tag, indices }
 }
 
-export function areLociEqual(lociA: Loci, lociB: Loci) {
-    if (isEveryLoci(lociA) && isEveryLoci(lociB)) return true
-    if (isEmptyLoci(lociA) && isEmptyLoci(lociB)) return true
-    if (isDataLoci(lociA) && isDataLoci(lociB)) {
-        return areDataLociEqual(lociA, lociB)
-    }
-    if (Structure.isLoci(lociA) && Structure.isLoci(lociB)) {
-        return Structure.areLociEqual(lociA, lociB)
-    }
-    if (StructureElement.isLoci(lociA) && StructureElement.isLoci(lociB)) {
-        return StructureElement.areLociEqual(lociA, lociB)
-    }
-    if (Link.isLoci(lociA) && Link.isLoci(lociB)) {
-        return Link.areLociEqual(lociA, lociB)
-    }
-    if (Shape.isLoci(lociA) && Shape.isLoci(lociB)) {
-        return Shape.areLociEqual(lociA, lociB)
-    }
-    return false
-}
-
-
 export { Loci }
 
 type Loci = StructureElement.Loci | Structure.Loci | Link.Loci | EveryLoci | EmptyLoci | DataLoci | Shape.Loci
 
 namespace Loci {
+    export function areEqual(lociA: Loci, lociB: Loci) {
+        if (isEveryLoci(lociA) && isEveryLoci(lociB)) return true
+        if (isEmptyLoci(lociA) && isEmptyLoci(lociB)) return true
+        if (isDataLoci(lociA) && isDataLoci(lociB)) {
+            return areDataLociEqual(lociA, lociB)
+        }
+        if (Structure.isLoci(lociA) && Structure.isLoci(lociB)) {
+            return Structure.areLociEqual(lociA, lociB)
+        }
+        if (StructureElement.isLoci(lociA) && StructureElement.isLoci(lociB)) {
+            return StructureElement.areLociEqual(lociA, lociB)
+        }
+        if (Link.isLoci(lociA) && Link.isLoci(lociB)) {
+            return Link.areLociEqual(lociA, lociB)
+        }
+        if (Shape.isLoci(lociA) && Shape.isLoci(lociB)) {
+            return Shape.areLociEqual(lociA, lociB)
+        }
+        return false
+    }
 
     const sphereHelper = new CentroidHelper(), tempPos = Vec3.zero();
 

+ 3 - 3
src/mol-plugin/behavior/dynamic/representation.ts

@@ -5,7 +5,7 @@
  */
 
 import { PluginBehavior } from '../behavior';
-import { EmptyLoci, Loci, areLociEqual } from 'mol-model/loci';
+import { EmptyLoci, Loci } from 'mol-model/loci';
 import { MarkerAction } from 'mol-geo/geometry/marker-data';
 import { labelFirst } from 'mol-theme/label';
 import { PluginContext } from 'mol-plugin/context';
@@ -18,7 +18,7 @@ export const HighlightLoci = PluginBehavior.create({
             this.subscribeObservable(this.ctx.behaviors.canvas.highlightLoci, current => {
                 if (!this.ctx.canvas3d) return;
 
-                if (current.repr !== prevRepr || !areLociEqual(current.loci, prevLoci)) {
+                if (current.repr !== prevRepr || !Loci.areEqual(current.loci, prevLoci)) {
                     this.ctx.canvas3d.mark(prevLoci, MarkerAction.RemoveHighlight, prevRepr);
                     this.ctx.canvas3d.mark(current.loci, MarkerAction.Highlight, current.repr);
                     prevLoci = current.loci;
@@ -37,7 +37,7 @@ export const SelectLoci = PluginBehavior.create({
             let prevLoci: Loci = EmptyLoci, prevRepr: any = void 0;
             this.subscribeObservable(this.ctx.behaviors.canvas.selectLoci, current => {
                 if (!this.ctx.canvas3d) return;
-                if (current.repr !== prevRepr || !areLociEqual(current.loci, prevLoci)) {
+                if (current.repr !== prevRepr || !Loci.areEqual(current.loci, prevLoci)) {
                     this.ctx.canvas3d.mark(prevLoci, MarkerAction.Deselect, prevRepr);
                     this.ctx.canvas3d.mark(current.loci, MarkerAction.Select, current.repr);
                     prevLoci = current.loci;

+ 2 - 2
src/mol-plugin/util/canvas3d-identify.ts

@@ -6,7 +6,7 @@
 
 import { PluginContext } from '../context';
 import { PickingId } from 'mol-geo/geometry/picking';
-import { EmptyLoci, Loci, areLociEqual } from 'mol-model/loci';
+import { EmptyLoci, Loci } from 'mol-model/loci';
 import { Representation } from 'mol-repr/representation';
 
 export class Canvas3dIdentifyHelper {
@@ -45,7 +45,7 @@ export class Canvas3dIdentifyHelper {
         }
 
         const loci = this.ctx.canvas3d.getLoci(this.id);
-        if (loci.repr !== this.prevLoci.repr || !areLociEqual(loci.loci, this.prevLoci.loci)) {
+        if (loci.repr !== this.prevLoci.repr || !Loci.areEqual(loci.loci, this.prevLoci.loci)) {
             this.ctx.behaviors.canvas.highlightLoci.next(loci);
             this.prevLoci = loci;
         }