From 9de8f2a133d1ba5b6da87b908abb7665a5243338 Mon Sep 17 00:00:00 2001
From: David Sehnal <david.sehnal@gmail.com>
Date: Wed, 11 Jul 2018 17:26:14 +0200
Subject: [PATCH] StructureElement type tweaks

---
 .../representation/structure/visual/polymer-trace-mesh.ts  | 2 +-
 .../representation/structure/visual/util/element.ts        | 2 +-
 src/mol-model/structure/query/selection.ts                 | 4 ++--
 src/mol-model/structure/structure/element.ts               | 7 ++++---
 4 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/src/mol-geo/representation/structure/visual/polymer-trace-mesh.ts b/src/mol-geo/representation/structure/visual/polymer-trace-mesh.ts
index f7a75b4eb..bae42eab9 100644
--- a/src/mol-geo/representation/structure/visual/polymer-trace-mesh.ts
+++ b/src/mol-geo/representation/structure/visual/polymer-trace-mesh.ts
@@ -134,7 +134,7 @@ export function PolymerTraceVisual(): UnitsVisual<PolymerTraceProps> {
             const { objectId, instanceId, elementId } = pickingId
             if (renderObject.id === objectId) {
                 const unit = currentGroup.units[instanceId]
-                const indices = OrderedSet.ofSingleton(elementId as StructureElement.Index);
+                const indices = OrderedSet.ofSingleton(elementId as StructureElement.UnitIndex);
                 return StructureElement.Loci([{ unit, indices }])
             }
             return EmptyLoci
diff --git a/src/mol-geo/representation/structure/visual/util/element.ts b/src/mol-geo/representation/structure/visual/util/element.ts
index 95b0ab5a8..50a44321e 100644
--- a/src/mol-geo/representation/structure/visual/util/element.ts
+++ b/src/mol-geo/representation/structure/visual/util/element.ts
@@ -96,7 +96,7 @@ export function getElementLoci(id: number, group: Unit.SymmetryGroup, pickingId:
     const { objectId, instanceId, elementId } = pickingId
     if (id === objectId) {
         const unit = group.units[instanceId]
-        const indices = OrderedSet.ofSingleton(elementId as StructureElement.Index);
+        const indices = OrderedSet.ofSingleton(elementId as StructureElement.UnitIndex);
         return StructureElement.Loci([{ unit, indices }])
     }
     return EmptyLoci
diff --git a/src/mol-model/structure/query/selection.ts b/src/mol-model/structure/query/selection.ts
index fe4ed8168..72ab29106 100644
--- a/src/mol-model/structure/query/selection.ts
+++ b/src/mol-model/structure/query/selection.ts
@@ -36,12 +36,12 @@ namespace Selection {
     }
 
     export function toLoci(sel: Selection): StructureElement.Loci {
-        const loci: { unit: Unit, indices: OrderedSet<StructureElement.Index> }[] = [];
+        const loci: { unit: Unit, indices: OrderedSet<StructureElement.UnitIndex> }[] = [];
         const { unitMap } = sel.source;
 
         for (const unit of unionStructure(sel).units) {
             if (unit === unitMap.get(unit.id)) {
-                loci[loci.length] = { unit, indices: OrderedSet.ofBounds(0 as StructureElement.Index, unit.elements.length as StructureElement.Index) };
+                loci[loci.length] = { unit, indices: OrderedSet.ofBounds(0 as StructureElement.UnitIndex, unit.elements.length as StructureElement.UnitIndex) };
             } else {
                 loci[loci.length] = {
                     unit,
diff --git a/src/mol-model/structure/structure/element.ts b/src/mol-model/structure/structure/element.ts
index 1bbaf84b6..f8e35caff 100644
--- a/src/mol-model/structure/structure/element.ts
+++ b/src/mol-model/structure/structure/element.ts
@@ -17,10 +17,11 @@ interface StructureElement<U = Unit> {
 namespace StructureElement {
     export function create(unit?: Unit, element?: ElementIndex): StructureElement { return { unit: unit as any, element: element || (0 as ElementIndex) }; }
 
+    // TODO: when nominal types are available, make this indexed by UnitIndex
     export type Set = SortedArray<ElementIndex>
 
     /** Index into Unit.elements */
-    export type Index = { readonly '@type': 'element-index' } & number
+    export type UnitIndex = { readonly '@type': 'structure-element-index' } & number
 
     export interface Property<T> { (location: StructureElement): T }
     export interface Predicate extends Property<boolean> { }
@@ -46,11 +47,11 @@ namespace StructureElement {
              * Indices into the unit.elements array.
              * Can use OrderedSet.forEach to iterate (or OrderedSet.size + OrderedSet.getAt)
              */
-            indices: OrderedSet<Index>
+            indices: OrderedSet<UnitIndex>
         }>
     }
 
-    export function Loci(elements: ArrayLike<{ unit: Unit, indices: OrderedSet<Index> }>): Loci {
+    export function Loci(elements: ArrayLike<{ unit: Unit, indices: OrderedSet<UnitIndex> }>): Loci {
         return { kind: 'element-loci', elements: elements as Loci['elements'] };
     }
 
-- 
GitLab