Compare commits
2 commits
ab867b6b5c
...
5d3d6240b3
Author | SHA1 | Date | |
---|---|---|---|
|
5d3d6240b3 | ||
|
4f7055000a |
2 changed files with 43 additions and 27 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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -240,39 +240,49 @@ function getAvailableWidths(
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the unallocated widths between two lines in 1D
|
* Returns the unallocated widths between two lines in 1D
|
||||||
* @param min1 left of the first line
|
* @param unalloctedSpaceLeft left of the first line
|
||||||
* @param max1 rigth of the first line
|
* @param unallocatedSpaceRight rigth of the first line
|
||||||
* @param min2 left of the second line
|
* @param rectLeft left of the second line
|
||||||
* @param max2 right of the second line
|
* @param rectRight right of the second line
|
||||||
* @returns Available widths
|
* @returns Available widths
|
||||||
*/
|
*/
|
||||||
function getAvailableWidthsTwoLines(
|
function getAvailableWidthsTwoLines(
|
||||||
min1: number,
|
unalloctedSpaceLeft: number,
|
||||||
max1: number,
|
unallocatedSpaceRight: number,
|
||||||
min2: number,
|
rectLeft: number,
|
||||||
max2: number
|
rectRight: number
|
||||||
): ISizePointer[] {
|
): ISizePointer[] {
|
||||||
if (min2 < min1 && max2 > max1) {
|
if (unallocatedSpaceRight < rectLeft ||
|
||||||
|
unalloctedSpaceLeft > rectRight
|
||||||
|
) {
|
||||||
|
// object 1 and 2 are not overlapping
|
||||||
|
return [{
|
||||||
|
x: unalloctedSpaceLeft,
|
||||||
|
width: unallocatedSpaceRight - unalloctedSpaceLeft
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rectLeft < unalloctedSpaceLeft && rectRight > unallocatedSpaceRight) {
|
||||||
// object 2 is overlapping full width
|
// object 2 is overlapping full width
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (min1 >= min2) {
|
if (unalloctedSpaceLeft >= rectLeft) {
|
||||||
// object 2 is partially overlapping on the left
|
// object 2 is partially overlapping on the left
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
x: max2,
|
x: rectRight,
|
||||||
width: max1 - max2
|
width: unallocatedSpaceRight - rectRight
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (max2 >= max1) {
|
if (rectRight >= unallocatedSpaceRight) {
|
||||||
// object 2 is partially overlapping on the right
|
// object 2 is partially overlapping on the right
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
x: min2,
|
x: rectLeft,
|
||||||
width: max2 - min1
|
width: rectRight - unalloctedSpaceLeft
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -280,12 +290,12 @@ function getAvailableWidthsTwoLines(
|
||||||
// object 2 is overlapping in the middle
|
// object 2 is overlapping in the middle
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
x: min1,
|
x: unalloctedSpaceLeft,
|
||||||
width: min2 - min1
|
width: rectLeft - unalloctedSpaceLeft
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
x: max2,
|
x: rectRight,
|
||||||
width: max1 - max2
|
width: unallocatedSpaceRight - rectRight
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue