Browse Source

better naming in SerialMapping

Alexander Rose 5 years ago
parent
commit
faae40c9e8

+ 6 - 10
src/mol-model/structure/structure/structure.ts

@@ -471,8 +471,8 @@ function getPolymerUnitCount(structure: Structure): number {
 }
 
 interface SerialMapping {
-    /** Cummulative count of elements for each unit */
-    unitElementCount: ArrayLike<number>
+    /** Cumulative count of elements for each unit */
+    cumulativeUnitElementCount: ArrayLike<number>
     /** Unit index for each serial element in the structure */
     unitIndices: ArrayLike<number>
     /** Element index for each serial element in the structure */
@@ -480,11 +480,11 @@ interface SerialMapping {
 }
 function getSerialMapping(structure: Structure): SerialMapping {
     const { units, elementCount } = structure
-    const unitElementCount = new Uint32Array(units.length)
+    const cumulativeUnitElementCount = new Uint32Array(units.length)
     const unitIndices = new Uint32Array(elementCount)
-    const elementIndices = new Uint32Array(elementCount)
+    const elementIndices = new Uint32Array(elementCount) as unknown as ElementIndex[]
     for (let i = 0, m = 0, il = units.length; i < il; ++i) {
-        unitElementCount[i] = m
+        cumulativeUnitElementCount[i] = m
         const { elements } = units[i]
         for (let j = 0, jl = elements.length; j < jl; ++j) {
             const mj = m + j
@@ -493,11 +493,7 @@ function getSerialMapping(structure: Structure): SerialMapping {
         }
         m += elements.length
     }
-    return {
-        unitElementCount,
-        unitIndices,
-        elementIndices: elementIndices as unknown as ElementIndex[]
-    }
+    return { cumulativeUnitElementCount, unitIndices, elementIndices }
 }
 
 namespace Structure {

+ 6 - 6
src/mol-repr/structure/visual/label-text.ts

@@ -71,7 +71,7 @@ function createChainText(ctx: VisualContext, structure: Structure, theme: Theme,
     const l = StructureElement.Location.create();
     const { units, serialMapping } = structure;
     const { auth_asym_id, label_asym_id } = StructureProperties.chain;
-    const { unitElementCount } = serialMapping
+    const { cumulativeUnitElementCount } = serialMapping
 
     const count = units.length
     const { chainScale } = props
@@ -86,7 +86,7 @@ function createChainText(ctx: VisualContext, structure: Structure, theme: Theme,
         const authId = auth_asym_id(l)
         const labelId = label_asym_id(l)
         const text = authId === labelId ? labelId : `${labelId} [${authId}]`
-        builder.add(text, tmpVec[0], tmpVec[1], tmpVec[2], radius, chainScale, unitElementCount[i])
+        builder.add(text, tmpVec[0], tmpVec[1], tmpVec[2], radius, chainScale, cumulativeUnitElementCount[i])
     }
 
     return builder.getText()
@@ -97,7 +97,7 @@ function createResidueText(ctx: VisualContext, structure: Structure, theme: Them
     const l = StructureElement.Location.create();
     const { units, serialMapping } = structure;
     const { auth_seq_id, label_comp_id } = StructureProperties.residue;
-    const { unitElementCount } = serialMapping
+    const { cumulativeUnitElementCount } = serialMapping
 
     const count = structure.polymerResidueCount * 2
     const { residueScale } = props
@@ -136,7 +136,7 @@ function createResidueText(ctx: VisualContext, structure: Structure, theme: Them
             const compId = label_comp_id(l)
 
             const text = `${compId} ${authSeqId}`
-            builder.add(text, center[0], center[1], center[2], radius, residueScale, unitElementCount[i])
+            builder.add(text, center[0], center[1], center[2], radius, residueScale, cumulativeUnitElementCount[i])
         }
     }
 
@@ -148,7 +148,7 @@ function createElementText(ctx: VisualContext, structure: Structure, theme: Them
     const l = StructureElement.Location.create();
     const { units, serialMapping } = structure;
     const { label_atom_id, label_alt_id } = StructureProperties.atom;
-    const { unitElementCount } = serialMapping
+    const { cumulativeUnitElementCount } = serialMapping
 
     const sizeTheme = PhysicalSizeTheme({}, {})
 
@@ -168,7 +168,7 @@ function createElementText(ctx: VisualContext, structure: Structure, theme: Them
             const atomId = label_atom_id(l)
             const altId = label_alt_id(l)
             const text = altId ? `${atomId}%${altId}` : atomId
-            builder.add(text, tmpVec[0], tmpVec[1], tmpVec[2], sizeTheme.size(l), elementScale, unitElementCount[i])
+            builder.add(text, tmpVec[0], tmpVec[1], tmpVec[2], sizeTheme.size(l), elementScale, cumulativeUnitElementCount[i])
         }
     }
 

+ 6 - 6
src/mol-repr/structure/visual/util/element.ts

@@ -122,17 +122,17 @@ export function eachSerialElement(loci: Loci, structure: Structure, apply: (inte
     let changed = false
     if (!StructureElement.Loci.is(loci)) return false
     if (!Structure.areEquivalent(loci.structure, structure)) return false
-    const { unitElementCount } = structure.serialMapping
+    const { cumulativeUnitElementCount } = structure.serialMapping
     for (const e of loci.elements) {
         const unitIdx = structure.unitIndexMap.get(e.unit.id)
         if (unitIdx !== undefined) {
             if (Interval.is(e.indices)) {
-                const start = unitElementCount[unitIdx] + Interval.start(e.indices)
-                const end = unitElementCount[unitIdx] + Interval.end(e.indices)
+                const start = cumulativeUnitElementCount[unitIdx] + Interval.start(e.indices)
+                const end = cumulativeUnitElementCount[unitIdx] + Interval.end(e.indices)
                 if (apply(Interval.ofBounds(start, end))) changed = true
             } else {
                 for (let i = 0, _i = e.indices.length; i < _i; i++) {
-                    const idx = unitElementCount[unitIdx] + e.indices[i]
+                    const idx = cumulativeUnitElementCount[unitIdx] + e.indices[i]
                     if (apply(Interval.ofSingleton(idx))) changed = true
                 }
             }
@@ -144,10 +144,10 @@ export function eachSerialElement(loci: Loci, structure: Structure, apply: (inte
 export function getSerialElementLoci(pickingId: PickingId, structure: Structure, id: number) {
     const { objectId, groupId } = pickingId
     if (id === objectId) {
-        const { unitIndices, unitElementCount } = structure.serialMapping
+        const { unitIndices, cumulativeUnitElementCount } = structure.serialMapping
         const unitIdx = unitIndices[groupId]
         const unit = structure.units[unitIdx]
-        const idx = groupId - unitElementCount[unitIdx]
+        const idx = groupId - cumulativeUnitElementCount[unitIdx]
         const indices = OrderedSet.ofSingleton(idx as StructureElement.UnitIndex)
         return StructureElement.Loci(structure, [{ unit, indices }])
     }