From e1ad67a059c137e3e4584f8478f841b25ab556c5 Mon Sep 17 00:00:00 2001 From: Alexander Rose <alexander.rose@weirdbyte.de> Date: Sun, 29 Aug 2021 10:35:05 -0700 Subject: [PATCH] StructureElement.Loci improvements - early return in .isEmpty - ensure Interval is used when possible in .extendToAllInstances --- src/mol-model/structure/structure/element/loci.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/mol-model/structure/structure/element/loci.ts b/src/mol-model/structure/structure/element/loci.ts index 654c357fc..cce5eff09 100644 --- a/src/mol-model/structure/structure/element/loci.ts +++ b/src/mol-model/structure/structure/element/loci.ts @@ -66,7 +66,10 @@ export namespace Loci { } export function isEmpty(loci: Loci) { - return size(loci) === 0; + for (const u of loci.elements) { + if(OrderedSet.size(u.indices) > 0) return false; + } + return true; } export function isWholeStructure(loci: Loci) { @@ -140,7 +143,7 @@ export namespace Loci { return Structure.create(units, { parent: loci.structure.parent }); } - // TODO: there should be a version that property supports partitioned units + // TODO: there should be a version that properly supports partitioned units export function remap(loci: Loci, structure: Structure): Loci { if (structure === loci.structure) return loci; @@ -467,7 +470,7 @@ export namespace Loci { } function getUnitIndices(elements: SortedArray<ElementIndex>, indices: SortedArray<ElementIndex>) { - return SortedArray.indicesOf<ElementIndex, UnitIndex>(elements, indices); + return OrderedSet.ofSortedArray(SortedArray.indicesOf<ElementIndex, UnitIndex>(elements, indices)); } export function extendToAllInstances(loci: Loci): Loci { -- GitLab