Skip to content

Commit a6b0feb

Browse files
committed
🐛 紧密堆积时,增加空隙
1 parent b5e10a9 commit a6b0feb

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

app/src/core/stage/stageManager/concreteMethods/layoutManager/layoutToTightSquareManager.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export namespace LayoutToTightSquareManager {
2828

2929
const sortedRects = sortRectangleGreedy(
3030
layoutItems.map((item) => item.rect),
31-
// 10,
31+
20,
3232
);
3333

3434
for (let i = 0; i < sortedRects.length; i++) {
@@ -68,7 +68,7 @@ export namespace LayoutToTightSquareManager {
6868

6969
// 从visual-file项目里抄过来的
7070

71-
function sortRectangleGreedy(rectangles: Rectangle[]): Rectangle[] {
71+
function sortRectangleGreedy(rectangles: Rectangle[], margin = 20): Rectangle[] {
7272
if (rectangles.length === 0) return [];
7373

7474
// 处理第一个矩形
@@ -86,7 +86,7 @@ function sortRectangleGreedy(rectangles: Rectangle[]): Rectangle[] {
8686

8787
for (const placedRect of ret) {
8888
// 尝试放在右侧
89-
const candidateRight = appendRight(placedRect, originalRect, ret);
89+
const candidateRight = appendRight(placedRect, originalRect, ret, margin);
9090
const rightSpaceScore =
9191
Math.max(currentWidth, candidateRight.right) -
9292
currentWidth +
@@ -102,7 +102,7 @@ function sortRectangleGreedy(rectangles: Rectangle[]): Rectangle[] {
102102
}
103103

104104
// 尝试放在下方
105-
const candidateBottom = appendBottom(placedRect, originalRect, ret);
105+
const candidateBottom = appendBottom(placedRect, originalRect, ret, margin);
106106
const bottomSpaceScore =
107107
Math.max(currentWidth, candidateBottom.right) -
108108
currentWidth +
@@ -133,9 +133,9 @@ function sortRectangleGreedy(rectangles: Rectangle[]): Rectangle[] {
133133
return ret;
134134
}
135135

136-
function appendRight(origin: Rectangle, originalRect: Rectangle, existingRects: Rectangle[]): Rectangle {
136+
function appendRight(origin: Rectangle, originalRect: Rectangle, existingRects: Rectangle[], margin = 20): Rectangle {
137137
const candidate = new Rectangle(
138-
new Vector(origin.right, origin.location.y),
138+
new Vector(origin.right + margin, origin.location.y),
139139
new Vector(originalRect.size.x, originalRect.size.y),
140140
);
141141

@@ -156,9 +156,9 @@ function appendRight(origin: Rectangle, originalRect: Rectangle, existingRects:
156156
return candidate;
157157
}
158158

159-
function appendBottom(origin: Rectangle, originalRect: Rectangle, existingRects: Rectangle[]): Rectangle {
159+
function appendBottom(origin: Rectangle, originalRect: Rectangle, existingRects: Rectangle[], margin = 20): Rectangle {
160160
const candidate = new Rectangle(
161-
new Vector(origin.location.x, origin.bottom),
161+
new Vector(origin.location.x, origin.bottom + margin),
162162
new Vector(originalRect.size.x, originalRect.size.y),
163163
);
164164

0 commit comments

Comments
 (0)