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';
|
||||
|
||||
/**
|
||||
* Impose the container position
|
||||
* Impose the container position to its siblings
|
||||
* Apply the following modification to the overlapping rigid body container :
|
||||
* @param container Container to impose its position
|
||||
*/
|
||||
export function ImposePosition(container: IContainerModel): IContainerModel {
|
||||
if (container.parent === undefined ||
|
||||
|
@ -26,7 +27,6 @@ export function ImposePosition(container: IContainerModel): IContainerModel {
|
|||
return container;
|
||||
}
|
||||
|
||||
// Get the closest one
|
||||
const rigidBodies = container.parent.children.filter(
|
||||
child => child.properties.isRigidBody && !child.properties.isAnchor
|
||||
);
|
||||
|
@ -38,27 +38,33 @@ export function ImposePosition(container: IContainerModel): IContainerModel {
|
|||
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(
|
||||
container: IContainerModel,
|
||||
siblings: IContainerModel[]
|
||||
containers: IContainerModel[]
|
||||
): IContainerModel[] {
|
||||
const min1 = container.properties.x;
|
||||
const max1 = container.properties.x + Number(container.properties.width);
|
||||
const overlappingContainers: IContainerModel[] = [];
|
||||
for (const sibling of siblings) {
|
||||
if (sibling === container) {
|
||||
for (const other of containers) {
|
||||
if (other === container) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const min2 = sibling.properties.x;
|
||||
const max2 = sibling.properties.x + Number(sibling.properties.width);
|
||||
const min2 = other.properties.x;
|
||||
const max2 = other.properties.x + Number(other.properties.width);
|
||||
const isOverlapping = Math.min(max1, max2) - Math.max(min1, min2) > 0;
|
||||
|
||||
if (!isOverlapping) {
|
||||
continue;
|
||||
}
|
||||
|
||||
overlappingContainers.push(sibling);
|
||||
overlappingContainers.push(other);
|
||||
}
|
||||
return overlappingContainers;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue