12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- //
- // BoxPositionTool.cpp
- // auto_fill_jewel_v3
- //
- // Created by Red on 2024/11/29.
- //
- #include "BoxPositionTool.hpp"
- #include <iostream>
- using std::cout;
- using std::endl;
- void BoxPositionTool::solve(const int visWidth,const int visHeight, vector<vector<int>>& boxSizeArr, vector<vector<int>>& 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<int>& 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 "<<x<<","<<y<<endl;
- x = x+box[0]-1 ;
- }
- }
- if( numSolv==0 ) break ;
- }
- if( numSolv==0 ) break ;
- }
- }
- bool BoxPositionTool::withinContainer(const int llx,const int lly,const int wid,const int hei)
- {
- if( llx < 0 ) return false ;
- if( llx + wid > 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 ;
- }
|