// // BoxPositionTool.cpp // auto_fill_jewel_v3 // // Created by Red on 2024/11/29. // #include "BoxPositionTool.hpp" #include using std::cout; using std::endl; void BoxPositionTool::solve(const int visWidth,const int visHeight, vector>& boxSizeArr, vector>& resultPositions) { _boxes.clear() ; int numSolv = boxSizeArr.size() ; int boxIndex = 0 ; for(int y = 0 ; y < visHeight; ++y ) { for(int x = 0 ; x < visWidth; ++ x ) { vector& box = boxSizeArr[boxIndex] ; if( withinContainer(x, y, box[0], box[1]) ) { BoostGeometryTools::BoostPolygon poly=BoostGeometryTools::makeBox(x, y, box[0], box[1]) ; if( interectsWithOthers(poly) == false ) { _boxes.push_back(poly) ; numSolv-- ; boxIndex++ ; resultPositions.push_back({x+box[0]/2, y+box[1]/2}) ; //cout<<"debug box at x,y "< BOXPOSITIONTOOL_CONTAINER_WIDTH ) return false ; return true ; } bool BoxPositionTool::interectsWithOthers(BoostGeometryTools::BoostPolygon& poly) { for(int io = 0 ; io < _boxes.size();++ io ) { if( BoostGeometryTools::isAIntersectsB(poly, _boxes[io]) ) { return true ; } } return false ; }