Skip to content
Snippets Groups Projects
Commit 2e013faf authored by dsehnal's avatar dsehnal
Browse files

Add StructureElement.Loci.forEachLocation

parent 0809379f
No related branches found
No related tags found
No related merge requests found
......@@ -17,6 +17,7 @@ Note that since we don't clearly distinguish between a public and private interf
- Update clip `defines` only when changed
- Check for identity in structure/unit areEqual methods
- Avoid cloning of structure representation parameters
- Add StructureElement.Loci.forEachLocation
## [v3.28.0] - 2022-12-20
......
......@@ -143,6 +143,26 @@ export namespace Loci {
return Structure.create(units, { parent: loci.structure.parent });
}
/**
* Iterates over all locations.
* The loc argument of the callback is mutable, use Location.clone() if you intend to keep
* the value around.
*/
export function forEachLocation(loci: Loci, f: (loc: Location) => any) {
if (Loci.isEmpty(loci)) return;
const location = Location.create(loci.structure);
for (const e of loci.elements) {
const { unit, indices } = e;
location.unit = unit;
const { elements } = e.unit;
for (let i = 0, _i = OrderedSet.size(indices); i < _i; i++) {
location.element = elements[OrderedSet.getAt(indices, i)];
f(location);
}
}
}
// 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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment