diff --git a/src/mol-model/loci.ts b/src/mol-model/loci.ts index a27e2d98f79d8fc53abc99dacfdf0be92e09f98f..8baa821d874336433c4feb407ff7edfc66615e70 100644 --- a/src/mol-model/loci.ts +++ b/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(); diff --git a/src/mol-plugin/behavior/dynamic/representation.ts b/src/mol-plugin/behavior/dynamic/representation.ts index 5119494f809bf19e7a89e978daa21be8c5a804c2..d537242995b40f19b8a00bad5b34e93b9adb6fc4 100644 --- a/src/mol-plugin/behavior/dynamic/representation.ts +++ b/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; diff --git a/src/mol-plugin/util/canvas3d-identify.ts b/src/mol-plugin/util/canvas3d-identify.ts index f2cf8c442edc73cfc87cd3f1b0211d2158664d9c..74562d92b5c968166cd0f2346af1d2ef92c0ef55 100644 --- a/src/mol-plugin/util/canvas3d-identify.ts +++ b/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; }