Fix rigid body wrong sorting due to not using the middle and the theorical position of the container
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
10d13b246d
commit
ab867b6b5c
1 changed files with 21 additions and 8 deletions
|
@ -90,7 +90,7 @@ function constraintBodyInsideSpace(
|
||||||
if (containerX < x) {
|
if (containerX < x) {
|
||||||
containerProperties.x = x;
|
containerProperties.x = x;
|
||||||
}
|
}
|
||||||
if (containerX + containerWidth > width) {
|
if (containerX + containerWidth > x + width) {
|
||||||
containerProperties.x = x + width - containerWidth;
|
containerProperties.x = x + width - containerWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ function constraintBodyInsideSpace(
|
||||||
if (containerY < y) {
|
if (containerY < y) {
|
||||||
containerProperties.y = y;
|
containerProperties.y = y;
|
||||||
}
|
}
|
||||||
if (containerY + containerHeight > height) {
|
if (containerY + containerHeight > y + height) {
|
||||||
containerProperties.y = y + height - containerHeight;
|
containerProperties.y = y + height - containerHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,12 +122,7 @@ export function constraintBodyInsideUnallocatedWidth(
|
||||||
// Get the available spaces of the parent
|
// Get the available spaces of the parent
|
||||||
const availableWidths = getAvailableWidths(container.parent, container);
|
const availableWidths = getAvailableWidths(container.parent, container);
|
||||||
const containerX = Number(container.properties.x);
|
const containerX = Number(container.properties.x);
|
||||||
|
const containerWidth = Number(container.properties.width);
|
||||||
// Sort the available width to find the closest one
|
|
||||||
availableWidths.sort(
|
|
||||||
(width1, width2) =>
|
|
||||||
Math.abs(width1.x - containerX) - Math.abs(width2.x - containerX)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Check if there is still some space
|
// Check if there is still some space
|
||||||
if (availableWidths.length === 0) {
|
if (availableWidths.length === 0) {
|
||||||
|
@ -136,6 +131,24 @@ export function constraintBodyInsideUnallocatedWidth(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const middle = containerX + containerWidth / 2;
|
||||||
|
// Sort the available width to find the space with the closest position
|
||||||
|
availableWidths.sort(
|
||||||
|
(width1, width2) => {
|
||||||
|
let compared1X = width1.x;
|
||||||
|
if (width1.x < containerX) {
|
||||||
|
compared1X = width1.x + width1.width - containerWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
let compared2X = width2.x;
|
||||||
|
if (width2.x < containerX) {
|
||||||
|
compared2X = width2.x + width2.width - containerWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Math.abs(compared1X - middle) - Math.abs(compared2X - middle);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
// Check if the container actually fit inside
|
// Check if the container actually fit inside
|
||||||
// It will usually fit if it was alrady fitting
|
// It will usually fit if it was alrady fitting
|
||||||
const availableWidthFound = availableWidths.find((width) =>
|
const availableWidthFound = availableWidths.find((width) =>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue