Skip to content

Commit c85e8ab

Browse files
committed
new examples, fixed segfault that was happening ofr large sheets
1 parent 65a492f commit c85e8ab

3 files changed

Lines changed: 93 additions & 11 deletions

File tree

examples/problem_200x100.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"problem": {
3+
"sheet_size": [200, 100],
4+
"items": [
5+
{"id": 0, "width": 5, "height": 10},
6+
{"id": 1, "width": 10, "height": 5},
7+
{"id": 2, "width": 7, "height": 12},
8+
{"id": 3, "width": 12, "height": 7},
9+
{"id": 4, "width": 8, "height": 14},
10+
{"id": 5, "width": 14, "height": 8},
11+
{"id": 6, "width": 6, "height": 11},
12+
{"id": 7, "width": 11, "height": 6},
13+
{"id": 8, "width": 9, "height": 15},
14+
{"id": 9, "width": 15, "height": 9},
15+
{"id": 10, "width": 4, "height": 7},
16+
{"id": 11, "width": 7, "height": 4},
17+
{"id": 12, "width": 13, "height": 6},
18+
{"id": 13, "width": 6, "height": 13},
19+
{"id": 14, "width": 5, "height": 8}
20+
],
21+
"defects": [
22+
{"x": 20, "y": 10, "width": 3, "height": 6},
23+
{"x": 50, "y": 30, "width": 4, "height": 2},
24+
{"x": 90, "y": 5, "width": 2, "height": 5},
25+
{"x": 130, "y": 25, "width": 3, "height": 4},
26+
{"x": 170, "y": 15, "width": 5, "height": 3},
27+
{"x": 40, "y": 70, "width": 2, "height": 6},
28+
{"x": 80, "y": 60, "width": 4, "height": 2},
29+
{"x": 120, "y": 50, "width": 3, "height": 5},
30+
{"x": 160, "y": 40, "width": 2, "height": 4},
31+
{"x": 190, "y": 80, "width": 5, "height": 3}
32+
]
33+
}
34+
}

examples/problem_400x200.json

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"problem": {
3+
"sheet_size": [400, 200],
4+
"items": [
5+
{"id": 0, "width": 5, "height": 10},
6+
{"id": 1, "width": 10, "height": 5},
7+
{"id": 2, "width": 8, "height": 12},
8+
{"id": 3, "width": 12, "height": 8},
9+
{"id": 4, "width": 6, "height": 15},
10+
{"id": 5, "width": 15, "height": 6},
11+
{"id": 6, "width": 7, "height": 11},
12+
{"id": 7, "width": 11, "height": 7},
13+
{"id": 8, "width": 9, "height": 14},
14+
{"id": 9, "width": 14, "height": 9},
15+
{"id": 10, "width": 4, "height": 8},
16+
{"id": 11, "width": 8, "height": 4},
17+
{"id": 12, "width": 13, "height": 6},
18+
{"id": 13, "width": 6, "height": 13},
19+
{"id": 14, "width": 5, "height": 9},
20+
{"id": 15, "width": 9, "height": 5},
21+
{"id": 16, "width": 16, "height": 10},
22+
{"id": 17, "width": 10, "height": 16},
23+
{"id": 18, "width": 7, "height": 13},
24+
{"id": 19, "width": 13, "height": 7}
25+
],
26+
"defects": [
27+
{"x": 20, "y": 15, "width": 3, "height": 5},
28+
{"x": 60, "y": 25, "width": 5, "height": 3},
29+
{"x": 100, "y": 20, "width": 2, "height": 6},
30+
{"x": 140, "y": 30, "width": 4, "height": 2},
31+
{"x": 180, "y": 15, "width": 6, "height": 4},
32+
{"x": 220, "y": 40, "width": 3, "height": 7},
33+
{"x": 260, "y": 25, "width": 2, "height": 5},
34+
{"x": 300, "y": 20, "width": 5, "height": 3},
35+
{"x": 40, "y": 80, "width": 3, "height": 6},
36+
{"x": 90, "y": 70, "width": 4, "height": 3},
37+
{"x": 140, "y": 60, "width": 2, "height": 5},
38+
{"x": 190, "y": 90, "width": 7, "height": 4},
39+
{"x": 240, "y": 85, "width": 3, "height": 6},
40+
{"x": 290, "y": 75, "width": 2, "height": 4},
41+
{"x": 340, "y": 70, "width": 4, "height": 3},
42+
{"x": 50, "y": 160, "width": 3, "height": 5},
43+
{"x": 110, "y": 170, "width": 5, "height": 3},
44+
{"x": 170, "y": 180, "width": 6, "height": 4},
45+
{"x": 230, "y": 185, "width": 2, "height": 6},
46+
{"x": 310, "y": 190, "width": 4, "height": 3}
47+
]
48+
}
49+
}

src/guillotine/core/_solver.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@
3939
* Fd_packed is 4D int16_t: shape (W0+1, H0+1, W0+1, H0+1), same layout
4040
*/
4141
#define IDX_2D(arr, stride1, i, j) ((arr)[(i) * (stride1) + (j)])
42-
#define IDX_4D(arr, stride0, stride1, stride2, w, h, x, y) ((arr)[(w) * (stride0) + (h) * (stride1) + (x) * (stride2) + (y)])
43-
42+
#define IDX_4D(arr, stride0, stride1, stride2, w, h, x, y) ((arr)[(int64_t)(w) * (stride0) + (int64_t)(h) * (stride1) + (int64_t)(x) * (stride2) + (y)])
4443
/*
4544
* Precompute g: best single-item tiling value and item index for each rectangle size.
4645
* g_values[w,h] = best area achievable by tiling w×h with copies of one item type
@@ -180,9 +179,9 @@ static void fill_Fd_core(
180179
) {
181180
int stride_p = H0 + 1;
182181
int stride_F = H0 + 1;
183-
int stride2 = H0 + 1;
184-
int stride1 = (W0 + 1) * stride2;
185-
int stride0 = (H0 + 1) * stride1;
182+
int64_t stride2 = H0 + 1;
183+
int64_t stride1 = (int64_t)(W0 + 1) * stride2;
184+
int64_t stride0 = (int64_t)(H0 + 1) * stride1;
186185

187186
for (int w = 1; w <= W0; w++) {
188187
int nx = np_x_len[w];
@@ -223,14 +222,14 @@ static void fill_Fd_core(
223222
if (x >= DEF_X_END(d) || DEF_X(d) >= x + w) continue;
224223
int z1 = DEF_X(d) - x;
225224
int z2 = DEF_X_END(d) - x;
226-
if (z1 > 0 && z1 < h) {
227-
int32_t total = IDX_4D(Fd_values, stride0, stride1, stride2, w, z1, x, y) +
228-
IDX_4D(Fd_values, stride0, stride1, stride2, w, h-z1, x, y+z1);
225+
if (z1 > 0 && z1 < w) {
226+
int32_t total = IDX_4D(Fd_values, stride0, stride1, stride2, z1, h, x, y) +
227+
IDX_4D(Fd_values, stride0, stride1, stride2, w-z1, h, x+z1, y);
229228
if (total > best_val) best_val = total;
230229
}
231-
if (z2 > 0 && z2 < h) {
232-
int32_t total = IDX_4D(Fd_values, stride0, stride1, stride2, w, z2, x, y) +
233-
IDX_4D(Fd_values, stride0, stride1, stride2, w, h-z2, x, y+z2);
230+
if (z2 > 0 && z2 < w) {
231+
int32_t total = IDX_4D(Fd_values, stride0, stride1, stride2, z2, h, x, y) +
232+
IDX_4D(Fd_values, stride0, stride1, stride2, w-z2, h, x+z2, y);
234233
if (total > best_val) best_val = total;
235234
}
236235
}

0 commit comments

Comments
 (0)