Implement anchor and fix bugs with rigid body #27
1 changed files with 14 additions and 8 deletions
|
@ -17,8 +17,9 @@ import { IContainerModel } from '../../../Interfaces/IContainerModel';
|
||||||
import { constraintBodyInsideUnallocatedWidth } from './RigidBodyBehaviors';
|
import { constraintBodyInsideUnallocatedWidth } from './RigidBodyBehaviors';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Impose the container position
|
* Impose the container position to its siblings
|
||||||
* Apply the following modification to the overlapping rigid body container :
|
* Apply the following modification to the overlapping rigid body container :
|
||||||
|
* @param container Container to impose its position
|
||||||
*/
|
*/
|
||||||
export function ImposePosition(container: IContainerModel): IContainerModel {
|
export function ImposePosition(container: IContainerModel): IContainerModel {
|
||||||
if (container.parent === undefined ||
|
if (container.parent === undefined ||
|
||||||
|
@ -26,7 +27,6 @@ export function ImposePosition(container: IContainerModel): IContainerModel {
|
||||||
return container;
|
return container;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the closest one
|
|
||||||
const rigidBodies = container.parent.children.filter(
|
const rigidBodies = container.parent.children.filter(
|
||||||
child => child.properties.isRigidBody && !child.properties.isAnchor
|
child => child.properties.isRigidBody && !child.properties.isAnchor
|
||||||
);
|
);
|
||||||
|
@ -38,27 +38,33 @@ export function ImposePosition(container: IContainerModel): IContainerModel {
|
||||||
return container;
|
return container;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the overlapping containers with container
|
||||||
|
* @param container A container
|
||||||
|
* @param containers A list of containers
|
||||||
|
* @returns A list of overlapping containers
|
||||||
|
*/
|
||||||
function getOverlappingContainers(
|
function getOverlappingContainers(
|
||||||
container: IContainerModel,
|
container: IContainerModel,
|
||||||
siblings: IContainerModel[]
|
containers: IContainerModel[]
|
||||||
): IContainerModel[] {
|
): IContainerModel[] {
|
||||||
const min1 = container.properties.x;
|
const min1 = container.properties.x;
|
||||||
const max1 = container.properties.x + Number(container.properties.width);
|
const max1 = container.properties.x + Number(container.properties.width);
|
||||||
const overlappingContainers: IContainerModel[] = [];
|
const overlappingContainers: IContainerModel[] = [];
|
||||||
for (const sibling of siblings) {
|
for (const other of containers) {
|
||||||
if (sibling === container) {
|
if (other === container) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const min2 = sibling.properties.x;
|
const min2 = other.properties.x;
|
||||||
const max2 = sibling.properties.x + Number(sibling.properties.width);
|
const max2 = other.properties.x + Number(other.properties.width);
|
||||||
const isOverlapping = Math.min(max1, max2) - Math.max(min1, min2) > 0;
|
const isOverlapping = Math.min(max1, max2) - Math.max(min1, min2) > 0;
|
||||||
|
|
||||||
if (!isOverlapping) {
|
if (!isOverlapping) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
overlappingContainers.push(sibling);
|
overlappingContainers.push(other);
|
||||||
}
|
}
|
||||||
return overlappingContainers;
|
return overlappingContainers;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue