Skip to content
Snippets Groups Projects
Commit 6873b798 authored by Alexander Rose's avatar Alexander Rose
Browse files

added StructureSelection.toLoci2 returning the source units

(propably won't work for queries that create units with new transforms)
parent 0814ff52
No related branches found
No related tags found
No related merge requests found
...@@ -36,21 +36,47 @@ namespace StructureSelection { ...@@ -36,21 +36,47 @@ namespace StructureSelection {
} }
export function toLoci(sel: StructureSelection): StructureElement.Loci { export function toLoci(sel: StructureSelection): StructureElement.Loci {
const loci: { unit: Unit, indices: OrderedSet<StructureElement.UnitIndex> }[] = []; const elements: { unit: Unit, indices: OrderedSet<StructureElement.UnitIndex> }[] = [];
const { unitMap } = sel.source; const { unitMap } = sel.source;
for (const unit of unionStructure(sel).units) { for (const unit of unionStructure(sel).units) {
if (unit === unitMap.get(unit.id)) { if (unit === unitMap.get(unit.id)) {
loci[loci.length] = { unit, indices: OrderedSet.ofBounds(0 as StructureElement.UnitIndex, unit.elements.length as StructureElement.UnitIndex) }; elements[elements.length] = {
unit,
indices: OrderedSet.ofBounds(0 as StructureElement.UnitIndex, unit.elements.length as StructureElement.UnitIndex)
};
} else {
elements[elements.length] = {
unit,
indices: OrderedSet.ofSortedArray(SortedArray.indicesOf(unitMap.get(unit.id).elements, unit.elements))
};
}
}
return StructureElement.Loci(sel.source, elements);
}
/** use source unit in loci.elements */
export function toLoci2(sel: StructureSelection): StructureElement.Loci {
const elements: { unit: Unit, indices: OrderedSet<StructureElement.UnitIndex> }[] = [];
const { unitMap } = sel.source;
for (const _unit of unionStructure(sel).units) {
const unit = unitMap.get(_unit.id)
if (unit === _unit) {
elements[elements.length] = {
unit,
indices: OrderedSet.ofBounds(0 as StructureElement.UnitIndex, unit.elements.length as StructureElement.UnitIndex)
};
} else { } else {
loci[loci.length] = { elements[elements.length] = {
unit, unit,
indices: OrderedSet.ofSortedArray(SortedArray.indicesOf(sel.source.unitMap.get(unit.id).elements, unit.elements)) indices: OrderedSet.ofSortedArray(SortedArray.indicesOf(unit.elements, _unit.elements))
}; };
} }
} }
return StructureElement.Loci(sel.source, loci); return StructureElement.Loci(sel.source, elements);
} }
export interface Builder { export interface Builder {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment