Merged PR 216: Deprecate parent from IContainerModel for FindContainerById
This commit is contained in:
parent
d40cd8cf8e
commit
b4eba6bb9b
19 changed files with 97 additions and 109 deletions
|
@ -123,16 +123,16 @@ export function * MakeRecursionDFSIterator(
|
|||
/**
|
||||
* Returns the depth of the container
|
||||
* @returns The depth of the container
|
||||
* @deprecated Please avoid using this function inside an iterationl,
|
||||
* @deprecated Please avoid using this function inside an iteration,
|
||||
* use recursive DFS or iterative BFS to get the depth
|
||||
*/
|
||||
export function GetDepth(parent: IContainerModel): number {
|
||||
export function GetDepth(containers: Map<string, IContainerModel>, parent: IContainerModel): number {
|
||||
let depth = 0;
|
||||
|
||||
let current: IContainerModel | null = parent;
|
||||
while (current != null) {
|
||||
depth++;
|
||||
current = current.parent;
|
||||
current = FindContainerById(containers, current.properties.parentId) ?? null;
|
||||
}
|
||||
|
||||
return depth;
|
||||
|
@ -142,22 +142,31 @@ export function GetDepth(parent: IContainerModel): number {
|
|||
* Returns the absolute position by iterating to the parent
|
||||
* @returns The absolute position of the container
|
||||
*/
|
||||
export function GetAbsolutePosition(container: IContainerModel): [number, number] {
|
||||
export function GetAbsolutePosition(containers: Map<string, IContainerModel>, container: IContainerModel): [number, number] {
|
||||
const x = container.properties.x;
|
||||
const y = container.properties.y;
|
||||
return CancelParentTransform(container.parent, x, y);
|
||||
const parent = FindContainerById(containers, container.properties.parentId) ?? null;
|
||||
return CancelParentTransform(containers, parent, x, y);
|
||||
}
|
||||
|
||||
export function GetContainerLinkedList(container: IContainerModel, stop?: IContainerModel): IContainerModel[] {
|
||||
const it = MakeContainerLinkedListIterator(container, stop);
|
||||
export function GetContainerLinkedList(
|
||||
containers: Map<string, IContainerModel>,
|
||||
container: IContainerModel,
|
||||
stop?: IContainerModel
|
||||
): IContainerModel[] {
|
||||
const it = MakeContainerLinkedListIterator(containers, container, stop);
|
||||
return [...it];
|
||||
}
|
||||
|
||||
export function * MakeContainerLinkedListIterator(container: IContainerModel, stop?: IContainerModel): Generator<IContainerModel, void, unknown> {
|
||||
export function * MakeContainerLinkedListIterator(
|
||||
containers: Map<string, IContainerModel>,
|
||||
container: IContainerModel,
|
||||
stop?: IContainerModel
|
||||
): Generator<IContainerModel, void, unknown> {
|
||||
let current: IContainerModel | null = container;
|
||||
while (current !== stop && current != null) {
|
||||
yield current;
|
||||
current = current.parent;
|
||||
current = FindContainerById(containers, current.properties.parentId) ?? null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -169,6 +178,7 @@ export function * MakeContainerLinkedListIterator(container: IContainerModel, st
|
|||
* @returns x and y such that the transformations of the parent are cancelled
|
||||
*/
|
||||
export function CancelParentTransform(
|
||||
containers: Map<string, IContainerModel>,
|
||||
parent: IContainerModel | null,
|
||||
x: number,
|
||||
y: number,
|
||||
|
@ -178,7 +188,7 @@ export function CancelParentTransform(
|
|||
return [x, y];
|
||||
}
|
||||
|
||||
const it = MakeContainerLinkedListIterator(parent, stop);
|
||||
const it = MakeContainerLinkedListIterator(containers, parent, stop);
|
||||
for (const current of it) {
|
||||
x += current.properties.x;
|
||||
y += current.properties.y;
|
||||
|
@ -195,6 +205,7 @@ export function CancelParentTransform(
|
|||
* @returns x and y such that the transformations of the parent are applied
|
||||
*/
|
||||
export function ApplyParentTransform(
|
||||
containers: Map<string, IContainerModel>,
|
||||
parent: IContainerModel | null,
|
||||
x: number,
|
||||
y: number,
|
||||
|
@ -204,7 +215,7 @@ export function ApplyParentTransform(
|
|||
return [x, y];
|
||||
}
|
||||
|
||||
const it = MakeContainerLinkedListIterator(parent, stop);
|
||||
const it = MakeContainerLinkedListIterator(containers, parent, stop);
|
||||
for (const current of it) {
|
||||
x -= current.properties.x;
|
||||
y -= current.properties.y;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue