polygon_generator.cpp 869 B

1234567891011121314151617181920212223242526272829303132
  1. #include "polygon_generator.hpp"
  2. //------------------------
  3. // PolygonGenerator::next
  4. //------------------------
  5. bool
  6. PolygonGenerator::next(){
  7. size_t nd=0;
  8. while(not s.empty()){
  9. Step step=s.top();
  10. s.pop();
  11. poly.apply(step);
  12. if(poly.is_closed()) return true;
  13. size_t h=poly.head;
  14. int64 xh=h%Polygon::grid_width;
  15. int64 yh=h/Polygon::grid_width;
  16. ++nd;
  17. if(abs(xh-Polygon::xinit)+abs(yh-Polygon::yinit)+step.t<=max_len+1){
  18. size_t l=Polygon::left(h);
  19. size_t r=Polygon::right(h);
  20. size_t d=Polygon::down(h);
  21. size_t u=Polygon::up(h);
  22. size_t nt=step.t+1;
  23. if(poly.test(nt,l,&step)) s.emplace(&step,l,++n);
  24. if(poly.test(nt,r,&step)) s.emplace(&step,r,++n);
  25. if(poly.test(nt,d,&step)) s.emplace(&step,d,++n);
  26. if(poly.test(nt,u,&step)) s.emplace(&step,u,++n);
  27. }
  28. }
  29. return false;
  30. }