Fix getAvailableWidthsTwoLines when there is no overlap
This commit is contained in:
parent
4f7055000a
commit
5d3d6240b3
1 changed files with 29 additions and 19 deletions
|
@ -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