Containers
Auxiliary container types for vision elements and functions to convert from one container type to another.
Vision elements have the ability to express parent-child relations via the parentId field. Using this information, it is possible to create a nested tree structure from a list of vision elements.
The basic container types are the following:
- List: Array of vision elements. Can be an heterogeneous list.
type List = VisionElement[];
- Tree: Nested structure of vision elements that represents the parent-child relationships expressed by the
parentIdfield.
interface TreeNode {
node: VisionElement;
children: Tree;
}
type Tree = TreeNode[];
- Dictionary: A pair of string tag and list of vision elements.
type Dictionary = Record<string, VisionElement[]>;
- DictionaryFlat: A pair of string tag and list of flat vision elements.
type DictionaryFlat = Record<string, IVisionElementFlat[]>;
treeFromList()
Creates a tree structure from a list of vision elements. The tree structure is created based on the parentId field of the vision elements.
function treeFromList(list: VisionElement[]): Tree;
treeFromDictionary()
Creates a tree structure from a dictionary of vision elements. The tree structure is created based on the parentId field of the vision elements.
The string tag is not used, it is lost in the conversion.
function treeFromDictionary(dict: Dictionary): Tree;
treeToList()
Returns a list of vision elements from a tree. The
function treeToList(tree: Tree): VisionElements[];
cloneTree()
Clone a tree, keeping the same nested structure. Creates new instances of the vision elements, with different id and, as a consequence, different parentId.
function cloneTree(tree: Tree): Tree;
cloneDictionary()
Clone a dictionary, keeping the same string tags and the same parent-child relationships expressed by new id and parentId fields. Creates new instances of the vision elements, with different id and, as a consequence, different parentId.
function cloneDictionary(dict: Dictionary): Dictionary;
cloneList()
Clone a tree, keeping the same parent-child relationships expressed by new id and parentId fields. Creates new instances of the vision elements, with different id and, as a consequence, different parentId.
function cloneList(list: VisionElement[]): VisionElement[];