Compare commits
No commits in common. "82eae4971e2eeb16f914167a5fb8ee13866e96e7" and "d29d1f5054dd3004531f5568c25064904ed2a1ff" have entirely different histories.
82eae4971e
...
d29d1f5054
1 changed files with 62 additions and 89 deletions
|
@ -181,17 +181,6 @@ export function constraintBodyInsideUnallocatedWidth(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if a container can fit inside a size space
|
|
||||||
* @param container Container to check
|
|
||||||
* @param sizePointer Size space to check
|
|
||||||
* @returns
|
|
||||||
*/
|
|
||||||
const isFitting = (
|
|
||||||
container: IContainerModel,
|
|
||||||
sizePointer: ISizePointer
|
|
||||||
): boolean => container.properties.width <= sizePointer.width;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the unallocated widths inside a container
|
* Get the unallocated widths inside a container
|
||||||
* An allocated width is defined by its the widths of the children that are rigid bodies.
|
* An allocated width is defined by its the widths of the children that are rigid bodies.
|
||||||
|
@ -233,9 +222,10 @@ function getAvailableWidths(
|
||||||
// We need to calculate the overlap between the two containers
|
// We need to calculate the overlap between the two containers
|
||||||
// We only works with widths meaning in 1D (with lines)
|
// We only works with widths meaning in 1D (with lines)
|
||||||
const newUnallocatedWidths = getAvailableWidthsTwoLines(
|
const newUnallocatedWidths = getAvailableWidthsTwoLines(
|
||||||
unallocatedSpace,
|
unallocatedSpace.x,
|
||||||
|
unallocatedSpace.x + unallocatedSpace.width,
|
||||||
childX,
|
childX,
|
||||||
childWidth
|
childX + childWidth
|
||||||
);
|
);
|
||||||
|
|
||||||
// Concat the new list of SizePointer pointing to availables spaces
|
// Concat the new list of SizePointer pointing to availables spaces
|
||||||
|
@ -250,90 +240,73 @@ function getAvailableWidths(
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the unallocated widths between two lines in 1D
|
* Returns the unallocated widths between two lines in 1D
|
||||||
* @param unalloctedSpace unallocated space
|
* @param unalloctedSpaceLeft left of the first line
|
||||||
* @param rectX left of the second line
|
* @param unallocatedSpaceRight rigth of the first line
|
||||||
* @param rectWidth width of the second line
|
* @param rectLeft left of the second line
|
||||||
|
* @param rectRight right of the second line
|
||||||
* @returns Available widths
|
* @returns Available widths
|
||||||
*/
|
*/
|
||||||
function getAvailableWidthsTwoLines(
|
function getAvailableWidthsTwoLines(
|
||||||
unallocatedSpace: ISizePointer,
|
unalloctedSpaceLeft: number,
|
||||||
rectX: number,
|
|
||||||
rectWidth: number
|
|
||||||
): ISizePointer[] {
|
|
||||||
const unallocatedSpaceRight = unallocatedSpace.x + unallocatedSpace.width;
|
|
||||||
const rectRight = rectX + rectWidth;
|
|
||||||
|
|
||||||
const isNotOverlapping = unallocatedSpaceRight < rectX ||
|
|
||||||
unallocatedSpace.x > rectRight;
|
|
||||||
if (isNotOverlapping) {
|
|
||||||
return [unallocatedSpace];
|
|
||||||
}
|
|
||||||
|
|
||||||
const isOverlappingFullWidth = rectX < unallocatedSpace.x && rectRight > unallocatedSpaceRight;
|
|
||||||
if (isOverlappingFullWidth) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
const isOverlappingOnTheLeft = unallocatedSpace.x >= rectX;
|
|
||||||
if (isOverlappingOnTheLeft) {
|
|
||||||
return getAvailableWidthsLeft(unallocatedSpaceRight, rectRight);
|
|
||||||
}
|
|
||||||
|
|
||||||
const isOverlappingOnTheRight = rectRight >= unallocatedSpaceRight;
|
|
||||||
if (isOverlappingOnTheRight) {
|
|
||||||
return getAvailableWidthsRight(unallocatedSpace.x, rectRight);
|
|
||||||
}
|
|
||||||
|
|
||||||
return getAvailableWidthsMiddle(unallocatedSpace.x, unallocatedSpaceRight, rectX, rectRight);
|
|
||||||
}
|
|
||||||
|
|
||||||
function getAvailableWidthsLeft(unallocatedSpaceRight: number, rectRight: number): ISizePointer[] {
|
|
||||||
if (unallocatedSpaceRight - rectRight <= 0) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
x: rectRight,
|
|
||||||
width: unallocatedSpaceRight - rectRight
|
|
||||||
}
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
function getAvailableWidthsRight(unalloctedSpaceX: number, rectRight: number): ISizePointer[] {
|
|
||||||
if (rectRight - unalloctedSpaceX <= 0) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
x: unalloctedSpaceX,
|
|
||||||
width: rectRight - unalloctedSpaceX
|
|
||||||
}
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
function getAvailableWidthsMiddle(
|
|
||||||
unalloctedSpaceX: number,
|
|
||||||
unallocatedSpaceRight: number,
|
unallocatedSpaceRight: number,
|
||||||
rectX: number,
|
rectLeft: number,
|
||||||
rectRight: number
|
rectRight: number
|
||||||
): ISizePointer[] {
|
): ISizePointer[] {
|
||||||
const sizePointers: ISizePointer[] = [];
|
if (unallocatedSpaceRight < rectLeft ||
|
||||||
|
unalloctedSpaceLeft > rectRight
|
||||||
if (rectX - unalloctedSpaceX > 0) {
|
) {
|
||||||
sizePointers.push({
|
// object 1 and 2 are not overlapping
|
||||||
x: unalloctedSpaceX,
|
return [{
|
||||||
width: rectX - unalloctedSpaceX
|
x: unalloctedSpaceLeft,
|
||||||
});
|
width: unallocatedSpaceRight - unalloctedSpaceLeft
|
||||||
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unallocatedSpaceRight - rectRight > 0) {
|
if (rectLeft < unalloctedSpaceLeft && rectRight > unallocatedSpaceRight) {
|
||||||
sizePointers.push({
|
// object 2 is overlapping full width
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (unalloctedSpaceLeft >= rectLeft) {
|
||||||
|
// object 2 is partially overlapping on the left
|
||||||
|
return [
|
||||||
|
{
|
||||||
x: rectRight,
|
x: rectRight,
|
||||||
width: unallocatedSpaceRight - rectRight
|
width: unallocatedSpaceRight - rectRight
|
||||||
});
|
}
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
return sizePointers;
|
if (rectRight >= unallocatedSpaceRight) {
|
||||||
|
// object 2 is partially overlapping on the right
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
x: unalloctedSpaceLeft,
|
||||||
|
width: rectRight - unalloctedSpaceLeft
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// object 2 is overlapping in the middle
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
x: unalloctedSpaceLeft,
|
||||||
|
width: rectLeft - unalloctedSpaceLeft
|
||||||
|
},
|
||||||
|
{
|
||||||
|
x: rectRight,
|
||||||
|
width: unallocatedSpaceRight - rectRight
|
||||||
|
}
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a container can fit inside a size space
|
||||||
|
* @param container Container to check
|
||||||
|
* @param sizePointer Size space to check
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
const isFitting = (
|
||||||
|
container: IContainerModel,
|
||||||
|
sizePointer: ISizePointer
|
||||||
|
): boolean => container.properties.width <= sizePointer.width;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue