Merged PR 167: Add Flex and fix bugs (read desc)
Note: The branch name does not fit the new features. - Implement Flex with simplex - Enable rigid body by default (removed IsRigidBody property) <=== possibly a bad idea - Sort children in add and update properties - Implement MaxWidth - Add more docs Fixes : - .env.production url - Symbols: not blocking the linked container when the parent is moving
This commit is contained in:
parent
ec3fddec9d
commit
7f3f6a489a
43 changed files with 1127 additions and 453 deletions
|
@ -14,7 +14,7 @@ export function * MakeIterator(root: IContainerModel): Generator<IContainerModel
|
|||
for (let i = container.children.length - 1; i >= 0; i--) {
|
||||
const child = container.children[i];
|
||||
if (visited.has(child)) {
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
visited.add(child);
|
||||
queue.push(child);
|
||||
|
@ -71,9 +71,20 @@ export function getDepth(parent: IContainerModel): number {
|
|||
* @returns The absolute position of the container
|
||||
*/
|
||||
export function getAbsolutePosition(container: IContainerModel): [number, number] {
|
||||
let x = container.properties.x;
|
||||
let y = container.properties.y;
|
||||
let current = container.parent;
|
||||
const x = container.properties.x;
|
||||
const y = container.properties.y;
|
||||
return cancelParentTransform(container.parent, x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel the hierarchic transformations to the given x, y
|
||||
* @param parent Parent of the container to remove its transform
|
||||
* @param x value to be restored
|
||||
* @param y value to be restored
|
||||
* @returns x and y such that the transformations of the parent are cancelled
|
||||
*/
|
||||
export function cancelParentTransform(parent: IContainerModel | null, x: number, y: number): [number, number] {
|
||||
let current = parent;
|
||||
while (current != null) {
|
||||
x += current.properties.x;
|
||||
y += current.properties.y;
|
||||
|
@ -82,6 +93,23 @@ export function getAbsolutePosition(container: IContainerModel): [number, number
|
|||
return [x, y];
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel the hierarchic transformations to the given x, y
|
||||
* @param parent Parent of the container to remove its transform
|
||||
* @param x value to be restored
|
||||
* @param y value to be restored
|
||||
* @returns x and y such that the transformations of the parent are cancelled
|
||||
*/
|
||||
export function applyParentTransform(parent: IContainerModel | null, x: number, y: number): [number, number] {
|
||||
let current = parent;
|
||||
while (current != null) {
|
||||
x -= current.properties.x;
|
||||
y -= current.properties.y;
|
||||
current = current.parent;
|
||||
}
|
||||
return [x, y];
|
||||
}
|
||||
|
||||
export function findContainerById(root: IContainerModel, id: string): IContainerModel | undefined {
|
||||
const it = MakeIterator(root);
|
||||
for (const container of it) {
|
||||
|
@ -91,3 +119,20 @@ export function findContainerById(root: IContainerModel, id: string): IContainer
|
|||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export interface IPair<T> {
|
||||
cur: T
|
||||
next: T
|
||||
}
|
||||
|
||||
export function * pairwise<T>(arr: T[]): Generator<IPair<T>, void, unknown> {
|
||||
for (let i = 0; i < arr.length - 1; i++) {
|
||||
yield { cur: arr[i], next: arr[i + 1] };
|
||||
}
|
||||
}
|
||||
|
||||
export function * reversePairwise<T>(arr: T[]): Generator<IPair<T>, void, unknown> {
|
||||
for (let i = arr.length - 1; i > 0; i--) {
|
||||
yield { cur: arr[i], next: arr[i - 1] };
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue