fix offset when solo rect
This commit is contained in:
parent
b278239c16
commit
559189c9d2
12
src/pack.cpp
12
src/pack.cpp
|
@ -64,12 +64,12 @@ std::optional<Frame> pack(const Frame& in_frame,
|
||||||
}
|
}
|
||||||
std::cout << "[pack] max area: " << max_area << "\n";
|
std::cout << "[pack] max area: " << max_area << "\n";
|
||||||
int optimal_size = int(ceil(std::sqrt(max_area)));
|
int optimal_size = int(ceil(std::sqrt(max_area)));
|
||||||
std::cout << "[pack] optimal image dimention: " << optimal_size << " x "
|
std::cout << "[pack] optimal image dimension: " << optimal_size << " x "
|
||||||
<< optimal_size << "\n";
|
<< optimal_size << "\n";
|
||||||
|
|
||||||
// cf. subject: D < min(M, N )
|
// cf. subject: D < min(M, N )
|
||||||
const int max_size = std::min(in_frame.width, in_frame.height) - 1;
|
const int max_size = std::min(in_frame.width, in_frame.height) - 1;
|
||||||
std::cout << "[pack] maximum image dimention: " << max_size << " x "
|
std::cout << "[pack] maximum image dimension: " << max_size << " x "
|
||||||
<< max_size << "\n";
|
<< max_size << "\n";
|
||||||
|
|
||||||
// We will try to fit all the rectangles in a given square of size S.
|
// We will try to fit all the rectangles in a given square of size S.
|
||||||
|
@ -93,7 +93,8 @@ std::optional<Frame> pack(const Frame& in_frame,
|
||||||
|
|
||||||
// If we don't have room in either dimension, we won't be able to
|
// If we don't have room in either dimension, we won't be able to
|
||||||
// pack within this size candidate.
|
// pack within this size candidate.
|
||||||
if (x + box.width >= size and next_row + box.height >= size) {
|
if (x + box.width - 1 >= size and
|
||||||
|
next_row + box.height - 1 >= size) {
|
||||||
std::cout << "[pack] -> no room left (last row height = "
|
std::cout << "[pack] -> no room left (last row height = "
|
||||||
<< size - y << ")\n";
|
<< size - y << ")\n";
|
||||||
room_left = false;
|
room_left = false;
|
||||||
|
@ -101,7 +102,7 @@ std::optional<Frame> pack(const Frame& in_frame,
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we cannot fit the rect on the right, we fit it below.
|
// If we cannot fit the rect on the right, we fit it below.
|
||||||
if (x + box.width >= size) {
|
if (x + box.width - 1 >= size) {
|
||||||
std::cout
|
std::cout
|
||||||
<< "[pack] -> cannot fit in current row (width left = "
|
<< "[pack] -> cannot fit in current row (width left = "
|
||||||
<< size - x << ")\n";
|
<< size - x << ")\n";
|
||||||
|
@ -120,7 +121,8 @@ std::optional<Frame> pack(const Frame& in_frame,
|
||||||
box.x = x;
|
box.x = x;
|
||||||
box.y = y;
|
box.y = y;
|
||||||
x += box.width;
|
x += box.width;
|
||||||
std::cout << "[pack] -> fit in (" << x << ", " << y << ")\n";
|
std::cout << "[pack] -> fit in (" << box.x << ", " << box.y
|
||||||
|
<< ")\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (room_left) {
|
if (room_left) {
|
||||||
|
|
Loading…
Reference in a new issue