rectpack2D: Regression in results from old rectpack2D
Hi, I am comparing the results of the old and current rectpack2D version. It appears the old version performs better in terms of the packing.
Results from the old version (33 rectangles packed):

Results from the current version (find_best_packing(), 12 rectangles packed):

Results from the current version (find_best_packing_dont_sort(), 22 rectangles packed):

This is the code I use in the new version:
using spaces_type = rectpack2D::empty_spaces<true, rectpack2D::default_empty_spaces>;
using rect_type = spaces_type::output_rect_type;
std::vector<rect_type> rectangles;
std::vector<bool> acceptedRects;
int numAcceptedRects = 0;
for (auto& img : sourceImages) {
rectangles.emplace_back(rectpack2D::rect_xywh(0, 0, ofx::width(img->bounds()) + xMargin, ofx::height(img->bounds()) + yMargin));
acceptedRects.push_back(false);
}
int maxSize = std::max(width, height) - std::max(xMargin, yMargin);
auto reportUnsuccessful = [&](rect_type& rect) { return false; };
auto reportSuccessful = [&](rect_type& rect) {
int index = (&rect - rectangles.data());
acceptedRects[index] = true;
numAcceptedRects++;
return !effect.abort();
};
std::cout << "sourceImages.size(): " << sourceImages.size() << "\n";
std::cout << "rectangles.size(): " << rectangles.size() << "\n";
std::cout << "discardStep: " << discardStep << "\n";
std::cout << "maxSize: " << maxSize << "\n";
rectpack2D::rect_wh const resultSize = rectpack2D::find_best_packing<spaces_type>(
rectangles,
rectpack2D::make_finder_input(
maxSize,
discardStep,
reportSuccessful,
reportUnsuccessful
)
);
Any idea where that regression comes from? Is it due to how I use the new version?
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 25 (16 by maintainers)
Commits related to this issue
- Refactor: use an enum to denote a callback result #5 — committed to TeamHypersomnia/rectpack2D by geneotech 6 years ago
- Can enable or disable flipping at runtime #5 — committed to TeamHypersomnia/rectpack2D by geneotech 6 years ago
- Fix the example #5 — committed to TeamHypersomnia/rectpack2D by geneotech 6 years ago
Of course! Unfortunately the 8k resolution as PNG is too much for GitHub (max 10MB per file) so here’s just a 2K version