@@ -28,7 +28,7 @@ export namespace LayoutToTightSquareManager {
28
28
29
29
const sortedRects = sortRectangleGreedy (
30
30
layoutItems . map ( ( item ) => item . rect ) ,
31
- // 10 ,
31
+ 20 ,
32
32
) ;
33
33
34
34
for ( let i = 0 ; i < sortedRects . length ; i ++ ) {
@@ -68,7 +68,7 @@ export namespace LayoutToTightSquareManager {
68
68
69
69
// 从visual-file项目里抄过来的
70
70
71
- function sortRectangleGreedy ( rectangles : Rectangle [ ] ) : Rectangle [ ] {
71
+ function sortRectangleGreedy ( rectangles : Rectangle [ ] , margin = 20 ) : Rectangle [ ] {
72
72
if ( rectangles . length === 0 ) return [ ] ;
73
73
74
74
// 处理第一个矩形
@@ -86,7 +86,7 @@ function sortRectangleGreedy(rectangles: Rectangle[]): Rectangle[] {
86
86
87
87
for ( const placedRect of ret ) {
88
88
// 尝试放在右侧
89
- const candidateRight = appendRight ( placedRect , originalRect , ret ) ;
89
+ const candidateRight = appendRight ( placedRect , originalRect , ret , margin ) ;
90
90
const rightSpaceScore =
91
91
Math . max ( currentWidth , candidateRight . right ) -
92
92
currentWidth +
@@ -102,7 +102,7 @@ function sortRectangleGreedy(rectangles: Rectangle[]): Rectangle[] {
102
102
}
103
103
104
104
// 尝试放在下方
105
- const candidateBottom = appendBottom ( placedRect , originalRect , ret ) ;
105
+ const candidateBottom = appendBottom ( placedRect , originalRect , ret , margin ) ;
106
106
const bottomSpaceScore =
107
107
Math . max ( currentWidth , candidateBottom . right ) -
108
108
currentWidth +
@@ -133,9 +133,9 @@ function sortRectangleGreedy(rectangles: Rectangle[]): Rectangle[] {
133
133
return ret ;
134
134
}
135
135
136
- function appendRight ( origin : Rectangle , originalRect : Rectangle , existingRects : Rectangle [ ] ) : Rectangle {
136
+ function appendRight ( origin : Rectangle , originalRect : Rectangle , existingRects : Rectangle [ ] , margin = 20 ) : Rectangle {
137
137
const candidate = new Rectangle (
138
- new Vector ( origin . right , origin . location . y ) ,
138
+ new Vector ( origin . right + margin , origin . location . y ) ,
139
139
new Vector ( originalRect . size . x , originalRect . size . y ) ,
140
140
) ;
141
141
@@ -156,9 +156,9 @@ function appendRight(origin: Rectangle, originalRect: Rectangle, existingRects:
156
156
return candidate ;
157
157
}
158
158
159
- function appendBottom ( origin : Rectangle , originalRect : Rectangle , existingRects : Rectangle [ ] ) : Rectangle {
159
+ function appendBottom ( origin : Rectangle , originalRect : Rectangle , existingRects : Rectangle [ ] , margin = 20 ) : Rectangle {
160
160
const candidate = new Rectangle (
161
- new Vector ( origin . location . x , origin . bottom ) ,
161
+ new Vector ( origin . location . x , origin . bottom + margin ) ,
162
162
new Vector ( originalRect . size . x , originalRect . size . y ) ,
163
163
) ;
164
164
0 commit comments