Compare commits

..

No commits in common. "5d3d6240b32f883509b3793c18fab1d305e3e7e1" and "ab867b6b5cec26af815a48969218e3420006a3c4" have entirely different histories.

2 changed files with 27 additions and 43 deletions

View file

@ -17,9 +17,8 @@ import { IContainerModel } from '../../../Interfaces/IContainerModel';
import { constraintBodyInsideUnallocatedWidth } from './RigidBodyBehaviors'; import { constraintBodyInsideUnallocatedWidth } from './RigidBodyBehaviors';
/** /**
* Impose the container position to its siblings * Impose the container position
* 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 ||
@ -27,6 +26,7 @@ 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,33 +38,27 @@ 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,
containers: IContainerModel[] siblings: 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 other of containers) { for (const sibling of siblings) {
if (other === container) { if (sibling === container) {
continue; continue;
} }
const min2 = other.properties.x; const min2 = sibling.properties.x;
const max2 = other.properties.x + Number(other.properties.width); const max2 = sibling.properties.x + Number(sibling.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(other); overlappingContainers.push(sibling);
} }
return overlappingContainers; return overlappingContainers;
} }

View file

@ -240,49 +240,39 @@ function getAvailableWidths(
/** /**
* Returns the unallocated widths between two lines in 1D * Returns the unallocated widths between two lines in 1D
* @param unalloctedSpaceLeft left of the first line * @param min1 left of the first line
* @param unallocatedSpaceRight rigth of the first line * @param max1 rigth of the first line
* @param rectLeft left of the second line * @param min2 left of the second line
* @param rectRight right of the second line * @param max2 right of the second line
* @returns Available widths * @returns Available widths
*/ */
function getAvailableWidthsTwoLines( function getAvailableWidthsTwoLines(
unalloctedSpaceLeft: number, min1: number,
unallocatedSpaceRight: number, max1: number,
rectLeft: number, min2: number,
rectRight: number max2: number
): ISizePointer[] { ): ISizePointer[] {
if (unallocatedSpaceRight < rectLeft || if (min2 < min1 && max2 > max1) {
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 (unalloctedSpaceLeft >= rectLeft) { if (min1 >= min2) {
// object 2 is partially overlapping on the left // object 2 is partially overlapping on the left
return [ return [
{ {
x: rectRight, x: max2,
width: unallocatedSpaceRight - rectRight width: max1 - max2
} }
]; ];
} }
if (rectRight >= unallocatedSpaceRight) { if (max2 >= max1) {
// object 2 is partially overlapping on the right // object 2 is partially overlapping on the right
return [ return [
{ {
x: rectLeft, x: min2,
width: rectRight - unalloctedSpaceLeft width: max2 - min1
} }
]; ];
} }
@ -290,12 +280,12 @@ function getAvailableWidthsTwoLines(
// object 2 is overlapping in the middle // object 2 is overlapping in the middle
return [ return [
{ {
x: unalloctedSpaceLeft, x: min1,
width: rectLeft - unalloctedSpaceLeft width: min2 - min1
}, },
{ {
x: rectRight, x: max2,
width: unallocatedSpaceRight - rectRight width: max1 - max2
} }
]; ];
} }